libtraceeval: Add delta interface
v3 cover libtraceeval: Add delta interface
From: "Steven Rostedt (Google)" <[email protected]>
The first iteration of libtraceeval sought out to facilitate timings between events. For instance, the time between waking up and scheduling in of a task (the wake up latency). But that code API quickly became unusable, as there were several use cases that did not need the timings, and it was awkward using it.
The libtraceeval was redesigned to be simple histograms that could be queried for the last instance, and easily have them be joined. This worked well.
Now this adds a new interface to only require a single traceeval again, but with a attached simple "delta" traceeval internally. This internal traceeval keeps track of the timestamps and calculates a delta to be used to insert.
Man pages will come later.
Changes since v2: https://lore.kernel.org/all/[email protected]/
- This is a basic redesign. Instead of creating a traceeval_delta instance, which when playing with it I found it to be too limiting in its use (although it was simple). This design is to just add a way to create a new key mapping for the start and stop events. This also allows the start to pass values to the stop (much like how the ftrace synthetic events work), and then these values can be used to insert into the main traceeval.
Steven Rostedt (Google) (2):
libtraceeval: Add traceeval_delta_start/continue/stop() API
libtraceeval: Add traceeval_iterator_delta_start_get()
include/traceeval.h | 59 ++++ samples/task-eval.c | 649 ++++++++++++++++++++++---------------------- samples/wake-lat.c | 61 ++--- src/Makefile | 1 + src/delta.c | 431 +++++++++++++++++++++++++++++ src/eval-local.h | 21 ++ src/histograms.c | 137 ++++++---- 7 files changed, 943 insertions(+), 416 deletions(-) create mode 100644 src/delta.c
Signature · 1 line
2.40.1
PATCH v3 1/2 libtraceeval: Add traceeval_delta_start/continue/stop() API
From: "Steven Rostedt (Google)" <[email protected]>
The first iteration of libtraceeval sought out to facilitate timings between events. For instance, the time between waking up and scheduling in of a task (the wake up latency). But that code API quickly became unusable, as there were several use cases that did not need the timings, and it was awkward using it.
The libtraceeval was redesigned to be simple histograms that could be queried for the last instance, and easily have them be joined. This worked well.
Now we can come up with a new helper that automatically combines two histograms to create that original idea of easily recording the delta between events. This new is traceeval_delta_create().
This attaches another light weight traceeval that is made up of two extra values:
1. A timestamp value
2. A delta value
This adds the following features:
* traceeval_delta_start() - that takes a timestamp that will be recorded in the extra timestamp value field.
* traceeval_delta_stop() - that takes another timestamp and will calculate the delta from the matching timestamp that was record by traceeval_delta_start() and save that into the delta field.
* traceeval_delta_continue() - This is pretty much the same as traceeval_delta_start(), but if a traceeval_delta_stop() has not been called for the given instance represented by the keys since the last traceeval_delta_start() or traceeval_delta_continue() then it will simply drop the event. This is used for cases that There could be many starts, but only the first one counts (as a new call to traceeval_delta_start() will reset the timestamp).
The start function may also take values that will be returned to the stop function so that it can be used together to insert into the main traceeval.
The two sample programs, task-eval.c and wakeup-lat.c were updated to use this and it greatly simplifies the code.
--- include/traceeval.h | 53 ++++ samples/task-eval.c | 587 +++++++++++++++++++------------------------- samples/wake-lat.c | 61 ++--- src/Makefile | 1 + src/delta.c | 338 +++++++++++++++++++++++++ src/eval-local.h | 20 ++ src/histograms.c | 127 +++++----- 7 files changed, 765 insertions(+), 422 deletions(-) create mode 100644 src/delta.c
include/traceeval.h +53 -0
@@ -265,6 +265,59 @@ void traceeval_results_release(struct traceeval *teval,size_t traceeval_count (struct traceeval *teval); +#define traceeval_delta_create (teval, keys, vals) \ + traceeval_delta_create_size(teval, keys, vals, \ + TRACEEVAL_ARRAY_SIZE(keys), \ + TRACEEVAL_ARRAY_SIZE(vals)) + +#define traceeval_delta_create_size (teval, keys, vals, nr_keys, nr_vals) \ + traceeval_delta_create_data_size(teval, keys, vals, nr_keys, nr_vals, \ + sizeof(struct traceeval_type), \ + sizeof(struct traceeval_data)) + +int traceeval_delta_create_data_size (struct traceeval *teval, +struct traceeval_type *keys, +struct traceeval_type *vals, +size_t nr_keys,size_t nr_vals, +size_t sizeof_type, +size_t sizeof_data); + +int traceeval_delta_start_size (struct traceeval *teval, +const struct traceeval_data *keys,size_t nr_keys, +const struct traceeval_data *vals,size_t nr_vals, +unsigned long long timestamp); + +#define traceeval_delta_start (teval, keys, vals, timestamp) \ + traceeval_delta_start_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), \ + vals, TRACEEVAL_ARRAY_SIZE(vals), timestamp) + +int traceeval_delta_query_size (struct traceeval *teval, +const struct traceeval_data *keys, +size_t nr_keys,const struct traceeval_data **results); + +#define traceeval_delta_query (teval, keys, results) \ + traceeval_delta_query_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), results) + +int traceeval_delta_continue_size (struct traceeval *teval, +const struct traceeval_data *keys,size_t nr_keys, +const struct traceeval_data *vals,size_t nr_vals, +unsigned long long timestamp); + +#define traceeval_delta_continue (teval, keys, vals, timestamp) \ + traceeval_delta_continue_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), \ + vals, TRACEEVAL_ARRAY_SIZE(vals), timestamp) + +int traceeval_delta_stop_size (struct traceeval *teval, +const struct traceeval_data *keys,size_t nr_keys, +const struct traceeval_data **results, +unsigned long long timestamp, +unsigned long long *delta, +unsigned long long *start_timestamp); + +#define traceeval_delta_stop (teval, keys, results, timestamp, delta, start_ts) \ + traceeval_delta_stop_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), \ + results, timestamp, delta, start_ts) +#define traceeval_stat (teval, keys, val_name) \ traceeval_stat_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), val_name)
samples/task-eval.c +257 -330
846 lines not on this page · raw message
samples/wake-lat.c +25 -36
122 lines not on this page · raw message
src/Makefile +1 -0
@@ -4,6 +4,7 @@ include $(src)/scripts/utils.mk OBJS = OBJS += histograms.o +OBJS += delta.o OBJS += hash.o OBJS := $(OBJS:%.o=$(bdir)/%.o)
src/delta.c new file +338 -0
338 lines not on this page · raw message
src/eval-local.h +20 -0
@@ -63,11 +63,19 @@ struct entry {struct traceeval_stat *val_stats; }; +enum { +TEVAL_FL_DELTA = (1 <<0 ), +}; + +struct traceeval_delta ; +/* Histogram */ struct traceeval {struct traceeval_type *key_types;struct traceeval_type *val_types;struct hash_table *hist; +struct traceeval_delta *tdelta; +unsigned int flags;ssize_t nr_key_types;ssize_t nr_val_types;size_t update_counter;
@@ -89,6 +97,12 @@ struct traceeval_iterator {bool needs_sort; }; +extern int _teval_get_entry (struct traceeval *teval,const struct traceeval_data *keys, +struct entry **result); + +extern void _teval_update_stat (struct traceeval_type *type,struct traceeval_stat *stat, +unsigned long long val,unsigned long long ts); +extern struct hash_table *hash_alloc (void );extern void hash_free (struct hash_table *hash);extern void hash_add (struct hash_table *hash,struct hash_item *item,unsigned key);
@@ -100,6 +114,8 @@ extern struct hash_item *hash_iter_next(struct hash_iter *iter);extern struct hash_iter *hash_iter_bucket (struct hash_table *hash,unsigned key);extern struct hash_item *hash_iter_bucket_next (struct hash_iter *iter); +extern void __delta_release (struct traceeval_delta *tdelta); +static inline size_t hash_nr_items (struct hash_table *hash) {return hash->nr_items;
@@ -117,6 +133,10 @@ static inline unsigned long long hash_string(const char *str)return key; } +int _teval_insert (struct traceeval *teval, +const struct traceeval_data *keys,size_t nr_keys, +const struct traceeval_data *vals,size_t nr_vals); +/* * This is a quick hashing function adapted from Donald E. Knuth's 32 * bit multiplicative hash. See The Art of Computer Programming (TAOCP).
src/histograms.c +71 -56
184 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v3 2/2 libtraceeval: Add traceeval_iterator_delta_start_get()
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Add APIs:
traceeval_iterator_delta_start_get()
traceeval_iterator_delta_stop()
After analysing events, there may be dangling deltas. That is, there may be elements in a traceeval_delta that had a traceeval_delta_start() but no matching traceeval_delta_stop(). Create an iterator that allows the developer to find all these dangling elements.
iter = traceeval_iterator_delta_start_get(teval);
Will return an iterator that will iterate over all the elements in the delta that was started by not stopped.
while (traceeval_iterator_next(iter, &keys) > 0) {
traceeval_iterator_delta(stop, &results, ts, &delta, &start_ts);
Will iterator over all the dangling events, where the traceeval_iterator_next() will get the keys of the dangling event and traceeval_iterator_delta_stop() will retrieve the values, and the "start_ts" that hold the timestamp of the traceeval_delta_start() and passing in the last timestamp will also calculate the "delta".
--- include/traceeval.h | 6 ++ samples/task-eval.c | 144 +++++++++++++++++++++++++++++++++----------- src/delta.c | 93 ++++++++++++++++++++++++++++ src/eval-local.h | 1 + src/histograms.c | 10 ++- 5 files changed, 219 insertions(+), 35 deletions(-)
include/traceeval.h +6 -0
@@ -336,6 +336,7 @@ unsigned long long traceeval_stat_min_timestamp(struct traceeval_stat *stat, unsigned long long *ts);struct traceeval_iterator *traceeval_iterator_get (struct traceeval *teval); +struct traceeval_iterator *traceeval_iterator_delta_start_get (struct traceeval *teval);void traceeval_iterator_put (struct traceeval_iterator *iter);int traceeval_iterator_sort (struct traceeval_iterator *iter,const char *sort_field,int level,bool ascending);
@@ -349,6 +350,11 @@ void traceeval_iterator_results_release(struct traceeval_iterator *iter, const struct traceeval_data *results);struct traceeval_stat *traceeval_iterator_stat (struct traceeval_iterator *iter,const char *val_name); +int traceeval_iterator_delta_stop (struct traceeval_iterator *iter, +const struct traceeval_data **results, +unsigned long long timestamp, +unsigned long long *delta, +unsigned long long *start_ts);int traceeval_iterator_remove (struct traceeval_iterator *iter);#endif /* __LIBTRACEEVAL_HIST_H__ */
samples/task-eval.c +110 -34
225 lines not on this page · raw message
src/delta.c +93 -0
96 lines not on this page · raw message
src/eval-local.h +1 -0
@@ -95,6 +95,7 @@ struct traceeval_iterator {size_t nr_sort;size_t next;bool needs_sort; +bool no_sort; }; extern int _teval_get_entry(struct traceeval *teval, const struct traceeval_data *keys,
src/histograms.c +9 -1
@@ -1299,6 +1299,10 @@ int traceeval_iterator_sort(struct traceeval_iterator *iter, const char *sort_fistruct traceeval_type *type;int num_levels = level +1 ; +/* delta iterators are not to be sorted */ +if (iter->no_sort) +return -1 ; + type =find_sort_type (iter->teval, sort_field);if (!type)return -1 ;
@@ -1445,6 +1449,10 @@ int traceeval_iterator_sort_custom(struct traceeval_iterator *iter, .data = data }; +/* delta iterators are not to be sorted */ +if (iter->no_sort) +return -1 ; +if (check_update (iter) <0 )return -1 ;
@@ -1473,7 +1481,7 @@ int traceeval_iterator_next(struct traceeval_iterator *iter,struct entry *entry;int ret; -if (iter->needs_sort) { +if (iter->needs_sort && !iter->no_sort) { ret =sort_iter (iter);if (ret <0 )return ret;
Signature · 1 line
2.40.1