History

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.

Ian Rogers committed 1 year ago

Commit 1ff2ca31 parent 04051b46 files · +19 −23Browse files

Unified · Split

6 files
  1. tools/perf/builtin-script.c +1 −14
  2. tools/perf/scripts/python/Perf-Trace-Util/Context.c +1 −1
  3. tools/perf/util/dlfilter.c +2 −1
  4. tools/perf/util/python.c +0 −6
  5. tools/perf/util/trace-event-scripting.c +14 −0
  6. tools/perf/util/trace-event.h +1 −1
tools/perf/builtin-script.c+1−14
@@ -1586,19 +1586,6 @@ static int perf_sample__fprintf_callindent(struct perf_sample *sample, · 1585 unmodified lines
15861586 return len + dlen;
15871587 }
15881588
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−
16021589 static int perf_sample__fprintf_insn(struct perf_sample *sample,
16031590 struct evsel *evsel,
16041591 struct perf_event_attr *attr,
@@ -1608,7 +1595,7 @@ static int perf_sample__fprintf_insn(struct perf_sample *sample, · 3 unmodified lines
16081595 {
16091596 int printed = 0;
16101597
1611− script_fetch_insn(sample, thread, machine);
1598+ script_fetch_insn(sample, thread, machine, native_arch);
16121599
16131600 if (PRINT_FIELD(INSNLEN))
16141601 printed += fprintf(fp, " ilen: %d", sample->insn_len);
tools/perf/scripts/python/Perf-Trace-Util/Context.c+1−1
@@ -93,7 +93,7 @@ static PyObject *perf_sample_insn(PyObject *obj, PyObject *args) · 92 unmodified lines
9393 if (c->sample->ip && !c->sample->insn_len && thread__maps(c->al->thread)) {
9494 struct machine *machine = maps__machine(thread__maps(c->al->thread));
9595
96− script_fetch_insn(c->sample, c->al->thread, machine);
96+ script_fetch_insn(c->sample, c->al->thread, machine, /*native_arch=*/true);
9797 }
9898 if (!c->sample->insn_len)
9999 Py_RETURN_NONE; /* N.B. This is a return statement */
tools/perf/util/dlfilter.c+2−1
@@ -234,7 +234,8 @@ static const __u8 *dlfilter__insn(void *ctx, __u32 *len) · 233 unmodified lines
234234 struct machine *machine = maps__machine(thread__maps(al->thread));
235235
236236 if (machine)
237− script_fetch_insn(d->sample, al->thread, machine);
237+ script_fetch_insn(d->sample, al->thread, machine,
238+ /*native_arch=*/true);
238239 }
239240 }
240241
tools/perf/util/python.c+0−6
@@ -1317,12 +1317,6 @@ struct kwork_work *perf_kwork_add_work(struct perf_kwork *kwork __maybe_unused, · 1316 unmodified lines
13171317 return NULL;
13181318 }
13191319
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−
13261320 int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe_unused,
13271321 size_t sz __maybe_unused)
13281322 {
tools/perf/util/trace-event-scripting.c+14−0
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #include <event-parse.h>
1414 #endif
1515
16+#include "archinsn.h"
1617 #include "debug.h"
1718 #include "trace-event.h"
1819 #include "evsel.h"
@@ -271,3 +272,16 @@ void setup_perl_scripting(void) · 252 unmodified lines
271272 }
272273 #endif
273274 #endif
275+
276+__weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused,
277+ struct thread *thread __maybe_unused,
278+ struct machine *machine __maybe_unused)
279+{
280+}
281+
282+void script_fetch_insn(struct perf_sample *sample, struct thread *thread,
283+ struct machine *machine, bool native_arch)
284+{
285+ if (sample->insn_len == 0 && native_arch)
286+ arch_fetch_insn(sample, thread, machine);
287+}
tools/perf/util/trace-event.h+1−1
@@ -117,7 +117,7 @@ struct scripting_ops *script_spec__lookup(const char *spec); · 116 unmodified lines
117117 int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec));
118118
119119 void script_fetch_insn(struct perf_sample *sample, struct thread *thread,
120− struct machine *machine);
120+ struct machine *machine, bool native_arch);
121121
122122 void setup_perl_scripting(void);
123123 void setup_python_scripting(void);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t