Skip to content

Commit 443b063

Browse files
rostedtacmel
authored andcommitted
perf scripting engines: Iterate on tep event arrays directly
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. Committer notes: This fixes a segfault when generating python scripts from perf.data files with multiple tracepoint events, i.e. the following use case is fixed by this patch: # perf record -e sched:* sleep 1 [ perf record: Woken up 31 times to write data ] [ perf record: Captured and wrote 0.031 MB perf.data (9 samples) ] # perf script -g python Segmentation fault (core dumped) # Reported-by: Daniel Bristot de Oliveira <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Tzvetomir Stoyanov <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 652521d commit 443b063

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

tools/perf/util/scripting-engines/trace-event-perl.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,11 @@ static int perl_stop_script(void)
539539

540540
static int perl_generate_script(struct tep_handle *pevent, const char *outfile)
541541
{
542+
int i, not_first, count, nr_events;
543+
struct tep_event **all_events;
542544
struct tep_event *event = NULL;
543545
struct tep_format_field *f;
544546
char fname[PATH_MAX];
545-
int not_first, count;
546547
FILE *ofp;
547548

548549
sprintf(fname, "%s.pl", outfile);
@@ -603,8 +604,11 @@ sub print_backtrace\n\
603604
}\n\n\
604605
");
605606

607+
nr_events = tep_get_events_count(pevent);
608+
all_events = tep_list_events(pevent, TEP_EVENT_SORT_ID);
606609

607-
while ((event = trace_find_next_event(pevent, event))) {
610+
for (i = 0; all_events && i < nr_events; i++) {
611+
event = all_events[i];
608612
fprintf(ofp, "sub %s::%s\n{\n", event->system, event->name);
609613
fprintf(ofp, "\tmy (");
610614

tools/perf/util/scripting-engines/trace-event-python.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,10 +1687,11 @@ static int python_stop_script(void)
16871687

16881688
static int python_generate_script(struct tep_handle *pevent, const char *outfile)
16891689
{
1690+
int i, not_first, count, nr_events;
1691+
struct tep_event **all_events;
16901692
struct tep_event *event = NULL;
16911693
struct tep_format_field *f;
16921694
char fname[PATH_MAX];
1693-
int not_first, count;
16941695
FILE *ofp;
16951696

16961697
sprintf(fname, "%s.py", outfile);
@@ -1735,7 +1736,11 @@ static int python_generate_script(struct tep_handle *pevent, const char *outfile
17351736
fprintf(ofp, "def trace_end():\n");
17361737
fprintf(ofp, "\tprint(\"in trace_end\")\n\n");
17371738

1738-
while ((event = trace_find_next_event(pevent, event))) {
1739+
nr_events = tep_get_events_count(pevent);
1740+
all_events = tep_list_events(pevent, TEP_EVENT_SORT_ID);
1741+
1742+
for (i = 0; all_events && i < nr_events; i++) {
1743+
event = all_events[i];
17391744
fprintf(ofp, "def %s__%s(", event->system, event->name);
17401745
fprintf(ofp, "event_name, ");
17411746
fprintf(ofp, "context, ");

0 commit comments

Comments
 (0)