libtraceeval: Move traceeval-hist.h to traceeval.h
PATCH v2 1/1 libtraceeval: Move traceeval-hist.h to traceeval.h
From: "Steven Rostedt (Google)" <[email protected]>
Now that the API of the new histogram logic of libtraceeval is rather stable, we can now remove the old version and replace it with the new version. The traceeval-hist.h was just a tempory header until it was to a point that it should be the default. It now is at that point. Remove the old code of the histogram and use the new code.
---
Changes since v1: https://lore.kernel.org/all/[email protected]/
- Committed the changes to src/Makefile to remove trace-analysis.o compilation.
- Forgot to replace traceeval-hist.h to traceeval.h in histograms.c.
include/traceeval-hist.h | 245 ------------ include/traceeval.h | 327 +++++++++++----- src/Makefile | 1 - src/histograms.c | 2 +- src/trace-analysis.c | 805 --------------------------------------- 5 files changed, 227 insertions(+), 1153 deletions(-) delete mode 100644 include/traceeval-hist.h delete mode 100644 src/trace-analysis.c
include/traceeval-hist.h deleted +0 -245
@@ -1,245 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* -* libtraceeval histogram interface. -* -* Copyright (C) 2023 Google Inc, Steven Rostedt <[email protected]> -* Copyright (C) 2023 Google Inc, Stevie Alvarez <[email protected]> -*/ -#ifndef __LIBTRACEEVAL_HIST_H__ -#define __LIBTRACEEVAL_HIST_H__ - -#include <stdlib.h> -#include <stddef.h> -#include <stdbool.h> - -/* Data definition interfaces */ - -/* Field name/descriptor for number of hits */ -#define TRACEEVAL_VAL_HITS ((const char *)(-1UL)) - -#define TRACEEVAL_ARRAY_SIZE (data) (sizeof(data) / sizeof((data)[0])) - -/* Data type distinguishers */ -enum traceeval_data_type { -TRACEEVAL_TYPE_NONE , -TRACEEVAL_TYPE_NUMBER_8 , -TRACEEVAL_TYPE_NUMBER_16 , -TRACEEVAL_TYPE_NUMBER_32 , -TRACEEVAL_TYPE_NUMBER_64 , -TRACEEVAL_TYPE_NUMBER , -TRACEEVAL_TYPE_POINTER , -TRACEEVAL_TYPE_STRING , -}; - -/* Statistics specification flags */ -enum traceeval_flags { -TRACEEVAL_FL_KEY = (1 <<0 ), -TRACEEVAL_FL_VALUE = (1 <<1 ), -TRACEEVAL_FL_SIGNED = (1 <<2 ), -TRACEEVAL_FL_TIMESTAMP = (1 <<3 ), -TRACEEVAL_FL_STAT = (1 <<4 ), -}; - -/* -* Trace data entry for a traceeval histogram -* Constitutes keys and values. -*/ -struct traceeval_data { -enum traceeval_data_type type; -union { -char *string; -const char *cstring; -void *pointer; -unsigned long number; -unsigned long long number_64; -unsigned int number_32; -unsigned short number_16; -unsigned char number_8; - }; -}; - -#define __TRACEEVAL_DATA (data_type, member, data) \ - { .type = TRACEEVAL_TYPE_##data_type, .member = (data) } - -#define DEFINE_TRACEEVAL_NUMBER (data) __TRACEEVAL_DATA(NUMBER, number, data) -#define DEFINE_TRACEEVAL_NUMBER_8 (data) __TRACEEVAL_DATA(NUMBER_8, number_8, data) -#define DEFINE_TRACEEVAL_NUMBER_16 (data) __TRACEEVAL_DATA(NUMBER_16, number_16, data) -#define DEFINE_TRACEEVAL_NUMBER_32 (data) __TRACEEVAL_DATA(NUMBER_32, number_32, data) -#define DEFINE_TRACEEVAL_NUMBER_64 (data) __TRACEEVAL_DATA(NUMBER_64, number_64, data) -#define DEFINE_TRACEEVAL_STRING (data) __TRACEEVAL_DATA(STRING, string, data) -#define DEFINE_TRACEEVAL_CSTRING (data) __TRACEEVAL_DATA(STRING, cstring, data) -#define DEFINE_TRACEEVAL_POINTER (data) __TRACEEVAL_DATA(POINTER, pointer, data) - -#define __TRACEEVAL_SET (data, data_type, member, val) \ - do { \ - (data).type = TRACEEVAL_TYPE_##data_type; \ - (data).member = (val); \ - } while (0) - -#define TRACEEVAL_SET_NUMBER (data, val) __TRACEEVAL_SET(data, NUMBER, number, val) -#define TRACEEVAL_SET_NUMBER_8 (data, val) __TRACEEVAL_SET(data, NUMBER_8, number_8, val) -#define TRACEEVAL_SET_NUMBER_16 (data, val) __TRACEEVAL_SET(data, NUMBER_16, number_16, val) -#define TRACEEVAL_SET_NUMBER_32 (data, val) __TRACEEVAL_SET(data, NUMBER_32, number_32, val) -#define TRACEEVAL_SET_NUMBER_64 (data, val) __TRACEEVAL_SET(data, NUMBER_64, number_64, val) -#define TRACEEVAL_SET_STRING (data, val) __TRACEEVAL_SET(data, STRING, string, val) -#define TRACEEVAL_SET_CSTRING (data, val) __TRACEEVAL_SET(data, STRING, cstring, val) -#define TRACEEVAL_SET_POINTER (data, val) __TRACEEVAL_SET(data, POINTER, pointer, val) - -struct traceeval_type ; -struct traceeval ; - -/* release function callback on traceeval_data */ -typedef void (*traceeval_data_release_fn )(const struct traceeval_type *type, -struct traceeval_data *data); - -/* compare function callback to compare traceeval_data */ -typedef int (*traceeval_data_cmp_fn )(struct traceeval *teval, -const struct traceeval_type *type, -const struct traceeval_data *A , -const struct traceeval_data *B ); - -/* make a unique value */ -typedef int (*traceeval_data_hash_fn )(struct traceeval *teval, -const struct traceeval_type *type, -const struct traceeval_data *data); - -typedef int (*traceeval_data_copy_fn )(const struct traceeval_type *type, -struct traceeval_data *dst, -const struct traceeval_data *src); - -typedef int (*traceeval_cmp_fn )(struct traceeval *teval, -const struct traceeval_data *Akeys, -const struct traceeval_data *Avals, -const struct traceeval_data *Bkeys, -const struct traceeval_data *Bvals, -void *data); - -/* -* struct traceeval_type - Describes the type of a traceevent_data instance -* @type: The enum type that describes the traceeval_data -* @name: The string name of the traceeval_data -* @flags: flags to describe the traceeval_data -* @id: User specified identifier -* @release: An optional callback for when the data is being released -* @cmp: An optional callback to specify a way to compare the type -* -* The traceeval_type structure defines expectations for a corresponding -* traceeval_data instance for a traceeval histogram instance. Used to -* describe both keys and values. -* -* The @id field is an optional value in case the user has multiple struct -* traceeval_type instances and needs to distinguish between them into -* 'sub-types'. -* -* For flexibility, @cmp() and @release() take a struct traceeval_type -* instance. This allows the user to handle pointer types. -* It may also be used for other types if the default cmp() or release() -* need to be overridden. Note for string types, even if the release() -* is called, the string freeing is still taken care of by the traceeval -* infrastructure. -* -* The @id field is a user specified field that may allow the same callback -* to be used by multiple types and not needing to do a strcmp() against the -* name (could be used for switch statements). -* -* @cmp() is used to override the default compare of a type. This is -* required to pointer types. It should return 0 on equality, 1 if the first -* argument is greater than the second, -1 for the other way around, -* and -2 on error. -* -* @release() is called when a data element is being released (or freed). -*/ -struct traceeval_type { -char *name; -enum traceeval_data_type type; -size_t flags; -size_t index; -size_t id; -traceeval_data_release_fn release; -traceeval_data_cmp_fn cmp; -traceeval_data_copy_fn copy; -traceeval_data_hash_fn hash; -}; - -/* Statistics about a given entry element */ -struct traceeval_stat ; - -/* Iterator over aggregated data */ -struct traceeval_iterator ; - -struct traceeval ; - -/* Histogram interfaces */ - -#define traceeval_init (keys, vals) \ - traceeval_init_size(keys, vals, \ - TRACEEVAL_ARRAY_SIZE(keys), \ - (void *)vals == NULL ? 0 : TRACEEVAL_ARRAY_SIZE(vals)) - -#define traceeval_init_size (keys, vals, nr_keys, nr_vals) \ - traceeval_init_data_size(keys, vals, nr_keys, nr_vals, \ - sizeof(struct traceeval_type), \ - sizeof(struct traceeval_data)) - -struct traceeval *traceeval_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_release (struct traceeval *teval); - -int traceeval_insert_size (struct traceeval *teval, -const struct traceeval_data *keys,size_t nr_keys, -const struct traceeval_data *vals,size_t nr_vals); - -#define traceeval_insert (teval, keys, vals) \ - traceeval_insert_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), \ - vals, (void *)vals == NULL ? 0 : TRACEEVAL_ARRAY_SIZE(vals)) - -int traceeval_remove_size (struct traceeval *teval, -const struct traceeval_data *keys,size_t nr_keys); - -#define traceeval_remove (teval, keys) \ - traceeval_remove_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys)) - -int traceeval_query_size (struct traceeval *teval,const struct traceeval_data *keys, -size_t nr_keys,const struct traceeval_data **results); - -#define traceeval_query (teval, keys, results) \ - traceeval_query_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), results) - -void traceeval_results_release (struct traceeval *teval, -const struct traceeval_data *results); - -size_t traceeval_count (struct traceeval *teval); - -#define traceeval_stat (teval, keys, type) \ - traceeval_stat_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), type) - -struct traceeval_stat *traceeval_stat_size (struct traceeval *teval, -const struct traceeval_data *keys, -size_t nr_keys, -struct traceeval_type *type); - -unsigned long long traceeval_stat_max (struct traceeval_stat *stat); -unsigned long long traceeval_stat_min (struct traceeval_stat *stat); -unsigned long long traceeval_stat_total (struct traceeval_stat *stat); -unsigned long long traceeval_stat_count (struct traceeval_stat *stat); - -struct traceeval_iterator *traceeval_iterator_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); -int traceeval_iterator_sort_custom (struct traceeval_iterator *iter, -traceeval_cmp_fn sort_fn,void *data); -int traceeval_iterator_next (struct traceeval_iterator *iter, -const struct traceeval_data **keys); -int traceeval_iterator_query (struct traceeval_iterator *iter, -const struct traceeval_data **results); -void traceeval_iterator_results_release (struct traceeval_iterator *iter, -const struct traceeval_data *results); -struct traceeval_stat *traceeval_iterator_stat (struct traceeval_iterator *iter, -struct traceeval_type *type); -int traceeval_iterator_remove (struct traceeval_iterator *iter); - -#endif /* __LIBTRACEEVAL_HIST_H__ */
include/traceeval.h +226 -101
346 lines not on this page · raw message
src/Makefile +0 -1
@@ -3,7 +3,6 @@ include $(src)/scripts/utils.mk OBJS = -OBJS += trace-analysis.o OBJS += histograms.o OBJS += hash.o
src/histograms.c +1 -1
@@ -11,7 +11,7 @@#include <stdarg.h> #include <stdio.h> -#include <traceeval-hist.h> +#include <traceeval.h> #include "eval-local.h" /*
src/trace-analysis.c deleted +0 -805
805 lines not on this page · raw message
Signature · 1 line
2.40.1
Quoted 9 lines · Steven Rostedt
From: "Steven Rostedt (Google)" <[email protected]>
Now that the API of the new histogram logic of libtraceeval is rather stable, we can now remove the old version and replace it with the new version. The
traceeval-hist.hwas just a tempory header until it was to a point that it should be the default. It now is at that point. Remove the old code of the histogram and use the new code.Signed-off-by Steven Rostedt (Google) <[email protected]>