Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf script: Move script_fetch_insn to trace-event-scripting.c

Add native_arch as a parameter to script_fetch_insn rather than
relying on the builtin-script value that won't be initialized for the
dlfilter and python Context use cases. Assume both of those cases are
running natively.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Veronika Molnarova <vmolnaro@redhat.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Link: https://lore.kernel.org/r/20241119011644.971342-11-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
1ff2ca39 04051b4a

+19 -23
+1 -14
tools/perf/builtin-script.c
··· 1586 1586 return len + dlen; 1587 1587 } 1588 1588 1589 - __weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused, 1590 - struct thread *thread __maybe_unused, 1591 - struct machine *machine __maybe_unused) 1592 - { 1593 - } 1594 - 1595 - void script_fetch_insn(struct perf_sample *sample, struct thread *thread, 1596 - struct machine *machine) 1597 - { 1598 - if (sample->insn_len == 0 && native_arch) 1599 - arch_fetch_insn(sample, thread, machine); 1600 - } 1601 - 1602 1589 static int perf_sample__fprintf_insn(struct perf_sample *sample, 1603 1590 struct evsel *evsel, 1604 1591 struct perf_event_attr *attr, ··· 1595 1608 { 1596 1609 int printed = 0; 1597 1610 1598 - script_fetch_insn(sample, thread, machine); 1611 + script_fetch_insn(sample, thread, machine, native_arch); 1599 1612 1600 1613 if (PRINT_FIELD(INSNLEN)) 1601 1614 printed += fprintf(fp, " ilen: %d", sample->insn_len);
+1 -1
tools/perf/scripts/python/Perf-Trace-Util/Context.c
··· 93 93 if (c->sample->ip && !c->sample->insn_len && thread__maps(c->al->thread)) { 94 94 struct machine *machine = maps__machine(thread__maps(c->al->thread)); 95 95 96 - script_fetch_insn(c->sample, c->al->thread, machine); 96 + script_fetch_insn(c->sample, c->al->thread, machine, /*native_arch=*/true); 97 97 } 98 98 if (!c->sample->insn_len) 99 99 Py_RETURN_NONE; /* N.B. This is a return statement */
+2 -1
tools/perf/util/dlfilter.c
··· 234 234 struct machine *machine = maps__machine(thread__maps(al->thread)); 235 235 236 236 if (machine) 237 - script_fetch_insn(d->sample, al->thread, machine); 237 + script_fetch_insn(d->sample, al->thread, machine, 238 + /*native_arch=*/true); 238 239 } 239 240 } 240 241
-6
tools/perf/util/python.c
··· 1317 1317 return NULL; 1318 1318 } 1319 1319 1320 - void script_fetch_insn(struct perf_sample *sample __maybe_unused, 1321 - struct thread *thread __maybe_unused, 1322 - struct machine *machine __maybe_unused) 1323 - { 1324 - } 1325 - 1326 1320 int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe_unused, 1327 1321 size_t sz __maybe_unused) 1328 1322 {
+14
tools/perf/util/trace-event-scripting.c
··· 13 13 #include <event-parse.h> 14 14 #endif 15 15 16 + #include "archinsn.h" 16 17 #include "debug.h" 17 18 #include "trace-event.h" 18 19 #include "evsel.h" ··· 272 271 } 273 272 #endif 274 273 #endif 274 + 275 + __weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused, 276 + struct thread *thread __maybe_unused, 277 + struct machine *machine __maybe_unused) 278 + { 279 + } 280 + 281 + void script_fetch_insn(struct perf_sample *sample, struct thread *thread, 282 + struct machine *machine, bool native_arch) 283 + { 284 + if (sample->insn_len == 0 && native_arch) 285 + arch_fetch_insn(sample, thread, machine); 286 + }
+1 -1
tools/perf/util/trace-event.h
··· 117 117 int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec)); 118 118 119 119 void script_fetch_insn(struct perf_sample *sample, struct thread *thread, 120 - struct machine *machine); 120 + struct machine *machine, bool native_arch); 121 121 122 122 void setup_perl_scripting(void); 123 123 void setup_python_scripting(void);