tools/lib/traceevent,tools/perf: Various changes in libtraceevent APIs
v2 cover tools/lib/traceevent,tools/perf: Various changes in libtraceevent APIs
This patch series includes changes, related to transformation of traceevent into a library:
Renamed few libtracevent APIs.
Introduced two new APIs: tep_get_ref() and tep_override_comm(). Changed return logic of tep_register_event_handler() and trace_seq_printf() Added support for pkg-config infrastructure
Changed describtion of few APIs, to be consistent with the man pages.
Tzvetomir Stoyanov (14):
tools/lib/traceevent: Implemented new API tep_get_ref() tools/lib/traceevent: Added support for pkg-config tools/lib/traceevent: Install trace-seq.h API header file tools/lib/traceevent, tools/perf: Rename struct tep_event_format to
struct tep_event
tools/lib/traceevent: Rename tep_free_format() to tep_free_event() tools/perf: traceevent API cleanup, remove __tep_data2host*() tools/lib/traceevent: traceevent API cleanup tools/lib/traceevent: Introduce new libtracevent API:
tep_override_comm()
tools/lib/traceevent: Initialize host_bigendian at tep_handle
allocation
tools/lib/traceevent: Rename struct cmdline to struct tep_cmdline tools/lib/traceevent: Changed return logic of trace_seq_printf() and
trace_seq_vprintf() APIs
tools/lib/traceevent: Changed return logic of
tep_register_event_handler() API
tools/lib/traceevent: Rename tep_is_file_bigendian() to
tep_file_bigendian()
tools/lib/traceevent: Change description of few APIs
tools/lib/traceevent/Makefile | 27 +- tools/lib/traceevent/event-parse-api.c | 37 +- tools/lib/traceevent/event-parse-local.h | 17 +- tools/lib/traceevent/event-parse.c | 343 ++++++++++-------- tools/lib/traceevent/event-parse.h | 94 +++-- .../lib/traceevent/libtraceevent.pc.template | 10 + tools/lib/traceevent/parse-filter.c | 42 +-- tools/lib/traceevent/plugin_function.c | 2 +- tools/lib/traceevent/plugin_hrtimer.c | 4 +- tools/lib/traceevent/plugin_kmem.c | 2 +- tools/lib/traceevent/plugin_kvm.c | 16 +- tools/lib/traceevent/plugin_mac80211.c | 4 +- tools/lib/traceevent/plugin_sched_switch.c | 4 +- tools/lib/traceevent/trace-seq.c | 17 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/evsel.h | 4 +- tools/perf/util/header.c | 2 +- tools/perf/util/python.c | 4 +- .../util/scripting-engines/trace-event-perl.c | 6 +- .../scripting-engines/trace-event-python.c | 8 +- tools/perf/util/trace-event-parse.c | 16 +- tools/perf/util/trace-event-read.c | 4 +- tools/perf/util/trace-event.c | 8 +- tools/perf/util/trace-event.h | 16 +- 24 files changed, 387 insertions(+), 302 deletions(-) create mode 100644 tools/lib/traceevent/libtraceevent.pc.template
Signature · 1 line
2.19.1
PATCH v2 1/14 tools/lib/traceevent: Implemented new API tep_get_ref()
This patch implements new API of the tracevent library:
int tep_get_ref(struct tep_handle *pevent);
The API returns the reference counter "ref_count" of the tep handler. As "struct tep_handle" is internal only, its members cannot be accessed by the library users, the API is used to get the reference counter.
--- tools/lib/traceevent/event-parse.c | 7 +++++++ tools/lib/traceevent/event-parse.h | 1 + 2 files changed, 8 insertions(+)
tools/lib/traceevent/event-parse.c +7 -0
@@ -6774,6 +6774,13 @@ void tep_ref(struct tep_handle *pevent) pevent->ref_count++; } +int tep_get_ref (struct tep_handle *pevent) +{ +if (pevent) +return pevent->ref_count; +return 0 ; +} +void tep_free_format_field (struct tep_format_field *field) {free (field->type);
tools/lib/traceevent/event-parse.h +1 -0
@@ -583,6 +583,7 @@ struct tep_handle *tep_alloc(void);void tep_free (struct tep_handle *pevent);void tep_ref (struct tep_handle *pevent);void tep_unref (struct tep_handle *pevent); +int tep_get_ref (struct tep_handle *pevent);/* access to the internal parser */ void tep_buffer_init (const char *buf,unsigned long long size);
Signature · 1 line
2.19.1
PATCH v2 2/14 tools/lib/traceevent: Added support for pkg-config
In reply to Tzvetomir StoyanovThis patch implements integration with pkg-config framework. pkg-config can be used by the library users to determine required CFLAGS and LDFLAGS in order to use the library
--- tools/lib/traceevent/Makefile | 26 ++++++++++++++++--- .../lib/traceevent/libtraceevent.pc.template | 10 +++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tools/lib/traceevent/libtraceevent.pc.template
tools/lib/traceevent/Makefile +23 -3
@@ -25,6 +25,7 @@ endef $(call allow-override,CC,$(CROSS_COMPILE)gcc) $(call allow-override,AR,$(CROSS_COMPILE)ar) $(call allow-override,NM,$(CROSS_COMPILE)nm) +$(call allow-override,PKG_CONFIG,pkg-config) EXT = -std=gnu99 INSTALL = install
@@ -47,6 +48,8 @@ prefix ?= /usr/local libdir = $(prefix)/$(libdir_relative) man_dir = $(prefix)/share/man man_dir_SQ = '$(subst ','\'',$(man_dir))' +pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \ + --variable pc_path pkg-config | tr ":" " ")) export man_dir man_dir_SQ INSTALL export DESTDIR DESTDIR_SQ
@@ -270,7 +273,19 @@ define do_generate_dynamic_list_file fi endef -install_lib: all_cmd install_plugins +PKG_CONFIG_FILE = libtraceevent.pc +define do_install_pkgconfig_file + if [ -n "${pkgconfig_dir}" ]; then \ + cp -f ${PKG_CONFIG_FILE}.template ${PKG_CONFIG_FILE}; \ + sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; \ + sed -i "s|LIB_VERSION|${EVENT_PARSE_VERSION}|g" ${PKG_CONFIG_FILE}; \ + $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); \ + else \ + (echo Failed to locate pkg-config directory) 1>&2; \ + fi +endef + +install_lib: all_cmd install_plugins install_pkgconfig $(call QUIET_INSTALL, $(LIB_TARGET)) \ $(call do_install_mkdir,$(libdir_SQ)); \ cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ)
@@ -279,6 +294,10 @@ install_plugins: $(PLUGINS) $(call QUIET_INSTALL, trace_plugins) \ $(call do_install_plugins, $(PLUGINS)) +install_pkgconfig: + $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \ + $(call do_install_pkgconfig_file,$(prefix)) + install_headers: $(call QUIET_INSTALL, headers) \ $(call do_install,event-parse.h,$(prefix)/include/traceevent,644); \
@@ -289,8 +308,9 @@ install: install_lib clean: $(call QUIET_CLEAN, libtraceevent) \ - $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \ - $(RM) TRACEEVENT-CFLAGS tags TAGS + $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \ + $(RM) TRACEEVENT-CFLAGS tags TAGS; \ + $(RM) $(PKG_CONFIG_FILE) PHONY += force plugins force:
tools/lib/traceevent/libtraceevent.pc.template new file +10 -0
@@ -0,0 +1,10 @@ +prefix=INSTALL_PREFIX +libdir=${prefix}/lib64 +includedir=${prefix}/include/traceevent + +Name: libtraceevent +URL: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git +Description: Linux kernel trace event library +Version: LIB_VERSION +Cflags: -I${includedir} +Libs: -L${libdir} -ltraceevent
Signature · 1 line
2.19.1
PATCH v2 3/14 tools/lib/traceevent: Install trace-seq.h API header file
In reply to Tzvetomir StoyanovThis patch installs trace-seq.h header file on "make install".
--- tools/lib/traceevent/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/lib/traceevent/Makefile +2 -1
@@ -285,7 +285,7 @@ define do_install_pkgconfig_file fi endef -install_lib: all_cmd install_plugins install_pkgconfig +install_lib: all_cmd install_plugins install_headers install_pkgconfig $(call QUIET_INSTALL, $(LIB_TARGET)) \ $(call do_install_mkdir,$(libdir_SQ)); \ cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ)
@@ -302,6 +302,7 @@ install_headers: $(call QUIET_INSTALL, headers) \ $(call do_install,event-parse.h,$(prefix)/include/traceevent,644); \ $(call do_install,event-utils.h,$(prefix)/include/traceevent,644); \ + $(call do_install,trace-seq.h,$(prefix)/include/traceevent,644); \ $(call do_install,kbuffer.h,$(prefix)/include/traceevent,644) install: install_lib
Signature · 1 line
2.19.1
PATCH v2 4/14 tools/lib/traceevent, tools/perf: Rename struct tep_event_format to struct tep_event
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, variables, data structures and functions require a unique prefix to prevent name space conflicts. This renames struct tep_event_format to struct tep_event, which describes more closely the purpose of the struct.
--- tools/lib/traceevent/event-parse-api.c | 2 +- tools/lib/traceevent/event-parse-local.h | 6 +- tools/lib/traceevent/event-parse.c | 188 +++++++++--------- tools/lib/traceevent/event-parse.h | 62 +++--- tools/lib/traceevent/parse-filter.c | 42 ++-- tools/lib/traceevent/plugin_function.c | 2 +- tools/lib/traceevent/plugin_hrtimer.c | 4 +- tools/lib/traceevent/plugin_kmem.c | 2 +- tools/lib/traceevent/plugin_kvm.c | 14 +- tools/lib/traceevent/plugin_mac80211.c | 4 +- tools/lib/traceevent/plugin_sched_switch.c | 4 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/evsel.h | 4 +- tools/perf/util/header.c | 2 +- tools/perf/util/python.c | 4 +- .../util/scripting-engines/trace-event-perl.c | 6 +- .../scripting-engines/trace-event-python.c | 8 +- tools/perf/util/trace-event-parse.c | 16 +- tools/perf/util/trace-event.c | 8 +- tools/perf/util/trace-event.h | 16 +- 20 files changed, 198 insertions(+), 198 deletions(-)
tools/lib/traceevent/event-parse-api.c +1 -1
@@ -15,7 +15,7 @@* This returns pointer to the first element of the events array * If @pevent is NULL, NULL is returned. */ -struct tep_event_format *tep_get_first_event (struct tep_handle *tep) +struct tep_event *tep_get_first_event (struct tep_handle *tep) {if (tep && tep->events)return tep->events[0 ];
tools/lib/traceevent/event-parse-local.h +3 -3
@@ -50,9 +50,9 @@ struct tep_handle {unsigned int printk_count; -struct tep_event_format **events; +struct tep_event **events;int nr_events; -struct tep_event_format **sort_events; +struct tep_event **sort_events;enum tep_event_sort_type last_type;int type_offset;
@@ -84,7 +84,7 @@ struct tep_handle {struct tep_function_handler *func_handlers;/* cache */ -struct tep_event_format *last_event; +struct tep_event *last_event;char *trace_clock; };
tools/lib/traceevent/event-parse.c +94 -94
664 lines not on this page · raw message
tools/lib/traceevent/event-parse.h +31 -31
152 lines not on this page · raw message
tools/lib/traceevent/parse-filter.c +21 -21
162 lines not on this page · raw message
tools/lib/traceevent/plugin_function.c +1 -1
@@ -124,7 +124,7 @@ static int add_and_get_index(const char *parent, const char *child, int cpu) }static int function_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {struct tep_handle *pevent = event->pevent;unsigned long long function;
tools/lib/traceevent/plugin_hrtimer.c +2 -2
@@ -27,7 +27,7 @@static int timer_expire_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {trace_seq_printf (s,"hrtimer=" );
@@ -47,7 +47,7 @@ static int timer_expire_handler(struct trace_seq *s,static int timer_start_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {trace_seq_printf (s,"hrtimer=" );
tools/lib/traceevent/plugin_kmem.c +1 -1
@@ -25,7 +25,7 @@#include "trace-seq.h" static int call_site_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {struct tep_format_field *field;unsigned long long val, addr;
tools/lib/traceevent/plugin_kvm.c +7 -7
@@ -249,7 +249,7 @@ static const char *find_exit_reason(unsigned isa, int val) }static int print_exit_reason (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,const char *field) +struct tep_event *event,const char *field) {unsigned long long isa;unsigned long long val;
@@ -270,7 +270,7 @@ static int print_exit_reason(struct trace_seq *s, struct tep_record *record, }static int kvm_exit_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {unsigned long long info1 =0 , info2 =0 ;
@@ -293,7 +293,7 @@ static int kvm_exit_handler(struct trace_seq *s, struct tep_record *record,static int kvm_emulate_insn_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {unsigned long long rip, csbase, len, flags, failed;int llen;
@@ -332,7 +332,7 @@ static int kvm_emulate_insn_handler(struct trace_seq *s,static int kvm_nested_vmexit_inject_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {if (print_exit_reason (s, record, event,"exit_code" ) <0 )return -1 ;
@@ -346,7 +346,7 @@ static int kvm_nested_vmexit_inject_handler(struct trace_seq *s, struct tep_reco }static int kvm_nested_vmexit_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {tep_print_num_field (s,"rip %llx " , event,"rip" , record,1 );
@@ -372,7 +372,7 @@ union kvm_mmu_page_role { };static int kvm_mmu_print_role (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {unsigned long long val;static const char *access_str[] = {
@@ -419,7 +419,7 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct tep_record *record,static int kvm_mmu_get_page_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {unsigned long long val;
tools/lib/traceevent/plugin_mac80211.c +2 -2
@@ -26,7 +26,7 @@#define INDENT 65 -static void print_string (struct trace_seq *s,struct tep_event_format *event, +static void print_string (struct trace_seq *s,struct tep_event *event,const char *name,const void *data) {struct tep_format_field *f =tep_find_field (event, name);
@@ -60,7 +60,7 @@ static void print_string(struct trace_seq *s, struct tep_event_format *event,static int drv_bss_info_changed (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {void *data = record->data;
tools/lib/traceevent/plugin_sched_switch.c +2 -2
@@ -67,7 +67,7 @@ static void write_and_save_comm(struct tep_format_field *field,static int sched_wakeup_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {struct tep_format_field *field;unsigned long long val;
@@ -96,7 +96,7 @@ static int sched_wakeup_handler(struct trace_seq *s,static int sched_switch_handler (struct trace_seq *s,struct tep_record *record, -struct tep_event_format *event,void *context) +struct tep_event *event,void *context) {struct tep_format_field *field;unsigned long long val;
tools/perf/builtin-trace.c +1 -1
@@ -804,7 +804,7 @@ static struct syscall_fmt *syscall_fmt__find(const char *name) }struct syscall { -struct tep_event_format *tp_format; +struct tep_event *tp_format;int nr_args;struct tep_format_field *args;const char *name;
tools/perf/util/evsel.h +2 -2
@@ -102,7 +102,7 @@ struct perf_evsel {char *name;double scale;const char *unit; -struct tep_event_format *tp_format; +struct tep_event *tp_format;off_t id_offset;struct perf_stat_evsel *stats;void *priv;
@@ -211,7 +211,7 @@ static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *struct perf_evsel *perf_evsel__new_cycles (bool precise); -struct tep_event_format *event_format__new (const char *sys,const char *name); +struct tep_event *event_format__new (const char *sys,const char *name);void perf_evsel__init (struct perf_evsel *evsel,struct perf_event_attr *attr,int idx);
tools/perf/util/header.c +1 -1
@@ -3209,7 +3209,7 @@ static int read_attr(int fd, struct perf_header *ph,static int perf_evsel__prepare_tracepoint_event (struct perf_evsel *evsel,struct tep_handle *pevent) { -struct tep_event_format *event; +struct tep_event *event;char bf[128 ];/* already prepared */
tools/perf/util/python.c +2 -2
@@ -385,7 +385,7 @@ get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name)struct tep_format_field *field;if (!evsel->tp_format) { -struct tep_event_format *tp_format; +struct tep_event *tp_format; tp_format =trace_event__tp_format_id (evsel->attr.config);if (!tp_format)
@@ -1222,7 +1222,7 @@ static struct {static PyObject *pyrf__tracepoint (struct pyrf_evsel *pevsel,PyObject *args,PyObject *kwargs) { -struct tep_event_format *tp_format; +struct tep_event *tp_format;static char *kwlist[] = {"sys" ,"name" ,NULL };char *sys =NULL ;char *name =NULL ;
tools/perf/util/scripting-engines/trace-event-perl.c +3 -3
@@ -189,7 +189,7 @@ static void define_flag_field(const char *ev_name,LEAVE ; } -static void define_event_symbols (struct tep_event_format *event, +static void define_event_symbols (struct tep_event *event,const char *ev_name,struct tep_print_arg *args) {
@@ -338,7 +338,7 @@ static void perl_process_tracepoint(struct perf_sample *sample, struct addr_location *al) {struct thread *thread = al->thread; -struct tep_event_format *event = evsel->tp_format; +struct tep_event *event = evsel->tp_format;struct tep_format_field *field;static char handler[256 ];unsigned long long val;
@@ -537,7 +537,7 @@ static int perl_stop_script(void)static int perl_generate_script (struct tep_handle *pevent,const char *outfile) { -struct tep_event_format *event =NULL ; +struct tep_event *event =NULL ;struct tep_format_field *f;char fname[PATH_MAX ];int not_first, count;
tools/perf/util/scripting-engines/trace-event-python.c +4 -4
@@ -264,7 +264,7 @@ static void define_field(enum tep_print_arg_type field_type,Py_DECREF (t); } -static void define_event_symbols (struct tep_event_format *event, +static void define_event_symbols (struct tep_event *event,const char *ev_name,struct tep_print_arg *args) {
@@ -332,7 +332,7 @@ static void define_event_symbols(struct tep_event_format *event,define_event_symbols (event, ev_name, args->next); } -static PyObject *get_field_numeric_entry (struct tep_event_format *event, +static PyObject *get_field_numeric_entry (struct tep_event *event,struct tep_format_field *field,void *data) {bool is_array = field->flags &TEP_FIELD_IS_ARRAY ;
@@ -790,7 +790,7 @@ static void python_process_tracepoint(struct perf_sample *sample,struct perf_evsel *evsel, struct addr_location *al) { - struct tep_event_format *event = evsel->tp_format; + struct tep_event *event = evsel->tp_format;PyObject *handler, *context, *t, *obj =NULL , *callchain;PyObject *dict =NULL , *all_entries_dict =NULL ;static char handler_name[256 ];
@@ -1590,7 +1590,7 @@ static int python_stop_script(void)static int python_generate_script (struct tep_handle *pevent,const char *outfile) { -struct tep_event_format *event =NULL ; +struct tep_event *event =NULL ;struct tep_format_field *f;char fname[PATH_MAX ];int not_first, count;
tools/perf/util/trace-event-parse.c +8 -8
@@ -33,7 +33,7 @@ static int get_common_field(struct scripting_context *context, int *offset, int *size, const char *type) { struct tep_handle *pevent = context->pevent; -struct tep_event_format *event; +struct tep_event *event;struct tep_format_field *field;if (!*size) {
@@ -95,7 +95,7 @@ int common_pc(struct scripting_context *context) }unsigned long long -raw_field_value (struct tep_event_format *event,const char *name,void *data) +raw_field_value (struct tep_event *event,const char *name,void *data) {struct tep_format_field *field;unsigned long long val;
@@ -109,12 +109,12 @@ raw_field_value(struct tep_event_format *event, const char *name, void *data)return val; } -unsigned long long read_size (struct tep_event_format *event,void *ptr,int size) +unsigned long long read_size (struct tep_event *event,void *ptr,int size) {return tep_read_number (event->pevent, ptr, size); } -void event_format__fprintf (struct tep_event_format *event, +void event_format__fprintf (struct tep_event *event,int cpu,void *data,int size,FILE *fp) {struct tep_record record;
@@ -131,7 +131,7 @@ void event_format__fprintf(struct tep_event_format *event,trace_seq_destroy (&s); } -void event_format__print (struct tep_event_format *event, +void event_format__print (struct tep_event *event,int cpu,void *data,int size) {return event_format__fprintf (event, cpu, data, size, stdout);
@@ -190,12 +190,12 @@ int parse_event_file(struct tep_handle *pevent,return tep_parse_event (pevent, buf, size, sys); } -struct tep_event_format *trace_find_next_event (struct tep_handle *pevent, -struct tep_event_format *event) +struct tep_event *trace_find_next_event (struct tep_handle *pevent, +struct tep_event *event) {static int idx;int events_count; -struct tep_event_format *all_events; +struct tep_event *all_events; all_events =tep_get_first_event (pevent); events_count =tep_get_events_count (pevent);
tools/perf/util/trace-event.c +4 -4
@@ -72,12 +72,12 @@ void trace_event__cleanup(struct trace_event *t)/* * Returns pointer with encoded error via <linux/err.h> interface. */ -static struct tep_event_format * +static struct tep_event *tp_format (const char *sys,const char *name) {char *tp_dir =get_events_file (sys);struct tep_handle *pevent = tevent.pevent; -struct tep_event_format *event =NULL ; +struct tep_event *event =NULL ;char path[PATH_MAX ];size_t size;char *data;
@@ -102,7 +102,7 @@ tp_format(const char *sys, const char *name)/* * Returns pointer with encoded error via <linux/err.h> interface. */ -struct tep_event_format * +struct tep_event *trace_event__tp_format (const char *sys,const char *name) {if (!tevent_initialized &&trace_event__init2 ())
@@ -111,7 +111,7 @@ trace_event__tp_format(const char *sys, const char *name)return tp_format (sys, name); } -struct tep_event_format *trace_event__tp_format_id (int id) +struct tep_event *trace_event__tp_format_id (int id) {if (!tevent_initialized &&trace_event__init2 ())return ERR_PTR (-ENOMEM );
tools/perf/util/trace-event.h +8 -8
@@ -22,17 +22,17 @@ int trace_event__init(struct trace_event *t);void trace_event__cleanup (struct trace_event *t);int trace_event__register_resolver (struct machine *machine,tep_func_resolver_t *func); -struct tep_event_format * +struct tep_event *trace_event__tp_format (const char *sys,const char *name); -struct tep_event_format *trace_event__tp_format_id (int id); +struct tep_event *trace_event__tp_format_id (int id);int bigendian (void ); -void event_format__fprintf (struct tep_event_format *event, +void event_format__fprintf (struct tep_event *event,int cpu,void *data,int size,FILE *fp); -void event_format__print (struct tep_event_format *event, +void event_format__print (struct tep_event *event,int cpu,void *data,int size);int parse_ftrace_file (struct tep_handle *pevent,char *buf,unsigned long size);
@@ -40,7 +40,7 @@ int parse_event_file(struct tep_handle *pevent, char *buf, unsigned long size, char *sys);unsigned long long -raw_field_value (struct tep_event_format *event,const char *name,void *data); +raw_field_value (struct tep_event *event,const char *name,void *data);void parse_proc_kallsyms (struct tep_handle *pevent,char *file,unsigned int size);void parse_ftrace_printk (struct tep_handle *pevent,char *file,unsigned int size);
@@ -48,9 +48,9 @@ void parse_saved_cmdline(struct tep_handle *pevent, char *file, unsigned int sizssize_t trace_report (int fd,struct trace_event *tevent,bool repipe); -struct tep_event_format *trace_find_next_event (struct tep_handle *pevent, -struct tep_event_format *event); -unsigned long long read_size (struct tep_event_format *event,void *ptr,int size); +struct tep_event *trace_find_next_event (struct tep_handle *pevent, +struct tep_event *event); +unsigned long long read_size (struct tep_event *event,void *ptr,int size);unsigned long long eval_flag (const char *flag);int read_tracing_data (int fd,struct list_head *pattrs);
Signature · 1 line
2.19.1
PATCH v2 5/14 tools/lib/traceevent: Rename tep_free_format() to tep_free_event()
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, variables, data structures and functions require a unique prefix to prevent name space conflicts. This renames tep_free_format() to tep_free_event(), which describes more closely the purpose of the function.
--- tools/lib/traceevent/event-parse.c | 6 +++--- tools/lib/traceevent/event-parse.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
tools/lib/traceevent/event-parse.c +3 -3
@@ -6169,7 +6169,7 @@ __parse_event(struct tep_handle *pevent,return 0 ; event_add_failed: -tep_free_format (event); +tep_free_event (event);return ret; }
@@ -6807,7 +6807,7 @@ static void free_formats(struct tep_format *format)free_format_fields (format->fields); } -void tep_free_format (struct tep_event *event) +void tep_free_event (struct tep_event *event) {free (event->name);free (event->system);
@@ -6893,7 +6893,7 @@ void tep_free(struct tep_handle *pevent) }for (i =0 ; i < pevent->nr_events; i++) -tep_free_format (pevent->events[i]); +tep_free_event (pevent->events[i]);while (pevent->handlers) { handle = pevent->handlers;
tools/lib/traceevent/event-parse.h +1 -1
@@ -477,7 +477,7 @@ enum tep_errno tep_parse_format(struct tep_handle *pevent,struct tep_event **eventp, const char *buf, unsigned long size, const char *sys); -void tep_free_format (struct tep_event *event); +void tep_free_event (struct tep_event *event);void tep_free_format_field (struct tep_format_field *field); void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event,
Signature · 1 line
2.19.1
PATCH v2 6/14 tools/perf: traceevent API cleanup, remove __tep_data2host*()
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, its API should be straightforward. The __tep_data2host*() functions are going to no longer be available as a libtraceevent API, tep_read_number() should be used instead. This patch replaces __tep_data2host*() usage with tep_read_number() in perf.
--- tools/perf/util/trace-event-read.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/trace-event-read.c +2 -2
@@ -102,7 +102,7 @@ static unsigned int read4(struct tep_handle *pevent)if (do_read (&data,4 ) <0 )return 0 ; -return __tep_data2host4 (pevent, data); +return tep_read_number (pevent, &data,4 ); }static unsigned long long read8 (struct tep_handle *pevent)
@@ -111,7 +111,7 @@ static unsigned long long read8(struct tep_handle *pevent)if (do_read (&data,8 ) <0 )return 0 ; -return __tep_data2host8 (pevent, data); +return tep_read_number (pevent, &data,8 ); }static char *read_string (void )
Signature · 1 line
2.19.1
PATCH v2 7/14 tools/lib/traceevent: traceevent API cleanup
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, its API should be straightforward. This patch hides few API functions, intended for internal usage only:tep_free_event(), tep_free_format_field(), __tep_data2host2(), __tep_data2host4() and __tep_data2host8().
The patch also alignes the libtraceevent summary man page with these API changes.
--- tools/lib/traceevent/event-parse-api.c | 6 +++--- tools/lib/traceevent/event-parse-local.h | 7 +++++++ tools/lib/traceevent/event-parse.c | 13 ++++++++----- tools/lib/traceevent/event-parse.h | 18 ------------------ 4 files changed, 18 insertions(+), 26 deletions(-)
tools/lib/traceevent/event-parse-api.c +3 -3
@@ -51,7 +51,7 @@ void tep_set_flag(struct tep_handle *tep, int flag) tep->flags |= flag; } -unsigned short __tep_data2host2 (struct tep_handle *pevent,unsigned short data) +unsigned short tep_data2host2 (struct tep_handle *pevent,unsigned short data) {unsigned short swap;
@@ -64,7 +64,7 @@ unsigned short __tep_data2host2(struct tep_handle *pevent, unsigned short data)return swap; } -unsigned int __tep_data2host4 (struct tep_handle *pevent,unsigned int data) +unsigned int tep_data2host4 (struct tep_handle *pevent,unsigned int data) {unsigned int swap;
@@ -80,7 +80,7 @@ unsigned int __tep_data2host4(struct tep_handle *pevent, unsigned int data) }unsigned long long -__tep_data2host8 (struct tep_handle *pevent,unsigned long long data) +tep_data2host8 (struct tep_handle *pevent,unsigned long long data) {unsigned long long swap;
tools/lib/traceevent/event-parse-local.h +7 -0
@@ -89,4 +89,11 @@ struct tep_handle { char *trace_clock; }; +void tep_free_event (struct tep_event *event); +void tep_free_format_field (struct tep_format_field *field); + +unsigned short tep_data2host2 (struct tep_handle *pevent,unsigned short data); +unsigned int tep_data2host4 (struct tep_handle *pevent,unsigned int data); +unsigned long long tep_data2host8 (struct tep_handle *pevent,unsigned long long data); +#endif /* _PARSE_EVENTS_INT_H */
tools/lib/traceevent/event-parse.c +8 -5
@@ -3343,15 +3343,18 @@ tep_find_any_field(struct tep_event *event, const char *name)unsigned long long tep_read_number (struct tep_handle *pevent,const void *ptr,int size) { +unsigned long long val; +switch (size) {case 1 :return *(unsigned char *)ptr;case 2 : -return tep_data2host2 (pevent, ptr); +return tep_data2host2 (pevent, *(unsigned short *)ptr);case 4 : -return tep_data2host4 (pevent, ptr); +return tep_data2host4 (pevent, *(unsigned int *)ptr);case 8 : -return tep_data2host8 (pevent, ptr); +memcpy (&val, (ptr),sizeof (unsigned long long )); +return tep_data2host8 (pevent, val);default :/* BUG! */ return 0 ;
@@ -4077,7 +4080,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, f =tep_find_any_field (event, arg->string.string); arg->string.offset = f->offset; } - str_offset =tep_data2host4 (pevent, data + arg->string.offset); + str_offset =tep_data2host4 (pevent, *(unsigned int *)(data + arg->string.offset)); str_offset &=0xffff ;print_str_to_seq (s, format, len_arg, ((char *)data) + str_offset);break ;
@@ -4095,7 +4098,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, f =tep_find_any_field (event, arg->bitmask.bitmask); arg->bitmask.offset = f->offset; } - bitmask_offset =tep_data2host4 (pevent, data + arg->bitmask.offset); + bitmask_offset =tep_data2host4 (pevent, *(unsigned int *)(data + arg->bitmask.offset)); bitmask_size = bitmask_offset >>16 ; bitmask_offset &=0xffff ; print_bitmask_to_seq(pevent, s, format, len_arg,
tools/lib/traceevent/event-parse.h +0 -18
@@ -409,22 +409,6 @@ void tep_print_plugins(struct trace_seq *s,typedef char *(tep_func_resolver_t )(void *priv,unsigned long long *addrp,char **modp);void tep_set_flag (struct tep_handle *tep,int flag); -unsigned short __tep_data2host2 (struct tep_handle *pevent,unsigned short data); -unsigned int __tep_data2host4 (struct tep_handle *pevent,unsigned int data); -unsigned long long -__tep_data2host8 (struct tep_handle *pevent,unsigned long long data); - -#define tep_data2host2 (pevent, ptr) \ - __tep_data2host2(pevent, *(unsigned short *)(ptr)) -#define tep_data2host4 (pevent, ptr) \ - __tep_data2host4(pevent, *(unsigned int *)(ptr)) -#define tep_data2host8 (pevent, ptr) \ -({ \ - unsigned long long __val; \ - \ - memcpy(&__val, (ptr), sizeof(unsigned long long)); \ - __tep_data2host8(pevent, __val); \ -})static inline int tep_host_bigendian (void ) {
@@ -477,8 +461,6 @@ enum tep_errno tep_parse_format(struct tep_handle *pevent,struct tep_event **eventp, const char *buf, unsigned long size, const char *sys); -void tep_free_event (struct tep_event *event); -void tep_free_format_field (struct tep_format_field *field); void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event, const char *name, struct tep_record *record,
Signature · 1 line
2.19.1
PATCH v2 8/14 tools/lib/traceevent: Introduce new libtracevent API: tep_override_comm()
In reply to Tzvetomir StoyanovThis patch adds a new API of tracevent library: tep_override_comm() It registers a pid / command mapping. If a mapping with the same pid already exists, the entry is updated with the new command.
--- tools/lib/traceevent/event-parse.c | 69 +++++++++++++++++++++++------- tools/lib/traceevent/event-parse.h | 1 + 2 files changed, 55 insertions(+), 15 deletions(-)
tools/lib/traceevent/event-parse.c +54 -15
@@ -247,11 +247,13 @@ int tep_pid_is_registered(struct tep_handle *pevent, int pid)* we must add this pid. This is much slower than when cmdlines * are added before the array is initialized. */ -static int add_new_comm (struct tep_handle *pevent,const char *comm,int pid) +static int add_new_comm (struct tep_handle *pevent, +const char *comm,int pid,bool override) {struct cmdline *cmdlines = pevent->cmdlines; -const struct cmdline *cmdline; +struct cmdline *cmdline;struct cmdline key; +char *new_comm;if (!pid)return 0 ;
@@ -262,8 +264,19 @@ static int add_new_comm(struct tep_handle *pevent, const char *comm, int pid) cmdline =bsearch (&key, pevent->cmdlines, pevent->cmdline_count,sizeof (*pevent->cmdlines), cmdline_cmp);if (cmdline) { - errno =EEXIST ; -return -1 ; +if (!override) { + errno =EEXIST ; +return -1 ; + } + new_comm =strdup (comm); +if (!new_comm) { + errno =ENOMEM ; +return -1 ; + } +free (cmdline->comm); + cmdline->comm = new_comm; + +return 0 ; } cmdlines =realloc (cmdlines,sizeof (*cmdlines) * (pevent->cmdline_count +1 ));
@@ -290,21 +303,13 @@ static int add_new_comm(struct tep_handle *pevent, const char *comm, int pid)return 0 ; } -/** -* tep_register_comm - register a pid / comm mapping -* @pevent: handle for the pevent -* @comm: the command line to register -* @pid: the pid to map the command line to -* -* This adds a mapping to search for command line names with -* a given pid. The comm is duplicated. -*/ -int tep_register_comm (struct tep_handle *pevent,const char *comm,int pid) +static int _tep_register_comm (struct tep_handle *pevent, +const char *comm,int pid,bool override) {struct cmdline_list *item;if (pevent->cmdlines) -return add_new_comm (pevent, comm, pid); +return add_new_comm (pevent, comm, pid, override); item =malloc (sizeof (*item));if (!item)
@@ -327,6 +332,40 @@ int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid)return 0 ; } +/** +* tep_register_comm - register a pid / comm mapping +* @pevent: handle for the pevent +* @comm: the command line to register +* @pid: the pid to map the command line to +* +* This adds a mapping to search for command line names with +* a given pid. The comm is duplicated. If a command with the same pid +* already exist, -1 is returned and errno is set to EEXIST +*/ +int tep_register_comm (struct tep_handle *pevent,const char *comm,int pid) +{ +return _tep_register_comm (pevent, comm, pid, false); +} + +/** +* tep_override_comm - register a pid / comm mapping +* @pevent: handle for the pevent +* @comm: the command line to register +* @pid: the pid to map the command line to +* +* This adds a mapping to search for command line names with +* a given pid. The comm is duplicated. If a command with the same pid +* already exist, the command string is udapted with the new one +*/ +int tep_override_comm (struct tep_handle *pevent,const char *comm,int pid) +{ +if (!pevent->cmdlines &&cmdline_init (pevent)) { + errno =ENOMEM ; +return -1 ; + } +return _tep_register_comm (pevent, comm, pid, true); +} +int tep_register_trace_clock (struct tep_handle *pevent,const char *trace_clock) { pevent->trace_clock =strdup (trace_clock);
tools/lib/traceevent/event-parse.h +1 -0
@@ -432,6 +432,7 @@ int tep_set_function_resolver(struct tep_handle *pevent, tep_func_resolver_t *func, void *priv);void tep_reset_function_resolver (struct tep_handle *pevent);int tep_register_comm (struct tep_handle *pevent,const char *comm,int pid); +int tep_override_comm (struct tep_handle *pevent,const char *comm,int pid);int tep_register_trace_clock (struct tep_handle *pevent,const char *trace_clock);int tep_register_function (struct tep_handle *pevent,char *name,unsigned long long addr,char *mod);
Signature · 1 line
2.19.1
PATCH v2 9/14 tools/lib/traceevent: Initialize host_bigendian at tep_handle allocation
In reply to Tzvetomir StoyanovThis patch initializes host_bigendian member of the tep_handle structure with the byte order of current host, when this handler is created - in tep_alloc() API. We need this in order to remove tep_set_host_bigendian() API.
--- tools/lib/traceevent/event-parse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/lib/traceevent/event-parse.c +3 -1
@@ -6805,8 +6805,10 @@ struct tep_handle *tep_alloc(void) {struct tep_handle *pevent =calloc (1 ,sizeof (*pevent)); -if (pevent) +if (pevent) { pevent->ref_count =1 ; + pevent->host_bigendian =tep_host_bigendian (); + }return pevent; }
Signature · 1 line
2.19.1
PATCH v2 10/14 tools/lib/traceevent: Rename struct cmdline to struct tep_cmdline
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, variables, data structures and functions require a unique prefix to prevent name space conflicts. That prefix will be "tep_".
This patch renames struct cmdline to struct tep_cmdline.
--- tools/lib/traceevent/event-parse-local.h | 4 +-- tools/lib/traceevent/event-parse.c | 36 ++++++++++++------------ tools/lib/traceevent/event-parse.h | 8 +++--- 3 files changed, 24 insertions(+), 24 deletions(-)
tools/lib/traceevent/event-parse-local.h +2 -2
@@ -7,7 +7,7 @@#ifndef _PARSE_EVENTS_INT_H#define _PARSE_EVENTS_INT_H -struct cmdline ; +struct tep_cmdline ;struct cmdline_list ;struct func_map ;struct func_list ;
@@ -36,7 +36,7 @@ struct tep_handle {int long_size;int page_size; -struct cmdline *cmdlines; +struct tep_cmdline *cmdlines;struct cmdline_list *cmdlist;int cmdline_count;
tools/lib/traceevent/event-parse.c +18 -18
@@ -139,15 +139,15 @@ struct tep_print_arg *alloc_arg(void)return calloc (1 ,sizeof (struct tep_print_arg )); } -struct cmdline { +struct tep_cmdline {char *comm;int pid; };static int cmdline_cmp (const void *a,const void *b) { -const struct cmdline *ca = a; -const struct cmdline *cb = b; +const struct tep_cmdline *ca = a; +const struct tep_cmdline *cb = b;if (ca->pid < cb->pid)return -1 ;
@@ -167,7 +167,7 @@ static int cmdline_init(struct tep_handle *pevent) {struct cmdline_list *cmdlist = pevent->cmdlist;struct cmdline_list *item; -struct cmdline *cmdlines; +struct tep_cmdline *cmdlines;int i; cmdlines =malloc (sizeof (*cmdlines) * pevent->cmdline_count);
@@ -194,8 +194,8 @@ static int cmdline_init(struct tep_handle *pevent)static const char *find_cmdline (struct tep_handle *pevent,int pid) { -const struct cmdline *comm; -struct cmdline key; +const struct tep_cmdline *comm; +struct tep_cmdline key;if (!pid)return "<idle>" ;
@@ -223,8 +223,8 @@ static const char *find_cmdline(struct tep_handle *pevent, int pid)*/ int tep_pid_is_registered (struct tep_handle *pevent,int pid) { -const struct cmdline *comm; -struct cmdline key; +const struct tep_cmdline *comm; +struct tep_cmdline key;if (!pid)return 1 ;
@@ -250,9 +250,9 @@ int tep_pid_is_registered(struct tep_handle *pevent, int pid)static int add_new_comm (struct tep_handle *pevent,const char *comm,int pid,bool override) { -struct cmdline *cmdlines = pevent->cmdlines; -struct cmdline *cmdline; -struct cmdline key; +struct tep_cmdline *cmdlines = pevent->cmdlines; +struct tep_cmdline *cmdline; +struct tep_cmdline key;char *new_comm;if (!pid)
@@ -5345,8 +5345,8 @@ const char *tep_data_comm_from_pid(struct tep_handle *pevent, int pid)return comm; } -static struct cmdline * -pid_from_cmdlist (struct tep_handle *pevent,const char *comm,struct cmdline *next) +static struct tep_cmdline * +pid_from_cmdlist (struct tep_handle *pevent,const char *comm,struct tep_cmdline *next) {struct cmdline_list *cmdlist = (struct cmdline_list *)next;
@@ -5358,7 +5358,7 @@ pid_from_cmdlist(struct tep_handle *pevent, const char *comm, struct cmdline *newhile (cmdlist &&strcmp (cmdlist->comm, comm) !=0 ) cmdlist = cmdlist->next; -return (struct cmdline *)cmdlist; +return (struct tep_cmdline *)cmdlist; }/**
@@ -5374,10 +5374,10 @@ pid_from_cmdlist(struct tep_handle *pevent, const char *comm, struct cmdline *ne* next pid. * Also, it does a linear seach, so it may be slow. */ -struct cmdline *tep_data_pid_from_comm (struct tep_handle *pevent,const char *comm, -struct cmdline *next) +struct tep_cmdline *tep_data_pid_from_comm (struct tep_handle *pevent,const char *comm, +struct tep_cmdline *next) { -struct cmdline *cmdline; +struct tep_cmdline *cmdline;/* * If the cmdlines have not been converted yet, then use
@@ -5416,7 +5416,7 @@ struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *co* Returns the pid for a give cmdline. If @cmdline is NULL, then * -1 is returned. */ -int tep_cmdline_pid (struct tep_handle *pevent,struct cmdline *cmdline) +int tep_cmdline_pid (struct tep_handle *pevent,struct tep_cmdline *cmdline) {struct cmdline_list *cmdlist = (struct cmdline_list *)cmdline;
tools/lib/traceevent/event-parse.h +4 -4
@@ -526,10 +526,10 @@ int tep_data_pid(struct tep_handle *pevent, struct tep_record *rec);int tep_data_preempt_count (struct tep_handle *pevent,struct tep_record *rec);int tep_data_flags (struct tep_handle *pevent,struct tep_record *rec);const char *tep_data_comm_from_pid (struct tep_handle *pevent,int pid); -struct cmdline ; -struct cmdline *tep_data_pid_from_comm (struct tep_handle *pevent,const char *comm, -struct cmdline *next); -int tep_cmdline_pid (struct tep_handle *pevent,struct cmdline *cmdline); +struct tep_cmdline ; +struct tep_cmdline *tep_data_pid_from_comm (struct tep_handle *pevent,const char *comm, +struct tep_cmdline *next); +int tep_cmdline_pid (struct tep_handle *pevent,struct tep_cmdline *cmdline);void tep_print_field (struct trace_seq *s,void *data,struct tep_format_field *field);
Signature · 1 line
2.19.1
PATCH v2 11/14 tools/lib/traceevent: Changed return logic of trace_seq_printf() and trace_seq_vprintf() APIs
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, its API should be straightforward. The trace_seq_printf() and trace_seq_vprintf() APIs have inconsistent returned values with the other trace_seq_* APIs. This path changes the return logic of trace_seq_printf() and trace_seq_vprintf() - to return the number of printed characters, as the other trace_seq_* related APIs.
--- tools/lib/traceevent/trace-seq.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
tools/lib/traceevent/trace-seq.c +12 -5
@@ -114,7 +114,8 @@ static void expand_buffer(struct trace_seq *s)* @fmt: printf format string * * It returns 0 if the trace oversizes the buffer's free -* space, 1 otherwise. +* space, the number of characters printed, or a negative +* value in case of an error. * * The tracer may use either sequence operations or its own * copy to user routines. To simplify formating of a trace
@@ -143,9 +144,10 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...) goto try_again; } - s->len += ret; +if (ret >0 ) + s->len += ret; -return 1 ; +return ret; }/**
@@ -153,6 +155,10 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)* @s: trace sequence descriptor * @fmt: printf format string * +* It returns 0 if the trace oversizes the buffer's free +* space, the number of characters printed, or a negative +* value in case of an error. +* * * The tracer may use either sequence operations or its own * copy to user routines. To simplify formating of a trace * trace_seq_printf is used to store strings into a special
@@ -177,9 +183,10 @@ trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args) goto try_again; } - s->len += ret; +if (ret >0 ) + s->len += ret; -return len; +return ret; }/**
Signature · 1 line
2.19.1
PATCH v2 12/14 tools/lib/traceevent: Changed return logic of tep_register_event_handler() API
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, its API should be straightforward. The tep_register_event_handler() functions returns -1 in case it successfully registers the new event handler. Such return code is used by the other library APIs in case of an error. To unify the return logic of tep_register_event_handler() with the other APIs, this patch introduces enum tep_reg_handler, which is used by this function as return value, to handle all possible successful return cases.
--- tools/lib/traceevent/event-parse.c | 22 ++++++++-------------- tools/lib/traceevent/event-parse.h | 6 +++++- 2 files changed, 13 insertions(+), 15 deletions(-)
tools/lib/traceevent/event-parse.c +8 -14
@@ -5279,18 +5279,6 @@ int tep_data_type(struct tep_handle *pevent, struct tep_record *rec)return trace_parse_common_type (pevent, rec->data); } -/** -* tep_data_event_from_type - find the event by a given type -* @pevent: a handle to the pevent -* @type: the type of the event. -* -* This returns the event form a given @type; -*/ -struct tep_event *tep_data_event_from_type (struct tep_handle *pevent,int type) -{ -return tep_find_event (pevent, type); -} -/** * tep_data_pid - parse the PID from record * @pevent: a handle to the pevent
@@ -6675,6 +6663,12 @@ static struct tep_event *search_event(struct tep_handle *pevent, int id,* * If @id is >= 0, then it is used to find the event. * else @sys_name and @event_name are used. +* +* Returns: +* TEP_REGISTER_SUCCESS_OVERWRITE if an existing handler is overwritten +* TEP_REGISTER_SUCCESS if a new handler is registered successfully +* negative TEP_ERRNO_... in case of an error +* */ int tep_register_event_handler(struct tep_handle *pevent, int id, const char *sys_name, const char *event_name,
@@ -6692,7 +6686,7 @@ int tep_register_event_handler(struct tep_handle *pevent, int id, event->handler = func; event->context = context; -return 0 ; +return TEP_REGISTER_SUCCESS_OVERWRITE ; not_found:/* Save for later use. */
@@ -6722,7 +6716,7 @@ int tep_register_event_handler(struct tep_handle *pevent, int id, pevent->handlers = handle; handle->context = context; -return -1 ; +return TEP_REGISTER_SUCCESS ; } static int handle_matches(struct event_handler *handler, int id,
tools/lib/traceevent/event-parse.h +5 -1
@@ -485,6 +485,11 @@ int tep_print_func_field(struct trace_seq *s, const char *fmt, struct tep_event *event, const char *name, struct tep_record *record, int err); +enum tep_reg_handler { +TEP_REGISTER_SUCCESS =0 , +TEP_REGISTER_SUCCESS_OVERWRITE , +}; +int tep_register_event_handler (struct tep_handle *pevent,int id,const char *sys_name,const char *event_name,tep_event_handler_func func,void *context);
@@ -521,7 +526,6 @@ tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record);void tep_data_lat_fmt (struct tep_handle *pevent,struct trace_seq *s,struct tep_record *record);int tep_data_type (struct tep_handle *pevent,struct tep_record *rec); -struct tep_event *tep_data_event_from_type (struct tep_handle *pevent,int type);int tep_data_pid (struct tep_handle *pevent,struct tep_record *rec);int tep_data_preempt_count (struct tep_handle *pevent,struct tep_record *rec);int tep_data_flags (struct tep_handle *pevent,struct tep_record *rec);
Signature · 1 line
2.19.1
PATCH v2 13/14 tools/lib/traceevent: Rename tep_is_file_bigendian() to tep_file_bigendian()
In reply to Tzvetomir StoyanovIn order to make libtraceevent into a proper library, its API should be straightforward. After discussion with Steven Rostedt, we decided to rename few APIs, to have more intuitive names. This patch renames tep_is_file_bigendian() to tep_file_bigendian().
--- tools/lib/traceevent/event-parse-api.c | 4 ++-- tools/lib/traceevent/event-parse.h | 2 +- tools/lib/traceevent/plugin_kvm.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
tools/lib/traceevent/event-parse-api.c +2 -2
@@ -194,13 +194,13 @@ void tep_set_page_size(struct tep_handle *pevent, int _page_size) }/** -* tep_is_file_bigendian - get if the file is in big endian order +* tep_file_bigendian - get if the file is in big endian order * @pevent: a handle to the tep_handle * * This returns if the file is in big endian order * If @pevent is NULL, 0 is returned. */ -int tep_is_file_bigendian (struct tep_handle *pevent) +int tep_file_bigendian (struct tep_handle *pevent) {if (pevent)return pevent->file_bigendian;
tools/lib/traceevent/event-parse.h +1 -1
@@ -558,7 +558,7 @@ int tep_get_long_size(struct tep_handle *pevent);void tep_set_long_size (struct tep_handle *pevent,int long_size);int tep_get_page_size (struct tep_handle *pevent);void tep_set_page_size (struct tep_handle *pevent,int _page_size); -int tep_is_file_bigendian (struct tep_handle *pevent); +int tep_file_bigendian (struct tep_handle *pevent);void tep_set_file_bigendian (struct tep_handle *pevent,enum tep_endian endian);int tep_is_host_bigendian (struct tep_handle *pevent);void tep_set_host_bigendian (struct tep_handle *pevent,enum tep_endian endian);
tools/lib/traceevent/plugin_kvm.c +1 -1
@@ -389,7 +389,7 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct tep_record *record,* We can only use the structure if file is of the same * endianess. */ -if (tep_is_file_bigendian (event->pevent) == +if (tep_file_bigendian (event->pevent) ==tep_is_host_bigendian (event->pevent)) { trace_seq_printf(s, "%u q%u%s %s%s %spae %snxe %swp%s%s%s",
Signature · 1 line
2.19.1
PATCH v2 14/14 tools/lib/traceevent: Change description of few APIs
In reply to Tzvetomir StoyanovAPIs descriptions should describe the purpose of the function, its parameters and return value. While working on man pages implementation, I noticed mismatches in the descriptions of few APIs. This patch changes the description of these APIs, making them consistent with the man pages:tep_print_num_field(), tep_print_func_field(), tep_get_header_page_size(), tep_get_long_size(), tep_set_long_size(), tep_get_page_size() and tep_set_page_size().
--- tools/lib/traceevent/event-parse-api.c | 25 ++++++++++++++++--------- tools/lib/traceevent/event-parse.c | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-)
tools/lib/traceevent/event-parse-api.c +16 -9
@@ -100,10 +100,10 @@ tep_data2host8(struct tep_handle *pevent, unsigned long long data) }/** -* tep_get_header_page_size - get size of the header page +* tep_get_header_page_size - get the size of a long integer, in kernel context * @pevent: a handle to the tep_handle * -* This returns size of the header page +* This returns the size of a long integer, in kernel context * If @pevent is NULL, 0 is returned. */ int tep_get_header_page_size (struct tep_handle *pevent)
@@ -140,10 +140,12 @@ void tep_set_cpus(struct tep_handle *pevent, int cpus) }/** -* tep_get_long_size - get the size of a long integer on the current machine +* tep_get_long_size - get the size of a long integer on the machine, +* where the trace is generated * @pevent: a handle to the tep_handle * -* This returns the size of a long integer on the current machine +* This returns the size of a long integer on the machine, +* where the trace is generated * If @pevent is NULL, 0 is returned. */ int tep_get_long_size (struct tep_handle *pevent)
@@ -154,7 +156,8 @@ int tep_get_long_size(struct tep_handle *pevent) }/** -* tep_set_long_size - set the size of a long integer on the current machine +* tep_set_long_size - set the size of a long integer on the machine, +* where the trace is generated * @pevent: a handle to the tep_handle * @size: size, in bytes, of a long integer *
@@ -167,10 +170,12 @@ void tep_set_long_size(struct tep_handle *pevent, int long_size) }/** -* tep_get_page_size - get the size of a memory page on the current machine +* tep_get_page_size - get the size of a memory page on the machine, +* where the trace is generated * @pevent: a handle to the tep_handle * -* This returns the size of a memory page on the current machine +* This returns the size of a memory page on the machine, +* where the trace is generated * If @pevent is NULL, 0 is returned. */ int tep_get_page_size (struct tep_handle *pevent)
@@ -181,11 +186,13 @@ int tep_get_page_size(struct tep_handle *pevent) }/** -* tep_set_page_size - set the size of a memory page on the current machine +* tep_set_page_size - set the size of a memory page on the machine, +* where the trace is generated * @pevent: a handle to the tep_handle * @_page_size: size of a memory page, in bytes * -* This sets the size of a memory page on the current machine +* This sets the size of a memory page on the machine, +* where the trace is generated */ void tep_set_page_size (struct tep_handle *pevent,int _page_size) {
tools/lib/traceevent/event-parse.c +2 -2
@@ -6429,7 +6429,7 @@ int tep_get_any_field_val(struct trace_seq *s, struct tep_event *event,* @record: The record with the field name. * @err: print default error if failed. * -* Returns: 0 on success, -1 field not found, or 1 if buffer is full. +* Returns: 1 on success, -1 field not found, or 0 if buffer is full. */ int tep_print_num_field(struct trace_seq *s, const char *fmt, struct tep_event *event, const char *name,
@@ -6461,7 +6461,7 @@ int tep_print_num_field(struct trace_seq *s, const char *fmt,* @record: The record with the field name. * @err: print default error if failed. * -* Returns: 0 on success, -1 field not found, or 1 if buffer is full. +* Returns: 1 on success, -1 field not found, or 0 if buffer is full. */ int tep_print_func_field(struct trace_seq *s, const char *fmt, struct tep_event *event, const char *name,
Signature · 1 line
2.19.1