perf: Remove trace_find_next_event()
cover perf: Remove trace_find_next_event()
The trace_find_next_event() is buggy and useless. Open code the current users (it's not much work), and nuke the function.
Steven Rostedt (VMware) (2):
perf: Iterate on tep event arrays directly
perf: Remove unused trace_find_next_event()
----
.../perf/util/scripting-engines/trace-event-perl.c | 8 ++++-- .../util/scripting-engines/trace-event-python.c | 9 +++++-- tools/perf/util/trace-event-parse.c | 31 ---------------------- tools/perf/util/trace-event.h | 2 -- 4 files changed, 13 insertions(+), 37 deletions(-)
PATCH 1/2 perf: Iterate on tep event arrays directly
From: "Steven Rostedt (VMware)" <[email protected]>
Instead of calling a useless (and broken) helper function to get the next event of a tep event array, just get the array directly and iterate over it.
Note, the broken part was from trace_find_next_event() which after this will no longer be used, and can be removed.
--- tools/perf/util/scripting-engines/trace-event-perl.c | 8 ++++++-- tools/perf/util/scripting-engines/trace-event-python.c | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-)
tools/perf/util/scripting-engines/trace-event-perl.c +6 -2
@@ -539,10 +539,11 @@ static int perl_stop_script(void)static int perl_generate_script (struct tep_handle *pevent,const char *outfile) { +int i, not_first, count, nr_events; +struct tep_event **all_events;struct tep_event *event =NULL ;struct tep_format_field *f;char fname[PATH_MAX ]; -int not_first, count;FILE *ofp;sprintf (fname,"%s.pl" , outfile);
@@ -603,8 +604,11 @@ sub print_backtrace\n\ }\n\n\ "); + nr_events =tep_get_events_count (pevent); + all_events =tep_list_events (pevent,TEP_EVENT_SORT_ID ); -while ((event =trace_find_next_event (pevent, event))) { +for (i =0 ; all_events && i < nr_events; i++) { + event = all_events[i];fprintf (ofp,"sub %s::%s\n{\n" , event->system, event->name);fprintf (ofp,"\tmy (" );
tools/perf/util/scripting-engines/trace-event-python.c +7 -2
@@ -1687,10 +1687,11 @@ static int python_stop_script(void)static int python_generate_script (struct tep_handle *pevent,const char *outfile) { +int i, not_first, count, nr_events; +struct tep_event **all_events;struct tep_event *event =NULL ;struct tep_format_field *f;char fname[PATH_MAX ]; -int not_first, count;FILE *ofp;sprintf (fname,"%s.py" , outfile);
@@ -1735,7 +1736,11 @@ static int python_generate_script(struct tep_handle *pevent, const char *outfilefprintf (ofp,"def trace_end():\n" );fprintf (ofp,"\tprint(\"in trace_end\")\n\n" ); -while ((event =trace_find_next_event (pevent, event))) { + nr_events =tep_get_events_count (pevent); + all_events =tep_list_events (pevent,TEP_EVENT_SORT_ID ); + +for (i =0 ; all_events && i < nr_events; i++) { + event = all_events[i];fprintf (ofp,"def %s__%s(" , event->system, event->name);fprintf (ofp,"event_name, " );fprintf (ofp,"context, " );
Signature · 1 line
2.23.0
Re: [PATCH 1/2] perf: Iterate on tep event arrays directly
Em Thu, Oct 17, 2019 at 05:05:22PM -0400, Steven Rostedt escreveu:
Quoted 9 lines
From: "Steven Rostedt (VMware)" <[email protected]>
Instead of calling a useless (and broken) helper function to get the next event of a tep event array, just get the array directly and iterate over it.
Note, the broken part was from
trace_find_next_event()which after this will no longer be used, and can be removed.
I'll add a:
As this is when this problem starts causing the segfault when generating python scripts from perf.data files with multiple tracepoint events, ok?
- Arnaldo
Quoted 71 lines
Reported-by Daniel Bristot de Oliveira <[email protected]>Signed-off-by Steven Rostedt (VMware) <[email protected]>--- tools/perf/util/scripting-engines/trace-event-perl.c | 8 ++++++-- tools/perf/util/scripting-engines/trace-event-python.c | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-)tools/perf/util/scripting-engines/trace-event-perl.c +6
-2@@ -539,10 +539,11 @@ static int perl_stop_script(void)static int perl_generate_script (struct tep_handle *pevent,const char *outfile) { +int i, not_first, count, nr_events; +struct tep_event **all_events;struct tep_event *event =NULL ;struct tep_format_field *f;char fname[PATH_MAX ]; -int not_first, count;FILE *ofp;sprintf (fname,"%s.pl" , outfile);@@ -603,8 +604,11 @@ sub print_backtrace\n\ }\n\n\ "); + nr_events =tep_get_events_count (pevent); + all_events =tep_list_events (pevent,TEP_EVENT_SORT_ID ); -while ((event =trace_find_next_event (pevent, event))) { +for (i =0 ; all_events && i < nr_events; i++) { + event = all_events[i];fprintf (ofp,"sub %s::%s\n{\n" , event->system, event->name);fprintf (ofp,"\tmy (" );tools/perf/util/scripting-engines/trace-event-python.c +7
-2@@ -1687,10 +1687,11 @@ static int python_stop_script(void)static int python_generate_script (struct tep_handle *pevent,const char *outfile) { +int i, not_first, count, nr_events; +struct tep_event **all_events;struct tep_event *event =NULL ;struct tep_format_field *f;char fname[PATH_MAX ]; -int not_first, count;FILE *ofp;sprintf (fname,"%s.py" , outfile);@@ -1735,7 +1736,11 @@ static int python_generate_script(struct tep_handle *pevent, const char *outfilefprintf (ofp,"def trace_end():\n" );fprintf (ofp,"\tprint(\"in trace_end\")\n\n" ); -while ((event =trace_find_next_event (pevent, event))) { + nr_events =tep_get_events_count (pevent); + all_events =tep_list_events (pevent,TEP_EVENT_SORT_ID ); + +for (i =0 ; all_events && i < nr_events; i++) { + event = all_events[i];fprintf (ofp,"def %s__%s(" , event->system, event->name);fprintf (ofp,"event_name, " );fprintf (ofp,"context, " );Signature · 1 line
2.23.0
Signature · 1 line
- Arnaldo
Re: [PATCH 1/2] perf: Iterate on tep event arrays directly
Quoted 7 lines · On Thu, 17 Oct 2019 18:24:31 -0300 Arnaldo Carvalho de Melo…
I'll add a:
Fixes bb3dd7e7c4d5 ("tools lib traceevent, perf tools: Move struct tep_handler definition in a local header file")Cc [email protected] : v4.20+As this is when this problem starts causing the segfault when generating python scripts from perf.data files with multiple tracepoint events, ok?
Sure, go ahead. I realized I forgot to add a Fixes tag when sending it.
-- Steve
Re: [PATCH 1/2] perf: Iterate on tep event arrays directly
Em Thu, Oct 17, 2019 at 05:28:23PM -0400, Steven Rostedt escreveu:
Quoted 5 lines
Quoted 2 lines · On Thu, 17 Oct 2019 18:24:31 -0300 Arnaldo Carvalho de Melo…
I'll add a:
Quoted 7 lines
Quoted 5 lines
Fixes bb3dd7e7c4d5 ("tools lib traceevent, perf tools: Move struct tep_handler definition in a local header file")Cc [email protected] : v4.20+As this is when this problem starts causing the segfault when generating python scripts from perf.data files with multiple tracepoint events, ok?
Sure, go ahead. I realized I forgot to add a Fixes tag when sending it.
np, I added it, thanks for the prompt fix!
- Arnaldo
PATCH 2/2 perf: Remove unused trace_find_next_event()
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
trace_find_next_event() was buggy and pretty much a useless helper. As there are no more users, just remove it.
--- tools/perf/util/trace-event-parse.c | 31 ----------------------------- tools/perf/util/trace-event.h | 2 -- 2 files changed, 33 deletions(-)
tools/perf/util/trace-event-parse.c +0 -31
@@ -173,37 +173,6 @@ int parse_event_file(struct tep_handle *pevent,return tep_parse_event (pevent, buf, size, sys); } -struct tep_event *trace_find_next_event (struct tep_handle *pevent, -struct tep_event *event) -{ -static int idx; -int events_count; -struct tep_event *all_events; - - all_events =tep_get_first_event (pevent); - events_count =tep_get_events_count (pevent); -if (!pevent || !all_events || events_count <1 ) -return NULL ; - -if (!event) { - idx =0 ; -return all_events; - } - -if (idx < events_count && event == (all_events + idx)) { - idx++; -if (idx == events_count) -return NULL ; -return (all_events + idx); - } - -for (idx =1 ; idx < events_count; idx++) { -if (event == (all_events + (idx -1 ))) -return (all_events + idx); - } -return NULL ; -} -struct flag {const char *name;unsigned long long value;
tools/perf/util/trace-event.h +0 -2
@@ -47,8 +47,6 @@ 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 *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);
Signature · 1 line
2.23.0
[tip: perf/core] perf tools: Remove unused trace_find_next_event()
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 9bdff5b6436655d42dd30253c521e86ce07b9961 Gitweb: https://git.kernel.org/tip/9bdff5b6436655d42dd30253c521e86ce07b9961 Author: Steven Rostedt (VMware) <[email protected]> AuthorDate: Thu, 17 Oct 2019 17:05:23 -04:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Fri, 18 Oct 2019 12:07:46 -03:00
perf tools: Remove unused trace_find_next_event()
trace_find_next_event() was buggy and pretty much a useless helper. As there are no more users, just remove it.
--- tools/perf/util/trace-event-parse.c | 31 +---------------------------- tools/perf/util/trace-event.h | 2 +-- 2 files changed, 33 deletions(-)
tools/perf/util/trace-event-parse.c +0 -31
@@ -173,37 +173,6 @@ int parse_event_file(struct tep_handle *pevent,return tep_parse_event (pevent, buf, size, sys); } -struct tep_event *trace_find_next_event (struct tep_handle *pevent, -struct tep_event *event) -{ -static int idx; -int events_count; -struct tep_event *all_events; - - all_events =tep_get_first_event (pevent); - events_count =tep_get_events_count (pevent); -if (!pevent || !all_events || events_count <1 ) -return NULL ; - -if (!event) { - idx =0 ; -return all_events; - } - -if (idx < events_count && event == (all_events + idx)) { - idx++; -if (idx == events_count) -return NULL ; -return (all_events + idx); - } - -for (idx =1 ; idx < events_count; idx++) { -if (event == (all_events + (idx -1 ))) -return (all_events + idx); - } -return NULL ; -} -struct flag {const char *name;unsigned long long value;
tools/perf/util/trace-event.h +0 -2
@@ -47,8 +47,6 @@ 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 *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);
[tip: perf/urgent] perf tools: Remove unused trace_find_next_event()
In reply to Steven RostedtThe following commit has been merged into the perf/urgent branch of tip:
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: 6047e1a81e9fe9851ed37e13c2438312c04435d9 Gitweb: https://git.kernel.org/tip/6047e1a81e9fe9851ed37e13c2438312c04435d9 Author: Steven Rostedt (VMware) <[email protected]> AuthorDate: Thu, 17 Oct 2019 17:05:23 -04:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 Nov 2019 08:39:27 -03:00
perf tools: Remove unused trace_find_next_event()
trace_find_next_event() was buggy and pretty much a useless helper. As there are no more users, just remove it.
--- tools/perf/util/trace-event-parse.c | 31 +---------------------------- tools/perf/util/trace-event.h | 2 +-- 2 files changed, 33 deletions(-)
tools/perf/util/trace-event-parse.c +0 -31
@@ -173,37 +173,6 @@ int parse_event_file(struct tep_handle *pevent,return tep_parse_event (pevent, buf, size, sys); } -struct tep_event *trace_find_next_event (struct tep_handle *pevent, -struct tep_event *event) -{ -static int idx; -int events_count; -struct tep_event *all_events; - - all_events =tep_get_first_event (pevent); - events_count =tep_get_events_count (pevent); -if (!pevent || !all_events || events_count <1 ) -return NULL ; - -if (!event) { - idx =0 ; -return all_events; - } - -if (idx < events_count && event == (all_events + idx)) { - idx++; -if (idx == events_count) -return NULL ; -return (all_events + idx); - } - -for (idx =1 ; idx < events_count; idx++) { -if (event == (all_events + (idx -1 ))) -return (all_events + idx); - } -return NULL ; -} -struct flag {const char *name;unsigned long long value;
tools/perf/util/trace-event.h +0 -2
@@ -47,8 +47,6 @@ 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 *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);