Skip to content

Commit 2b29175

Browse files
committed
tools lib traceevent: Carve out events format parsing routine
The pevent_parse_event() routine will parse a events/sys/tp/format file and add an event_format instance to the pevent struct. This patch introduces a pevent_parse_format() routine with just the bits needed to parse the event/sys/tp/format file and just return the event_format instance, useful for when all we want is to parse the format file, without requiring the pevent struct. Acked-by: Steven Rostedt <[email protected]> Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Steven Rostedt <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent a6d2a61 commit 2b29175

File tree

2 files changed

+75
-24
lines changed

2 files changed

+75
-24
lines changed

tools/lib/traceevent/event-parse.c

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4794,8 +4794,7 @@ static int find_event_handle(struct pevent *pevent, struct event_format *event)
47944794
}
47954795

47964796
/**
4797-
* pevent_parse_event - parse the event format
4798-
* @pevent: the handle to the pevent
4797+
* __pevent_parse_format - parse the event format
47994798
* @buf: the buffer storing the event format string
48004799
* @size: the size of @buf
48014800
* @sys: the system the event belongs to
@@ -4807,15 +4806,16 @@ static int find_event_handle(struct pevent *pevent, struct event_format *event)
48074806
*
48084807
* /sys/kernel/debug/tracing/events/.../.../format
48094808
*/
4810-
enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
4811-
unsigned long size, const char *sys)
4809+
enum pevent_errno __pevent_parse_format(struct event_format **eventp,
4810+
struct pevent *pevent, const char *buf,
4811+
unsigned long size, const char *sys)
48124812
{
48134813
struct event_format *event;
48144814
int ret;
48154815

48164816
init_input_buf(buf, size);
48174817

4818-
event = alloc_event();
4818+
*eventp = event = alloc_event();
48194819
if (!event)
48204820
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
48214821

@@ -4849,9 +4849,6 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
48494849
goto event_alloc_failed;
48504850
}
48514851

4852-
/* Add pevent to event so that it can be referenced */
4853-
event->pevent = pevent;
4854-
48554852
ret = event_read_format(event);
48564853
if (ret < 0) {
48574854
ret = PEVENT_ERRNO__READ_FORMAT_FAILED;
@@ -4862,19 +4859,16 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
48624859
* If the event has an override, don't print warnings if the event
48634860
* print format fails to parse.
48644861
*/
4865-
if (find_event_handle(pevent, event))
4862+
if (pevent && find_event_handle(pevent, event))
48664863
show_warning = 0;
48674864

48684865
ret = event_read_print(event);
4866+
show_warning = 1;
4867+
48694868
if (ret < 0) {
4870-
show_warning = 1;
48714869
ret = PEVENT_ERRNO__READ_PRINT_FAILED;
48724870
goto event_parse_failed;
48734871
}
4874-
show_warning = 1;
4875-
4876-
if (add_event(pevent, event))
4877-
goto event_alloc_failed;
48784872

48794873
if (!ret && (event->flags & EVENT_FL_ISFTRACE)) {
48804874
struct format_field *field;
@@ -4898,21 +4892,75 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
48984892
return 0;
48994893
}
49004894

4901-
#define PRINT_ARGS 0
4902-
if (PRINT_ARGS && event->print_fmt.args)
4903-
print_args(event->print_fmt.args);
4904-
49054895
return 0;
49064896

49074897
event_parse_failed:
49084898
event->flags |= EVENT_FL_FAILED;
4909-
/* still add it even if it failed */
4910-
if (add_event(pevent, event))
4911-
goto event_alloc_failed;
4912-
49134899
return ret;
49144900

49154901
event_alloc_failed:
4902+
free(event->system);
4903+
free(event->name);
4904+
free(event);
4905+
*eventp = NULL;
4906+
return ret;
4907+
}
4908+
4909+
/**
4910+
* pevent_parse_format - parse the event format
4911+
* @buf: the buffer storing the event format string
4912+
* @size: the size of @buf
4913+
* @sys: the system the event belongs to
4914+
*
4915+
* This parses the event format and creates an event structure
4916+
* to quickly parse raw data for a given event.
4917+
*
4918+
* These files currently come from:
4919+
*
4920+
* /sys/kernel/debug/tracing/events/.../.../format
4921+
*/
4922+
enum pevent_errno pevent_parse_format(struct event_format **eventp, const char *buf,
4923+
unsigned long size, const char *sys)
4924+
{
4925+
return __pevent_parse_format(eventp, NULL, buf, size, sys);
4926+
}
4927+
4928+
/**
4929+
* pevent_parse_event - parse the event format
4930+
* @pevent: the handle to the pevent
4931+
* @buf: the buffer storing the event format string
4932+
* @size: the size of @buf
4933+
* @sys: the system the event belongs to
4934+
*
4935+
* This parses the event format and creates an event structure
4936+
* to quickly parse raw data for a given event.
4937+
*
4938+
* These files currently come from:
4939+
*
4940+
* /sys/kernel/debug/tracing/events/.../.../format
4941+
*/
4942+
enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
4943+
unsigned long size, const char *sys)
4944+
{
4945+
struct event_format *event = NULL;
4946+
int ret = __pevent_parse_format(&event, pevent, buf, size, sys);
4947+
4948+
if (event == NULL)
4949+
return ret;
4950+
4951+
/* Add pevent to event so that it can be referenced */
4952+
event->pevent = pevent;
4953+
4954+
if (add_event(pevent, event))
4955+
goto event_add_failed;
4956+
4957+
#define PRINT_ARGS 0
4958+
if (PRINT_ARGS && event->print_fmt.args)
4959+
print_args(event->print_fmt.args);
4960+
4961+
return 0;
4962+
4963+
event_add_failed:
49164964
free(event->system);
49174965
free(event->name);
49184966
free(event);
@@ -5365,7 +5413,7 @@ static void free_formats(struct format *format)
53655413
free_format_fields(format->fields);
53665414
}
53675415

5368-
static void free_event(struct event_format *event)
5416+
void pevent_free_format(struct event_format *event)
53695417
{
53705418
free(event->name);
53715419
free(event->system);
@@ -5451,7 +5499,7 @@ void pevent_free(struct pevent *pevent)
54515499
}
54525500

54535501
for (i = 0; i < pevent->nr_events; i++)
5454-
free_event(pevent->events[i]);
5502+
pevent_free_format(pevent->events[i]);
54555503

54565504
while (pevent->handlers) {
54575505
handle = pevent->handlers;

tools/lib/traceevent/event-parse.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long siz
540540

541541
enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
542542
unsigned long size, const char *sys);
543+
enum pevent_errno pevent_parse_format(struct event_format **eventp, const char *buf,
544+
unsigned long size, const char *sys);
545+
void pevent_free_format(struct event_format *event);
543546

544547
void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
545548
const char *name, struct pevent_record *record,

0 commit comments

Comments
 (0)