Skip to contentSkip to conversation

tools/perf: Use perf_tool__init() to initialize default values in builtin trace

PATCH Applied Athira Rajeev 2 participants 4 messages Feb 25, 2025 – Feb 27, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/perf: Use perf_tool__init() to initialize default values in builtin trace

Perf trace on perf.data fails as below:

./perf trace record -- sleep 1
./perf trace -i perf.data
perf: Segmentation fault
Segmentation fault (core dumped)

Backtrace pointed to :

	?? ()
	perf_session.process_user_event ()
	reader.read_event ()
	perf_session.process_events ()
	cmd_trace ()
	run_builtin ()
	handle_internal_command ()
	main ()

Further debug pointed that, segmentation fault happens when trying to access id_index. Code snippet:

	case PERF_RECORD_ID_INDEX:
		err = tool->id_index(session, event);

Since 'commit 15d4a6f41d72 ("perf tool: Remove perf_tool__fill_defaults()")', perf_tool__fill_defaults is removed. All tools are initialized using perf_tool__init() prior to use. But in builtin-trace, perf_tool__init is not used and hence the defaults are not initialized. Use perf_tool__init() in perf trace to handle the initialization.

---
 tools/perf/builtin-trace.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/builtin-trace.c +1 -0
index f55a8a6481f2..092c5f6404ba 100644
@@ -4589,6 +4589,7 @@ static int trace__replay(struct trace *trace)
 	struct evsel *evsel;
 	int err = -1;
 
+	perf_tool__init(&trace->tool, /*ordered_events=*/true);
 	trace->tool.sample	  = trace__process_sample;
 	trace->tool.mmap	  = perf_event__process_mmap;
 	trace->tool.mmap2	  = perf_event__process_mmap2;
Signature · 1 line
2.43.5
maintainer
#1 lore raw
Quoted 23 lines · Athira Rajeev

Perf trace on perf.data fails as below:

./perf trace record -- sleep 1
./perf trace -i perf.data
perf: Segmentation fault
Segmentation fault (core dumped)

Backtrace pointed to :

	?? ()
	perf_session.process_user_event ()
	reader.read_event ()
	perf_session.process_events ()
	cmd_trace ()
	run_builtin ()
	handle_internal_command ()
	main ()

Further debug pointed that, segmentation fault happens when trying to access id_index. Code snippet:

	case PERF_RECORD_ID_INDEX:
		err = tool->id_index(session, event);
Quoted 6 lines

Since 'commit 15d4a6f41d72 ("perf tool: Remove perf_tool__fill_defaults()")', perf_tool__fill_defaults is removed. All tools are initialized using perf_tool__init() prior to use. But in builtin-trace, perf_tool__init is not used and hence the defaults are not initialized. Use perf_tool__init() in perf trace to handle the initialization.

Thanks for fixing this. I can reproduce the problem and confirmed this patch fixed it.

Thanks,
Namhyung

Quoted 22 lines
---
 tools/perf/builtin-trace.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/builtin-trace.c +1 -0
index f55a8a6481f2..092c5f6404ba 100644
@@ -4589,6 +4589,7 @@ static int trace__replay(struct trace *trace)
 	struct evsel *evsel;
 	int err = -1;
 
+	perf_tool__init(&trace->tool, /*ordered_events=*/true);
 	trace->tool.sample	  = trace__process_sample;
 	trace->tool.mmap	  = perf_event__process_mmap;
 	trace->tool.mmap2	  = perf_event__process_mmap2;
Signature · 1 line
2.43.5
#2 lore raw
Quoted 35 lines · Namhyung Kim
Quoted 23 lines · Athira Rajeev

Perf trace on perf.data fails as below:

./perf trace record -- sleep 1
./perf trace -i perf.data
perf: Segmentation fault
Segmentation fault (core dumped)

Backtrace pointed to :
?? ()
perf_session.process_user_event ()
reader.read_event ()
perf_session.process_events ()
cmd_trace ()
run_builtin ()
handle_internal_command ()
main ()

Further debug pointed that, segmentation fault happens when trying to access id_index. Code snippet:

case PERF_RECORD_ID_INDEX:
err = tool->id_index(session, event);

Quoted 6 lines

Since 'commit 15d4a6f41d72 ("perf tool: Remove perf_tool__fill_defaults()")', perf_tool__fill_defaults is removed. All tools are initialized using perf_tool__init() prior to use. But in builtin-trace, perf_tool__init is not used and hence the defaults are not initialized. Use perf_tool__init() in perf trace to handle the initialization.

Quoted 5 lines

Thanks for fixing this. I can reproduce the problem and confirmed this patch fixed it.

Thanks,
Namhyung

Thanks Namhyung for checking the patch

Athira

Quoted 22 lines
Quoted 22 lines

---
tools/perf/builtin-trace.c | 1 +

1 file changed, 1 insertion(+)
tools/perf/builtin-trace.c +1 -0
index f55a8a6481f2..092c5f6404ba 100644
@@ -4589,6 +4589,7 @@ static int trace__replay(struct trace *trace)
 struct evsel *evsel;
 int err = -1;
 
+ perf_tool__init(&trace->tool, /*ordered_events=*/true);
 trace->tool.sample   = trace__process_sample;
 trace->tool.mmap   = perf_event__process_mmap;
 trace->tool.mmap2   = perf_event__process_mmap2;
Signature · 1 line
2.43.5
maintainer Applied
#3 lore raw
In reply to Athira Rajeev
Quoted 8 lines · Athira Rajeev

Perf trace on perf.data fails as below:

./perf trace record -- sleep 1
./perf trace -i perf.data
perf: Segmentation fault
Segmentation fault (core dumped)

[...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung