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
1586 return len + dlen;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
1595void 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
1602static int perf_sample__fprintf_insn(struct perf_sample *sample,1589static int perf_sample__fprintf_insn(struct perf_sample *sample,
1603 struct evsel *evsel,1590 struct evsel *evsel,
1604 struct perf_event_attr *attr,1591 struct perf_event_attr *attr,
@@ -1608,7 +1595,7 @@ static int perf_sample__fprintf_insn(struct perf_sample *sample, · 3 unmodified lines
1608{1595{
1609 int printed = 0;1596 int printed = 0;
1610 1597
1611 script_fetch_insn(sample, thread, machine);1598 script_fetch_insn(sample, thread, machine, native_arch);
1612 1599
1613 if (PRINT_FIELD(INSNLEN))1600 if (PRINT_FIELD(INSNLEN))
1614 printed += fprintf(fp, " ilen: %d", sample->insn_len);1601 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
93 if (c->sample->ip && !c->sample->insn_len && thread__maps(c->al->thread)) {93 if (c->sample->ip && !c->sample->insn_len && thread__maps(c->al->thread)) {
94 struct machine *machine = maps__machine(thread__maps(c->al->thread));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 if (!c->sample->insn_len)98 if (!c->sample->insn_len)
99 Py_RETURN_NONE; /* N.B. This is a return statement */99 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
234 struct machine *machine = maps__machine(thread__maps(al->thread));234 struct machine *machine = maps__machine(thread__maps(al->thread));
235 235
236 if (machine)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
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
1317 return NULL;1317 return NULL;
1318}1318}
1319 1319
1320void script_fetch_insn(struct perf_sample *sample __maybe_unused,
1321 struct thread *thread __maybe_unused,
1322 struct machine *machine __maybe_unused)
1323{
1324}
1325
1326int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe_unused,1320int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe_unused,
1327 size_t sz __maybe_unused)1321 size_t sz __maybe_unused)
1328{1322{
tools/perf/util/trace-event-scripting.c+14−0
@@ -13,6 +13,7 @@ · 12 unmodified lines
13#include <event-parse.h>13#include <event-parse.h>
14#endif14#endif
15 15
16#include "archinsn.h"
16#include "debug.h"17#include "debug.h"
17#include "trace-event.h"18#include "trace-event.h"
18#include "evsel.h"19#include "evsel.h"
@@ -271,3 +272,16 @@ void setup_perl_scripting(void) · 252 unmodified lines
271}272}
272#endif273#endif
273#endif274#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
282void 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
117int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec));117int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char *spec));
118 118
119void script_fetch_insn(struct perf_sample *sample, struct thread *thread,119void script_fetch_insn(struct perf_sample *sample, struct thread *thread,
120 struct machine *machine);120 struct machine *machine, bool native_arch);
121 121
122void setup_perl_scripting(void);122void setup_perl_scripting(void);
123void setup_python_scripting(void);123void 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