aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTzvetomir Stoyanov <tstoyanov@vmware.com>2019-04-01 12:43:12 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-04-01 14:18:09 -0400
commit80c5526c8544ae76cba31fb9702ab8accac1f0f3 (patch)
tree4f27eb1dc3c529ad365b0b0c82ff6008c58eab09
parentd5d2d05bd5b02efa8545a3323a60465de9efb21e (diff)
tools lib traceevent: Implement new traceevent APIs for accessing struct tep_handler fields
As struct tep_handler definition is not exposed as part of libtraceevent API, its fields cannot be accessed directly by the library users. This patch implements new APIs, which can be used to access the struct tep_handler fields: tep_get_event() - retrieves an event pointer at a specific index tep_get_first_event() - is modified to use tep_get_event() tep_clear_flag() - clears a tep handle flag tep_test_flag() - test if a given flag is set tep_get_header_timestamp_size() - returns the size of the timestamp stored in the header. tep_get_cpus() - returns the number of CPUs tep_is_old_format() - returns true if data was created by an older kernel with the old data format tep_set_print_raw() - have the output print in the raw format tep_set_test_filters() - debugging utility for testing tep filters Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Link: http://lore.kernel.org/linux-trace-devel/20190325145017.30246-4-tstoyanov@vmware.com Link: http://lkml.kernel.org/r/20190401164343.679629539@goodmis.org [ Renamed some newly added "pevent" to "tep" ] Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/lib/traceevent/event-parse-api.c106
-rw-r--r--tools/lib/traceevent/event-parse.h6
2 files changed, 108 insertions, 4 deletions
diff --git a/tools/lib/traceevent/event-parse-api.c b/tools/lib/traceevent/event-parse-api.c
index 3716a9142aef..2ac8b44854ce 100644
--- a/tools/lib/traceevent/event-parse-api.c
+++ b/tools/lib/traceevent/event-parse-api.c
@@ -9,6 +9,22 @@
9#include "event-utils.h" 9#include "event-utils.h"
10 10
11/** 11/**
12 * tep_get_event - returns the event with the given index
13 * @tep: a handle to the tep_handle
14 * @index: index of the requested event, in the range 0 .. nr_events
15 *
16 * This returns pointer to the element of the events array with the given index
17 * If @tep is NULL, or @index is not in the range 0 .. nr_events, NULL is returned.
18 */
19struct tep_event *tep_get_event(struct tep_handle *tep, int index)
20{
21 if (tep && tep->events && index < tep->nr_events)
22 return tep->events[index];
23
24 return NULL;
25}
26
27/**
12 * tep_get_first_event - returns the first event in the events array 28 * tep_get_first_event - returns the first event in the events array
13 * @tep: a handle to the tep_handle 29 * @tep: a handle to the tep_handle
14 * 30 *
@@ -17,10 +33,7 @@
17 */ 33 */
18struct tep_event *tep_get_first_event(struct tep_handle *tep) 34struct tep_event *tep_get_first_event(struct tep_handle *tep)
19{ 35{
20 if (tep && tep->events) 36 return tep_get_event(tep, 0);
21 return tep->events[0];
22
23 return NULL;
24} 37}
25 38
26/** 39/**
@@ -51,6 +64,34 @@ void tep_set_flag(struct tep_handle *tep, int flag)
51 tep->flags |= flag; 64 tep->flags |= flag;
52} 65}
53 66
67/**
68 * tep_clear_flag - clear event parser flag
69 * @tep: a handle to the tep_handle
70 * @flag: flag to be cleared
71 *
72 * This clears a tep flag
73 */
74void tep_clear_flag(struct tep_handle *tep, enum tep_flag flag)
75{
76 if (tep)
77 tep->flags &= ~flag;
78}
79
80/**
81 * tep_test_flag - check the state of event parser flag
82 * @tep: a handle to the tep_handle
83 * @flag: flag to be checked
84 *
85 * This returns the state of the requested tep flag.
86 * Returns: true if the flag is set, false otherwise.
87 */
88bool tep_test_flag(struct tep_handle *tep, enum tep_flag flag)
89{
90 if (tep)
91 return (tep->flags & flag);
92 return false;
93}
94
54unsigned short tep_data2host2(struct tep_handle *pevent, unsigned short data) 95unsigned short tep_data2host2(struct tep_handle *pevent, unsigned short data)
55{ 96{
56 unsigned short swap; 97 unsigned short swap;
@@ -114,6 +155,20 @@ int tep_get_header_page_size(struct tep_handle *pevent)
114} 155}
115 156
116/** 157/**
158 * tep_get_header_timestamp_size - get size of the time stamp in the header page
159 * @tep: a handle to the tep_handle
160 *
161 * This returns size of the time stamp in the header page
162 * If @tep is NULL, 0 is returned.
163 */
164int tep_get_header_timestamp_size(struct tep_handle *tep)
165{
166 if (tep)
167 return tep->header_page_ts_size;
168 return 0;
169}
170
171/**
117 * tep_get_cpus - get the number of CPUs 172 * tep_get_cpus - get the number of CPUs
118 * @pevent: a handle to the tep_handle 173 * @pevent: a handle to the tep_handle
119 * 174 *
@@ -273,3 +328,46 @@ void tep_set_latency_format(struct tep_handle *pevent, int lat)
273 if (pevent) 328 if (pevent)
274 pevent->latency_format = lat; 329 pevent->latency_format = lat;
275} 330}
331
332/**
333 * tep_is_old_format - get if an old kernel is used
334 * @tep: a handle to the tep_handle
335 *
336 * This returns true, if an old kernel is used to generate the tracing events or
337 * false if a new kernel is used. Old kernels did not have header page info.
338 * If @tep is NULL, false is returned.
339 */
340bool tep_is_old_format(struct tep_handle *tep)
341{
342 if (tep)
343 return !!(tep->old_format);
344 return false;
345}
346
347/**
348 * tep_set_print_raw - set a flag to force print in raw format
349 * @tep: a handle to the tep_handle
350 * @print_raw: the new value of the print_raw flag
351 *
352 * This sets a flag to force print in raw format
353 */
354void tep_set_print_raw(struct tep_handle *tep, int print_raw)
355{
356 if (tep)
357 tep->print_raw = print_raw;
358}
359
360/**
361 * tep_set_test_filters - set a flag to test a filter string
362 * @tep: a handle to the tep_handle
363 * @test_filters: the new value of the test_filters flag
364 *
365 * This sets a flag to test a filter string. If this flag is set, when
366 * tep_filter_add_filter_str() API as called,it will print the filter string
367 * instead of adding it.
368 */
369void tep_set_test_filters(struct tep_handle *tep, int test_filters)
370{
371 if (tep)
372 tep->test_filters = test_filters;
373}
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 41159358abc2..be082f9692f1 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -409,6 +409,8 @@ void tep_print_plugins(struct trace_seq *s,
409typedef char *(tep_func_resolver_t)(void *priv, 409typedef char *(tep_func_resolver_t)(void *priv,
410 unsigned long long *addrp, char **modp); 410 unsigned long long *addrp, char **modp);
411void tep_set_flag(struct tep_handle *tep, int flag); 411void tep_set_flag(struct tep_handle *tep, int flag);
412void tep_clear_flag(struct tep_handle *tep, enum tep_flag flag);
413bool tep_check_flags(struct tep_handle *tep, enum tep_flag flags);
412 414
413static inline int tep_host_bigendian(void) 415static inline int tep_host_bigendian(void)
414{ 416{
@@ -568,6 +570,10 @@ void tep_set_host_bigendian(struct tep_handle *pevent, enum tep_endian endian);
568int tep_is_latency_format(struct tep_handle *pevent); 570int tep_is_latency_format(struct tep_handle *pevent);
569void tep_set_latency_format(struct tep_handle *pevent, int lat); 571void tep_set_latency_format(struct tep_handle *pevent, int lat);
570int tep_get_header_page_size(struct tep_handle *pevent); 572int tep_get_header_page_size(struct tep_handle *pevent);
573int tep_get_header_timestamp_size(struct tep_handle *tep);
574bool tep_is_old_format(struct tep_handle *tep);
575void tep_set_print_raw(struct tep_handle *tep, int print_raw);
576void tep_set_test_filters(struct tep_handle *tep, int test_filters);
571 577
572struct tep_handle *tep_alloc(void); 578struct tep_handle *tep_alloc(void);
573void tep_free(struct tep_handle *pevent); 579void tep_free(struct tep_handle *pevent);