aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-09-18 10:13:15 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-09-24 11:26:31 -0400
commit2b29175d2b212d88f100c8819aaea097be61e062 (patch)
treec24d3e7c849bc5cb2a8ad06924ab3c1e235dd56b /tools/lib
parenta6d2a61ac653a85718aa61000d2648803f211ba3 (diff)
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 <rostedt@goodmis.org> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Steven Rostedt <rostedt@goodmis.org> Link: http://lkml.kernel.org/n/tip-lge0afl47arh86om0m6a5bqr@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/traceevent/event-parse.c96
-rw-r--r--tools/lib/traceevent/event-parse.h3
2 files changed, 75 insertions, 24 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index b3bc13079c44..1fa71caf295a 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -4794,8 +4794,7 @@ static int find_event_handle(struct pevent *pevent, struct event_format *event)
4794} 4794}
4795 4795
4796/** 4796/**
4797 * pevent_parse_event - parse the event format 4797 * __pevent_parse_format - parse the event format
4798 * @pevent: the handle to the pevent
4799 * @buf: the buffer storing the event format string 4798 * @buf: the buffer storing the event format string
4800 * @size: the size of @buf 4799 * @size: the size of @buf
4801 * @sys: the system the event belongs to 4800 * @sys: the system the event belongs to
@@ -4807,15 +4806,16 @@ static int find_event_handle(struct pevent *pevent, struct event_format *event)
4807 * 4806 *
4808 * /sys/kernel/debug/tracing/events/.../.../format 4807 * /sys/kernel/debug/tracing/events/.../.../format
4809 */ 4808 */
4810enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf, 4809enum pevent_errno __pevent_parse_format(struct event_format **eventp,
4811 unsigned long size, const char *sys) 4810 struct pevent *pevent, const char *buf,
4811 unsigned long size, const char *sys)
4812{ 4812{
4813 struct event_format *event; 4813 struct event_format *event;
4814 int ret; 4814 int ret;
4815 4815
4816 init_input_buf(buf, size); 4816 init_input_buf(buf, size);
4817 4817
4818 event = alloc_event(); 4818 *eventp = event = alloc_event();
4819 if (!event) 4819 if (!event)
4820 return PEVENT_ERRNO__MEM_ALLOC_FAILED; 4820 return PEVENT_ERRNO__MEM_ALLOC_FAILED;
4821 4821
@@ -4849,9 +4849,6 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
4849 goto event_alloc_failed; 4849 goto event_alloc_failed;
4850 } 4850 }
4851 4851
4852 /* Add pevent to event so that it can be referenced */
4853 event->pevent = pevent;
4854
4855 ret = event_read_format(event); 4852 ret = event_read_format(event);
4856 if (ret < 0) { 4853 if (ret < 0) {
4857 ret = PEVENT_ERRNO__READ_FORMAT_FAILED; 4854 ret = PEVENT_ERRNO__READ_FORMAT_FAILED;
@@ -4862,19 +4859,16 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
4862 * If the event has an override, don't print warnings if the event 4859 * If the event has an override, don't print warnings if the event
4863 * print format fails to parse. 4860 * print format fails to parse.
4864 */ 4861 */
4865 if (find_event_handle(pevent, event)) 4862 if (pevent && find_event_handle(pevent, event))
4866 show_warning = 0; 4863 show_warning = 0;
4867 4864
4868 ret = event_read_print(event); 4865 ret = event_read_print(event);
4866 show_warning = 1;
4867
4869 if (ret < 0) { 4868 if (ret < 0) {
4870 show_warning = 1;
4871 ret = PEVENT_ERRNO__READ_PRINT_FAILED; 4869 ret = PEVENT_ERRNO__READ_PRINT_FAILED;
4872 goto event_parse_failed; 4870 goto event_parse_failed;
4873 } 4871 }
4874 show_warning = 1;
4875
4876 if (add_event(pevent, event))
4877 goto event_alloc_failed;
4878 4872
4879 if (!ret && (event->flags & EVENT_FL_ISFTRACE)) { 4873 if (!ret && (event->flags & EVENT_FL_ISFTRACE)) {
4880 struct format_field *field; 4874 struct format_field *field;
@@ -4898,24 +4892,78 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
4898 return 0; 4892 return 0;
4899 } 4893 }
4900 4894
4901#define PRINT_ARGS 0
4902 if (PRINT_ARGS && event->print_fmt.args)
4903 print_args(event->print_fmt.args);
4904
4905 return 0; 4895 return 0;
4906 4896
4907 event_parse_failed: 4897 event_parse_failed:
4908 event->flags |= EVENT_FL_FAILED; 4898 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
4913 return ret; 4899 return ret;
4914 4900
4915 event_alloc_failed: 4901 event_alloc_failed:
4916 free(event->system); 4902 free(event->system);
4917 free(event->name); 4903 free(event->name);
4918 free(event); 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 */
4922enum 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 */
4942enum 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
4963event_add_failed:
4964 free(event->system);
4965 free(event->name);
4966 free(event);
4919 return ret; 4967 return ret;
4920} 4968}
4921 4969
@@ -5365,7 +5413,7 @@ static void free_formats(struct format *format)
5365 free_format_fields(format->fields); 5413 free_format_fields(format->fields);
5366} 5414}
5367 5415
5368static void free_event(struct event_format *event) 5416void pevent_free_format(struct event_format *event)
5369{ 5417{
5370 free(event->name); 5418 free(event->name);
5371 free(event->system); 5419 free(event->system);
@@ -5451,7 +5499,7 @@ void pevent_free(struct pevent *pevent)
5451 } 5499 }
5452 5500
5453 for (i = 0; i < pevent->nr_events; i++) 5501 for (i = 0; i < pevent->nr_events; i++)
5454 free_event(pevent->events[i]); 5502 pevent_free_format(pevent->events[i]);
5455 5503
5456 while (pevent->handlers) { 5504 while (pevent->handlers) {
5457 handle = pevent->handlers; 5505 handle = pevent->handlers;
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index a4bbe2437925..24a4bbabc5d5 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -540,6 +540,9 @@ int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long siz
540 540
541enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf, 541enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
542 unsigned long size, const char *sys); 542 unsigned long size, const char *sys);
543enum pevent_errno pevent_parse_format(struct event_format **eventp, const char *buf,
544 unsigned long size, const char *sys);
545void pevent_free_format(struct event_format *event);
543 546
544void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event, 547void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
545 const char *name, struct pevent_record *record, 548 const char *name, struct pevent_record *record,