tools lib traceevent, perf tools: Move struct tep_handler definition in a local header file
PATCH 1/1 tools lib traceevent, perf tools: Move struct tep_handler definition in a local header file
As traceevent is going to be transferred into a proper library, its local data should be protected from the library users. This patch encapsulates struct tep_handler into a local header, not visible outside of the library. It implements also a bunch of new APIs, which library users can use to access tep_handler members.
--- include/traceevent/event-parse.h | 238 +++----------- kernel-shark-qt/examples/datafilter.c | 4 +- kernel-shark-qt/src/libkshark-configio.c | 13 +- lib/trace-cmd/trace-input.c | 26 +- lib/trace-cmd/trace-util.c | 2 +- lib/traceevent/Makefile | 1 + lib/traceevent/event-parse-api.c | 401 +++++++++++++++++++++++ lib/traceevent/event-parse-local.h | 94 ++++++ lib/traceevent/event-parse.c | 2 + lib/traceevent/event-plugin.c | 1 + lib/traceevent/parse-filter.c | 1 + tracecmd/trace-check-events.c | 2 +- tracecmd/trace-output.c | 2 +- tracecmd/trace-read.c | 10 +- tracecmd/trace-split.c | 2 +- 15 files changed, 569 insertions(+), 230 deletions(-) create mode 100644 lib/traceevent/event-parse-api.c create mode 100644 lib/traceevent/event-parse-local.h
include/traceevent/event-parse.h +37 -201
@@ -391,151 +391,21 @@ void tep_print_plugins(struct trace_seq *s, const char *prefix, const char *suffix, const struct tep_plugin_list *list); -struct cmdline ; -struct cmdline_list ; -struct func_map ; -struct func_list ; -struct event_handler ; -struct func_resolver ; - +/* tep_handle */ typedef char *(tep_func_resolver_t )(void *priv,unsigned long long *addrp,char **modp); +void tep_set_flag (struct tep_handle *tep,enum tep_flag flag); +void tep_reset_flag (struct tep_handle *tep,enum tep_flag flag); +int tep_check_flag (struct tep_handle *tep,enum tep_flag flag); -struct tep_handle { -int ref_count; - -int header_page_ts_offset; -int header_page_ts_size; -int header_page_size_offset; -int header_page_size_size; -int header_page_data_offset; -int header_page_data_size; -int header_page_overwrite; - -int file_bigendian; -int host_bigendian; - -int latency_format; - -int old_format; - -int cpus; -int long_size; -int page_size; - -struct cmdline *cmdlines; -struct cmdline_list *cmdlist; -int cmdline_count; - -struct func_map *func_map; -struct func_resolver *func_resolver; -struct func_list *funclist; -unsigned int func_count; - -struct printk_map *printk_map; -struct printk_list *printklist; -unsigned int printk_count; - - -struct tep_event_format **events; -int nr_events; -struct tep_event_format **sort_events; -enum tep_event_sort_type last_type; - -int type_offset; -int type_size; - -int pid_offset; -int pid_size; - -int pc_offset; -int pc_size; - -int flags_offset; -int flags_size; - -int ld_offset; -int ld_size; - -int print_raw; - -int test_filters; - -int flags; - -struct tep_format_field *bprint_ip_field; -struct tep_format_field *bprint_fmt_field; -struct tep_format_field *bprint_buf_field; - -struct event_handler *handlers; -struct tep_function_handler *func_handlers; - -int parsing_failures; - -/* cache */ -struct tep_event_format *last_event; - -char *trace_clock; -}; - -static inline void tep_set_flag (struct tep_handle *pevent,int flag) -{ - pevent->flags |= flag; -} - -static inline unsigned short -__tep_data2host2 (struct tep_handle *pevent,unsigned short data) -{ -unsigned short swap; - -if (pevent->host_bigendian == pevent->file_bigendian) -return data; - - swap = ((data &0xffULL ) <<8 ) | - ((data & (0xffULL <<8 )) >>8 ); - -return swap; -} - -static inline unsigned int -__tep_data2host4 (struct tep_handle *pevent,unsigned int data) -{ -unsigned int swap; - -if (pevent->host_bigendian == pevent->file_bigendian) -return data; - - swap = ((data &0xffULL ) <<24 ) | - ((data & (0xffULL <<8 )) <<8 ) | - ((data & (0xffULL <<16 )) >>8 ) | - ((data & (0xffULL <<24 )) >>24 ); - -return swap; -} - -static inline unsigned long long -__tep_data2host8 (struct tep_handle *pevent,unsigned long long data) -{ -unsigned long long swap; - -if (pevent->host_bigendian == pevent->file_bigendian) -return data; - - swap = ((data &0xffULL ) <<56 ) | - ((data & (0xffULL <<8 )) <<40 ) | - ((data & (0xffULL <<16 )) <<24 ) | - ((data & (0xffULL <<24 )) <<8 ) | - ((data & (0xffULL <<32 )) >>8 ) | - ((data & (0xffULL <<40 )) >>24 ) | - ((data & (0xffULL <<48 )) >>40 ) | - ((data & (0xffULL <<56 )) >>56 ); - -return swap; -} +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) \ +#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; \ \
@@ -643,11 +513,13 @@ unsigned long long tep_read_number(struct tep_handle *pevent, const void *ptr, iint tep_read_number_field (struct tep_format_field *field,const void *data,unsigned long long *value); +struct tep_event_format *tep_get_first_event (struct tep_handle *tep); +struct tep_event_format *tep_get_event (struct tep_handle *tep,int index); +int tep_get_events_count (struct tep_handle *tep);struct tep_event_format *tep_find_event (struct tep_handle *pevent,int id);struct tep_event_format *tep_find_event_by_name (struct tep_handle *pevent,const char *sys,const char *name); -struct tep_event_format *tep_find_event_by_record (struct tep_handle *pevent,struct tep_record *record);
@@ -677,65 +549,29 @@ struct tep_event_format **tep_list_events(struct tep_handle *pevent, enum tep_evstruct tep_format_field **tep_event_common_fields (struct tep_event_format *event);struct tep_format_field **tep_event_fields (struct tep_event_format *event); -static inline int tep_get_cpus (struct tep_handle *pevent) -{ -return pevent->cpus; -} - -static inline void tep_set_cpus (struct tep_handle *pevent,int cpus) -{ - pevent->cpus = cpus; -} - -static inline int tep_get_long_size (struct tep_handle *pevent) -{ -return pevent->long_size; -} - -static inline void tep_set_long_size (struct tep_handle *pevent,int long_size) -{ - pevent->long_size = long_size; -} - -static inline int tep_get_page_size (struct tep_handle *pevent) -{ -return pevent->page_size; -} - -static inline void tep_set_page_size (struct tep_handle *pevent,int _page_size) -{ - pevent->page_size = _page_size; -} - -static inline int tep_is_file_bigendian (struct tep_handle *pevent) -{ -return pevent->file_bigendian; -} - -static inline void tep_set_file_bigendian (struct tep_handle *pevent,int endian) -{ - pevent->file_bigendian = endian; -} - -static inline int tep_is_host_bigendian (struct tep_handle *pevent) -{ -return pevent->host_bigendian; -} - -static inline void tep_set_host_bigendian (struct tep_handle *pevent,int endian) -{ - pevent->host_bigendian = endian; -} - -static inline int tep_is_latency_format (struct tep_handle *pevent) -{ -return pevent->latency_format; -} - -static inline void tep_set_latency_format (struct tep_handle *pevent,int lat) -{ - pevent->latency_format = lat; -} +enum tep_endian { +TEP_LITTLE_ENDIAN =0 , +TEP_BIG_ENDIAN +}; +int tep_get_cpus (struct tep_handle *pevent); +void tep_set_cpus (struct tep_handle *pevent,int cpus); +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); +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); +int tep_is_latency_format (struct tep_handle *pevent); +void tep_set_latency_format (struct tep_handle *pevent,int lat); +int tep_get_header_page_size (struct tep_handle *pevent); +void tep_set_parsing_failures (struct tep_handle *tep,int parsing_failures); +int tep_get_parsing_failures (struct tep_handle *tep); +int tep_get_header_page_ts_size (struct tep_handle *tep); +int tep_is_old_format (struct tep_handle *pevent); +void tep_set_print_raw (struct tep_handle *tep,int print_raw); +void tep_set_test_filters (struct tep_handle *tep,int test_filters);struct tep_handle *tep_alloc (void );void tep_free (struct tep_handle *pevent);
kernel-shark-qt/examples/datafilter.c +2 -2
@@ -83,9 +83,9 @@ int main(int argc, char **argv)puts ("\n\n" );/* Show only "sched" events. */ - n_evts = kshark_ctx->pevent->nr_events; + n_evts =tep_get_events_count (kshark_ctx->pevent);for (i =0 ; i < n_evts; ++i) { - event = kshark_ctx->pevent->events[i]; + event =tep_get_event (kshark_ctx->pevent, i);if (strcmp (event->system,"sched" ) ==0 )kshark_filter_add_id (kshark_ctx,KS_SHOW_EVENT_FILTER , event->id);
kernel-shark-qt/src/libkshark-configio.c +8 -5
@@ -691,7 +691,8 @@ static bool kshark_event_filter_to_json(struct tep_handle *pevent, struct json_object *jobj) {json_object *jfilter_data, *jevent, *jsystem, *jname; -int i, evt, *ids; +struct tep_event_format *event; +int i, evt, *ids, nr_events;char *temp; jevent = jsystem = jname =NULL ;
@@ -712,15 +713,17 @@ static bool kshark_event_filter_to_json(struct tep_handle *pevent,if (!jfilter_data) goto fail; + nr_events =tep_get_events_count (pevent);for (i =0 ; i < filter->count; ++i) { -for (evt =0 ; evt < pevent->nr_events; ++evt) { -if (pevent->events[evt]->id == ids[i]) { +for (evt =0 ; evt < nr_events; ++evt) { + event =tep_get_event (pevent, evt); +if (event->id == ids[i]) { jevent =json_object_new_object (); - temp = pevent->events[evt]->system; + temp = event->system; jsystem =json_object_new_string (temp); - temp = pevent->events[evt]->name; + temp = event->name; jname =json_object_new_string (temp);if (!jevent || !jsystem || !jname)
lib/trace-cmd/trace-input.c +13 -13
@@ -340,7 +340,7 @@ static int read_header_files(struct tracecmd_input *handle)* The size field in the page is of type long, * use that instead, since it represents the kernel. */ - handle->long_size = pevent->header_page_size_size; + handle->long_size =tep_get_header_page_size (pevent);if (do_read_check (handle, buf,13 ))return -1 ;
@@ -422,7 +422,7 @@ static int read_ftrace_file(struct tracecmd_input *handle,printf ("%.*s\n" , (int )size, buf); }else {if (tep_parse_event (pevent, buf, size,"ftrace" )) - pevent->parsing_failures =1 ; +tep_set_parsing_failures (pevent,1 ); }free (buf);
@@ -456,7 +456,7 @@ static int read_event_file(struct tracecmd_input *handle, } }else {if (tep_parse_event (pevent, buf, size, system)) - pevent->parsing_failures =1 ; +tep_set_parsing_failures (pevent,1 ); }free (buf);
@@ -1047,7 +1047,7 @@ static int update_page_info(struct tracecmd_input *handle, int cpu)struct kbuffer *kbuf = handle->cpu_data[cpu].kbuf;/* FIXME: handle header page */ -if (pevent->header_page_ts_size !=8 ) { +if (tep_get_header_page_ts_size (pevent) !=8 ) {warning ("expected a long long type for timestamp" );return -1 ; }
@@ -1619,7 +1619,7 @@ tracecmd_translate_data(struct tracecmd_input *handle,memset (record,0 ,sizeof (*record)); record->ref_count =1 ; -if (pevent->host_bigendian == pevent->file_bigendian) +if (tep_is_host_bigendian (pevent) ==tep_is_file_bigendian (pevent)) swap =0 ; record->data =kbuffer_translate_data (swap, ptr, &length); record->size = length;
@@ -1661,12 +1661,12 @@ tracecmd_read_page_record(struct tep_handle *pevent, void *page, int size,enum kbuffer_endian endian;void *ptr; -if (pevent->file_bigendian) +if (tep_is_file_bigendian (pevent)) endian =KBUFFER_ENDIAN_BIG ;else endian =KBUFFER_ENDIAN_LITTLE ; -if (pevent->header_page_size_size ==8 ) +if (tep_get_header_page_size (pevent) ==8 ) long_size =KBUFFER_LSIZE_8 ;else long_size =KBUFFER_LSIZE_4 ;
@@ -2266,7 +2266,7 @@ static int read_cpu_data(struct tracecmd_input *handle)else long_size =KBUFFER_LSIZE_4 ; -if (handle->pevent->file_bigendian) +if (tep_is_file_bigendian (handle->pevent)) endian =KBUFFER_ENDIAN_BIG ;else endian =KBUFFER_ENDIAN_LITTLE ;
@@ -2279,7 +2279,7 @@ static int read_cpu_data(struct tracecmd_input *handle) handle->cpu_data[cpu].kbuf =kbuffer_alloc (long_size, endian);if (!handle->cpu_data[cpu].kbuf) goto out_free; -if (pevent->old_format) +if (tep_is_old_format (pevent))kbuffer_set_old_format (handle->cpu_data[cpu].kbuf);read8 (handle, &offset);
@@ -2475,7 +2475,7 @@ int tracecmd_make_pipe(struct tracecmd_input *handle, int cpu, int fd, int cpus)else long_size =KBUFFER_LSIZE_4 ; -if (handle->pevent->file_bigendian) +if (tep_is_file_bigendian (handle->pevent)) endian =KBUFFER_ENDIAN_BIG ;else endian =KBUFFER_ENDIAN_LITTLE ;
@@ -2487,7 +2487,7 @@ int tracecmd_make_pipe(struct tracecmd_input *handle, int cpu, int fd, int cpus) handle->cpu_data[cpu].kbuf =kbuffer_alloc (long_size, endian);if (!handle->cpu_data[cpu].kbuf)return -1 ; -if (handle->pevent->old_format) +if (tep_is_old_format (handle->pevent))kbuffer_set_old_format (handle->cpu_data[cpu].kbuf); handle->cpu_data[cpu].file_offset =0 ;
@@ -2644,8 +2644,8 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd) handle->plugin_list =tracecmd_load_plugins (handle->pevent); - handle->pevent->file_bigendian = buf[0 ]; - handle->pevent->host_bigendian =tracecmd_host_bigendian (); +tep_set_file_bigendian (handle->pevent, buf[0 ]); +tep_set_host_bigendian (handle->pevent,tracecmd_host_bigendian ());do_read_check (handle, buf,1 ); handle->long_size = buf[0 ];
lib/trace-cmd/trace-util.c +1 -1
@@ -1212,7 +1212,7 @@ int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *peven out_free:free (events_dir); - pevent->parsing_failures = failure; +tep_set_parsing_failures (pevent, failure);return ret; }
lib/traceevent/Makefile +1 -0
@@ -13,6 +13,7 @@ OBJS += kbuffer-parse.o OBJS += trace-seq.o OBJS += parse-filter.o OBJS += parse-utils.o +OBJS += event-parse-api.o # Additional util objects OBJS += str_error_r.o
lib/traceevent/event-parse-api.c new file +401 -0
401 lines not on this page · raw message
lib/traceevent/event-parse-local.h new file +94 -0
94 lines not on this page · raw message
lib/traceevent/event-parse.c +2 -0
@@ -23,6 +23,8 @@#include <netinet/in.h> #include "event-parse.h" + +#include "event-parse-local.h" #include "event-utils.h" #include "trace-seq.h"
lib/traceevent/event-plugin.c +1 -0
@@ -14,6 +14,7 @@#include <unistd.h> #include <dirent.h> #include "event-parse.h" +#include "event-parse-local.h" #include "event-utils.h" #include "trace-seq.h"
lib/traceevent/parse-filter.c +1 -0
@@ -11,6 +11,7 @@#include <sys/types.h> #include "event-parse.h" +#include "event-parse-local.h" #include "event-utils.h" #define COMM "COMM"
tracecmd/trace-check-events.c +1 -1
@@ -43,7 +43,7 @@ void trace_check_events(int argc, char **argv)exit (EINVAL ); list =tracecmd_load_plugins (pevent); ret =tracecmd_fill_local_events (tracing, pevent); -if (ret || pevent->parsing_failures) +if (ret ||tep_get_parsing_failures (pevent)) ret =EINVAL ;tracecmd_unload_plugins (list, pevent);tep_free (pevent);
tracecmd/trace-output.c +1 -1
@@ -809,7 +809,7 @@ create_file_fd(int fd, struct tracecmd_input *ihandle,/* Use the pevent of the ihandle for later writes */ handle->pevent =tracecmd_get_pevent (ihandle);tep_ref (pevent); -if (pevent->file_bigendian) +if (tep_is_file_bigendian (pevent)) buf[0 ] =1 ;else buf[0 ] =0 ;
tracecmd/trace-read.c +5 -5
@@ -798,7 +798,7 @@ void trace_show_data(struct tracecmd_input *handle, struct tep_record *record)tep_print_event_time (pevent, &s, event, record, use_trace_clock); buf[0 ] =0 ; -if (use_trace_clock && !(pevent->flags &TEP_NSEC_OUTPUT )) +if (use_trace_clock && !tep_check_flag (pevent,TEP_NSEC_OUTPUT )) rec_ts = (rec_ts +500 ) /1000 ;if (last_ts) { diff_ts = rec_ts - last_ts;
@@ -1687,13 +1687,13 @@ void trace_report (int argc, char **argv) pevent =tracecmd_get_pevent (handle);if (nanosec) - pevent->flags |=TEP_NSEC_OUTPUT ; +tep_set_flag (pevent,TEP_NSEC_OUTPUT );if (raw) - pevent->print_raw =1 ; +tep_set_print_raw (pevent,1 );if (test_filters) - pevent->test_filters =1 ; +tep_set_test_filters (pevent,1 );if (functions)add_functions (pevent, functions);
@@ -1717,7 +1717,7 @@ void trace_report (int argc, char **argv) ret =tracecmd_read_headers (handle);if (check_event_parsing) { -if (ret || pevent->parsing_failures) +if (ret ||tep_get_parsing_failures (pevent))exit (EINVAL );else exit (0 );
tracecmd/trace-split.c +1 -1
@@ -65,7 +65,7 @@ static int create_type_len(struct tep_handle *pevent, int time, int len) bigendian =1 ; } -if (pevent->file_bigendian) +if (tep_is_file_bigendian (pevent)) time |= (len <<27 );else time = (time <<5 ) | len;
Signature · 1 line
2.17.1
Quoted 17 lines · On Wed, 10 Oct 2018 10:51:17 +0000 Tzvetomir Stoyanov <[email protected]>…
lib/traceevent/event-parse-api.c new file +16
-0@@ -0,0 +1,401 @@ +// SPDX-License-Identifier: LGPL-2.1 +/* +* Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <[email protected]> +* +*/ + +#include "event-parse.h" +#include "event-parse-local.h" +#include "event-utils.h" + +/** +* tep_get_event - returns the event with the given index +* @tep: a handle to the tep_handle +* @index: index of the requested event, in the range 0 .. nr_events +* +* This returns pointer to the element of the events array with the given index
lib/traceevent/event-parse-api.c line 26
Quoted 10 lines
lib/traceevent/event-parse-api.c new file +10
-0+* If @tep is NULL, or @index is not in the range 0 .. nr_events, NULL is returned. +*/ +struct tep_event_format *tep_get_event (struct tep_handle *tep,int index) +{ +if (tep && tep->events && index < tep->nr_events) +return tep->events[index]; + +return NULL ; +} +
I just noticed that this is different than what we submitted to Linux tools directory.
I'll send an update to fix this because we need to keep trace-cmd and Linux tools libtraceevent need to stay totally in sync.
-- Steve
Quoted 17 lines · On Wed, 10 Oct 2018 10:51:17 +0000 Tzvetomir Stoyanov <[email protected]>…
+++
b/lib/traceevent/event-parse-api.clib/traceevent/event-parse-api.c new file +15
-0@@ -0,0 +1,401 @@ +// SPDX-License-Identifier: LGPL-2.1 +/* +* Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <[email protected]> +* +*/ + +#include "event-parse.h" +#include "event-parse-local.h" +#include "event-utils.h" + +/** +* tep_get_event - returns the event with the given index +* @tep: a handle to the tep_handle +* @index: index of the requested event, in the range 0 .. nr_events +*
lib/traceevent/event-parse-api.c line 25
Quoted 10 lines
lib/traceevent/event-parse-api.c new file +10
-0+* This returns pointer to the element of the events array with the given index +* If @tep is NULL, or @index is not in the range 0 .. nr_events, NULL is returned. +*/ +struct tep_event_format *tep_get_event (struct tep_handle *tep,int index) +{ +if (tep && tep->events && index < tep->nr_events) +return tep->events[index]; + +return NULL ; +}
It looks like a upstream backport added this function to the event-parse-api.c file to accommodate kernelshark.
Please be careful not to do this on backports. If you need to add functionality, it needs to be a separate patch so that we can upstream it. Otherwise, I get confused to see why the traceevent code is different between trace-cmd and linux/tools when all the commits have been added.
-- Steve
Quoted 13 lines
kernel-shark-qt/examples/datafilter.c +3
-2+++ b/kernel-shark-qt/examples/datafilter.c@@ -83,9 +83,9 @@ int main(int argc, char **argv)puts ("\n\n" );/* Show only "sched" events. */ - n_evts = kshark_ctx->pevent->nr_events; + n_evts =tep_get_events_count (kshark_ctx->pevent);for (i =0 ; i < n_evts; ++i) { - event = kshark_ctx->pevent->events[i]; + event =tep_get_event (kshark_ctx->pevent, i);if (strcmp (event->system,"sched" ) ==0 )kshark_filter_add_id (kshark_ctx,KS_SHOW_EVENT_FILTER , event->id);
Quoted 5 lines · On Thu, 14 Mar 2019 12:08:52 -0400 Steven Rostedt <[email protected]> wrote:
Please be careful not to do this on backports. If you need to add functionality, it needs to be a separate patch so that we can upstream it. Otherwise, I get confused to see why the traceevent code is different between trace-cmd and linux/tools when all the commits have been added.
Tzvetomir,
Can you prepare a new patch to send to tools lib traceevent upstream that has the following changes in it (plus you the headers need to updated).
Thanks!
-- Steve
traceevent/event-parse-api.c renamed from linux-test.git/tools/lib/traceevent/event-parse-api.c +148 -22
@@ -9,6 +9,22 @@#include "event-utils.h" /** +* tep_get_event - returns the event with the given index +* @tep: a handle to the tep_handle +* @index: index of the requested event, in the range 0 .. nr_events +* +* This returns pointer to the element of the events array with the given index +* If @tep is NULL, or @index is not in the range 0 .. nr_events, NULL is returned. +*/ +struct tep_event *tep_get_event (struct tep_handle *tep,int index) +{ +if (tep && tep->events && index < tep->nr_events) +return tep->events[index]; + +return NULL ; +} + +/** * tep_get_first_event - returns the first event in the events array * @tep: a handle to the tep_handle *
@@ -17,10 +33,7 @@*/ struct tep_event *tep_get_first_event (struct tep_handle *tep) { -if (tep && tep->events) -return tep->events[0 ]; - -return NULL ; +return tep_get_event (tep,0 ); }/**
@@ -32,7 +45,7 @@*/ int tep_get_events_count (struct tep_handle *tep) { -if (tep) +if (tep)return tep->nr_events;return 0 ; }
@@ -43,14 +56,43 @@* @flag: flag, or combination of flags to be set * can be any combination from enum tep_flag * -* This sets a flag or mbination of flags from enum tep_flag -*/ -void tep_set_flag (struct tep_handle *tep,int flag) +* This sets a flag or combination of flags from enum tep_flag +*/ +void tep_set_flag (struct tep_handle *tep,enum tep_flag flag) { -if (tep) +if (tep) tep->flags |= flag; } +/** +* tep_reset_flag - reset event parser flag +* @tep: a handle to the tep_handle +* @flag: flag, or combination of flags to be reseted +* can be any combination from enum tep_flag +* +* This resets a flag or combination of flags from enum tep_flag +*/ +void tep_reset_flag (struct tep_handle *tep,enum tep_flag flag) +{ +if (tep) + tep->flags &= ~flag; +} + +/** +* tep_check_flag - check the state of event parser flag +* @tep: a handle to the tep_handle +* @flag: flag, or combination of flags to be checked +* can be any combination from enum tep_flag +* +* This checks the state of a flag or combination of flags from enum tep_flag +*/ +int tep_check_flag (struct tep_handle *tep,enum tep_flag flag) +{ +if (tep) +return (tep->flags & flag); +return 0 ; +} +unsigned short tep_data2host2 (struct tep_handle *pevent,unsigned short data) {unsigned short swap;
@@ -108,12 +150,26 @@*/ int tep_get_header_page_size (struct tep_handle *pevent) { -if (pevent) +if (pevent)return pevent->header_page_size_size;return 0 ; }/** +* tep_get_header_page_ts_size - get size of the time stamp in the header page +* @tep: a handle to the tep_handle +* +* This returns size of the time stamp in the header page +* If @tep is NULL, 0 is returned. +*/ +int tep_get_header_page_ts_size (struct tep_handle *tep) +{ +if (tep) +return tep->header_page_ts_size; +return 0 ; +} + +/** * tep_get_cpus - get the number of CPUs * @pevent: a handle to the tep_handle *
@@ -122,7 +178,7 @@*/ int tep_get_cpus (struct tep_handle *pevent) { -if (pevent) +if (pevent)return pevent->cpus;return 0 ; }
@@ -135,7 +191,7 @@*/ void tep_set_cpus (struct tep_handle *pevent,int cpus) { -if (pevent) +if (pevent) pevent->cpus = cpus; }
@@ -148,7 +204,7 @@*/ int tep_get_long_size (struct tep_handle *pevent) { -if (pevent) +if (pevent)return pevent->long_size;return 0 ; }
@@ -162,7 +218,7 @@*/ void tep_set_long_size (struct tep_handle *pevent,int long_size) { -if (pevent) +if (pevent) pevent->long_size = long_size; }
@@ -175,7 +231,7 @@*/ int tep_get_page_size (struct tep_handle *pevent) { -if (pevent) +if (pevent)return pevent->page_size;return 0 ; }
@@ -189,7 +245,7 @@*/ void tep_set_page_size (struct tep_handle *pevent,int _page_size) { -if (pevent) +if (pevent) pevent->page_size = _page_size; }
@@ -202,7 +258,7 @@*/ int tep_file_bigendian (struct tep_handle *pevent) { -if (pevent) +if (pevent)return pevent->file_bigendian;return 0 ; }
@@ -216,7 +272,7 @@*/ void tep_set_file_bigendian (struct tep_handle *pevent,enum tep_endian endian) { -if (pevent) +if (pevent) pevent->file_bigendian = endian; }
@@ -229,7 +285,7 @@*/ int tep_is_host_bigendian (struct tep_handle *pevent) { -if (pevent) +if (pevent)return pevent->host_bigendian;return 0 ; }
@@ -243,7 +299,7 @@*/ void tep_set_host_bigendian (struct tep_handle *pevent,enum tep_endian endian) { -if (pevent) +if (pevent) pevent->host_bigendian = endian; }
@@ -256,7 +312,7 @@*/ int tep_is_latency_format (struct tep_handle *pevent) { -if (pevent) +if (pevent)return pevent->latency_format;return 0 ; }
@@ -270,6 +326,76 @@*/ void tep_set_latency_format (struct tep_handle *pevent,int lat) { -if (pevent) +if (pevent) pevent->latency_format = lat; } + +/** +* tep_set_parsing_failures - set parsing failures flag +* @tep: a handle to the tep_handle +* @parsing_failures: the new value of the parsing_failures flag +* +* This sets flag "parsing_failures" to the given count +*/ +void tep_set_parsing_failures (struct tep_handle *tep,int parsing_failures) +{ +if (tep) + tep->parsing_failures = parsing_failures; +} + +/** +* tep_get_parsing_failures - get the parsing failures flag +* @tep: a handle to the tep_handle +* +* This returns value of flag "parsing_failures" +* If @tep is NULL, 0 is returned. +*/ +int tep_get_parsing_failures (struct tep_handle *tep) +{ +if (tep) +return tep->parsing_failures; +return 0 ; +} + +/** +* tep_is_old_format - get if an old kernel is used +* @tep: a handle to the tep_handle +* +* This returns 1, if an old kernel is used to generate the tracing events or +* 0 if a new kernel is used. Old kernels did not have header page info. +* If @pevent is NULL, 0 is returned. +*/ +int tep_is_old_format (struct tep_handle *tep) +{ +if (tep) +return tep->old_format; +return 0 ; +} + +/** +* tep_set_print_raw - set a flag to force print in raw format +* @tep: a handle to the tep_handle +* @print_raw: the new value of the print_raw flag +* +* This sets a flag to force print in raw format +*/ +void tep_set_print_raw (struct tep_handle *tep,int print_raw) +{ +if (tep) + tep->print_raw = print_raw; +} + +/** +* tep_set_print_raw - set a flag to test a filter string +* @tep: a handle to the tep_handle +* @test_filters: the new value of the test_filters flag +* +* This sets a flag to fjust test a filter string. If this flag is set, +* when a filter string is added, then it will print the filters strings +* that were created and exit. +*/ +void tep_set_test_filters (struct tep_handle *tep,int test_filters) +{ +if (tep) + tep->test_filters = test_filters; +}