Skip to contentSkip to conversation

libtraceeval: Add traceeval_data_start/continue/stop() API

PATCH Superseded Steven Rostedt 1 participant 2 messages Oct 6, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtraceeval: Add traceeval_data_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 descriptor that automatically combines two histograms to create that original idea of easily recording the delta between events. This new descriptor is called a traceeval_delta.

A traceeval_delta is simply a traceeval with two extra values.

1. A timestamp value
2. A delta value

It has the same type of APIs as a traceeval has:

* traceeval_delta_init()
* traceeval_delta_release()
* traceeval_delta_insert()
* traceeval_delta_query()

But now has:

* 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).

Some extra functions are added like traceeval_delta_teval_get() to get the traceeval descriptor that it uses. traceeval_delta_stat() returns the traceeval_delta_stat for the delta value, and traceeval_iterator_delta_stat() does the same thing but for the iterator instance.

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 |  78 +++++++++
 samples/task-eval.c | 221 +++++++----------------
 samples/wake-lat.c  |  70 ++------
 src/Makefile        |   1 +
 src/delta.c         | 418 ++++++++++++++++++++++++++++++++++++++++++++
 src/eval-local.h    |  15 ++
 src/histograms.c    | 159 +++++++++--------
 7 files changed, 678 insertions(+), 284 deletions(-)
 create mode 100644 src/delta.c
include/traceeval.h +78 -0
index d8095ba5c1a1..f332aec289fc 100644
@@ -234,6 +234,83 @@ void traceeval_results_release(struct traceeval *teval,
 
 size_t traceeval_count(struct traceeval *teval);
 
+struct traceeval_delta;
+
+#define traceeval_delta_init(keys, vals)				\
+	traceeval_delta_init_size(keys, vals,				\
+				  TRACEEVAL_ARRAY_SIZE(keys),		\
+				  TRACEEVAL_ARRAY_SIZE(vals))
+
+#define traceeval_delta_init_size(keys, vals, nr_keys, nr_vals)		\
+	traceeval_delta_init_data_size(keys, vals, nr_keys, nr_vals,	\
+				       sizeof(struct traceeval_type),	\
+				       sizeof(struct traceeval_data))
+
+struct traceeval_delta *traceeval_delta_init_data_size(struct traceeval_type *keys,
+						       struct traceeval_type *vals,
+						       size_t nr_keys, size_t nr_vals,
+						       size_t sizeof_type,
+						       size_t sizeof_data);
+
+void traceeval_delta_release(struct traceeval_delta *tdelta);
+
+int traceeval_delta_insert_size(struct traceeval_delta *tdelta,
+				const struct traceeval_data *keys, size_t nr_keys,
+				const struct traceeval_data *vals, size_t nr_vals);
+
+#define traceeval_delta_insert(teval, keys, vals)			\
+	traceeval_delta_insert_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), \
+				    vals, TRACEEVAL_ARRAY_SIZE(vals))
+
+#define traceeval_delta_remove(teval, keys)				\
+	traceeval_delta_remove_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys))
+
+int traceeval_delta_remove_size(struct traceeval_delta *tdelta,
+				const struct traceeval_data *keys, size_t nr_keys);
+
+int traceeval_delta_query_size(struct traceeval_delta *tdelta,
+			       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_start_size(struct traceeval_delta *tdelta,
+			       const struct traceeval_data *keys, size_t nr_keys,
+			       unsigned long long timestamp);
+
+#define traceeval_delta_start(teval, keys, timestamp)			\
+	traceeval_delta_start_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), timestamp)
+
+int traceeval_delta_continue_size(struct traceeval_delta *tdelta,
+				  const struct traceeval_data *keys, size_t nr_keys,
+				  unsigned long long timestamp);
+
+#define traceeval_delta_continue(teval, keys, timestamp)		\
+	traceeval_delta_continue_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), timestamp)
+
+int traceeval_delta_stop_size(struct traceeval_delta *tdelta,
+			      const struct traceeval_data *keys, size_t nr_keys,
+			      unsigned long long timestamp);
+
+#define traceeval_delta_stop(teval, keys, timestamp)			\
+	traceeval_delta_stop_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), timestamp)
+
+void traceeval_delta_results_release(struct traceeval_delta *tdelta,
+				     const struct traceeval_data *results);
+
+#define traceeval_delta_stat(teval, keys)				\
+	traceeval_delta_stat_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys))
+
+struct traceeval_stat *traceeval_delta_stat_size(struct traceeval_delta *tdelta,
+						 const struct traceeval_data *keys,
+						 size_t nr_keys);
+
+struct traceeval *traceeval_delta_teval_get(struct traceeval_delta *tdelta);
+
+void traceeval_delta_teval_put(struct traceeval_delta *tdelta,
+			       struct traceeval *teval);
+
 #define traceeval_stat(teval, keys, val_name)				\
 	traceeval_stat_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), val_name)
 
@@ -265,6 +342,7 @@ 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);
+struct traceeval_stat *traceeval_iterator_delta_stat(struct traceeval_iterator *iter);
 int traceeval_iterator_remove(struct traceeval_iterator *iter);
 
 #endif /* __LIBTRACEEVAL_HIST_H__ */
samples/task-eval.c +63 -158

477 lines not on this page · raw message

samples/wake-lat.c +14 -56

135 lines not on this page · raw message

src/Makefile +1 -0
index 168d90a67cab..6f790b21bae4 100644
@@ -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 +418 -0

418 lines not on this page · raw message

src/eval-local.h +15 -0
index fabb1a06e7df..9804fbd34e29 100644
@@ -63,11 +63,16 @@ struct entry {
 	struct traceeval_stat	*val_stats;
 };
 
+enum {
+	TEVAL_FL_DELTA		= (1 << 0),
+};
+
 /* Histogram */
 struct traceeval {
 	struct traceeval_type		*key_types;
 	struct traceeval_type		*val_types;
 	struct hash_table		*hist;
+	unsigned int			flags;
 	ssize_t				nr_key_types;
 	ssize_t				nr_val_types;
 	size_t				update_counter;
@@ -89,6 +94,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);
@@ -117,6 +128,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 +89 -70

273 lines not on this page · raw message

Signature · 1 line
2.40.1
#1 lore raw
Quoted 1 line · On Thu, 5 Oct 2023 22:27:05 -0400 Steven Rostedt <[email protected]> wrote:

Subject: [PATCH] libtraceeval: Add traceeval_data_start/continue/stop() API

Bah, as it was sent, I noticed the subject said "data" and not "delta".

Oh well, I'm sure there's going to be a v2 on this.

-- Steve