perf/core improvements and fixes
Subsystems (2)
Arnaldo Carvalho de Melo
maintainerHi Ingo,
Please consider pulling, more to come soon,
- Arnaldo
The following changes since commit 5b24e8cf618f03b4f1275c229d0a1d464648f9e2:
Merge tag 'perf-core-for-mingo-2' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent (2015-04-14 14:10:56 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo
for you to fetch changes up to 83c4bb5d87922f336a77125e3698928b661ee57e:
perf bench numa: Show more stats of particular threads in verbose mode (2015-04-28 09:57:26 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
User visible:
- Add 'perf stat' metrics support for exclude_(host|guest|hv|idle) (Jiri Olsa)
- Fix 'perf stat' metrics calculation with event qualifiers (Andi Kleen)
- Improve event parsing error reporting (Jiri Olsa)
- Fix 'perf trace' --filter-pids OPTION description (Arnaldo Carvalho de Melo)
- Clarify that 'perf trace -e' is about syscalls, not perf events in general (Arnaldo Carvalho de Melo)
- Show error message when 'perf data' conversion failed (He Kuang)
- Remove all probe matches given pattern at once in 'perf probe --del' (Masami Hiramatsu)
- Make 'perf probe --funcs' option exclusive (Masami Hiramatsu)
- Document --children option (top, report) in more detail (Namhyung Kim)
- Show more stats of particular threads in verbose mode in 'perf bench numa' (Petr Holasek)
Infrastructure:
- AUX area tracing work needed for processing Intel PT data (Adrian Hunter)
- Add build tests for building perf from kernel source root and tools (Jiri Olsa)
- Enable 'perf data' stream flush within processing (Jiri Olsa)
- Add support for setting ordered_events queue size in 'perf data' (Jiri Olsa)
- Refactor the perf hists browser (top, report) to break down big function into smaller ones, remove unused state (Namhyung Kim)
- Switch 'perf data' to libbabeltrace's multiple cpu stream files (Sebastian Andrzej Siewior)
- Fix duplicate field names and avoid reserved keywords in 'perf data' CTF support (Wang Nan)
- Fix signedness of value in 'perf data' (Wang Nan)
- Use getconf to determine number of online CPUs, making the build process to find the right number of online CPUs on ARM (Will Deacon)
----------------------------------------------------------------
Adrian Hunter (20):
perf header: Add AUX area tracing feature
perf evlist: Add support for mmapping an AUX area buffer
perf tools: Add user events for AUX area tracing
perf auxtrace: Add support for AUX area recording
perf record: Add basic AUX area tracing support
perf record: Extend -m option for AUX area tracing mmap pages perf tools: Add a user event for AUX area tracing errors
perf session: Add hooks to allow transparent decoding of AUX area tracing data perf session: Add instruction tracing options
perf auxtrace: Add helpers for AUX area tracing errors
perf auxtrace: Add helpers for queuing AUX area tracing data perf auxtrace: Add a heap for sorting AUX area tracing queues perf auxtrace: Add processing for AUX area tracing events
perf auxtrace: Add a hashtable for caching
perf tools: Add member to struct dso for an instruction cache perf script: Add Instruction Tracing support
perf inject: Re-pipe AUX area tracing events
perf inject: Add Instruction Tracing support
perf script: Add field option 'flags' to print sample flags
perf tools: Add aux_watermark member of struct perf_event_attr
Andi Kleen (1):
perf stat: Fix metrics calculation with event qualifiers
Arnaldo Carvalho de Melo (2):
perf trace: Fix --filter-pids OPTION description
perf trace: Clarify that -e is about syscalls, not perf events in general
He Kuang (1):
perf data: Show error message when conversion failed
Jiri Olsa (19):
tools lib traceevent: Add alias field to struct format_field tools build: No need to make libapi for perf explicitly
tools build: Fix Makefile(s) to properly invoke tools build
perf tests: Add build tests for building perf from kernel source root and tools perf data: Enable stream flush within processing
perf data: Add support for setting ordered_events queue size
perf tools: Add parse_events_error interface
perf tools: Add flex support for parse_events_error
perf tools: Always bail out when config_attr function fails
perf tools: Change parse_events_add_pmu interface
perf tools: Add location to pmu event terms
perf tools: Add term support for parse_events_error
perf tools: Add static terms support for parse_events_error
perf tools: Add tracepoint support for parse_events_error
perf tools: Add symbolic events support for parse_events_error perf stat: Change metrics context calculation
perf stat: Add metrics support for exclude_hv
perf stat: Add metrics support for exclude_(host|guest)
perf stat: Add metrics support for exclude_idle
Masami Hiramatsu (2):
perf probe: Make --funcs option exclusive
perf probe: Remove all probes matches given pattern at once
Namhyung Kim (14):
perf hists: Get rid of position field from struct hist_entry perf diff: Make hist_entry_diff fields union
perf tools: Document --children option in more detail perf tools: Move TUI-specific fields into unnamed union perf tools: Move init_have_children field to the unnamed union perf hists browser: Fix possible memory leak
perf hists browser: Save hist_browser_timer pointer in hist_browser perf hists browser: Save pstack in the hist_browser perf hists browser: Save perf_session_env in the hist_browser perf hists browser: Split popup menu actions
perf hists browser: Split popup menu actions - part 2 perf tools: Introduce pstack_peek()
perf hists browser: Simplify zooming code using pstack_peek() perf tools: Move TUI-specific fields out of map_symbol
Petr Holasek (1):
perf bench numa: Show more stats of particular threads in verbose mode
Sebastian Andrzej Siewior (1):
perf data: Switch to multiple cpu stream files
Wang Nan (2):
perf data: Fix duplicate field names and avoid reserved keywords perf data: Fix signedness of value
Will Deacon (1):
perf tools: Use getconf to determine number of online CPUs
Makefile | 5 +- tools/Makefile | 20 +- tools/lib/traceevent/event-parse.c | 6 +- tools/lib/traceevent/event-parse.h | 1 + .../callchain-overhead-calculation.txt | 108 ++ tools/perf/Documentation/perf-inject.txt | 26 + tools/perf/Documentation/perf-probe.txt | 2 + tools/perf/Documentation/perf-record.txt | 2 + tools/perf/Documentation/perf-report.txt | 4 + tools/perf/Documentation/perf-script.txt | 36 +- tools/perf/Documentation/perf-top.txt | 3 +- tools/perf/Documentation/perf-trace.txt | 2 +- tools/perf/Makefile | 2 +- tools/perf/bench/numa.c | 32 +- tools/perf/builtin-inject.c | 134 ++- tools/perf/builtin-probe.c | 2 + tools/perf/builtin-record.c | 130 ++- tools/perf/builtin-script.c | 45 +- tools/perf/builtin-stat.c | 146 ++- tools/perf/builtin-trace.c | 7 +- tools/perf/perf.h | 2 + tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 4 +- tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 4 +- tools/perf/tests/hists_link.c | 4 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/keep-tracking.c | 4 +- tools/perf/tests/make | 14 +- tools/perf/tests/parse-events.c | 2 +- tools/perf/tests/perf-time-to-tsc.c | 2 +- tools/perf/tests/pmu.c | 3 +- tools/perf/tests/switch-tracking.c | 8 +- tools/perf/ui/browsers/hists.c | 611 ++++++----- tools/perf/util/Build | 1 + tools/perf/util/auxtrace.c | 1069 ++++++++++++++++++++ tools/perf/util/auxtrace.h | 426 ++++++++ tools/perf/util/callchain.h | 4 + tools/perf/util/data-convert-bt.c | 410 +++++++- tools/perf/util/dso.c | 2 + tools/perf/util/dso.h | 3 + tools/perf/util/event.c | 3 + tools/perf/util/event.h | 46 + tools/perf/util/evlist.c | 71 +- tools/perf/util/evlist.h | 6 + tools/perf/util/evsel.c | 1 + tools/perf/util/header.c | 14 + tools/perf/util/header.h | 1 + tools/perf/util/hist.c | 2 +- tools/perf/util/parse-events.c | 194 +++- tools/perf/util/parse-events.h | 36 +- tools/perf/util/parse-events.l | 41 +- tools/perf/util/parse-events.y | 48 +- tools/perf/util/pmu.c | 57 +- tools/perf/util/pmu.h | 6 +- tools/perf/util/probe-event.c | 26 +- tools/perf/util/pstack.c | 7 + tools/perf/util/pstack.h | 1 + tools/perf/util/record.c | 15 +- tools/perf/util/session.c | 152 ++- tools/perf/util/session.h | 5 + tools/perf/util/sort.h | 38 +- tools/perf/util/symbol.h | 2 - tools/perf/util/tool.h | 10 +- 64 files changed, 3563 insertions(+), 511 deletions(-) create mode 100644 tools/perf/Documentation/callchain-overhead-calculation.txt create mode 100644 tools/perf/util/auxtrace.c create mode 100644 tools/perf/util/auxtrace.h
Arnaldo Carvalho de Melo
maintainerPATCH 1/64 perf hists: Get rid of position field from struct hist_entry
From: Namhyung Kim <[email protected]>
It's not used anywhere, let's get rid of it.
--- tools/perf/util/sort.h | 1 - 1 file changed, 1 deletion(-)
tools/perf/util/sort.h +0 -1
@@ -106,7 +106,6 @@ struct hist_entry {u8 filtered;char *srcline;struct symbol *parent; -unsigned long position;struct rb_root sorted_chain;struct branch_info *branch_info;struct hists *hists;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 2/64 perf diff: Make hist_entry_diff fields union
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
The period_ratio_delta, period_ratio and wdiff are never by used at the same time. Instead, Just one of them is accessed according to a comparison method. So make it union to reduce memory footprint.
--- tools/perf/util/sort.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
tools/perf/util/sort.h +8 -7
@@ -58,15 +58,16 @@ struct he_stat {struct hist_entry_diff {bool computed; +union { +/* PERF_HPP__DELTA */ +double period_ratio_delta; -/* PERF_HPP__DELTA */ -double period_ratio_delta; - -/* PERF_HPP__RATIO */ -double period_ratio; +/* PERF_HPP__RATIO */ +double period_ratio; -/* HISTC_WEIGHTED_DIFF */ -s64 wdiff; +/* HISTC_WEIGHTED_DIFF */ +s64 wdiff; + }; };/**
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 3/64 perf data: Show error message when conversion failed
In reply to Arnaldo Carvalho de MeloFrom: He Kuang <[email protected]>
Show message when errors occurred during conversion setup and conversion process.
Before this patch:
$ ./perf data convert --to-ctf=ctf $ echo $? 255
After this patch:
$ ./perf data convert --to-ctf=ctf Error during conversion setup.
--- tools/perf/util/data-convert-bt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/data-convert-bt.c +8 -2
@@ -837,6 +837,8 @@ int bt_convert__perf2ctf(const char *input, const char *path, bool force) err =perf_session__process_events (session);if (!err) err =bt_ctf_stream_flush (cw->stream); +else +pr_err ("Error during conversion.\n" ); fprintf(stderr, "[ perf data convert: Converted '%s' into CTF data '%s' ]\n",
@@ -847,11 +849,15 @@ int bt_convert__perf2ctf(const char *input, const char *path, bool force) (double ) c.events_size /1024.0 /1024.0 , c.events_count); -/* its all good */ -free_session:perf_session__delete (session); +ctf_writer__cleanup (cw); +return err; + +free_session: +perf_session__delete (session); free_writer:ctf_writer__cleanup (cw); +pr_err ("Error during conversion setup.\n" );return err; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 4/64 tools lib traceevent: Add alias field to struct format_field
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Introduce an 'alias' field to 'struct format_field' to be able to use alternative name for the field.
It is initialized with same string pointer as 'name' field. The free logic checks the 'alias' pointer being reset by user and frees it.
This will be handy when converting data into CTF, where each field within event needs to have a unique name (while this is not required for tracepoint). Converter can easily assign unique name into the format_field struct.
--- tools/lib/traceevent/event-parse.c | 6 ++++-- tools/lib/traceevent/event-parse.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
tools/lib/traceevent/event-parse.c +4 -2
@@ -1387,7 +1387,7 @@ static int event_read_fields(struct event_format *event, struct format_field **fdo_warning_event (event,"%s: no type found" , __func__); goto fail; } - field->name = last_token; + field->name = field->alias = last_token;if (test_type (type,EVENT_OP )) goto fail;
@@ -1469,7 +1469,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f size_dynamic =type_size (field->name);free_token (field->name);strcat (field->type, brackets); - field->name = token; + field->name = field->alias = token; type =read_token (&token); }else {char *new_type;
@@ -6444,6 +6444,8 @@ void pevent_ref(struct pevent *pevent)void pevent_free_format_field (struct format_field *field) {free (field->type); +if (field->alias != field->name) +free (field->alias);free (field->name);free (field); }
tools/lib/traceevent/event-parse.h +1 -0
@@ -191,6 +191,7 @@ struct format_field {struct event_format *event;char *type;char *name; +char *alias;int offset;int size;unsigned int arraylen;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 5/64 tools build: No need to make libapi for perf explicitly
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
The perf build handles its dependencies by itself.
Also renaming libapi libapikfs to libapi as it got changed just recently.
--- tools/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/Makefile +4 -4
@@ -47,10 +47,10 @@ cgroup firewire hv guest usb virtio vm net: FORCE liblockdep: FORCE $(call descend,lib/lockdep) -libapikfs: FORCE +libapi: FORCE $(call descend,lib/api) -perf: libapikfs FORCE +perf: FORCE $(call descend,$@) selftests: FORCE
@@ -97,10 +97,10 @@ cgroup_clean hv_clean firewire_clean lguest_clean usb_clean virtio_clean vm_clea liblockdep_clean: $(call descend,lib/lockdep,clean) -libapikfs_clean: +libapi_clean: $(call descend,lib/api,clean) -perf_clean: libapikfs_clean +perf_clean: $(call descend,$(@:_clean=),clean) selftests_clean:
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 6/64 tools build: Fix Makefile(s) to properly invoke tools build
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Several fixes were needed to allow following builds:
$ make tools/tmon $ make -C <kernelsrc> tools/perf $ make -C <kernelsrc>/tools perf
- some of the tools (perf) use same make variables as in kernel build, unsetting srctree and objtree
- using original $(O) for O variable
- perf build does not follow the descend function setup invoking it via it's own make rule
I tried the rest of the tools/Makefile targets and they seem to work now.
--- Makefile | 5 ++--- tools/Makefile | 12 +++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-)
Makefile +2 -3
@@ -214,7 +214,6 @@ VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD)) export srctree objtree VPATH - # SUBARCH tells the usermode build what the underlying arch is. That is set # first, and if a usermode build is happening, the "ARCH=um" on the command # line overrides the setting of ARCH below. If a native build is happening,
@@ -1504,11 +1503,11 @@ image_name: # Clear a bunch of variables before executing the submake tools/: FORCE $(Q)mkdir -p $(objtree)/tools - $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(filter --j% -j,$(MAKEFLAGS))" O=$(objtree) subdir=tools -C $(src)/tools/ + $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(filter --j% -j,$(MAKEFLAGS))" O=$(O) subdir=tools -C $(src)/tools/ tools/%: FORCE $(Q)mkdir -p $(objtree)/tools - $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(filter --j% -j,$(MAKEFLAGS))" O=$(objtree) subdir=tools -C $(src)/tools/ $* + $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(filter --j% -j,$(MAKEFLAGS))" O=$(O) subdir=tools -C $(src)/tools/ $* # Single targets # ---------------------------------------------------------------------------
tools/Makefile +11 -1
@@ -1,3 +1,8 @@ +# Some of the tools (perf) use same make variables +# as in kernel build. +export srctree= +export objtree= + include scripts/Makefile.include help:
@@ -50,8 +55,13 @@ liblockdep: FORCE libapi: FORCE $(call descend,lib/api) +# The perf build does not follow the descend function setup, +# invoking it via it's own make rule. +PERF_O = $(if $(O),$(O)/tools/perf,) + perf: FORCE - $(call descend,$@) + $(Q)mkdir -p $(PERF_O) . + $(Q)$(MAKE) --no-print-directory -C perf O=$(PERF_O) subdir= selftests: FORCE $(call descend,testing/$@)
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 7/64 perf tests: Add build tests for building perf from kernel source root and tools
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding build tests for following make commands:
$ make -C <kernelsrc> tools/perf $ make -C <kernelsrc>/tools perf
--- tools/perf/tests/make | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
tools/perf/tests/make +13 -1
@@ -223,7 +223,19 @@ tarpkg: echo "- $@: $$cmd" && echo $$cmd > $@ && \ ( eval $$cmd ) >> $@ 2>&1 -all: $(run) $(run_O) tarpkg +make_kernelsrc: + @echo " - make -C <kernelsrc> tools/perf" + $(call clean); \ + (make -C ../.. tools/perf) > $@ 2>&1 && \ + test -x perf && rm -f $@ || (cat $@ ; false) + +make_kernelsrc_tools: + @echo " - make -C <kernelsrc>/tools perf" + $(call clean); \ + (make -C ../../tools perf) > $@ 2>&1 && \ + test -x perf && rm -f $@ || (cat $@ ; false) + +all: $(run) $(run_O) tarpkg make_kernelsrc make_kernelsrc_tools @echo OK out: $(run_O)
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 8/64 perf data: Switch to multiple cpu stream files
In reply to Arnaldo Carvalho de MeloFrom: Sebastian Andrzej Siewior <[email protected]>
Currently we store the data into single data strea/file. The cpu if data is stored within the event sample. The lttng puts the CPU number that belongs to the event into the packet context instead into the event.
This patch makes sure that the trace produce by perf does look the same way. We now use one stream per-CPU. Having it all in one stream increased the total size of the resulting file. The test went from 416KiB (with perf_cpu event member) to 24MiB due to the required (and pointless) flush. With the per-cpu streams the total size went up to 588KiB.
--- tools/perf/util/data-convert-bt.c | 206 +++++++++++++++++++++++++++++++++----- 1 file changed, 182 insertions(+), 24 deletions(-)
tools/perf/util/data-convert-bt.c +182 -24
@@ -38,12 +38,20 @@ struct evsel_priv {struct bt_ctf_event_class *event_class; }; +#define MAX_CPUS 4096 + +struct ctf_stream { +struct bt_ctf_stream *stream; +int cpu; +}; +struct ctf_writer {/* writer primitives */ -struct bt_ctf_writer *writer; -struct bt_ctf_stream *stream; -struct bt_ctf_stream_class *stream_class; -struct bt_ctf_clock *clock; +struct bt_ctf_writer *writer; +struct ctf_stream **stream; +int stream_cnt; +struct bt_ctf_stream_class *stream_class; +struct bt_ctf_clock *clock;/* data types */ union {
@@ -346,12 +354,6 @@ static int add_generic_values(struct ctf_writer *cw,return -1 ; } -if (type &PERF_SAMPLE_CPU ) { - ret =value_set_u32 (cw, event,"perf_cpu" , sample->cpu); -if (ret) -return -1 ; - } -if (type &PERF_SAMPLE_PERIOD ) { ret =value_set_u64 (cw, event,"perf_period" , sample->period);if (ret)
@@ -381,6 +383,113 @@ static int add_generic_values(struct ctf_writer *cw,return 0 ; } +static int ctf_stream__flush (struct ctf_stream *cs) +{ +int err =0 ; + +if (cs) { + err =bt_ctf_stream_flush (cs->stream); +if (err) +pr_err ("CTF stream %d flush failed\n" , cs->cpu); + +pr ("Flush stream for cpu %d\n" , cs->cpu); + } + +return err; +} + +static struct ctf_stream *ctf_stream__create (struct ctf_writer *cw,int cpu) +{ +struct ctf_stream *cs; +struct bt_ctf_field *pkt_ctx =NULL ; +struct bt_ctf_field *cpu_field =NULL ; +struct bt_ctf_stream *stream =NULL ; +int ret; + + cs =zalloc (sizeof (*cs)); +if (!cs) { +pr_err ("Failed to allocate ctf stream\n" ); +return NULL ; + } + + stream =bt_ctf_writer_create_stream (cw->writer, cw->stream_class); +if (!stream) { +pr_err ("Failed to create CTF stream\n" ); + goto out; + } + + pkt_ctx =bt_ctf_stream_get_packet_context (stream); +if (!pkt_ctx) { +pr_err ("Failed to obtain packet context\n" ); + goto out; + } + + cpu_field =bt_ctf_field_structure_get_field (pkt_ctx,"cpu_id" ); +bt_ctf_field_put (pkt_ctx); +if (!cpu_field) { +pr_err ("Failed to obtain cpu field\n" ); + goto out; + } + + ret =bt_ctf_field_unsigned_integer_set_value (cpu_field, (u32 ) cpu); +if (ret) { +pr_err ("Failed to update CPU number\n" ); + goto out; + } + +bt_ctf_field_put (cpu_field); + + cs->cpu = cpu; + cs->stream = stream; +return cs; + +out: +if (cpu_field) +bt_ctf_field_put (cpu_field); +if (stream) +bt_ctf_stream_put (stream); + +free (cs); +return NULL ; +} + +static void ctf_stream__delete (struct ctf_stream *cs) +{ +if (cs) { +bt_ctf_stream_put (cs->stream); +free (cs); + } +} + +static struct ctf_stream *ctf_stream (struct ctf_writer *cw,int cpu) +{ +struct ctf_stream *cs = cw->stream[cpu]; + +if (!cs) { + cs =ctf_stream__create (cw, cpu); + cw->stream[cpu] = cs; + } + +return cs; +} + +static int get_sample_cpu (struct ctf_writer *cw,struct perf_sample *sample, +struct perf_evsel *evsel) +{ +int cpu =0 ; + +if (evsel->attr.sample_type &PERF_SAMPLE_CPU ) + cpu = sample->cpu; + +if (cpu > cw->stream_cnt) { +pr_err ("Event was recorded for CPU %d, limit is at %d.\n" , + cpu, cw->stream_cnt); + cpu =0 ; + } + +return cpu; +} + static int process_sample_event(struct perf_tool *tool, union perf_event *_event __maybe_unused, struct perf_sample *sample,
@@ -390,6 +499,7 @@ static int process_sample_event(struct perf_tool *tool, struct convert *c = container_of(tool, struct convert, tool);struct evsel_priv *priv = evsel->priv;struct ctf_writer *cw = &c->writer; +struct ctf_stream *cs;struct bt_ctf_event_class *event_class;struct bt_ctf_event *event;int ret;
@@ -424,9 +534,12 @@ static int process_sample_event(struct perf_tool *tool,return -1 ; } -bt_ctf_stream_append_event (cw->stream, event); + cs =ctf_stream (cw,get_sample_cpu (cw, sample, evsel)); +if (cs) +bt_ctf_stream_append_event (cs->stream, event); +bt_ctf_event_put (event); -return 0 ; +return cs ?0 :-1 ; } static int add_tracepoint_fields_types(struct ctf_writer *cw,
@@ -528,9 +641,6 @@ static int add_generic_types(struct ctf_writer *cw, struct perf_evsel *evsel,if (type &PERF_SAMPLE_STREAM_ID )ADD_FIELD (event_class, cw->data.u64,"perf_stream_id" ); -if (type &PERF_SAMPLE_CPU ) -ADD_FIELD (event_class, cw->data.u32,"perf_cpu" ); -if (type &PERF_SAMPLE_PERIOD )ADD_FIELD (event_class, cw->data.u64,"perf_period" );
@@ -604,6 +714,39 @@ static int setup_events(struct ctf_writer *cw, struct perf_session *session)return 0 ; } +static int setup_streams (struct ctf_writer *cw,struct perf_session *session) +{ +struct ctf_stream **stream; +struct perf_header *ph = &session->header; +int ncpus; + +/* +* Try to get the number of cpus used in the data file, +* if not present fallback to the MAX_CPUS. +*/ + ncpus = ph->env.nr_cpus_avail ?:MAX_CPUS ; + + stream =zalloc (sizeof (*stream) * ncpus); +if (!stream) { +pr_err ("Failed to allocate streams.\n" ); +return -ENOMEM ; + } + + cw->stream = stream; + cw->stream_cnt = ncpus; +return 0 ; +} + +static void free_streams (struct ctf_writer *cw) +{ +int cpu; + +for (cpu =0 ; cpu < cw->stream_cnt; cpu++) +ctf_stream__delete (cw->stream[cpu]); + +free (cw->stream); +} +static int ctf_writer__setup_env (struct ctf_writer *cw,struct perf_session *session) {
@@ -713,7 +856,7 @@ static void ctf_writer__cleanup(struct ctf_writer *cw)ctf_writer__cleanup_data (cw);bt_ctf_clock_put (cw->clock); -bt_ctf_stream_put (cw->stream); +free_streams (cw);bt_ctf_stream_class_put (cw->stream_class);bt_ctf_writer_put (cw->writer);
@@ -725,8 +868,9 @@ static int ctf_writer__init(struct ctf_writer *cw, const char *path) {struct bt_ctf_writer *writer;struct bt_ctf_stream_class *stream_class; -struct bt_ctf_stream *stream;struct bt_ctf_clock *clock; +struct bt_ctf_field_type *pkt_ctx_type; +int ret;/* CTF writer */ writer =bt_ctf_writer_create (path);
@@ -767,14 +911,15 @@ static int ctf_writer__init(struct ctf_writer *cw, const char *path)if (ctf_writer__init_data (cw)) goto err_cleanup; -/* CTF stream instance */ - stream =bt_ctf_writer_create_stream (writer, stream_class); -if (!stream) { -pr ("Failed to create CTF stream.\n" ); +/* Add cpu_id for packet context */ + pkt_ctx_type =bt_ctf_stream_class_get_packet_context_type (stream_class); +if (!pkt_ctx_type) goto err_cleanup; - } - cw->stream = stream; + ret =bt_ctf_field_type_structure_add_field (pkt_ctx_type, cw->data.u32,"cpu_id" ); +bt_ctf_field_type_put (pkt_ctx_type); +if (ret) + goto err_cleanup;/* CTF clock writer setup */ if (bt_ctf_writer_add_clock (writer, clock)) {
@@ -791,6 +936,16 @@ err:return -1 ; } +static int ctf_writer__flush_streams (struct ctf_writer *cw) +{ +int cpu, ret =0 ; + +for (cpu =0 ; cpu < cw->stream_cnt && !ret; cpu++) + ret =ctf_stream__flush (cw->stream[cpu]); + +return ret; +} +int bt_convert__perf2ctf (const char *input,const char *path,bool force) {struct perf_session *session;
@@ -834,9 +989,12 @@ int bt_convert__perf2ctf(const char *input, const char *path, bool force)if (setup_events (cw, session)) goto free_session; +if (setup_streams (cw, session)) + goto free_session; + err =perf_session__process_events (session);if (!err) - err =bt_ctf_stream_flush (cw->stream); + err =ctf_writer__flush_streams (cw);else pr_err ("Error during conversion.\n" );
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 9/64 perf data: Enable stream flush within processing
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
For big data files the size of data allocated for stream instance could get really high. It's needed to flush the data out of the stream once in a while.
Unfortunately there's no size indication in the stream object, so we govern the flush based on the number of stored events. Current flush limit is set ot 100000 events.
--- tools/perf/util/data-convert-bt.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)
tools/perf/util/data-convert-bt.c +24 -2
@@ -43,6 +43,7 @@ struct evsel_priv {struct ctf_stream {struct bt_ctf_stream *stream;int cpu; +u32 count; };struct ctf_writer {
@@ -392,7 +393,10 @@ static int ctf_stream__flush(struct ctf_stream *cs)if (err)pr_err ("CTF stream %d flush failed\n" , cs->cpu); -pr ("Flush stream for cpu %d\n" , cs->cpu); +pr ("Flush stream for cpu %d (%u samples)\n" , + cs->cpu, cs->count); + + cs->count =0 ; }return err;
@@ -490,6 +494,19 @@ static int get_sample_cpu(struct ctf_writer *cw, struct perf_sample *sample,return cpu; } +#define STREAM_FLUSH_COUNT 100000 + +/* +* Currently we have no other way to determine the +* time for the stream flush other than keep track +* of the number of events and check it against +* threshold. +*/ +static bool is_flush_needed (struct ctf_stream *cs) +{ +return cs->count >=STREAM_FLUSH_COUNT ; +} + static int process_sample_event(struct perf_tool *tool, union perf_event *_event __maybe_unused, struct perf_sample *sample,
@@ -535,8 +552,13 @@ static int process_sample_event(struct perf_tool *tool, } cs =ctf_stream (cw,get_sample_cpu (cw, sample, evsel)); -if (cs) +if (cs) { +if (is_flush_needed (cs)) +ctf_stream__flush (cs); + + cs->count++;bt_ctf_stream_append_event (cs->stream, event); + }bt_ctf_event_put (event);return cs ?0 :-1 ;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 10/64 perf data: Add support for setting ordered_events queue size
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding support to limit the size of ordered_events queue, so we could control allocation size of perf data files without proper finished round events.
--- tools/perf/util/data-convert-bt.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
tools/perf/util/data-convert-bt.c +22 -0
@@ -74,6 +74,9 @@ struct convert {u64 events_size;u64 events_count; + +/* Ordered events configured queue size. */ +u64 queue_size; }; static int value_set(struct bt_ctf_field_type *type,
@@ -968,6 +971,18 @@ static int ctf_writer__flush_streams(struct ctf_writer *cw)return ret; } +static int convert__config (const char *var,const char *value,void *cb) +{ +struct convert *c = cb; + +if (!strcmp (var,"convert.queue-size" )) { + c->queue_size =perf_config_u64 (var, value); +return 0 ; + } + +return perf_default_config (var, value, cb); +} +int bt_convert__perf2ctf (const char *input,const char *path,bool force) {struct perf_session *session;
@@ -994,6 +1009,8 @@ int bt_convert__perf2ctf(const char *input, const char *path, bool force)struct ctf_writer *cw = &c.writer;int err =-1 ; +perf_config (convert__config, &c); +/* CTF writer */ if (ctf_writer__init (cw, path))return -1 ;
@@ -1003,6 +1020,11 @@ int bt_convert__perf2ctf(const char *input, const char *path, bool force)if (!session) goto free_writer; +if (c.queue_size) { +ordered_events__set_alloc_size (&session->ordered_events, + c.queue_size); + } +/* CTF writer env/clock setup */ if (ctf_writer__setup_env (cw, session)) goto free_session;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 11/64 perf data: Fix duplicate field names and avoid reserved keywords
In reply to Arnaldo Carvalho de MeloFrom: Wang Nan <[email protected]>
Some parameters of syscall tracepoints named as 'nr', 'event', etc. When dealing with them, perf convert to ctf meets some problem:
1. If a parameter with name 'nr', it will duplicate syscall's common field 'nr'. One such syscall is io_submit().
2. If a parameter with name 'event', it is denied to be inserted because 'event' is a CTF spec keyword[1]. One such syscall is epoll_ctl.
This patch appends '_dupl_X' suffix to avoid problem 1, prepend a '_' prefix to avoid problem 2.
[1] http://diamon.org/docs/ctf/v1.8.2/#specC.1.2
--- tools/perf/util/data-convert-bt.c | 86 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 4 deletions(-)
tools/perf/util/data-convert-bt.c +82 -4
@@ -14,6 +14,7 @@#include <babeltrace/ctf-writer/event.h> #include <babeltrace/ctf-writer/event-types.h> #include <babeltrace/ctf-writer/event-fields.h> +#include <babeltrace/ctf-ir/utils.h> #include <babeltrace/ctf/events.h> #include <traceevent/event-parse.h> #include "asm/bug.h"
@@ -184,6 +185,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,unsigned int len;int ret; + name = fmtf->alias; offset = fmtf->offset; len = fmtf->size;if (flags &FIELD_IS_STRING )
@@ -567,6 +569,82 @@ static int process_sample_event(struct perf_tool *tool,return cs ?0 :-1 ; } +/* If dup < 0, add a prefix. Else, add _dupl_X suffix. */ +static char *change_name (char *name,char *orig_name,int dup) +{ +char *new_name =NULL ; +size_t len; + +if (!name) + name = orig_name; + +if (dup >=10 ) + goto out; +/* +* Add '_' prefix to potential keywork. According to +* Mathieu Desnoyers (https://lkml.org/lkml/2015/1/23/652), +* futher CTF spec updating may require us to use '$'. +*/ +if (dup <0 ) + len =strlen (name) +sizeof ("_" ); +else + len =strlen (orig_name) +sizeof ("_dupl_X" ); + + new_name =malloc (len); +if (!new_name) + goto out; + +if (dup <0 ) +snprintf (new_name, len,"_%s" , name); +else +snprintf (new_name, len,"%s_dupl_%d" , orig_name, dup); + +out: +if (name != orig_name) +free (name); +return new_name; +} + +static int event_class_add_field (struct bt_ctf_event_class *event_class, +struct bt_ctf_field_type *type, +struct format_field *field) +{ +struct bt_ctf_field_type *t =NULL ; +char *name; +int dup =1 ; +int ret; + +/* alias was already assigned */ +if (field->alias != field->name) +return bt_ctf_event_class_add_field (event_class, type, + (char *)field->alias); + + name = field->name; + +/* If 'name' is a keywork, add prefix. */ +if (bt_ctf_validate_identifier (name)) + name =change_name (name, field->name,-1 ); + +if (!name) { +pr_err ("Failed to fix invalid identifier." ); +return -1 ; + } +while ((t =bt_ctf_event_class_get_field_by_name (event_class, name))) { +bt_ctf_field_type_put (t); + name =change_name (name, field->name, dup++); +if (!name) { +pr_err ("Failed to create dup name for '%s'\n" , field->name); +return -1 ; + } + } + + ret =bt_ctf_event_class_add_field (event_class, type, name); +if (!ret) + field->alias = name; + +return ret; +} +static int add_tracepoint_fields_types (struct ctf_writer *cw,struct format_field *fields,struct bt_ctf_event_class *event_class)
@@ -595,14 +673,14 @@ static int add_tracepoint_fields_types(struct ctf_writer *cw,if (flags &FIELD_IS_ARRAY ) type =bt_ctf_field_type_array_create (type, field->arraylen); - ret =bt_ctf_event_class_add_field (event_class, type, - field->name); + ret =event_class_add_field (event_class, type, field);if (flags &FIELD_IS_ARRAY )bt_ctf_field_type_put (type);if (ret) { -pr_err ("Failed to add field '%s\n" , field->name); +pr_err ("Failed to add field '%s': %d\n" , + field->name, ret);return -1 ; } }
@@ -646,7 +724,7 @@ static int add_generic_types(struct ctf_writer *cw, struct perf_evsel *evsel,do { \pr2 (" field '%s'\n" , n); \if (bt_ctf_event_class_add_field (cl, t, n)) { \ -pr_err ("Failed to add field '%s;\n" , n); \ +pr_err ("Failed to add field '%s';\n" , n); \return -1 ; \ } \ }while (0 )
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 12/64 perf data: Fix signedness of value
In reply to Arnaldo Carvalho de MeloFrom: Wang Nan <[email protected]>
When converting int values, perf first extractes it to a ulonglong, then feeds it to babeltrace as a signed value.
For negative 32 bit values (for example, return values of failed syscalls), the extracted data should be something like 0xfffffffe (-2). It becomes a large int64 value.
Babeltrace denies to insert it with bt_ctf_field_signed_integer_set_value() because it is larger than 0x7fffffff, the largest positive value a
32 bit int can be.
This patch introduces adjust_signedness(), which fills high bits of ulonglong with 1 if the value is negative.
--- tools/perf/util/data-convert-bt.c | 64 +++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 12 deletions(-)
tools/perf/util/data-convert-bt.c +52 -12
@@ -166,6 +166,43 @@ get_tracepoint_field_type(struct ctf_writer *cw, struct format_field *field)return cw->data.u32; } +static unsigned long long adjust_signedness (unsigned long long value_int,int size) +{ +unsigned long long value_mask; + +/* +* value_mask = (1 << (size * 8 - 1)) - 1. +* Directly set value_mask for code readers. +*/ +switch (size) { +case 1 : + value_mask =0x7fULL ; +break ; +case 2 : + value_mask =0x7fffULL ; +break ; +case 4 : + value_mask =0x7fffffffULL ; +break ; +case 8 : +/* +* For 64 bit value, return it self. There is no need +* to fill high bit. +*/ +/* Fall through */ +default : +/* BUG! */ +return value_int; + } + +/* If it is a positive value, don't adjust. */ +if ((value_int & (~0ULL - value_mask)) ==0 ) +return value_int; + +/* Fill upper part of value_int with 1 to make it a negative long long. */ +return (value_int & value_mask) | ~value_mask; +} + static int add_tracepoint_field_value(struct ctf_writer *cw, struct bt_ctf_event_class *event_class, struct bt_ctf_event *event,
@@ -177,7 +214,6 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,struct bt_ctf_field *field;const char *name = fmtf->name;void *data = sample->raw_data; -unsigned long long value_int;unsigned long flags = fmtf->flags;unsigned int n_items;unsigned int i;
@@ -222,11 +258,6 @@ static int add_tracepoint_field_value(struct ctf_writer *cw, type =get_tracepoint_field_type (cw, fmtf);for (i =0 ; i < n_items; i++) { -if (!(flags &FIELD_IS_STRING )) - value_int =pevent_read_number ( - fmtf->event->pevent, - data + offset + i * len, len); -if (flags &FIELD_IS_ARRAY ) field =bt_ctf_field_array_get_field (array_field, i);else
@@ -240,12 +271,21 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,if (flags &FIELD_IS_STRING ) ret =bt_ctf_field_string_set_value (field, data + offset + i * len); -else if (!(flags &FIELD_IS_SIGNED )) - ret =bt_ctf_field_unsigned_integer_set_value ( - field, value_int); -else - ret =bt_ctf_field_signed_integer_set_value ( - field, value_int); +else { +unsigned long long value_int; + + value_int =pevent_read_number ( + fmtf->event->pevent, + data + offset + i * len, len); + +if (!(flags &FIELD_IS_SIGNED )) + ret =bt_ctf_field_unsigned_integer_set_value ( + field, value_int); +else + ret =bt_ctf_field_signed_integer_set_value ( + field,adjust_signedness (value_int, len)); + } +if (ret) {pr_err ("failed to set file value %s\n" , name); goto err_put_field;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 13/64 perf header: Add AUX area tracing feature
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add a feature to indicate that a perf.data file contains AUX area data.
--- tools/perf/util/header.c | 14 ++++++++++++++ tools/perf/util/header.h | 1 + 2 files changed, 15 insertions(+)
tools/perf/util/header.c +14 -0
@@ -869,6 +869,13 @@ static int write_branch_stack(int fd __maybe_unused,return 0 ; } +static int write_auxtrace (int fd__maybe_unused , +struct perf_header *h__maybe_unused , +struct perf_evlist *evlist__maybe_unused ) +{ +return 0 ; +} +static void print_hostname (struct perf_header *ph,int fd__maybe_unused ,FILE *fp) {
@@ -1151,6 +1158,12 @@ static void print_branch_stack(struct perf_header *ph __maybe_unused,fprintf (fp,"# contains samples with branch stack\n" ); } +static void print_auxtrace (struct perf_header *ph__maybe_unused , +int fd__maybe_unused ,FILE *fp) +{ +fprintf (fp,"# contains AUX area data (e.g. instruction trace)\n" ); +} +static void print_pmu_mappings (struct perf_header *ph,int fd__maybe_unused ,FILE *fp) {
@@ -1861,6 +1874,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {FEAT_OPA (HEADER_BRANCH_STACK , branch_stack),FEAT_OPP (HEADER_PMU_MAPPINGS , pmu_mappings),FEAT_OPP (HEADER_GROUP_DESC , group_desc), + FEAT_OPA(HEADER_AUXTRACE, auxtrace), }; struct header_print_data {
tools/perf/util/header.h +1 -0
@@ -30,6 +30,7 @@ enum {HEADER_BRANCH_STACK ,HEADER_PMU_MAPPINGS ,HEADER_GROUP_DESC , +HEADER_AUXTRACE ,HEADER_LAST_FEATURE , HEADER_FEAT_BITS = 256, };
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 14/64 perf evlist: Add support for mmapping an AUX area buffer
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
This patch supports the addition to the kernel of AUX area buffers that can be mmapped separately from the perf-events buffer.
The AUX buffer can be configured to contain hardware-produced trace information. The first implementation will support Intel BTS and Intel PT.
One auxtrace buffer is mmapped per perf-events buffer. If the requested auxtrace buffer size is zero, which it will be until further support is added, then no auxtrace mmapping is attempted.
--- tools/perf/util/Build | 1 + tools/perf/util/auxtrace.c | 113 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/auxtrace.h | 117 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/evlist.c | 61 +++++++++++++++++++++-- tools/perf/util/evlist.h | 5 ++ 5 files changed, 294 insertions(+), 3 deletions(-) create mode 100644 tools/perf/util/auxtrace.c create mode 100644 tools/perf/util/auxtrace.h
tools/perf/util/Build +1 -0
@@ -74,6 +74,7 @@ libperf-y += data.o libperf-$(CONFIG_X86) += tsc.o libperf-y += cloexec.o libperf-y += thread-stack.o +libperf-y += auxtrace.o libperf-$(CONFIG_LIBELF) += symbol-elf.o libperf-$(CONFIG_LIBELF) += probe-event.o
tools/perf/util/auxtrace.c new file +113 -0
113 lines not on this page · raw message
tools/perf/util/auxtrace.h new file +117 -0
117 lines not on this page · raw message
tools/perf/util/evlist.c +58 -3
125 lines not on this page · raw message
tools/perf/util/evlist.h +5 -0
@@ -8,6 +8,7 @@#include "event.h" #include "evsel.h" #include "util.h" +#include "auxtrace.h" #include <unistd.h> struct pollfd ;
@@ -28,6 +29,7 @@ struct perf_mmap {int mask;int refcnt;u64 prev; +struct auxtrace_mmap auxtrace_mmap; char event_copy[PERF_SAMPLE_MAX_SIZE] __attribute__((aligned(8))); };
@@ -126,6 +128,9 @@ int perf_evlist__parse_mmap_pages(const struct option *opt,const char *str, int unset); +int perf_evlist__mmap_ex (struct perf_evlist *evlist,unsigned int pages, +bool overwrite,unsigned int auxtrace_pages, +bool auxtrace_overwrite);int perf_evlist__mmap (struct perf_evlist *evlist,unsigned int pages,bool overwrite);void perf_evlist__munmap (struct perf_evlist *evlist);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 15/64 perf tools: Add user events for AUX area tracing
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add two user events for AUX area tracing.
PERF_RECORD_AUXTRACE_INFO contains metadata, consisting primarily the type of the AUX area tracing data plus some amount of architecture-specific information. There should be only one PERF_RECORD_AUXTRACE_INFO event.
PERF_RECORD_AUXTRACE identifies AUX area tracing data copied from the mmapped AUX area tracing region. The actual data is not part of the event but immediately follows it.
--- tools/perf/util/event.c | 2 ++ tools/perf/util/event.h | 22 +++++++++++++++ tools/perf/util/session.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/tool.h | 9 ++++++- 4 files changed, 101 insertions(+), 1 deletion(-)
tools/perf/util/event.c +2 -0
@@ -29,6 +29,8 @@ static const char *perf_event__names[] = { [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID", [PERF_RECORD_FINISHED_ROUND] = "FINISHED_ROUND", [PERF_RECORD_ID_INDEX] = "ID_INDEX", + [PERF_RECORD_AUXTRACE_INFO] = "AUXTRACE_INFO", + [PERF_RECORD_AUXTRACE] = "AUXTRACE", };const char *perf_event__name (unsigned int id)
tools/perf/util/event.h +22 -0
@@ -215,6 +215,8 @@ enum perf_user_event_type { /* above any possible kernel type */PERF_RECORD_HEADER_BUILD_ID =67 ,PERF_RECORD_FINISHED_ROUND =68 ,PERF_RECORD_ID_INDEX =69 , +PERF_RECORD_AUXTRACE_INFO =70 , +PERF_RECORD_AUXTRACE =71 , PERF_RECORD_HEADER_MAX };
@@ -280,6 +282,24 @@ struct id_index_event {struct id_index_entry entries[0 ]; }; +struct auxtrace_info_event { +struct perf_event_header header; +u32 type; +u32 reserved__;/* For alignment */ +u64 priv[]; +}; + +struct auxtrace_event { +struct perf_event_header header; +u64 size; +u64 offset; +u64 reference; +u32 idx; +u32 tid; +u32 cpu; +u32 reserved__;/* For alignment */ +}; +union perf_event {struct perf_event_header header;struct mmap_event mmap;
@@ -295,6 +315,8 @@ union perf_event {struct tracing_data_event tracing_data;struct build_id_event build_id;struct id_index_event id_index; +struct auxtrace_info_event auxtrace_info; +struct auxtrace_event auxtrace; };void perf_event__print_totals (void );
tools/perf/util/session.c +69 -0
99 lines not on this page · raw message
tools/perf/util/tool.h +8 -1
@@ -3,6 +3,8 @@#include <stdbool.h> +#include <linux/types.h> +struct perf_session ;union perf_event ;struct perf_evlist ;
@@ -29,6 +31,9 @@ typedef int (*event_op2)(struct perf_tool *tool, union perf_event *event,typedef int (*event_oe )(struct perf_tool *tool,union perf_event *event,struct ordered_events *oe); +typedef s64 (*event_op3 )(struct perf_tool *tool,union perf_event *event, +struct perf_session *session); +struct perf_tool {event_sample sample, read;
@@ -44,7 +49,9 @@ struct perf_tool {event_op2 tracing_data;event_oe finished_round;event_op2 build_id, - id_index; + id_index, + auxtrace_info; +event_op3 auxtrace;bool ordered_events;bool ordering_requires_timestamps; };
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 16/64 perf auxtrace: Add support for AUX area recording
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add support for reading from the AUX area tracing mmap and synthesizing AUX area tracing events.
This patch introduces an abstraction for recording AUX area data.
Recording is initialized by auxtrace_record__init() which is a weak function to be implemented by the architecture to provide recording callbacks.
Recording is mainly handled by auxtrace_mmap__read() and perf_event__synthesize_auxtrace() but there are callbacks for miscellaneous needs including validating and processing user options, populating private data in auxtrace_info_event, and freeing the structure when finished.
--- tools/perf/perf.h | 2 + tools/perf/util/auxtrace.c | 176 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/auxtrace.h | 56 ++++++++++++++- tools/perf/util/record.c | 11 ++- 4 files changed, 243 insertions(+), 2 deletions(-)
tools/perf/perf.h +2 -0
@@ -54,8 +54,10 @@ struct record_opts {bool period;bool sample_intr_regs;bool running_time; +bool full_auxtrace;unsigned int freq;unsigned int mmap_pages; +unsigned int auxtrace_mmap_pages;unsigned int user_freq;u64 branch_stack;u64 default_interval;
tools/perf/util/auxtrace.c +176 -0
191 lines not on this page · raw message
tools/perf/util/auxtrace.h +55 -1
78 lines not on this page · raw message
tools/perf/util/record.c +10 -1
@@ -119,7 +119,16 @@ void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts) evsel->attr.comm_exec =1 ; } -if (evlist->nr_entries >1 ) { +if (opts->full_auxtrace) { +/* +* Need to be able to synthesize and parse selected events with +* arbitrary sample types, which requires always being able to +* match the id. +*/ + use_sample_identifier =perf_can_sample_identifier (); +evlist__for_each (evlist, evsel) +perf_evsel__set_sample_id (evsel, use_sample_identifier); + }else if (evlist->nr_entries >1 ) {struct perf_evsel *first =perf_evlist__first (evlist);evlist__for_each (evlist, evsel) {
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 17/64 perf record: Add basic AUX area tracing support
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Amend the perf record tool to read the AUX area tracing mmap and synthesize AUX area tracing events.
--- tools/perf/builtin-record.c | 81 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 4 deletions(-)
tools/perf/builtin-record.c +77 -4
@@ -27,6 +27,7 @@#include "util/cpumap.h" #include "util/thread_map.h" #include "util/data.h" +#include "util/auxtrace.h" #include <unistd.h> #include <sched.h>
@@ -38,6 +39,7 @@ struct record {struct record_opts opts;u64 bytes_written;struct perf_data_file file; +struct auxtrace_record *itr;struct perf_evlist *evlist;struct perf_session *session;const char *progname;
@@ -110,6 +112,44 @@ out:return rc; } +static int record__process_auxtrace (struct perf_tool *tool, +union perf_event *event,void *data1, +size_t len1,void *data2,size_t len2) +{ + struct record *rec = container_of(tool, struct record, tool); +size_t padding; +u8 pad[8 ] = {0 }; + +/* event.auxtrace.size includes padding, see __auxtrace_mmap__read() */ + padding = (len1 + len2) &7 ; +if (padding) + padding =8 - padding; + +record__write (rec, event, event->header.size); +record__write (rec, data1, len1); +if (len2) +record__write (rec, data2, len2); +record__write (rec, &pad, padding); + +return 0 ; +} + +static int record__auxtrace_mmap_read (struct record *rec, +struct auxtrace_mmap *mm) +{ +int ret; + + ret =auxtrace_mmap__read (mm, rec->itr, &rec->tool, + record__process_auxtrace); +if (ret <0 ) +return ret; + +if (ret) + rec->samples++; + +return 0 ; +} +static volatile int done =0 ;static volatile int signr =-1 ;static volatile int child_finished =0 ;
@@ -169,13 +209,15 @@ try_again: goto out; } -if (perf_evlist__mmap (evlist, opts->mmap_pages, false) <0 ) { +if (perf_evlist__mmap_ex (evlist, opts->mmap_pages, false, + opts->auxtrace_mmap_pages, false) <0 ) {if (errno ==EPERM ) {pr_err ("Permission error mapping pages.\n" "Consider increasing " "/proc/sys/kernel/perf_event_mlock_kb,\n" "or try again with a smaller value of -m/--mmap_pages.\n" -"(current value: %u)\n" , opts->mmap_pages); +"(current value: %u,%u)\n" , + opts->mmap_pages, opts->auxtrace_mmap_pages); rc = -errno; }else { pr_err("failed to mmap with %d (%s)\n", errno,
@@ -270,12 +312,20 @@ static int record__mmap_read_all(struct record *rec)int rc =0 ;for (i =0 ; i < rec->evlist->nr_mmaps; i++) { +struct auxtrace_mmap *mm = &rec->evlist->mmap[i].auxtrace_mmap; +if (rec->evlist->mmap[i].base) {if (record__mmap_read (rec, i) !=0 ) { rc =-1 ; goto out; } } + +if (mm->base && +record__auxtrace_mmap_read (rec, mm) !=0 ) { + rc =-1 ; + goto out; + } }/*
@@ -305,6 +355,9 @@ static void record__init_features(struct record *rec)if (!rec->opts.branch_stack)perf_header__clear_feat (&session->header,HEADER_BRANCH_STACK ); + +if (!rec->opts.full_auxtrace) +perf_header__clear_feat (&session->header,HEADER_AUXTRACE ); }static volatile int workload_exec_errno;
@@ -421,6 +474,13 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) } } +if (rec->opts.full_auxtrace) { + err =perf_event__synthesize_auxtrace_info (rec->itr, tool, + session, process_synthesized_event); +if (err) + goto out_delete_session; + } + err =perf_event__synthesize_kernel_mmap (tool, process_synthesized_event, machine);if (err <0 )
@@ -553,7 +613,7 @@ out_child:if (!err && !quiet) {char samples[128 ]; -if (rec->samples) +if (rec->samples && !rec->opts.full_auxtrace)scnprintf (samples,sizeof (samples)," (%" PRIu64" samples)" , rec->samples);else
@@ -936,7 +996,7 @@ struct option *record_options = __record_options;int cmd_record (int argc,const char **argv,const char *prefix__maybe_unused ) { -int err = -ENOMEM ; +int err;struct record *rec = &record;char errbuf[BUFSIZ ];
@@ -957,6 +1017,14 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)usage_with_options (record_usage, record_options); } +if (!rec->itr) { + rec->itr =auxtrace_record__init (rec->evlist, &err); +if (err) +return err; + } + + err = -ENOMEM ; +symbol__init (NULL );if (symbol_conf.kptr_restrict)
@@ -1002,6 +1070,10 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)if (perf_evlist__create_maps (rec->evlist, &rec->opts.target) <0 )usage_with_options (record_usage, record_options); + err =auxtrace_record__options (rec->itr, rec->evlist, &rec->opts); +if (err) + goto out_symbol_exit; +if (record_opts__config (&rec->opts)) { err = -EINVAL ; goto out_symbol_exit;
@@ -1011,5 +1083,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) out_symbol_exit:perf_evlist__delete (rec->evlist);symbol__exit (); +auxtrace_record__free (rec->itr);return err; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 18/64 perf record: Extend -m option for AUX area tracing mmap pages
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Extend the -m option so that the number of mmap pages for AUX area tracing can be specified by adding a comma followed by the number of pages.
--- tools/perf/Documentation/perf-record.txt | 2 ++ tools/perf/builtin-record.c | 49 ++++++++++++++++++++++++++++++-- tools/perf/util/evlist.c | 10 +++++-- tools/perf/util/evlist.h | 1 + 4 files changed, 56 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-record.txt +2 -0
@@ -108,6 +108,8 @@ OPTIONS Number of mmap data pages (must be a power of two) or size specification with appended unit character - B/K/M/G. The size is rounded up to have nearest pages power of two value. + Also, by adding a comma, the number of mmap pages for AUX + area tracing can be specified. --group:: Put all events in a single event group. This precedes the --event
tools/perf/builtin-record.c +46 -3
61 lines not on this page · raw message
tools/perf/util/evlist.c +7 -3
@@ -1000,10 +1000,8 @@ static long parse_pages_arg(const char *str, unsigned long min,return pages; } -int perf_evlist__parse_mmap_pages (const struct option *opt,const char *str, -int unset__maybe_unused ) +int __perf_evlist__parse_mmap_pages (unsigned int *mmap_pages,const char *str) { -unsigned int *mmap_pages = opt->value;unsigned long max =UINT_MAX ;long pages;
@@ -1020,6 +1018,12 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,return 0 ; } +int perf_evlist__parse_mmap_pages (const struct option *opt,const char *str, +int unset__maybe_unused ) +{ +return __perf_evlist__parse_mmap_pages (opt->value, str); +} +/** * perf_evlist__mmap_ex - Create mmaps to receive events. * @evlist: list of events
tools/perf/util/evlist.h +1 -0
@@ -124,6 +124,7 @@ int perf_evlist__start_workload(struct perf_evlist *evlist);struct option ; +int __perf_evlist__parse_mmap_pages (unsigned int *mmap_pages,const char *str);int perf_evlist__parse_mmap_pages (const struct option *opt,const char *str,int unset);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 19/64 perf tools: Add a user event for AUX area tracing errors
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Errors encountered when decoding an AUX area trace need to be reported to the user. However the "user" might be a script or another tool, so provide a new user event to capture those errors.
--- tools/perf/util/event.c | 1 + tools/perf/util/event.h | 16 ++++++++++++++++ tools/perf/util/session.c | 25 +++++++++++++++++++++++++ tools/perf/util/tool.h | 3 ++- 4 files changed, 44 insertions(+), 1 deletion(-)
tools/perf/util/event.c +1 -0
@@ -31,6 +31,7 @@ static const char *perf_event__names[] = { [PERF_RECORD_ID_INDEX] = "ID_INDEX", [PERF_RECORD_AUXTRACE_INFO] = "AUXTRACE_INFO", [PERF_RECORD_AUXTRACE] = "AUXTRACE", + [PERF_RECORD_AUXTRACE_ERROR] = "AUXTRACE_ERROR", };const char *perf_event__name (unsigned int id)
tools/perf/util/event.h +16 -0
@@ -217,6 +217,7 @@ enum perf_user_event_type { /* above any possible kernel type */PERF_RECORD_ID_INDEX =69 ,PERF_RECORD_AUXTRACE_INFO =70 ,PERF_RECORD_AUXTRACE =71 , +PERF_RECORD_AUXTRACE_ERROR =72 , PERF_RECORD_HEADER_MAX };
@@ -300,6 +301,20 @@ struct auxtrace_event {u32 reserved__;/* For alignment */ }; +#define MAX_AUXTRACE_ERROR_MSG 64 + +struct auxtrace_error_event { +struct perf_event_header header; +u32 type; +u32 code; +u32 cpu; +u32 pid; +u32 tid; +u32 reserved__;/* For alignment */ +u64 ip; +char msg[MAX_AUXTRACE_ERROR_MSG ]; +}; +union perf_event {struct perf_event_header header;struct mmap_event mmap;
@@ -317,6 +332,7 @@ union perf_event {struct id_index_event id_index;struct auxtrace_info_event auxtrace_info;struct auxtrace_event auxtrace; +struct auxtrace_error_event auxtrace_error; };void perf_event__print_totals (void );
tools/perf/util/session.c +25 -0
@@ -296,6 +296,15 @@ static s64 process_event_auxtrace_stub(struct perf_tool *tool __maybe_unused,return event->auxtrace.size; } +static +int process_event_auxtrace_error_stub (struct perf_tool *tool__maybe_unused , +union perf_event *event__maybe_unused , +struct perf_session *session__maybe_unused ) +{ +dump_printf (": unhandled!\n" ); +return 0 ; +} +void perf_tool__fill_defaults (struct perf_tool *tool) {if (tool->sample ==NULL )
@@ -336,6 +345,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool) tool->auxtrace_info = process_event_auxtrace_info_stub;if (tool->auxtrace ==NULL ) tool->auxtrace = process_event_auxtrace_stub; +if (tool->auxtrace_error ==NULL ) + tool->auxtrace_error = process_event_auxtrace_error_stub; }static void swap_sample_id_all (union perf_event *event,void *data)
@@ -539,6 +550,17 @@ static void perf_event__auxtrace_swap(union perf_event *event, event->auxtrace.cpu =bswap_32 (event->auxtrace.cpu); } +static void perf_event__auxtrace_error_swap (union perf_event *event, +bool sample_id_all__maybe_unused ) +{ + event->auxtrace_error.type =bswap_32 (event->auxtrace_error.type); + event->auxtrace_error.code =bswap_32 (event->auxtrace_error.code); + event->auxtrace_error.cpu =bswap_32 (event->auxtrace_error.cpu); + event->auxtrace_error.pid =bswap_32 (event->auxtrace_error.pid); + event->auxtrace_error.tid =bswap_32 (event->auxtrace_error.tid); + event->auxtrace_error.ip =bswap_64 (event->auxtrace_error.ip); +} +typedef void (*perf_event__swap_op )(union perf_event *event,bool sample_id_all);
@@ -560,6 +582,7 @@ static perf_event__swap_op perf_event__swap_ops[] = { [PERF_RECORD_ID_INDEX] = perf_event__all64_swap, [PERF_RECORD_AUXTRACE_INFO] = perf_event__auxtrace_info_swap, [PERF_RECORD_AUXTRACE] = perf_event__auxtrace_swap, + [PERF_RECORD_AUXTRACE_ERROR] = perf_event__auxtrace_error_swap, [PERF_RECORD_HEADER_MAX] = NULL, };
@@ -1049,6 +1072,8 @@ static s64 perf_session__process_user_event(struct perf_session *session,/* setup for reading amidst mmap */ lseek (fd, file_offset + event->header.size,SEEK_SET );return tool->auxtrace (tool, event, session); +case PERF_RECORD_AUXTRACE_ERROR : +return tool->auxtrace_error (tool, event, session);default :return -EINVAL ; }
tools/perf/util/tool.h +2 -1
@@ -50,7 +50,8 @@ struct perf_tool {event_oe finished_round;event_op2 build_id, id_index, - auxtrace_info; + auxtrace_info, + auxtrace_error;event_op3 auxtrace;bool ordered_events;bool ordering_requires_timestamps;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 20/64 perf session: Add hooks to allow transparent decoding of AUX area tracing data
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Hook into session processing so that AUX area decoding can synthesize events transparently to the tools.
The advantages of transparent decoding are that tools can be used directly with perf.data files containing AUX area tracing data, which is easier for the user and more efficient than having a separate decoding tool.
This will work as follows:
1. Tools will feed auxtrace events to the decoder using perf_tool->auxtrace() (support for that still to come).
2. The decoder can process side-band events as needed due to the auxtrace->process_event() hook.
3. The decoder can deliver synthesized events into the event stream using perf_session__deliver_synth_event().
Note the expectation is that decoding will work on data that is time-ordered with respect to the per-cpu or per-thread contexts that were recorded.
--- tools/perf/util/auxtrace.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/session.c | 54 ++++++++++++++++++++++++++++++++++++--------- tools/perf/util/session.h | 3 +++ 3 files changed, 102 insertions(+), 10 deletions(-)
tools/perf/util/auxtrace.h +55 -0
@@ -23,6 +23,7 @@#include <linux/types.h> #include "../perf.h" +#include "session.h" union perf_event ;struct perf_session ;
@@ -32,6 +33,24 @@ struct record_opts;struct auxtrace_info_event ;/** +* struct auxtrace - session callbacks to allow AUX area data decoding. +* @process_event: lets the decoder see all session events +* @flush_events: process any remaining data +* @free_events: free resources associated with event processing +* @free: free resources associated with the session +*/ +struct auxtrace { +int (*process_event)(struct perf_session *session, +union perf_event *event, +struct perf_sample *sample, +struct perf_tool *tool); +int (*flush_events)(struct perf_session *session, +struct perf_tool *tool); +void (*free_events)(struct perf_session *session); +void (*free)(struct perf_session *session); +}; + +/** * struct auxtrace_mmap - records an mmap of the auxtrace buffer. * @base: address of mapped area * @userpg: pointer to buffer's perf_event_mmap_page
@@ -168,4 +187,40 @@ int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr,struct perf_session *session, perf_event__handler_t process); +static inline int auxtrace__process_event (struct perf_session *session, +union perf_event *event, +struct perf_sample *sample, +struct perf_tool *tool) +{ +if (!session->auxtrace) +return 0 ; + +return session->auxtrace->process_event (session, event, sample, tool); +} + +static inline int auxtrace__flush_events (struct perf_session *session, +struct perf_tool *tool) +{ +if (!session->auxtrace) +return 0 ; + +return session->auxtrace->flush_events (session, tool); +} + +static inline void auxtrace__free_events (struct perf_session *session) +{ +if (!session->auxtrace) +return ; + +return session->auxtrace->free_events (session); +} + +static inline void auxtrace__free (struct perf_session *session) +{ +if (!session->auxtrace) +return ; + +return session->auxtrace->free (session); +} +#endif
tools/perf/util/session.c +44 -10
111 lines not on this page · raw message
tools/perf/util/session.h +3 -0
@@ -15,10 +15,13 @@struct ip_callchain ;struct thread ; +struct auxtrace ; +struct perf_session {struct perf_header header;struct machines machines;struct perf_evlist *evlist; +struct auxtrace *auxtrace;struct trace_event tevent;bool repipe;bool one_mmap;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 21/64 perf session: Add instruction tracing options
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
It is assumed that AUX area decoding will synthesize events for consumption by other tools.
At this time, the main use of AUX area tracing will be to capture instruction trace (aka processor trace) data.
The nature of instruction tracing suggests the initial inclusion of options for "instructions" and "branches" events, but more could be added as needed.
--- tools/perf/util/auxtrace.c | 136 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/auxtrace.h | 43 ++++++++++++++ tools/perf/util/session.h | 2 + 3 files changed, 181 insertions(+)
tools/perf/util/auxtrace.c +136 -0
@@ -37,6 +37,7 @@#include "event.h" #include "debug.h" +#include "parse-options.h" int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, struct auxtrace_mmap_params *mp,
@@ -200,6 +201,141 @@ out_free:return err; } +#define PERF_ITRACE_DEFAULT_PERIOD_TYPE PERF_ITRACE_PERIOD_NANOSECS +#define PERF_ITRACE_DEFAULT_PERIOD 100000 +#define PERF_ITRACE_DEFAULT_CALLCHAIN_SZ 16 +#define PERF_ITRACE_MAX_CALLCHAIN_SZ 1024 + +void itrace_synth_opts__set_default (struct itrace_synth_opts *synth_opts) +{ + synth_opts->instructions = true; + synth_opts->branches = true; + synth_opts->errors = true; + synth_opts->period_type =PERF_ITRACE_DEFAULT_PERIOD_TYPE ; + synth_opts->period =PERF_ITRACE_DEFAULT_PERIOD ; + synth_opts->callchain_sz =PERF_ITRACE_DEFAULT_CALLCHAIN_SZ ; +} + +/* +* Please check tools/perf/Documentation/perf-script.txt for information +* about the options parsed here, which is introduced after this cset, +* when support in 'perf script' for these options is introduced. +*/ +int itrace_parse_synth_opts (const struct option *opt,const char *str, +int unset) +{ +struct itrace_synth_opts *synth_opts = opt->value; +const char *p; +char *endptr; + + synth_opts->set = true; + +if (unset) { + synth_opts->dont_decode = true; +return 0 ; + } + +if (!str) { +itrace_synth_opts__set_default (synth_opts); +return 0 ; + } + +for (p = str; *p;) { +switch (*p++) { +case 'i' : + synth_opts->instructions = true; +while (*p ==' ' || *p ==',' ) + p +=1 ; +if (isdigit (*p)) { + synth_opts->period =strtoull (p, &endptr,10 ); + p = endptr; +while (*p ==' ' || *p ==',' ) + p +=1 ; +switch (*p++) { +case 'i' : + synth_opts->period_type = +PERF_ITRACE_PERIOD_INSTRUCTIONS ; +break ; +case 't' : + synth_opts->period_type = +PERF_ITRACE_PERIOD_TICKS ; +break ; +case 'm' : + synth_opts->period *=1000 ; +/* Fall through */ +case 'u' : + synth_opts->period *=1000 ; +/* Fall through */ +case 'n' : +if (*p++ !='s' ) + goto out_err; + synth_opts->period_type = +PERF_ITRACE_PERIOD_NANOSECS ; +break ; +case '\0' : + goto out; +default : + goto out_err; + } + } +break ; +case 'b' : + synth_opts->branches = true; +break ; +case 'e' : + synth_opts->errors = true; +break ; +case 'd' : + synth_opts->log = true; +break ; +case 'c' : + synth_opts->branches = true; + synth_opts->calls = true; +break ; +case 'r' : + synth_opts->branches = true; + synth_opts->returns = true; +break ; +case 'g' : + synth_opts->instructions = true; + synth_opts->callchain = true; + synth_opts->callchain_sz = +PERF_ITRACE_DEFAULT_CALLCHAIN_SZ ; +while (*p ==' ' || *p ==',' ) + p +=1 ; +if (isdigit (*p)) { +unsigned int val; + + val =strtoul (p, &endptr,10 ); + p = endptr; +if (!val || val >PERF_ITRACE_MAX_CALLCHAIN_SZ ) + goto out_err; + synth_opts->callchain_sz = val; + } +break ; +case ' ' : +case ',' : +break ; +default : + goto out_err; + } + } +out: +if (synth_opts->instructions) { +if (!synth_opts->period_type) + synth_opts->period_type = +PERF_ITRACE_DEFAULT_PERIOD_TYPE ; +if (!synth_opts->period) + synth_opts->period =PERF_ITRACE_DEFAULT_PERIOD ; + } + +return 0 ; + +out_err: +pr_err ("Bad Instruction Tracing options '%s'\n" , str); +return -EINVAL ; +} +int auxtrace_mmap__read (struct auxtrace_mmap *mm,struct auxtrace_record *itr,struct perf_tool *tool,process_auxtrace_t fn) {
tools/perf/util/auxtrace.h +43 -0
58 lines not on this page · raw message
tools/perf/util/session.h +2 -0
@@ -16,12 +16,14 @@ struct ip_callchain;struct thread ;struct auxtrace ; +struct itrace_synth_opts ;struct perf_session {struct perf_header header;struct machines machines;struct perf_evlist *evlist;struct auxtrace *auxtrace; +struct itrace_synth_opts *itrace_synth_opts;struct trace_event tevent;bool repipe;bool one_mmap;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 22/64 perf auxtrace: Add helpers for AUX area tracing errors
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add functions to synthesize, count and print AUX area tracing error events.
--- tools/perf/util/auxtrace.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/auxtrace.h | 14 ++++++++ tools/perf/util/event.h | 6 ++++ tools/perf/util/session.c | 3 ++ 4 files changed, 104 insertions(+)
tools/perf/util/auxtrace.c +81 -0
@@ -24,6 +24,7 @@#include <linux/log2.h> #include <stdlib.h> +#include <stdio.h> #include <string.h> #include <errno.h>
@@ -36,6 +37,7 @@#include "auxtrace.h" #include "event.h" +#include "session.h" #include "debug.h" #include "parse-options.h"
@@ -172,6 +174,28 @@ auxtrace_record__init(struct perf_evlist *evlist __maybe_unused, int *err)return NULL ; } +void auxtrace_synth_error (struct auxtrace_error_event *auxtrace_error,int type, +int code,int cpu,pid_t pid,pid_t tid,u64 ip, +const char *msg) +{ +size_t size; + +memset (auxtrace_error,0 ,sizeof (struct auxtrace_error_event )); + + auxtrace_error->header.type =PERF_RECORD_AUXTRACE_ERROR ; + auxtrace_error->type = type; + auxtrace_error->code = code; + auxtrace_error->cpu = cpu; + auxtrace_error->pid = pid; + auxtrace_error->tid = tid; + auxtrace_error->ip = ip; +strlcpy (auxtrace_error->msg, msg,MAX_AUXTRACE_ERROR_MSG ); + + size = (void *)auxtrace_error->msg - (void *)auxtrace_error + +strlen (auxtrace_error->msg) +1 ; + auxtrace_error->header.size =PERF_ALIGN (size,sizeof (u64)); +} + int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr, struct perf_tool *tool, struct perf_session *session,
@@ -336,6 +360,63 @@ out_err:return -EINVAL ; } +static const char *const auxtrace_error_type_name[] = { + [PERF_AUXTRACE_ERROR_ITRACE ] ="instruction trace" , +}; + +static const char *auxtrace_error_name (int type) +{ +const char *error_type_name =NULL ; + +if (type <PERF_AUXTRACE_ERROR_MAX ) + error_type_name = auxtrace_error_type_name[type]; +if (!error_type_name) + error_type_name ="unknown AUX" ; +return error_type_name; +} + +size_t perf_event__fprintf_auxtrace_error (union perf_event *event,FILE *fp) +{ +struct auxtrace_error_event *e = &event->auxtrace_error; +int ret; + + ret =fprintf (fp," %s error type %u" , +auxtrace_error_name (e->type), e->type); + ret +=fprintf (fp," cpu %d pid %d tid %d ip %#" PRIx64" code %u: %s\n" , + e->cpu, e->pid, e->tid, e->ip, e->code, e->msg); +return ret; +} + +void perf_session__auxtrace_error_inc (struct perf_session *session, +union perf_event *event) +{ +struct auxtrace_error_event *e = &event->auxtrace_error; + +if (e->type <PERF_AUXTRACE_ERROR_MAX ) + session->evlist->stats.nr_auxtrace_errors[e->type] +=1 ; +} + +void events_stats__auxtrace_error_warn (const struct events_stats *stats) +{ +int i; + +for (i =0 ; i <PERF_AUXTRACE_ERROR_MAX ; i++) { +if (!stats->nr_auxtrace_errors[i]) +continue ; +ui__warning ("%u %s errors\n" , + stats->nr_auxtrace_errors[i], +auxtrace_error_name (i)); + } +} + +int perf_event__process_auxtrace_error (struct perf_tool *tool__maybe_unused , +union perf_event *event, +struct perf_session *session__maybe_unused ) +{ +perf_event__fprintf_auxtrace_error (event, stdout); +return 0 ; +} +int auxtrace_mmap__read (struct auxtrace_mmap *mm,struct auxtrace_record *itr,struct perf_tool *tool,process_auxtrace_t fn) {
tools/perf/util/auxtrace.h +14 -0
@@ -23,6 +23,7 @@#include <linux/types.h> #include "../perf.h" +#include "event.h" #include "session.h" union perf_event ;
@@ -32,6 +33,7 @@ struct perf_tool;struct option ;struct record_opts ;struct auxtrace_info_event ; +struct events_stats ;enum itrace_period_type {PERF_ITRACE_PERIOD_INSTRUCTIONS ,
@@ -222,14 +224,26 @@ int auxtrace_record__info_fill(struct auxtrace_record *itr,void auxtrace_record__free (struct auxtrace_record *itr);u64 auxtrace_record__reference (struct auxtrace_record *itr); +void auxtrace_synth_error (struct auxtrace_error_event *auxtrace_error,int type, +int code,int cpu,pid_t pid,pid_t tid,u64 ip, +const char *msg); +int perf_event__synthesize_auxtrace_info (struct auxtrace_record *itr,struct perf_tool *tool,struct perf_session *session,perf_event__handler_t process); +int perf_event__process_auxtrace_error (struct perf_tool *tool, +union perf_event *event, +struct perf_session *session);int itrace_parse_synth_opts (const struct option *opt,const char *str,int unset);void itrace_synth_opts__set_default (struct itrace_synth_opts *synth_opts); +size_t perf_event__fprintf_auxtrace_error (union perf_event *event,FILE *fp); +void perf_session__auxtrace_error_inc (struct perf_session *session, +union perf_event *event); +void events_stats__auxtrace_error_warn (const struct events_stats *stats); + static inline int auxtrace__process_event(struct perf_session *session, union perf_event *event, struct perf_sample *sample,
tools/perf/util/event.h +6 -0
@@ -221,6 +221,11 @@ enum perf_user_event_type { /* above any possible kernel type */ PERF_RECORD_HEADER_MAX }; +enum auxtrace_error_type { +PERF_AUXTRACE_ERROR_ITRACE =1 , +PERF_AUXTRACE_ERROR_MAX +}; +/* * The kernel collects the number of events it couldn't send in a stretch and * when possible sends this number in a PERF_RECORD_LOST event. The number of
@@ -245,6 +250,7 @@ struct events_stats {u32 nr_invalid_chains;u32 nr_unknown_id;u32 nr_unprocessable_samples; +u32 nr_auxtrace_errors[PERF_AUXTRACE_ERROR_MAX ]; };struct attr_event {
tools/perf/util/session.c +3 -0
@@ -1093,6 +1093,7 @@ static s64 perf_session__process_user_event(struct perf_session *session,lseek (fd, file_offset + event->header.size,SEEK_SET );return tool->auxtrace (tool, event, session);case PERF_RECORD_AUXTRACE_ERROR : +perf_session__auxtrace_error_inc (session, event);return tool->auxtrace_error (tool, event, session);default :return -EINVAL ;
@@ -1282,6 +1283,8 @@ static void perf_session__warn_about_errors(const struct perf_session *session)if (oe->nr_unordered_events !=0 )ui__warning ("%u out of order events recorded.\n" , oe->nr_unordered_events); + +events_stats__auxtrace_error_warn (stats); }volatile int session_done;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 23/64 perf auxtrace: Add helpers for queuing AUX area tracing data
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Provide functions to queue AUX area tracing data buffers for processing. A AUX area decoder need not use the queues, however Intel BTS and Intel PT will use them.
There is one queue for each of the mmap buffers that were used for recording. Because those mmaps were associated with per-cpu or per-thread contexts, the data is time-ordered with respect to those contexts.
--- tools/perf/util/auxtrace.c | 305 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/auxtrace.h | 87 +++++++++++++ 2 files changed, 392 insertions(+)
tools/perf/util/auxtrace.c +305 -0
@@ -22,11 +22,15 @@#include <linux/types.h> #include <linux/bitops.h> #include <linux/log2.h> +#include <linux/string.h> +#include <sys/param.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <limits.h> #include <errno.h> +#include <linux/list.h> #include "../perf.h" #include "util.h"
@@ -122,6 +126,241 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp, } } +#define AUXTRACE_INIT_NR_QUEUES 32 + +static struct auxtrace_queue *auxtrace_alloc_queue_array (unsigned int nr_queues) +{ +struct auxtrace_queue *queue_array; +unsigned int max_nr_queues, i; + + max_nr_queues =UINT_MAX /sizeof (struct auxtrace_queue ); +if (nr_queues > max_nr_queues) +return NULL ; + + queue_array =calloc (nr_queues,sizeof (struct auxtrace_queue )); +if (!queue_array) +return NULL ; + +for (i =0 ; i < nr_queues; i++) { +INIT_LIST_HEAD (&queue_array[i].head); + queue_array[i].priv =NULL ; + } + +return queue_array; +} + +int auxtrace_queues__init (struct auxtrace_queues *queues) +{ + queues->nr_queues =AUXTRACE_INIT_NR_QUEUES ; + queues->queue_array =auxtrace_alloc_queue_array (queues->nr_queues); +if (!queues->queue_array) +return -ENOMEM ; +return 0 ; +} + +static int auxtrace_queues__grow (struct auxtrace_queues *queues, +unsigned int new_nr_queues) +{ +unsigned int nr_queues = queues->nr_queues; +struct auxtrace_queue *queue_array; +unsigned int i; + +if (!nr_queues) + nr_queues =AUXTRACE_INIT_NR_QUEUES ; + +while (nr_queues && nr_queues < new_nr_queues) + nr_queues <<=1 ; + +if (nr_queues < queues->nr_queues || nr_queues < new_nr_queues) +return -EINVAL ; + + queue_array =auxtrace_alloc_queue_array (nr_queues); +if (!queue_array) +return -ENOMEM ; + +for (i =0 ; i < queues->nr_queues; i++) { +list_splice_tail (&queues->queue_array[i].head, + &queue_array[i].head); + queue_array[i].priv = queues->queue_array[i].priv; + } + + queues->nr_queues = nr_queues; + queues->queue_array = queue_array; + +return 0 ; +} + +static void *auxtrace_copy_data (u64 size,struct perf_session *session) +{ +int fd =perf_data_file__fd (session->file); +void *p; +ssize_t ret; + +if (size >SSIZE_MAX ) +return NULL ; + + p =malloc (size); +if (!p) +return NULL ; + + ret =readn (fd, p, size); +if (ret != (ssize_t )size) { +free (p); +return NULL ; + } + +return p; +} + +static int auxtrace_queues__add_buffer (struct auxtrace_queues *queues, +unsigned int idx, +struct auxtrace_buffer *buffer) +{ +struct auxtrace_queue *queue; +int err; + +if (idx >= queues->nr_queues) { + err =auxtrace_queues__grow (queues, idx +1 ); +if (err) +return err; + } + + queue = &queues->queue_array[idx]; + +if (!queue->set) { + queue->set = true; + queue->tid = buffer->tid; + queue->cpu = buffer->cpu; + }else if (buffer->cpu != queue->cpu || buffer->tid != queue->tid) { +pr_err ("auxtrace queue conflict: cpu %d, tid %d vs cpu %d, tid %d\n" , + queue->cpu, queue->tid, buffer->cpu, buffer->tid); +return -EINVAL ; + } + + buffer->buffer_nr = queues->next_buffer_nr++; + +list_add_tail (&buffer->list, &queue->head); + + queues->new_data = true; + queues->populated = true; + +return 0 ; +} + +/* Limit buffers to 32MiB on 32-bit */ +#define BUFFER_LIMIT_FOR_32_BIT (32 * 1024 * 1024) + +static int auxtrace_queues__split_buffer (struct auxtrace_queues *queues, +unsigned int idx, +struct auxtrace_buffer *buffer) +{ +u64 sz = buffer->size; +bool consecutive = false; +struct auxtrace_buffer *b; +int err; + +while (sz >BUFFER_LIMIT_FOR_32_BIT ) { + b =memdup (buffer,sizeof (struct auxtrace_buffer )); +if (!b) +return -ENOMEM ; + b->size =BUFFER_LIMIT_FOR_32_BIT ; + b->consecutive = consecutive; + err =auxtrace_queues__add_buffer (queues, idx, b); +if (err) { +auxtrace_buffer__free (b); +return err; + } + buffer->data_offset +=BUFFER_LIMIT_FOR_32_BIT ; + sz -=BUFFER_LIMIT_FOR_32_BIT ; + consecutive = true; + } + + buffer->size = sz; + buffer->consecutive = consecutive; + +return 0 ; +} + +static int auxtrace_queues__add_event_buffer (struct auxtrace_queues *queues, +struct perf_session *session, +unsigned int idx, +struct auxtrace_buffer *buffer) +{ +if (session->one_mmap) { + buffer->data = buffer->data_offset - session->one_mmap_offset + + session->one_mmap_addr; + }else if (perf_data_file__is_pipe (session->file)) { + buffer->data =auxtrace_copy_data (buffer->size, session); +if (!buffer->data) +return -ENOMEM ; + buffer->data_needs_freeing = true; + }else if (BITS_PER_LONG ==32 && + buffer->size >BUFFER_LIMIT_FOR_32_BIT ) { +int err; + + err =auxtrace_queues__split_buffer (queues, idx, buffer); +if (err) +return err; + } + +return auxtrace_queues__add_buffer (queues, idx, buffer); +} + +int auxtrace_queues__add_event (struct auxtrace_queues *queues, +struct perf_session *session, +union perf_event *event,off_t data_offset, +struct auxtrace_buffer **buffer_ptr) +{ +struct auxtrace_buffer *buffer; +unsigned int idx; +int err; + + buffer =zalloc (sizeof (struct auxtrace_buffer )); +if (!buffer) +return -ENOMEM ; + + buffer->pid =-1 ; + buffer->tid = event->auxtrace.tid; + buffer->cpu = event->auxtrace.cpu; + buffer->data_offset = data_offset; + buffer->offset = event->auxtrace.offset; + buffer->reference = event->auxtrace.reference; + buffer->size = event->auxtrace.size; + idx = event->auxtrace.idx; + + err =auxtrace_queues__add_event_buffer (queues, session, idx, buffer); +if (err) + goto out_err; + +if (buffer_ptr) + *buffer_ptr = buffer; + +return 0 ; + +out_err: +auxtrace_buffer__free (buffer); +return err; +} + +void auxtrace_queues__free (struct auxtrace_queues *queues) +{ +unsigned int i; + +for (i =0 ; i < queues->nr_queues; i++) { +while (!list_empty (&queues->queue_array[i].head)) { +struct auxtrace_buffer *buffer; + + buffer =list_entry (queues->queue_array[i].head.next, + struct auxtrace_buffer, list); +list_del (&buffer->list); +auxtrace_buffer__free (buffer); + } + } + +zfree (&queues->queue_array); + queues->nr_queues =0 ; +} +size_t auxtrace_record__info_priv_size (struct auxtrace_record *itr) {if (itr)
@@ -174,6 +413,72 @@ auxtrace_record__init(struct perf_evlist *evlist __maybe_unused, int *err)return NULL ; } +struct auxtrace_buffer *auxtrace_buffer__next (struct auxtrace_queue *queue, +struct auxtrace_buffer *buffer) +{ +if (buffer) { +if (list_is_last (&buffer->list, &queue->head)) +return NULL ; + return list_entry(buffer->list.next, struct auxtrace_buffer, + list); + }else { +if (list_empty (&queue->head)) +return NULL ; + return list_entry(queue->head.next, struct auxtrace_buffer, + list); + } +} + +void *auxtrace_buffer__get_data (struct auxtrace_buffer *buffer,int fd) +{ +size_t adj = buffer->data_offset & (page_size -1 ); +size_t size = buffer->size + adj; +off_t file_offset = buffer->data_offset - adj; +void *addr; + +if (buffer->data) +return buffer->data; + + addr =mmap (NULL , size,PROT_READ ,MAP_SHARED , fd, file_offset); +if (addr ==MAP_FAILED ) +return NULL ; + + buffer->mmap_addr = addr; + buffer->mmap_size = size; + + buffer->data = addr + adj; + +return buffer->data; +} + +void auxtrace_buffer__put_data (struct auxtrace_buffer *buffer) +{ +if (!buffer->data || !buffer->mmap_addr) +return ; +munmap (buffer->mmap_addr, buffer->mmap_size); + buffer->mmap_addr =NULL ; + buffer->mmap_size =0 ; + buffer->data =NULL ; + buffer->use_data =NULL ; +} + +void auxtrace_buffer__drop_data (struct auxtrace_buffer *buffer) +{ +auxtrace_buffer__put_data (buffer); +if (buffer->data_needs_freeing) { + buffer->data_needs_freeing = false; +zfree (&buffer->data); + buffer->use_data =NULL ; + buffer->size =0 ; + } +} + +void auxtrace_buffer__free (struct auxtrace_buffer *buffer) +{ +auxtrace_buffer__drop_data (buffer); +free (buffer); +} +void auxtrace_synth_error (struct auxtrace_error_event *auxtrace_error,int type,int code,int cpu,pid_t pid,pid_t tid,u64 ip,const char *msg)
tools/perf/util/auxtrace.h +87 -0
105 lines not on this page · raw message
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 24/64 perf auxtrace: Add a heap for sorting AUX area tracing queues
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
In order to process AUX area tracing data in time order, the queue with data with the lowest timestamp must be processed first. Provide a heap to keep track of which queue that is.
As with the queues, a decoder does not have to use the heap, but Intel BTS and Intel PT will use it.
--- tools/perf/util/auxtrace.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/auxtrace.h | 29 ++++++++++++++++ 2 files changed, 114 insertions(+)
tools/perf/util/auxtrace.c +85 -0
@@ -361,6 +361,91 @@ void auxtrace_queues__free(struct auxtrace_queues *queues) queues->nr_queues =0 ; } +static void auxtrace_heapify (struct auxtrace_heap_item *heap_array, +unsigned int pos,unsigned int queue_nr, +u64 ordinal) +{ +unsigned int parent; + +while (pos) { + parent = (pos -1 ) >>1 ; +if (heap_array[parent].ordinal <= ordinal) +break ; + heap_array[pos] = heap_array[parent]; + pos = parent; + } + heap_array[pos].queue_nr = queue_nr; + heap_array[pos].ordinal = ordinal; +} + +int auxtrace_heap__add (struct auxtrace_heap *heap,unsigned int queue_nr, +u64 ordinal) +{ +struct auxtrace_heap_item *heap_array; + +if (queue_nr >= heap->heap_sz) { +unsigned int heap_sz =AUXTRACE_INIT_NR_QUEUES ; + +while (heap_sz <= queue_nr) + heap_sz <<=1 ; + heap_array =realloc (heap->heap_array, + heap_sz *sizeof (struct auxtrace_heap_item )); +if (!heap_array) +return -ENOMEM ; + heap->heap_array = heap_array; + heap->heap_sz = heap_sz; + } + +auxtrace_heapify (heap->heap_array, heap->heap_cnt++, queue_nr, ordinal); + +return 0 ; +} + +void auxtrace_heap__free (struct auxtrace_heap *heap) +{ +zfree (&heap->heap_array); + heap->heap_cnt =0 ; + heap->heap_sz =0 ; +} + +void auxtrace_heap__pop (struct auxtrace_heap *heap) +{ +unsigned int pos, last, heap_cnt = heap->heap_cnt; +struct auxtrace_heap_item *heap_array; + +if (!heap_cnt) +return ; + + heap->heap_cnt -=1 ; + + heap_array = heap->heap_array; + + pos =0 ; +while (1 ) { +unsigned int left, right; + + left = (pos <<1 ) +1 ; +if (left >= heap_cnt) +break ; + right = left +1 ; +if (right >= heap_cnt) { + heap_array[pos] = heap_array[left]; +return ; + } +if (heap_array[left].ordinal < heap_array[right].ordinal) { + heap_array[pos] = heap_array[left]; + pos = left; + }else { + heap_array[pos] = heap_array[right]; + pos = right; + } + } + + last = heap_cnt -1 ; +auxtrace_heapify (heap_array, pos, heap_array[last].queue_nr, + heap_array[last].ordinal); +} +size_t auxtrace_record__info_priv_size (struct auxtrace_record *itr) {if (itr)
tools/perf/util/auxtrace.h +29 -0
@@ -168,6 +168,29 @@ struct auxtrace_queues { };/** +* struct auxtrace_heap_item - element of struct auxtrace_heap. +* @queue_nr: queue number +* @ordinal: value used for sorting (lowest ordinal is top of the heap) expected +* to be a timestamp +*/ +struct auxtrace_heap_item { +unsigned int queue_nr; +u64 ordinal; +}; + +/** +* struct auxtrace_heap - a heap suitable for sorting AUX area tracing queues. +* @heap_array: the heap +* @heap_cnt: the number of elements in the heap +* @heap_sz: maximum number of elements (grows as needed) +*/ +struct auxtrace_heap { +struct auxtrace_heap_item *heap_array; +unsigned int heap_cnt; +unsigned int heap_sz; +}; + +/** * struct auxtrace_mmap - records an mmap of the auxtrace buffer. * @base: address of mapped area * @userpg: pointer to buffer's perf_event_mmap_page
@@ -297,6 +320,12 @@ void *auxtrace_buffer__get_data(struct auxtrace_buffer *buffer, int fd);void auxtrace_buffer__put_data (struct auxtrace_buffer *buffer);void auxtrace_buffer__drop_data (struct auxtrace_buffer *buffer);void auxtrace_buffer__free (struct auxtrace_buffer *buffer); + +int auxtrace_heap__add (struct auxtrace_heap *heap,unsigned int queue_nr, +u64 ordinal); +void auxtrace_heap__pop (struct auxtrace_heap *heap); +void auxtrace_heap__free (struct auxtrace_heap *heap); +struct auxtrace_record *auxtrace_record__init (struct perf_evlist *evlist,int *err);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 25/64 perf auxtrace: Add processing for AUX area tracing events
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Provide hooks so that an AUX area decoder can process AUX area tracing events.
--- tools/perf/util/auxtrace.c | 52 +++++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/auxtrace.h | 13 ++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-)
tools/perf/util/auxtrace.c +51 -1
@@ -615,6 +615,53 @@ out_free:return err; } +static bool auxtrace__dont_decode (struct perf_session *session) +{ +return !session->itrace_synth_opts || + session->itrace_synth_opts->dont_decode; +} + +int perf_event__process_auxtrace_info (struct perf_tool *tool__maybe_unused , +union perf_event *event, +struct perf_session *session__maybe_unused ) +{ +enum auxtrace_type type = event->auxtrace_info.type; + +if (dump_trace) +fprintf (stdout," type: %u\n" , type); + +switch (type) { +case PERF_AUXTRACE_UNKNOWN : +default : +return -EINVAL ; + } +} + +s64 perf_event__process_auxtrace (struct perf_tool *tool, +union perf_event *event, +struct perf_session *session) +{ +s64 err; + +if (dump_trace) +fprintf (stdout," size: %#" PRIx64" offset: %#" PRIx64" ref: %#" PRIx64" idx: %u tid: %d cpu: %d\n" , + event->auxtrace.size, event->auxtrace.offset, + event->auxtrace.reference, event->auxtrace.idx, + event->auxtrace.tid, event->auxtrace.cpu); + +if (auxtrace__dont_decode (session)) +return event->auxtrace.size; + +if (!session->auxtrace || event->header.type !=PERF_RECORD_AUXTRACE ) +return -EINVAL ; + + err = session->auxtrace->process_auxtrace_event (session, event, tool); +if (err <0 ) +return err; + +return event->auxtrace.size; +} +#define PERF_ITRACE_DEFAULT_PERIOD_TYPE PERF_ITRACE_PERIOD_NANOSECS#define PERF_ITRACE_DEFAULT_PERIOD 100000#define PERF_ITRACE_DEFAULT_CALLCHAIN_SZ 16
@@ -801,8 +848,11 @@ void events_stats__auxtrace_error_warn(const struct events_stats *stats)int perf_event__process_auxtrace_error (struct perf_tool *tool__maybe_unused ,union perf_event *event, -struct perf_session *session__maybe_unused ) +struct perf_session *session) { +if (auxtrace__dont_decode (session)) +return 0 ; +perf_event__fprintf_auxtrace_error (event, stdout);return 0 ; }
tools/perf/util/auxtrace.h +13 -0
@@ -36,6 +36,10 @@ struct record_opts;struct auxtrace_info_event ;struct events_stats ; +enum auxtrace_type { +PERF_AUXTRACE_UNKNOWN , +}; +enum itrace_period_type {PERF_ITRACE_PERIOD_INSTRUCTIONS ,PERF_ITRACE_PERIOD_TICKS ,
@@ -87,6 +91,9 @@ struct auxtrace {union perf_event *event, struct perf_sample *sample, struct perf_tool *tool); +int (*process_auxtrace_event)(struct perf_session *session, +union perf_event *event, +struct perf_tool *tool);int (*flush_events)(struct perf_session *session,struct perf_tool *tool);void (*free_events)(struct perf_session *session);
@@ -348,6 +355,12 @@ int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr,struct perf_tool *tool, struct perf_session *session, perf_event__handler_t process); +int perf_event__process_auxtrace_info (struct perf_tool *tool, +union perf_event *event, +struct perf_session *session); +s64 perf_event__process_auxtrace (struct perf_tool *tool, +union perf_event *event, +struct perf_session *session);int perf_event__process_auxtrace_error (struct perf_tool *tool,union perf_event *event,struct perf_session *session);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 26/64 perf auxtrace: Add a hashtable for caching
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Decoding AUX area data may involve walking object code. Rather than repetitively decoding the same instructions, a cache can be used to cache the results.
This patch implements a fairly generic hashtable with a 32-bit key that could be used for other purposes as well.
--- tools/perf/util/auxtrace.c | 123 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/auxtrace.h | 14 ++++++ 2 files changed, 137 insertions(+)
tools/perf/util/auxtrace.c +123 -0
@@ -40,6 +40,8 @@#include "asm/bug.h" #include "auxtrace.h" +#include <linux/hash.h> +#include "event.h" #include "session.h" #include "debug.h"
@@ -944,3 +946,124 @@ int auxtrace_mmap__read(struct auxtrace_mmap *mm, struct auxtrace_record *itr,return 1 ; } + +/** +* struct auxtrace_cache - hash table to implement a cache +* @hashtable: the hashtable +* @sz: hashtable size (number of hlists) +* @entry_size: size of an entry +* @limit: limit the number of entries to this maximum, when reached the cache +* is dropped and caching begins again with an empty cache +* @cnt: current number of entries +* @bits: hashtable size (@sz = 2^@bits) +*/ +struct auxtrace_cache { +struct hlist_head *hashtable; +size_t sz; +size_t entry_size; +size_t limit; +size_t cnt; +unsigned int bits; +}; + +struct auxtrace_cache *auxtrace_cache__new (unsigned int bits,size_t entry_size, +unsigned int limit_percent) +{ +struct auxtrace_cache *c; +struct hlist_head *ht; +size_t sz, i; + + c =zalloc (sizeof (struct auxtrace_cache )); +if (!c) +return NULL ; + + sz =1UL << bits; + + ht =calloc (sz,sizeof (struct hlist_head )); +if (!ht) + goto out_free; + +for (i =0 ; i < sz; i++) +INIT_HLIST_HEAD (&ht[i]); + + c->hashtable = ht; + c->sz = sz; + c->entry_size = entry_size; + c->limit = (c->sz * limit_percent) /100 ; + c->bits = bits; + +return c; + +out_free: +free (c); +return NULL ; +} + +static void auxtrace_cache__drop (struct auxtrace_cache *c) +{ +struct auxtrace_cache_entry *entry; +struct hlist_node *tmp; +size_t i; + +if (!c) +return ; + +for (i =0 ; i < c->sz; i++) { +hlist_for_each_entry_safe (entry, tmp, &c->hashtable[i], hash) { +hlist_del (&entry->hash); +auxtrace_cache__free_entry (c, entry); + } + } + + c->cnt =0 ; +} + +void auxtrace_cache__free (struct auxtrace_cache *c) +{ +if (!c) +return ; + +auxtrace_cache__drop (c); +free (c->hashtable); +free (c); +} + +void *auxtrace_cache__alloc_entry (struct auxtrace_cache *c) +{ +return malloc (c->entry_size); +} + +void auxtrace_cache__free_entry (struct auxtrace_cache *c__maybe_unused , +void *entry) +{ +free (entry); +} + +int auxtrace_cache__add (struct auxtrace_cache *c,u32 key, +struct auxtrace_cache_entry *entry) +{ +if (c->limit && ++c->cnt > c->limit) +auxtrace_cache__drop (c); + + entry->key = key; +hlist_add_head (&entry->hash, &c->hashtable[hash_32 (key, c->bits)]); + +return 0 ; +} + +void *auxtrace_cache__lookup (struct auxtrace_cache *c,u32 key) +{ +struct auxtrace_cache_entry *entry; +struct hlist_head *hlist; + +if (!c) +return NULL ; + + hlist = &c->hashtable[hash_32 (key, c->bits)]; +hlist_for_each_entry (entry, hlist, hash) { +if (entry->key == key) +return entry; + } + +return NULL ; +}
tools/perf/util/auxtrace.h +14 -0
@@ -333,6 +333,20 @@ int auxtrace_heap__add(struct auxtrace_heap *heap, unsigned int queue_nr,void auxtrace_heap__pop (struct auxtrace_heap *heap);void auxtrace_heap__free (struct auxtrace_heap *heap); +struct auxtrace_cache_entry { +struct hlist_node hash; +u32 key; +}; + +struct auxtrace_cache *auxtrace_cache__new (unsigned int bits,size_t entry_size, +unsigned int limit_percent); +void auxtrace_cache__free (struct auxtrace_cache *auxtrace_cache); +void *auxtrace_cache__alloc_entry (struct auxtrace_cache *c); +void auxtrace_cache__free_entry (struct auxtrace_cache *c,void *entry); +int auxtrace_cache__add (struct auxtrace_cache *c,u32 key, +struct auxtrace_cache_entry *entry); +void *auxtrace_cache__lookup (struct auxtrace_cache *c,u32 key); +struct auxtrace_record *auxtrace_record__init (struct perf_evlist *evlist,int *err);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 27/64 perf tools: Add member to struct dso for an instruction cache
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add a member to struct dso that can be used by Instruction Trace implementations to hold a cache for decoded instructions.
--- tools/perf/util/dso.c | 2 ++ tools/perf/util/dso.h | 3 +++ 2 files changed, 5 insertions(+)
tools/perf/util/dso.c +2 -0
@@ -4,6 +4,7 @@#include "symbol.h" #include "dso.h" #include "machine.h" +#include "auxtrace.h" #include "util.h" #include "debug.h"
@@ -961,6 +962,7 @@ void dso__delete(struct dso *dso) }dso__data_close (dso); +auxtrace_cache__free (dso->auxtrace_cache);dso_cache__free (&dso->data.cache);dso__free_a2l (dso);zfree (&dso->symsrc_filename);
tools/perf/util/dso.h +3 -0
@@ -126,6 +126,8 @@ struct dsos {struct rb_root root;/* rbtree root sorted by long name */ }; +struct auxtrace_cache ; +struct dso {struct list_head node;struct rb_node rb_node;/* rbtree node sorted by long name */
@@ -156,6 +158,7 @@ struct dso {u16 long_name_len;u16 short_name_len;void *dwfl;/* DWARF debug info */ +struct auxtrace_cache *auxtrace_cache;/* dso data file */ struct {
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 28/64 perf script: Add Instruction Tracing support
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add support for decoding an AUX area assuming it contains instruction tracing data.
--- tools/perf/Documentation/perf-script.txt | 27 +++++++++++++++++++++++++++ tools/perf/builtin-script.c | 11 +++++++++++ 2 files changed, 38 insertions(+)
tools/perf/Documentation/perf-script.txt +27 -0
@@ -221,6 +221,33 @@ OPTIONS --header-only Show only perf.data header. +--itrace:: + Options for decoding instruction tracing data. The options are: + + i synthesize instructions events + b synthesize branches events + c synthesize branches events (calls only) + r synthesize branches events (returns only) + e synthesize error events + d create a debug log + g synthesize a call chain for instructions events + + The default is all events i.e. the same as --itrace=ibe + + In addition, the period (default 100000) for instructions events + can be specified in units of: + + i instructions + t ticks + ms milliseconds + us microseconds + ns nanoseconds (default) + + Also the call chain size (default 16, max. 1024) for instructions + events can be specified. + + To disable decoding entirely, use --no-itrace. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +11 -0
@@ -16,6 +16,7 @@#include "util/evsel.h" #include "util/sort.h" #include "util/data.h" +#include "util/auxtrace.h" #include <linux/bitmap.h> static char const *script_name;
@@ -1497,6 +1498,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)char *rec_script_path =NULL ;char *rep_script_path =NULL ;struct perf_session *session; +struct itrace_synth_opts itrace_synth_opts = {0 };char *script_path =NULL ;const char **__argv;int i, j, err =0 ;
@@ -1511,6 +1513,10 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) .attr = process_attr, .tracing_data = perf_event__process_tracing_data, .build_id = perf_event__process_build_id, + .id_index = perf_event__process_id_index, + .auxtrace_info = perf_event__process_auxtrace_info, + .auxtrace = perf_event__process_auxtrace, + .auxtrace_error = perf_event__process_auxtrace_error, .ordered_events = true, .ordering_requires_timestamps = true, },
@@ -1570,6 +1576,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN ('\0' ,"show-mmap-events" , &script.show_mmap_events,"Show the mmap events" ),OPT_BOOLEAN ('f' ,"force" , &file.force,"don't complain, do it" ), +OPT_CALLBACK_OPTARG (0 ,"itrace" , &itrace_synth_opts,NULL ,"opts" , +"Instruction Tracing options" , + itrace_parse_synth_opts), OPT_END() };const char *const script_subcommands[] = {"record" ,"report" ,NULL };
@@ -1765,6 +1774,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) script.session = session; + session->itrace_synth_opts = &itrace_synth_opts; +if (cpu_list) { err =perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap);if (err <0 )
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 29/64 perf inject: Re-pipe AUX area tracing events
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
New AUX area tracing events must be re-piped by default.
--- tools/perf/builtin-inject.c | 63 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 5 deletions(-)
tools/perf/builtin-inject.c +58 -5
@@ -38,14 +38,11 @@ struct event_entry {union perf_event event[0 ]; }; -static int perf_event__repipe_synth (struct perf_tool *tool, -union perf_event *event) +static int output_bytes (struct perf_inject *inject,void *buf,size_t sz) { - struct perf_inject *inject = container_of(tool, struct perf_inject, tool);ssize_t size; - size =perf_data_file__write (&inject->output, event, - event->header.size); + size =perf_data_file__write (&inject->output, buf, sz);if (size <0 )return -errno;
@@ -53,6 +50,34 @@ static int perf_event__repipe_synth(struct perf_tool *tool,return 0 ; } +static int copy_bytes (struct perf_inject *inject,int fd,off_t size) +{ +char buf[4096 ]; +ssize_t ssz; +int ret; + +while (size >0 ) { + ssz =read (fd, buf,min (size, (off_t )sizeof (buf))); +if (ssz <0 ) +return -errno; + ret =output_bytes (inject, buf, ssz); +if (ret) +return ret; + size -= ssz; + } + +return 0 ; +} + +static int perf_event__repipe_synth (struct perf_tool *tool, +union perf_event *event) +{ + struct perf_inject *inject = container_of(tool, struct perf_inject, + tool); + +return output_bytes (inject, event, event->header.size); +} +static int perf_event__repipe_oe_synth (struct perf_tool *tool,union perf_event *event,struct ordered_events *oe__maybe_unused )
@@ -86,6 +111,31 @@ static int perf_event__repipe_attr(struct perf_tool *tool,return perf_event__repipe_synth (tool, event); } +static s64 perf_event__repipe_auxtrace (struct perf_tool *tool, +union perf_event *event, +struct perf_session *session +__maybe_unused ) +{ + struct perf_inject *inject = container_of(tool, struct perf_inject, + tool); +int ret; + +if (perf_data_file__is_pipe (session->file) || !session->one_mmap) { + ret =output_bytes (inject, event, event->header.size); +if (ret <0 ) +return ret; + ret =copy_bytes (inject,perf_data_file__fd (session->file), + event->auxtrace.size); + }else { + ret =output_bytes (inject, event, + event->header.size + event->auxtrace.size); + } +if (ret <0 ) +return ret; + +return event->auxtrace.size; +} + static int perf_event__repipe(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused,
@@ -413,6 +463,9 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) .unthrottle = perf_event__repipe, .attr = perf_event__repipe_attr, .tracing_data = perf_event__repipe_op2_synth, + .auxtrace_info = perf_event__repipe_op2_synth, + .auxtrace = perf_event__repipe_auxtrace, + .auxtrace_error = perf_event__repipe_op2_synth, .finished_round = perf_event__repipe_oe_synth, .build_id = perf_event__repipe_op2_synth, .id_index = perf_event__repipe_op2_synth,
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 30/64 perf inject: Add Instruction Tracing support
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add support for decoding an AUX area assuming it contains instruction tracing data. The AUX area tracing events are stripped and replaced by synthesized events.
--- tools/perf/Documentation/perf-inject.txt | 26 ++++++++++++ tools/perf/builtin-inject.c | 71 +++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-inject.txt +26 -0
@@ -44,6 +44,32 @@ OPTIONS --kallsyms=<file>:: kallsyms pathname +--itrace:: + Decode Instruction Tracing data, replacing it with synthesized events. + Options are: + + i synthesize instructions events + b synthesize branches events + c synthesize branches events (calls only) + r synthesize branches events (returns only) + e synthesize error events + d create a debug log + g synthesize a call chain for instructions events + + The default is all events i.e. the same as --itrace=ibe + + In addition, the period (default 100000) for instructions events + can be specified in units of: + + i instructions + t ticks + ms milliseconds + us microseconds + ns nanoseconds (default) + + Also the call chain size (default 16, max. 1024) for instructions + events can be specified. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-archive[1]
tools/perf/builtin-inject.c +69 -2
131 lines not on this page · raw message
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 31/64 perf script: Add field option 'flags' to print sample flags
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Instruction tracing will typically have access to information about the instruction being executed for a particular ip sample. Some of that information will be available in the 'flags' member of struct perf_sample.
With the addition of transactions events synthesis to Instruction Tracing options, there is a need to be able easily to see the flags because they show whether the ip is at the start, commit or abort of a tranasaction.
Consequently add an option to display the flags.
The flags are "bcrosyiABEx" which stand for branch, call, return, conditional, system, asynchronous, interrupt, transaction abort, trace begin, trace end, and in transaction, respectively.
Example using Intel PT:
perf script -fip,time,event,sym,addr,flags
...
1288.721584105: branches:u: bo 401146 main => 401152 main
1288.721584105: transactions: x 0 401164 main
1288.721584105: branches:u: bx 40117c main => 40119b main 1288.721584105: branches:u: box 4011a4 main => 40117e main 1288.721584105: branches:u: bcx 401187 main => 401094 g ... 1288.721591645: branches:u: bx 4010c4 g => 4010cb g 1288.721591645: branches:u: brx 4010cc g => 401189 main 1288.721591645: transactions: 0 4011a6 main 1288.721593199: branches:u: b 4011a9 main => 4011af main 1288.721593199: branches:u: bo 4011bc main => 40113e main 1288.721593199: branches:u: b 401150 main => 40115a main 1288.721593199: transactions: x 0 401164 main 1288.721593199: branches:u: bx 40117c main => 40119b main 1288.721593199: branches:u: box 4011a4 main => 40117e main 1288.721593199: branches:u: bcx 401187 main => 40105e f ... 1288.722284747: branches:u: brx 401093 f => 401189 main 1288.722284747: branches:u: box 4011a4 main => 40117e main 1288.722284747: branches:u: bcx 401187 main => 40105e f 1288.722285883: transactions: bA 0 401071 f 1288.722285883: branches:u: bA 401071 f => 40116a main 1288.722285883: branches:u: bE 40116a main => 0 [unknown] 1288.722297174: branches:u: bB 0 [unknown] => 40116a main
...
--- tools/perf/Documentation/perf-script.txt | 9 ++++++++- tools/perf/builtin-script.c | 34 +++++++++++++++++++++++++++----- tools/perf/util/event.h | 2 ++ 3 files changed, 39 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-script.txt +8 -1
@@ -115,7 +115,8 @@ OPTIONS -f:: --fields:: Comma separated list of fields to print. Options are: - comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, srcline, period. + comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, + srcline, period, flags. Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace
@@ -165,6 +166,12 @@ OPTIONS At this point usage is displayed, and perf-script exits. + The flags field is synthesized and may have a value when Instruction + Trace decoding. The flags are "bcrosyiABEx" which stand for branch, + call, return, conditional, system, asynchronous, interrupt, + transaction abort, trace begin, trace end, and in transaction, + respectively. + Finally, a user may not set fields to none for all event types. i.e., -f "" is not allowed.
tools/perf/builtin-script.c +29 -5
@@ -27,6 +27,7 @@ static u64 nr_unordered;static bool no_callchain;static bool latency_format;static bool system_wide; +static bool print_flags;static const char *cpu_list; static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -446,6 +447,25 @@ static void print_sample_bts(union perf_event *event,printf ("\n" ); } +static void print_sample_flags (u32 flags) +{ +const char *chars =PERF_IP_FLAG_CHARS ; +const int n =strlen (PERF_IP_FLAG_CHARS ); +char str[33 ]; +int i, pos =0 ; + +for (i =0 ; i < n; i++, flags >>=1 ) { +if (flags &1 ) + str[pos++] = chars[i]; + } +for (; i <32 ; i++, flags >>=1 ) { +if (flags &1 ) + str[pos++] ='?' ; + } + str[pos] =0 ; +printf (" %-4s " , str); +} +static void process_event (union perf_event *event,struct perf_sample *sample,struct perf_evsel *evsel,struct addr_location *al) {
@@ -465,6 +485,9 @@ static void process_event(union perf_event *event, struct perf_sample *sample,printf ("%s: " , evname ? evname :"[unknown]" ); } +if (print_flags) +print_sample_flags (sample->flags); +if (is_bts_event (attr)) {print_sample_bts (event, sample, evsel, thread, al);return ;
@@ -1000,12 +1023,15 @@ static int parse_output_fields(const struct option *opt __maybe_unused, } } - tok =strtok (tok,"," ); -while (tok) { +for (tok =strtok (tok,"," ); tok; tok =strtok (NULL ,"," )) {for (i =0 ; i < imax; ++i) {if (strcmp (tok, all_output_options[i].str) ==0 )break ; } +if (i == imax &&strcmp (tok,"flags" ) ==0 ) { + print_flags = true; +continue ; + }if (i == imax) {fprintf (stderr,"Invalid field requested.\n" ); rc = -EINVAL ;
@@ -1033,8 +1059,6 @@ static int parse_output_fields(const struct option *opt __maybe_unused, } output[type].fields |= all_output_options[i].field; } - - tok =strtok (NULL ,"," ); }if (type >=0 ) {
@@ -1555,7 +1579,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) "comma separated output fields prepend with 'type:'. " "Valid types: hw,sw,trace,raw. " "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," - "addr,symoff,period", parse_output_fields), + "addr,symoff,period,flags", parse_output_fields),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide,"system-wide collection from all CPUs" ), OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
tools/perf/util/event.h +2 -0
@@ -157,6 +157,8 @@ enum { PERF_IP_FLAG_IN_TX = 1ULL << 10, }; +#define PERF_IP_FLAG_CHARS "bcrosyiABEx" +#define PERF_BRANCH_MASK (\ PERF_IP_FLAG_BRANCH |\ PERF_IP_FLAG_CALL |\
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 32/64 perf tools: Add aux_watermark member of struct perf_event_attr
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add new AUX area member (aux_watermark) of struct perf_event_attr to debug prints and byte swapping.
--- tools/perf/util/evsel.c | 1 + tools/perf/util/session.c | 1 + 2 files changed, 2 insertions(+)
tools/perf/util/evsel.c +1 -0
@@ -1121,6 +1121,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,PRINT_ATTRf (sample_stack_user, p_unsigned);PRINT_ATTRf (clockid, p_signed);PRINT_ATTRf (sample_regs_intr, p_hex); +PRINT_ATTRf (aux_watermark, p_unsigned);return ret; }
tools/perf/util/session.c +1 -0
@@ -500,6 +500,7 @@ void perf_event__attr_swap(struct perf_event_attr *attr) attr->branch_sample_type =bswap_64 (attr->branch_sample_type); attr->sample_regs_user =bswap_64 (attr->sample_regs_user); attr->sample_stack_user =bswap_32 (attr->sample_stack_user); + attr->aux_watermark =bswap_32 (attr->aux_watermark);swap_bitfield ((u8 *) (&attr->read_format +1 ),sizeof (u64)); }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 33/64 perf tools: Add parse_events_error interface
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding support to return error information from parse_events function. Following struct will be populated by parse_events function on return:
struct parse_events_error {
int idx;
char *str;
char *help;
};where 'idx' is the position in the string where the parsing failed, 'str' contains dynamically allocated error string describing the error and 'help' is optional help string.
The change contains reporting function, which currently does not display anything. The code changes to supply error data for specific event types are coming in next patches. However this is what the expected output is:
$ sudo perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
... $ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
...
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...The output functions cut the beginning of the event string so the error starts up to 10th character and cut the end of the string of it crosses the terminal width.
--- tools/perf/builtin-stat.c | 2 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 4 +- tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 4 +- tools/perf/tests/hists_link.c | 4 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/keep-tracking.c | 4 +- tools/perf/tests/parse-events.c | 2 +- tools/perf/tests/perf-time-to-tsc.c | 2 +- tools/perf/tests/switch-tracking.c | 8 +-- tools/perf/util/parse-events.c | 100 +++++++++++++++++++++++++++++--- tools/perf/util/parse-events.h | 19 ++++-- tools/perf/util/record.c | 4 +- 14 files changed, 127 insertions(+), 32 deletions(-)
tools/perf/builtin-stat.c +1 -1
@@ -1541,7 +1541,7 @@ static int setup_events(const char * const *attrs, unsigned len)unsigned i;for (i =0 ; i < len; i++) { -if (parse_events (evsel_list, attrs[i])) +if (parse_events (evsel_list, attrs[i],NULL ))return -1 ; }return 0 ;
tools/perf/tests/code-reading.c +1 -1
@@ -482,7 +482,7 @@ static int do_test_code_reading(bool try_kcore)else str ="cycles" ;pr_debug ("Parsing event '%s'\n" , str); - ret =parse_events (evlist, str); + ret =parse_events (evlist, str,NULL );if (ret <0 ) {pr_debug ("parse_events failed\n" ); goto out_err;
tools/perf/tests/evsel-roundtrip-name.c +2 -2
@@ -23,7 +23,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)for (i =0 ; i <PERF_COUNT_HW_CACHE_RESULT_MAX ; i++) {__perf_evsel__hw_cache_type_op_res_name (type, op, i, name,sizeof (name)); - err =parse_events (evlist, name); + err =parse_events (evlist, name,NULL );if (err) ret = err; }
@@ -71,7 +71,7 @@ static int __perf_evsel__name_array_test(const char *names[], int nr_names)return -ENOMEM ;for (i =0 ; i < nr_names; ++i) { - err =parse_events (evlist, names[i]); + err =parse_events (evlist, names[i],NULL );if (err) {pr_debug ("failed to parse event '%s', err %d\n" , names[i], err);
tools/perf/tests/hists_cumulate.c +1 -1
@@ -695,7 +695,7 @@ int test__hists_cumulate(void)TEST_ASSERT_VAL ("No memory" , evlist); - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out;
tools/perf/tests/hists_filter.c +2 -2
@@ -108,10 +108,10 @@ int test__hists_filter(void)TEST_ASSERT_VAL ("No memory" , evlist); - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out; - err =parse_events (evlist,"task-clock" ); + err =parse_events (evlist,"task-clock" ,NULL );if (err) goto out;
tools/perf/tests/hists_link.c +2 -2
@@ -282,10 +282,10 @@ int test__hists_link(void)if (evlist ==NULL )return -ENOMEM ; - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out; - err =parse_events (evlist,"task-clock" ); + err =parse_events (evlist,"task-clock" ,NULL );if (err) goto out;
tools/perf/tests/hists_output.c +1 -1
@@ -590,7 +590,7 @@ int test__hists_output(void)TEST_ASSERT_VAL ("No memory" , evlist); - err =parse_events (evlist,"cpu-clock" ); + err =parse_events (evlist,"cpu-clock" ,NULL );if (err) goto out;
tools/perf/tests/keep-tracking.c +2 -2
@@ -78,8 +78,8 @@ int test__keep_tracking(void)perf_evlist__set_maps (evlist, cpus, threads); -CHECK__ (parse_events (evlist,"dummy:u" )); -CHECK__ (parse_events (evlist,"cycles:u" )); +CHECK__ (parse_events (evlist,"dummy:u" ,NULL )); +CHECK__ (parse_events (evlist,"cycles:u" ,NULL ));perf_evlist__config (evlist, &opts);
tools/perf/tests/parse-events.c +1 -1
@@ -1571,7 +1571,7 @@ static int test_event(struct evlist_test *e)if (evlist ==NULL )return -ENOMEM ; - ret =parse_events (evlist, e->name); + ret =parse_events (evlist, e->name,NULL );if (ret) {pr_debug ("failed to parse event '%s', err %d\n" , e->name, ret);
tools/perf/tests/perf-time-to-tsc.c +1 -1
@@ -68,7 +68,7 @@ int test__perf_time_to_tsc(void)perf_evlist__set_maps (evlist, cpus, threads); -CHECK__ (parse_events (evlist,"cycles:u" )); +CHECK__ (parse_events (evlist,"cycles:u" ,NULL ));perf_evlist__config (evlist, &opts);
tools/perf/tests/switch-tracking.c +4 -4
@@ -347,7 +347,7 @@ int test__switch_tracking(void)perf_evlist__set_maps (evlist, cpus, threads);/* First event */ - err =parse_events (evlist,"cpu-clock:u" ); + err =parse_events (evlist,"cpu-clock:u" ,NULL );if (err) {pr_debug ("Failed to parse event dummy:u\n" ); goto out_err;
@@ -356,7 +356,7 @@ int test__switch_tracking(void) cpu_clocks_evsel =perf_evlist__last (evlist);/* Second event */ - err =parse_events (evlist,"cycles:u" ); + err =parse_events (evlist,"cycles:u" ,NULL );if (err) {pr_debug ("Failed to parse event cycles:u\n" ); goto out_err;
@@ -371,7 +371,7 @@ int test__switch_tracking(void) goto out; } - err =parse_events (evlist, sched_switch); + err =parse_events (evlist, sched_switch,NULL );if (err) {pr_debug ("Failed to parse event %s\n" , sched_switch); goto out_err;
@@ -401,7 +401,7 @@ int test__switch_tracking(void)perf_evsel__set_sample_bit (cycles_evsel,TIME );/* Fourth event */ - err =parse_events (evlist,"dummy:u" ); + err =parse_events (evlist,"dummy:u" ,NULL );if (err) {pr_debug ("Failed to parse event dummy:u\n" ); goto out_err;
tools/perf/util/parse-events.c +92 -8
128 lines not on this page · raw message
tools/perf/util/parse-events.h +15 -4
@@ -12,6 +12,7 @@struct list_head ;struct perf_evsel ;struct perf_evlist ; +struct parse_events_error ;struct option ;
@@ -29,7 +30,8 @@ const char *event_type(int type);extern int parse_events_option (const struct option *opt,const char *str,int unset); -extern int parse_events (struct perf_evlist *evlist,const char *str); +extern int parse_events (struct perf_evlist *evlist,const char *str, +struct parse_events_error *error);extern int parse_events_terms (struct list_head *terms,const char *str);extern int parse_filter (const struct option *opt,const char *str,int unset);
@@ -74,10 +76,17 @@ struct parse_events_term {bool used; }; +struct parse_events_error { +int idx;/* index in the parsed string */ +char *str;/* string to display at the index */ +char *help;/* optional help string */ +}; +struct parse_events_evlist { -struct list_head list; -int idx; -int nr_groups; +struct list_head list; +int idx; +int nr_groups; +struct parse_events_error *error; };struct parse_events_terms {
@@ -114,6 +123,8 @@ void parse_events__set_leader(char *name, struct list_head *list);void parse_events_update_lists (struct list_head *list_event,struct list_head *list_all);void parse_events_error (void *data,void *scanner,char const *msg); +void parse_events_evlist_error (struct parse_events_evlist *data, +int idx,const char *str);void print_events (const char *event_glob,bool name_only);
tools/perf/util/record.c +2 -2
@@ -20,7 +20,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)if (!evlist)return -ENOMEM ; -if (parse_events (evlist, str)) +if (parse_events (evlist, str,NULL )) goto out_delete; evsel =perf_evlist__first (evlist);
@@ -216,7 +216,7 @@ bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)if (!temp_evlist)return false; - err =parse_events (temp_evlist, str); + err =parse_events (temp_evlist, str,NULL );if (err) goto out_delete;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 34/64 perf tools: Add flex support for parse_events_error
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Allowing flex parser to report back event parsing error, like:
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...--- tools/perf/util/parse-events.h | 1 - tools/perf/util/parse-events.l | 37 +++++++++++++++++++++++++++++++++---- tools/perf/util/parse-events.y | 7 ++++--- 3 files changed, 37 insertions(+), 8 deletions(-)
tools/perf/util/parse-events.h +0 -1
@@ -122,7 +122,6 @@ perf_pmu__parse_check(const char *name);void parse_events__set_leader (char *name,struct list_head *list);void parse_events_update_lists (struct list_head *list_event,struct list_head *list_all); -void parse_events_error (void *data,void *scanner,char const *msg);void parse_events_evlist_error (struct parse_events_evlist *data,int idx,const char *str);
tools/perf/util/parse-events.l +33 -4
@@ -3,6 +3,8 @@ %option bison-bridge %option prefix="parse_events_" %option stack +%option bison-locations +%option yylineno %{ #include <errno.h>
@@ -51,6 +53,18 @@ static int str(yyscan_t scanner, int token) return token; } +#define REWIND(__alloc) \ +do { \ + YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \ + char *text = parse_events_get_text(yyscanner); \ + \ + if (__alloc) \ + __yylval->str = strdup(text); \ + \ + yycolumn -= strlen(text); \ + yyless(0); \ +} while (0) + static int pmu_str_check(yyscan_t scanner) { YYSTYPE *yylval = parse_events_get_lval(scanner);
@@ -85,6 +99,13 @@ static int term(yyscan_t scanner, int type) return PE_TERM; } +#define YY_USER_ACTION \ +do { \ + yylloc->last_column = yylloc->first_column; \ + yylloc->first_column = yycolumn; \ + yycolumn += yyleng; \ +} while (0); + %} %x mem
@@ -119,6 +140,12 @@ modifier_bp [rwx]{1,3} if (start_token) { parse_events_set_extra(NULL, yyscanner); + /* + * The flex parser does not init locations variable + * via the scan_string interface, so we need do the + * init in here. + */ + yycolumn = 0; return start_token; } }
@@ -127,19 +154,21 @@ modifier_bp [rwx]{1,3} <event>{ {group} { - BEGIN(INITIAL); yyless(0); + BEGIN(INITIAL); + REWIND(0); } {event_pmu} | {event} { - str(yyscanner, PE_EVENT_NAME); - BEGIN(INITIAL); yyless(0); + BEGIN(INITIAL); + REWIND(1); return PE_EVENT_NAME; } . | <<EOF>> { - BEGIN(INITIAL); yyless(0); + BEGIN(INITIAL); + REWIND(0); } }
tools/perf/util/parse-events.y +4 -3
@@ -2,6 +2,7 @@ %parse-param {void *_data} %parse-param {void *scanner} %lex-param {void* scanner} +%locations %{
@@ -14,8 +15,6 @@ #include "parse-events.h" #include "parse-events-bison.h" -extern int parse_events_lex (YYSTYPE* lvalp, void* scanner); - #define ABORT_ON(val) \ do { \ if (val) \
@@ -520,7 +519,9 @@ sep_slash_dc: '/' | ':' | %% -void parse_events_error(void *data __maybe_unused, void *scanner __maybe_unused, +void parse_events_error(YYLTYPE *loc, void *data, + void *scanner __maybe_unused, char const *msg __maybe_unused) { + parse_events_evlist_error(data, loc->last_column, "parser error"); }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 35/64 perf tools: Always bail out when config_attr function fails
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Not sure why we allowed the fail state, but it's wrong. Wrong type for 'name' term can cause segfault, and there's probably more fun hidden.
--- tools/perf/util/parse-events.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
tools/perf/util/parse-events.c +11 -4
@@ -549,6 +549,12 @@ do { \ }while (0 )switch (term->type_term) { +case PARSE_EVENTS__TERM_TYPE_USER : +/* +* Always succeed for sysfs terms, as we dont know +* at this point what type they need to have. +*/ +return 0 ;case PARSE_EVENTS__TERM_TYPE_CONFIG :CHECK_TYPE_VAL (NUM ); attr->config = term->val.num;
@@ -583,12 +589,12 @@ do { \ }static int config_attr (struct perf_event_attr *attr, -struct list_head *head,int fail) +struct list_head *head) {struct parse_events_term *term;list_for_each_entry (term, head, list) -if (config_term (attr, term) && fail) +if (config_term (attr, term))return -EINVAL ;return 0 ;
@@ -605,7 +611,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config;if (head_config && -config_attr (&attr, head_config,1 )) +config_attr (&attr, head_config))return -EINVAL ;return add_event (list, idx, &attr,NULL );
@@ -659,7 +665,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx,* Configure hardcoded terms first, no need to check * return value when called with fail == 0 ;) */ -config_attr (&attr, head_config,0 ); +if (config_attr (&attr, head_config)) +return -EINVAL ;if (perf_pmu__config (pmu, &attr, head_config))return -EINVAL ;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 36/64 perf tools: Change parse_events_add_pmu interface
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Changing parse_events_add_pmu interface to allow propagating of the parse_events_error info.
--- tools/perf/util/parse-events.c | 11 ++++++----- tools/perf/util/parse-events.h | 5 +++-- tools/perf/util/parse-events.y | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-)
tools/perf/util/parse-events.c +6 -5
@@ -633,8 +633,9 @@ static char *pmu_event_name(struct list_head *head_terms)return NULL ; } -int parse_events_add_pmu (struct list_head *list,int *idx, -char *name,struct list_head *head_config) +int parse_events_add_pmu (struct parse_events_evlist *data, +struct list_head *list,char *name, +struct list_head *head_config) {struct perf_event_attr attr;struct perf_pmu_info info;
@@ -654,7 +655,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx,if (!head_config) { attr.type = pmu->type; - evsel =__add_event (list, idx, &attr,NULL , pmu->cpus); + evsel =__add_event (list, &data->idx, &attr,NULL , pmu->cpus);return evsel ?0 : -ENOMEM ; }
@@ -671,8 +672,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx,if (perf_pmu__config (pmu, &attr, head_config))return -EINVAL ; - evsel =__add_event (list, idx, &attr,pmu_event_name (head_config), - pmu->cpus); + evsel =__add_event (list, &data->idx, &attr, +pmu_event_name (head_config), pmu->cpus);if (evsel) { evsel->unit = info.unit; evsel->scale = info.scale;
tools/perf/util/parse-events.h +3 -2
@@ -115,8 +115,9 @@ int parse_events_add_cache(struct list_head *list, int *idx, char *type, char *op_result1, char *op_result2);int parse_events_add_breakpoint (struct list_head *list,int *idx,void *ptr,char *type,u64 len); -int parse_events_add_pmu (struct list_head *list,int *idx, -char *pmu ,struct list_head *head_config); +int parse_events_add_pmu (struct parse_events_evlist *data, +struct list_head *list,char *name, +struct list_head *head_config);enum perf_pmu_event_symbol_type perf_pmu__parse_check (const char *name);void parse_events__set_leader (char *name,struct list_head *list);
tools/perf/util/parse-events.y +3 -3
@@ -207,7 +207,7 @@ PE_NAME '/' event_config '/' struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(list, &data->idx, $1, $3)); + ABORT_ON(parse_events_add_pmu(data, list, $1, $3)); parse_events__free_terms($3); $$ = list; }
@@ -218,7 +218,7 @@ PE_NAME '/' '/' struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(list, &data->idx, $1, NULL)); + ABORT_ON(parse_events_add_pmu(data, list, $1, NULL)); $$ = list; } |
@@ -235,7 +235,7 @@ PE_KERNEL_PMU_EVENT sep_dc list_add_tail(&term->list, head); ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(list, &data->idx, "cpu", head)); + ABORT_ON(parse_events_add_pmu(data, list, "cpu", head)); parse_events__free_terms(head); $$ = list; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 37/64 perf tools: Add location to pmu event terms
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Saving the terms location within term struct, so it could be used later for report.
--- tools/perf/util/parse-events.c | 32 ++++++++++++++++++++++++-------- tools/perf/util/parse-events.h | 8 ++++---- tools/perf/util/parse-events.y | 16 ++++++++-------- 3 files changed, 36 insertions(+), 20 deletions(-)
tools/perf/util/parse-events.c +24 -8
@@ -25,6 +25,12 @@extern int parse_events_debug;#endif int parse_events_parse (void *data,void *scanner); +int parse_events_term__num (struct parse_events_term **term, +int type_term,char *config,u64 num, +YYLTYPE *loc_term,YYLTYPE *loc_val); +int parse_events_term__str (struct parse_events_term **term, +int type_term,char *config,char *str, +YYLTYPE *loc_term,YYLTYPE *loc_val);static struct perf_pmu_event_symbol *perf_pmu_events_list;/*
@@ -1542,7 +1548,7 @@ int parse_events__is_hardcoded_term(struct parse_events_term *term)static int new_term (struct parse_events_term **_term,int type_val,int type_term,char *config, -char *str,u64 num) +char *str,u64 num,int err_term,int err_val) {struct parse_events_term *term;
@@ -1554,6 +1560,8 @@ static int new_term(struct parse_events_term **_term, int type_val, term->type_val = type_val; term->type_term = type_term; term->config = config; + term->err_term = err_term; + term->err_val = err_val;switch (type_val) {case PARSE_EVENTS__TERM_TYPE_NUM :
@@ -1572,17 +1580,23 @@ static int new_term(struct parse_events_term **_term, int type_val, }int parse_events_term__num (struct parse_events_term **term, -int type_term,char *config,u64 num) +int type_term,char *config,u64 num, +YYLTYPE *loc_term,YYLTYPE *loc_val) {return new_term (term,PARSE_EVENTS__TERM_TYPE_NUM , type_term, - config,NULL , num); + config,NULL , num, + loc_term ? loc_term->first_column :0 , + loc_val ? loc_val->first_column :0 ); }int parse_events_term__str (struct parse_events_term **term, -int type_term,char *config,char *str) +int type_term,char *config,char *str, +YYLTYPE *loc_term,YYLTYPE *loc_val) {return new_term (term,PARSE_EVENTS__TERM_TYPE_STR , type_term, - config, str,0 ); + config, str,0 , + loc_term ? loc_term->first_column :0 , + loc_val ? loc_val->first_column :0 ); } int parse_events_term__sym_hw(struct parse_events_term **term,
@@ -1596,18 +1610,20 @@ int parse_events_term__sym_hw(struct parse_events_term **term,if (config)return new_term (term,PARSE_EVENTS__TERM_TYPE_STR ,PARSE_EVENTS__TERM_TYPE_USER , config, - (char *) sym->symbol,0 ); + (char *) sym->symbol,0 ,0 ,0 );else return new_term (term,PARSE_EVENTS__TERM_TYPE_STR ,PARSE_EVENTS__TERM_TYPE_USER , - (char *)"event" , (char *) sym->symbol,0 ); + (char *)"event" , (char *) sym->symbol, +0 ,0 ,0 ); }int parse_events_term__clone (struct parse_events_term **new,struct parse_events_term *term) {return new_term (new, term->type_val, term->type_term, term->config, - term->val.str, term->val.num); + term->val.str, term->val.num, + term->err_term, term->err_val); }void parse_events__free_terms (struct list_head *terms)
tools/perf/util/parse-events.h +4 -4
@@ -74,6 +74,10 @@ struct parse_events_term {int type_term;struct list_head list;bool used; + +/* error string indexes for within parsed string */ +int err_term; +int err_val; };struct parse_events_error {
@@ -94,10 +98,6 @@ struct parse_events_terms { };int parse_events__is_hardcoded_term (struct parse_events_term *term); -int parse_events_term__num (struct parse_events_term **_term, -int type_term,char *config,u64 num); -int parse_events_term__str (struct parse_events_term **_term, -int type_term,char *config,char *str);int parse_events_term__sym_hw (struct parse_events_term **term,char *config,unsigned idx); int parse_events_term__clone(struct parse_events_term **new,
tools/perf/util/parse-events.y +8 -8
@@ -231,7 +231,7 @@ PE_KERNEL_PMU_EVENT sep_dc ALLOC_LIST(head); ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, 1)); + $1, 1, &@1, NULL)); list_add_tail(&term->list, head); ALLOC_LIST(list);
@@ -251,7 +251,7 @@ PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc ALLOC_LIST(head); ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - &pmu_name, 1)); + &pmu_name, 1, &@1, NULL)); list_add_tail(&term->list, head); ALLOC_LIST(list);
@@ -449,7 +449,7 @@ PE_NAME '=' PE_NAME struct parse_events_term *term; ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3)); + $1, $3, &@1, &@3)); $$ = term; } |
@@ -458,7 +458,7 @@ PE_NAME '=' PE_VALUE struct parse_events_term *term; ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3)); + $1, $3, &@1, &@3)); $$ = term; } |
@@ -476,7 +476,7 @@ PE_NAME struct parse_events_term *term; ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, 1)); + $1, 1, &@1, NULL)); $$ = term; } |
@@ -493,7 +493,7 @@ PE_TERM '=' PE_NAME { struct parse_events_term *term; - ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3)); + ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)); $$ = term; } |
@@ -501,7 +501,7 @@ PE_TERM '=' PE_VALUE { struct parse_events_term *term; - ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3)); + ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, &@1, &@3)); $$ = term; } |
@@ -509,7 +509,7 @@ PE_TERM { struct parse_events_term *term; - ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1)); + ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL)); $$ = term; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 38/64 perf tools: Add term support for parse_events_error
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Allowing event's term processing to report back error, like:
$ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown termvalid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
--- tools/perf/tests/pmu.c | 3 ++- tools/perf/util/parse-events.c | 2 +- tools/perf/util/parse-events.l | 4 +++ tools/perf/util/pmu.c | 57 +++++++++++++++++++++++++++++++++++++----- tools/perf/util/pmu.h | 6 +++-- 5 files changed, 62 insertions(+), 10 deletions(-)
tools/perf/tests/pmu.c +2 -1
@@ -152,7 +152,8 @@ int test__pmu(void)if (ret)break ; - ret =perf_pmu__config_terms (&formats, &attr, terms, false); + ret =perf_pmu__config_terms (&formats, &attr, terms, + false,NULL );if (ret)break ;
tools/perf/util/parse-events.c +1 -1
@@ -675,7 +675,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,if (config_attr (&attr, head_config))return -EINVAL ; -if (perf_pmu__config (pmu, &attr, head_config)) +if (perf_pmu__config (pmu, &attr, head_config, data->error))return -EINVAL ; evsel = __add_event(list, &data->idx, &attr,
tools/perf/util/parse-events.l +4 -0
@@ -174,6 +174,10 @@ modifier_bp [rwx]{1,3} } <config>{ + /* + * Please update formats_error_string any time + * new static term is added. + */ config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); } config1 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG1); } config2 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
tools/perf/util/pmu.c +51 -6
103 lines not on this page · raw message
tools/perf/util/pmu.h +4 -2
@@ -4,6 +4,7 @@#include <linux/bitmap.h> #include <linux/perf_event.h> #include <stdbool.h> +#include "parse-events.h" enum {PERF_PMU_FORMAT_VALUE_CONFIG ,
@@ -47,11 +48,12 @@ struct perf_pmu_alias {struct perf_pmu *perf_pmu__find (const char *name);int perf_pmu__config (struct perf_pmu *pmu,struct perf_event_attr *attr, -struct list_head *head_terms); +struct list_head *head_terms, +struct parse_events_error *error);int perf_pmu__config_terms (struct list_head *formats,struct perf_event_attr *attr,struct list_head *head_terms, -bool zero); +bool zero,struct parse_events_error *error);int perf_pmu__check_alias (struct perf_pmu *pmu,struct list_head *head_terms,struct perf_pmu_info *info); struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 39/64 perf tools: Add static terms support for parse_events_error
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Allowing static terms like 'name,period,config,config1..' processing to report back error.
$ perf record -e 'cpu/event=1,name=1/' ls
event syntax error: '..=1,name=1/'
\___ expected string value $ perf record -e 'cpu/event=1,period=krava/' ls
event syntax error: '..,period=krava/'
\___ expected numeric value $ perf record -e 'cpu/config=krava1/' ls
event syntax error: '../config=krava1/'
\___ expected numeric value--- tools/perf/util/parse-events.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-)
tools/perf/util/parse-events.c +28 -9
@@ -545,13 +545,31 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,return add_event (list, idx, &attr,NULL ); } +static int check_type_val (struct parse_events_term *term, +struct parse_events_error *error, +int type) +{ +if (type == term->type_val) +return 0 ; + +if (error) { + error->idx = term->err_val; +if (type ==PARSE_EVENTS__TERM_TYPE_NUM ) + error->str =strdup ("expected numeric value" ); +else + error->str =strdup ("expected string value" ); + } +return -EINVAL ; +} +static int config_term (struct perf_event_attr *attr, -struct parse_events_term *term) +struct parse_events_term *term, +struct parse_events_error *error) { -#define CHECK_TYPE_VAL (type) \ -do { \ - if (PARSE_EVENTS__TERM_TYPE_ ## type != term->type_val) \ - return -EINVAL; \ +#define CHECK_TYPE_VAL (type) \ +do { \ + if (check_type_val(term, error, PARSE_EVENTS__TERM_TYPE_ ## type)) \ + return -EINVAL; \ } while (0)switch (term->type_term) {
@@ -595,12 +613,13 @@ do { \ }static int config_attr (struct perf_event_attr *attr, -struct list_head *head) +struct list_head *head, +struct parse_events_error *error) {struct parse_events_term *term;list_for_each_entry (term, head, list) -if (config_term (attr, term)) +if (config_term (attr, term, error))return -EINVAL ;return 0 ;
@@ -617,7 +636,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config;if (head_config && -config_attr (&attr, head_config)) +config_attr (&attr, head_config,NULL ))return -EINVAL ;return add_event (list, idx, &attr,NULL );
@@ -672,7 +691,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,* Configure hardcoded terms first, no need to check * return value when called with fail == 0 ;) */ -if (config_attr (&attr, head_config)) +if (config_attr (&attr, head_config, data->error))return -EINVAL ;if (perf_pmu__config (pmu, &attr, head_config, data->error))
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 40/64 perf tools: Add tracepoint support for parse_events_error
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Allowing tracepoint events processing to report back error.
$ perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
...--- tools/perf/util/parse-events.y | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/parse-events.y +7 -1
@@ -388,7 +388,13 @@ PE_NAME ':' PE_NAME struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_tracepoint(list, &data->idx, $1, $3)); + if (parse_events_add_tracepoint(list, &data->idx, $1, $3)) { + struct parse_events_error *error = data->error; + + error->idx = @1.first_column; + error->str = strdup("unknown tracepoint"); + return -1; + } $$ = list; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 41/64 perf tools: Add symbolic events support for parse_events_error
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Allowing symbolic events processing to report back error.
$ perf record -e 'cycles/period=krava/' ls
event syntax error: '../period=krava/'
\___ expected numeric value $ perf record -e 'cycles/name=1/' ls
event syntax error: '..es/name=1/'
\___ expected string value--- tools/perf/util/parse-events.c | 7 ++++--- tools/perf/util/parse-events.h | 3 ++- tools/perf/util/parse-events.y | 11 ++++------- 3 files changed, 10 insertions(+), 11 deletions(-)
tools/perf/util/parse-events.c +4 -3
@@ -625,7 +625,8 @@ static int config_attr(struct perf_event_attr *attr,return 0 ; } -int parse_events_add_numeric (struct list_head *list,int *idx, +int parse_events_add_numeric (struct parse_events_evlist *data, +struct list_head *list,u32 type,u64 config,struct list_head *head_config) {
@@ -636,10 +637,10 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config;if (head_config && -config_attr (&attr, head_config,NULL )) +config_attr (&attr, head_config, data->error))return -EINVAL ; -return add_event (list, idx, &attr,NULL ); +return add_event (list, &data->idx, &attr,NULL ); }static int parse_events__is_name_term (struct parse_events_term *term)
tools/perf/util/parse-events.h +2 -1
@@ -108,7 +108,8 @@ int parse_events__modifier_group(struct list_head *list, char *event_mod);int parse_events_name (struct list_head *list,char *name);int parse_events_add_tracepoint (struct list_head *list,int *idx,char *sys,char *event); -int parse_events_add_numeric (struct list_head *list,int *idx, +int parse_events_add_numeric (struct parse_events_evlist *data, +struct list_head *list,u32 type,u64 config,struct list_head *head_config); int parse_events_add_cache(struct list_head *list, int *idx,
tools/perf/util/parse-events.y +4 -7
@@ -274,8 +274,7 @@ value_sym '/' event_config '/' int config = $1 & 255; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, - type, config, $3)); + ABORT_ON(parse_events_add_numeric(data, list, type, config, $3)); parse_events__free_terms($3); $$ = list; }
@@ -288,8 +287,7 @@ value_sym sep_slash_dc int config = $1 & 255; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, - type, config, NULL)); + ABORT_ON(parse_events_add_numeric(data, list, type, config, NULL)); $$ = list; }
@@ -405,7 +403,7 @@ PE_VALUE ':' PE_VALUE struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, (u32)$1, $3, NULL)); + ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, NULL)); $$ = list; }
@@ -416,8 +414,7 @@ PE_RAW struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_numeric(list, &data->idx, - PERF_TYPE_RAW, $1, NULL)); + ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, NULL)); $$ = list; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 42/64 perf probe: Make --funcs option exclusive
In reply to Arnaldo Carvalho de MeloFrom: Masami Hiramatsu <[email protected]>
The --funcs option should be given exclusively. This adds PARSE_OPT_EXCUSIVE flag on --funcs (-F) option.
Without this, 'perf probe --funcs -l' just shows the list of probes.
With this, it shows error message correctly.
This also fixes the help message and the documentation.
--- tools/perf/Documentation/perf-probe.txt | 2 ++ tools/perf/builtin-probe.c | 2 ++ 2 files changed, 4 insertions(+)
tools/perf/Documentation/perf-probe.txt +2 -0
@@ -19,6 +19,8 @@ or 'perf probe' [options] --line='LINE' or 'perf probe' [options] --vars='PROBEPOINT' +or +'perf probe' [options] --funcs DESCRIPTION -----------
tools/perf/builtin-probe.c +2 -0
@@ -321,6 +321,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) "perf probe [<options>] --line 'LINEDESC'", "perf probe [<options>] --vars 'PROBEPOINT'", #endif + "perf probe [<options>] --funcs", NULL }; struct option options[] = {
@@ -402,6 +403,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)set_option_flag (options,'L' ,"line" ,PARSE_OPT_EXCLUSIVE );set_option_flag (options,'V' ,"vars" ,PARSE_OPT_EXCLUSIVE );#endif +set_option_flag (options,'F' ,"funcs" ,PARSE_OPT_EXCLUSIVE ); argc =parse_options (argc, argv, options, probe_usage,PARSE_OPT_STOP_AT_NON_OPTION );
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 43/64 perf probe: Remove all probes matches given pattern at once
In reply to Arnaldo Carvalho de MeloFrom: Masami Hiramatsu <[email protected]>
Fix perf-probe --del option to delete all matched probes in both of kprobes and uprobes at once.
When we have 2 or more events on different binaries as below,
----
# ./perf probe -l probe:vfs_read (on vfs_read@ksrc/linux-3/fs/read_write.c) probe_libc:malloc (on __libc_malloc@malloc/malloc.c in /usr/lib64/libc-2.17 ----
Trying to remove all event with '*' just removes kprobe events at first.
----
# ./perf probe -d \* Removed event: probe:vfs_read ----
And in 2nd try, it removes all uprobe events.
----
# ./perf probe -d \* Removed event: probe_libc:malloc ----
This fixes to remove all event at once as below.
----
# ./perf probe -d \* Removed event: probe:vfs_read Removed event: probe_libc:malloc ----
--- tools/perf/util/probe-event.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
tools/perf/util/probe-event.c +17 -9
@@ -2686,7 +2686,7 @@ static int del_trace_probe_event(int fd, const char *buf, struct strlist *namelist) {struct str_node *ent, *n; -int ret =-1 ; +int ret = -ENOENT ;if (strpbrk (buf,"*?" )) {/* Glob-exp */ strlist__for_each_safe (ent, n, namelist)
@@ -2710,7 +2710,7 @@ static int del_trace_probe_event(int fd, const char *buf,int del_perf_probe_events (struct strlist *dellist) { -int ret =-1 , ufd =-1 , kfd =-1 ; +int ret =-1 , ret2, ufd =-1 , kfd =-1 ;char buf[128 ];const char *group, *event;char *p, *str;
@@ -2731,8 +2731,10 @@ int del_perf_probe_events(struct strlist *dellist) goto error; } -if (namelist ==NULL && unamelist ==NULL ) +if (namelist ==NULL && unamelist ==NULL ) { + ret = -ENOENT ; goto error; + }strlist__for_each (ent, dellist) { str =strdup (ent->s);
@@ -2759,17 +2761,23 @@ int del_perf_probe_events(struct strlist *dellist) }pr_debug ("Group: %s, Event: %s\n" , group, event); +free (str); + ret = ret2 = -ENOENT ;if (namelist) ret =del_trace_probe_event (kfd, buf, namelist); -if (unamelist && ret !=0 ) - ret =del_trace_probe_event (ufd, buf, unamelist); - -if (ret !=0 ) -pr_info ("Info: Event \"%s\" does not exist.\n" , buf); +if ((ret >=0 || ret == -ENOENT ) && unamelist) + ret2 =del_trace_probe_event (ufd, buf, unamelist); -free (str); +/* Since we can remove probes which already removed, don't check it */ +if (ret == -ENOENT && ret2 == -ENOENT ) +pr_debug ("Event \"%s\" does not exist.\n" , buf); +else if (ret <0 || ret2 <0 ) { +if (ret >=0 ) + ret = ret2; +break ; + } } error:
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 44/64 perf trace: Fix --filter-pids OPTION description
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Cut't'paste error, fix it.
--- tools/perf/builtin-trace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-trace.c +2 -2
@@ -2668,8 +2668,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) "trace events on existing process id"),OPT_STRING ('t' ,"tid" , &trace.opts.target.tid,"tid" ,"trace events on existing thread id" ), -OPT_CALLBACK (0 ,"filter-pids" , &trace,"float" , -"show only events with duration > N.M ms" , trace__set_filter_pids), +OPT_CALLBACK (0 ,"filter-pids" , &trace,"CSV list of pids" , +"pids to filter (by the kernel)" , trace__set_filter_pids),OPT_BOOLEAN ('a' ,"all-cpus" , &trace.opts.target.system_wide,"system-wide collection from all CPUs" ), OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu",
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 45/64 perf trace: Clarify that -e is about syscalls, not perf events in general
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
This comes from the desire of having -e/--expr to have the same meaning as for 'strace', while other perf tools use it for --event, which 'trace' honours, i.e. all perf tools have --event in common, but trace uses -e for strace's --expr.
Clarify it in the --help output.
--- tools/perf/Documentation/perf-trace.txt | 2 +- tools/perf/builtin-trace.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-trace.txt +1 -1
@@ -35,7 +35,7 @@ OPTIONS -e:: --expr:: - List of events to show, currently only syscall names. + List of syscalls to show, currently only syscall names. Prefixing with ! shows all syscalls but the ones specified. You may need to escape it.
tools/perf/builtin-trace.c +1 -2
@@ -2660,8 +2660,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN (0 ,"comm" , &trace.show_comm,"show the thread COMM next to its id" ),OPT_BOOLEAN (0 ,"tool_stats" , &trace.show_tool_stats,"show tool stats" ), -OPT_STRING ('e' ,"expr" , &ev_qualifier_str,"expr" , -"list of events to trace" ), +OPT_STRING ('e' ,"expr" , &ev_qualifier_str,"expr" ,"list of syscalls to trace" ),OPT_STRING ('o' ,"output" , &output_name,"file" ,"output file name" ),OPT_STRING ('i' ,"input" , &input_name,"file" ,"Analyze events in file" ), OPT_STRING('p', "pid", &trace.opts.target.pid, "pid",
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 46/64 perf stat: Fix metrics calculation with event qualifiers
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Currently in perf IPC and other metrics cannot be directly shown separately for both user and kernel in a single run. The problem was that the metrics matching code did not check event qualifiers.
With this patch the following case works correctly.
% perf stat -e cycles:k,cycles:u,instructions:k,instructions:u true
Performance counter stats for 'true':
531,718 cycles:k
203,895 cycles:u
338,151 instructions:k # 0.64 insns per cycle
105,961 instructions:u # 0.52 insns per cycle0.002989739 seconds time elapsed
Previously it would misreport the ratios because they were matching the wrong value.
The patch is fairly big, but quite mechanic as it just adds context indexes everywhere.
--- tools/perf/builtin-stat.c | 129 +++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 52 deletions(-)
tools/perf/builtin-stat.c +77 -52
@@ -247,21 +247,35 @@ out_free:return -1 ; } +#define NUM_CTX 3 + +enum {CTX_USER ,CTX_KERNEL ,CTX_ALL }; +static struct stats runtime_nsecs_stats[MAX_NR_CPUS ]; -static struct stats runtime_cycles_stats[MAX_NR_CPUS ]; -static struct stats runtime_stalled_cycles_front_stats[MAX_NR_CPUS ]; -static struct stats runtime_stalled_cycles_back_stats[MAX_NR_CPUS ]; -static struct stats runtime_branches_stats[MAX_NR_CPUS ]; -static struct stats runtime_cacherefs_stats[MAX_NR_CPUS ]; -static struct stats runtime_l1_dcache_stats[MAX_NR_CPUS ]; -static struct stats runtime_l1_icache_stats[MAX_NR_CPUS ]; -static struct stats runtime_ll_cache_stats[MAX_NR_CPUS ]; -static struct stats runtime_itlb_cache_stats[MAX_NR_CPUS ]; -static struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS ]; -static struct stats runtime_cycles_in_tx_stats[MAX_NR_CPUS ]; +static struct stats runtime_cycles_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_stalled_cycles_front_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_stalled_cycles_back_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_branches_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_cacherefs_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_l1_dcache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_l1_icache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_ll_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_itlb_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_dtlb_cache_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_cycles_in_tx_stats[NUM_CTX ][MAX_NR_CPUS ];static struct stats walltime_nsecs_stats; -static struct stats runtime_transaction_stats[MAX_NR_CPUS ]; -static struct stats runtime_elision_stats[MAX_NR_CPUS ]; +static struct stats runtime_transaction_stats[NUM_CTX ][MAX_NR_CPUS ]; +static struct stats runtime_elision_stats[NUM_CTX ][MAX_NR_CPUS ]; + +static int evsel_context (struct perf_evsel *evsel) +{ +if (evsel->attr.exclude_kernel) +return CTX_USER ; +if (evsel->attr.exclude_user) +return CTX_KERNEL ; +/* Handle hypervisor too? */ +return CTX_ALL ; +}static void perf_stat__reset_stats (struct perf_evlist *evlist) {
@@ -356,37 +370,39 @@ static struct perf_evsel *nth_evsel(int n)static void update_shadow_stats (struct perf_evsel *counter,u64 *count,int cpu) { +int ctx =evsel_context (counter); +if (perf_evsel__match (counter,SOFTWARE ,SW_TASK_CLOCK ))update_stats (&runtime_nsecs_stats[cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_CPU_CYCLES )) -update_stats (&runtime_cycles_stats[cpu], count[0 ]); +update_stats (&runtime_cycles_stats[ctx][cpu], count[0 ]);else if (transaction_run &&perf_evsel__cmp (counter,nth_evsel (T_CYCLES_IN_TX ))) -update_stats (&runtime_cycles_in_tx_stats[cpu], count[0 ]); +update_stats (&runtime_transaction_stats[ctx][cpu], count[0 ]);else if (transaction_run &&perf_evsel__cmp (counter,nth_evsel (T_TRANSACTION_START ))) -update_stats (&runtime_transaction_stats[cpu], count[0 ]); +update_stats (&runtime_transaction_stats[ctx][cpu], count[0 ]);else if (transaction_run &&perf_evsel__cmp (counter,nth_evsel (T_ELISION_START ))) -update_stats (&runtime_elision_stats[cpu], count[0 ]); +update_stats (&runtime_elision_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_STALLED_CYCLES_FRONTEND )) -update_stats (&runtime_stalled_cycles_front_stats[cpu], count[0 ]); +update_stats (&runtime_stalled_cycles_front_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_STALLED_CYCLES_BACKEND )) -update_stats (&runtime_stalled_cycles_back_stats[cpu], count[0 ]); +update_stats (&runtime_stalled_cycles_back_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_BRANCH_INSTRUCTIONS )) -update_stats (&runtime_branches_stats[cpu], count[0 ]); +update_stats (&runtime_branches_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HARDWARE ,HW_CACHE_REFERENCES )) -update_stats (&runtime_cacherefs_stats[cpu], count[0 ]); +update_stats (&runtime_cacherefs_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_L1D )) -update_stats (&runtime_l1_dcache_stats[cpu], count[0 ]); +update_stats (&runtime_l1_dcache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_L1I )) -update_stats (&runtime_l1_icache_stats[cpu], count[0 ]); +update_stats (&runtime_ll_cache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_LL )) -update_stats (&runtime_ll_cache_stats[cpu], count[0 ]); +update_stats (&runtime_ll_cache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_DTLB )) -update_stats (&runtime_dtlb_cache_stats[cpu], count[0 ]); +update_stats (&runtime_dtlb_cache_stats[ctx][cpu], count[0 ]);else if (perf_evsel__match (counter,HW_CACHE ,HW_CACHE_ITLB )) -update_stats (&runtime_itlb_cache_stats[cpu], count[0 ]); +update_stats (&runtime_itlb_cache_stats[ctx][cpu], count[0 ]); }static void zero_per_pkg (struct perf_evsel *counter)
@@ -908,8 +924,9 @@ static void print_stalled_cycles_frontend(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -927,8 +944,9 @@ static void print_stalled_cycles_backend(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -946,8 +964,9 @@ static void print_branch_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_branches_stats[cpu]); + total =avg_stats (&runtime_branches_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -965,8 +984,9 @@ static void print_l1_dcache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_l1_dcache_stats[cpu]); + total =avg_stats (&runtime_l1_dcache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -984,8 +1004,9 @@ static void print_l1_icache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_l1_icache_stats[cpu]); + total =avg_stats (&runtime_l1_icache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1003,8 +1024,9 @@ static void print_dtlb_cache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_dtlb_cache_stats[cpu]); + total =avg_stats (&runtime_dtlb_cache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1022,8 +1044,9 @@ static void print_itlb_cache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_itlb_cache_stats[cpu]); + total =avg_stats (&runtime_itlb_cache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1041,8 +1064,9 @@ static void print_ll_cache_misses(int cpu, {double total, ratio =0.0 ;const char *color; +int ctx =evsel_context (evsel); - total =avg_stats (&runtime_ll_cache_stats[cpu]); + total =avg_stats (&runtime_ll_cache_stats[ctx][cpu]);if (total) ratio = avg / total *100.0 ;
@@ -1060,6 +1084,7 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)double sc = evsel->scale;const char *fmt;int cpu =cpu_map__id_to_cpu (id); +int ctx =evsel_context (evsel);if (csv_output) { fmt = sc !=1.0 ?"%.2f%s" :"%.0f%s" ;
@@ -1091,15 +1116,15 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)return ;if (perf_evsel__match (evsel,HARDWARE ,HW_INSTRUCTIONS )) { - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total) { ratio = avg / total;fprintf (output," # %5.2f insns per cycle " , ratio); }else {fprintf (output," " ); } - total =avg_stats (&runtime_stalled_cycles_front_stats[cpu]); - total =max (total,avg_stats (&runtime_stalled_cycles_back_stats[cpu])); + total =avg_stats (&runtime_stalled_cycles_front_stats[ctx][cpu]); + total =max (total,avg_stats (&runtime_stalled_cycles_back_stats[ctx][cpu]));if (total && avg) { ratio = total / avg;
@@ -1110,46 +1135,46 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) } }else if (perf_evsel__match (evsel,HARDWARE ,HW_BRANCH_MISSES ) && - runtime_branches_stats[cpu].n !=0 ) { + runtime_branches_stats[ctx][cpu].n !=0 ) {print_branch_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_L1D | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_l1_dcache_stats[cpu].n !=0 ) { + runtime_l1_dcache_stats[ctx][cpu].n !=0 ) {print_l1_dcache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_L1I | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_l1_icache_stats[cpu].n !=0 ) { + runtime_l1_icache_stats[ctx][cpu].n !=0 ) {print_l1_icache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_DTLB | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_dtlb_cache_stats[cpu].n !=0 ) { + runtime_dtlb_cache_stats[ctx][cpu].n !=0 ) {print_dtlb_cache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_ITLB | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_itlb_cache_stats[cpu].n !=0 ) { + runtime_itlb_cache_stats[ctx][cpu].n !=0 ) {print_itlb_cache_misses (cpu, evsel, avg); }else if ( evsel->attr.type ==PERF_TYPE_HW_CACHE && evsel->attr.config == (PERF_COUNT_HW_CACHE_LL | ((PERF_COUNT_HW_CACHE_OP_READ ) <<8 ) | ((PERF_COUNT_HW_CACHE_RESULT_MISS ) <<16 )) && - runtime_ll_cache_stats[cpu].n !=0 ) { + runtime_ll_cache_stats[ctx][cpu].n !=0 ) {print_ll_cache_misses (cpu, evsel, avg); }else if (perf_evsel__match (evsel,HARDWARE ,HW_CACHE_MISSES ) && - runtime_cacherefs_stats[cpu].n !=0 ) { - total =avg_stats (&runtime_cacherefs_stats[cpu]); + runtime_cacherefs_stats[ctx][cpu].n !=0 ) { + total =avg_stats (&runtime_cacherefs_stats[ctx][cpu]);if (total) ratio = avg *100 / total;
@@ -1171,15 +1196,15 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) } }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_CYCLES_IN_TX ))) { - total =avg_stats (&runtime_cycles_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]);if (total)fprintf (output," # %5.2f%% transactional cycles " ,100.0 * (avg / total)); }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_CYCLES_IN_TX_CP ))) { - total =avg_stats (&runtime_cycles_stats[cpu]); - total2 =avg_stats (&runtime_cycles_in_tx_stats[cpu]); + total =avg_stats (&runtime_cycles_stats[ctx][cpu]); + total2 =avg_stats (&runtime_cycles_in_tx_stats[ctx][cpu]);if (total2 < avg) total2 = avg;if (total)
@@ -1189,8 +1214,8 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_TRANSACTION_START )) && avg >0 && - runtime_cycles_in_tx_stats[cpu].n !=0 ) { - total =avg_stats (&runtime_cycles_in_tx_stats[cpu]); + runtime_cycles_in_tx_stats[ctx][cpu].n !=0 ) { + total =avg_stats (&runtime_cycles_in_tx_stats[ctx][cpu]);if (total) ratio = total / avg;
@@ -1199,8 +1224,8 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) }else if (transaction_run &&perf_evsel__cmp (evsel,nth_evsel (T_ELISION_START )) && avg >0 && - runtime_cycles_in_tx_stats[cpu].n !=0 ) { - total =avg_stats (&runtime_cycles_in_tx_stats[cpu]); + runtime_cycles_in_tx_stats[ctx][cpu].n !=0 ) { + total =avg_stats (&runtime_cycles_in_tx_stats[ctx][cpu]);if (total) ratio = total / avg;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 47/64 perf stat: Change metrics context calculation
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Changing metrics context calculation to allow more than 2 types of context.
Following patches will add support for the rest of the exclude_* bits so we need separate array element for all context combinations.
--- tools/perf/builtin-stat.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
tools/perf/builtin-stat.c +11 -6
@@ -247,9 +247,13 @@ out_free:return -1 ; } -#define NUM_CTX 3 +enum { +CTX_BIT_USER =1 <<0 , +CTX_BIT_KERNEL =1 <<1 , +CTX_BIT_MAX =1 <<2 , +}; -enum {CTX_USER ,CTX_KERNEL ,CTX_ALL }; +#define NUM_CTX CTX_BIT_MAXstatic struct stats runtime_nsecs_stats[MAX_NR_CPUS ];static struct stats runtime_cycles_stats[NUM_CTX ][MAX_NR_CPUS ];
@@ -269,12 +273,13 @@ static struct stats runtime_elision_stats[NUM_CTX][MAX_NR_CPUS];static int evsel_context (struct perf_evsel *evsel) { +int ctx =0 ; +if (evsel->attr.exclude_kernel) -return CTX_USER ; + ctx |=CTX_BIT_KERNEL ;if (evsel->attr.exclude_user) -return CTX_KERNEL ; -/* Handle hypervisor too? */ -return CTX_ALL ; + ctx |=CTX_BIT_USER ; +return ctx; }static void perf_stat__reset_stats (struct perf_evlist *evlist)
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 48/64 perf stat: Add metrics support for exclude_hv
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Separating metrics values for exclude_hv bit.
--- tools/perf/builtin-stat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
@@ -250,7 +250,8 @@ out_free:enum {CTX_BIT_USER =1 <<0 ,CTX_BIT_KERNEL =1 <<1 , -CTX_BIT_MAX =1 <<2 , +CTX_BIT_HV =1 <<2 , +CTX_BIT_MAX =1 <<3 , };#define NUM_CTX CTX_BIT_MAX
@@ -279,6 +280,8 @@ static int evsel_context(struct perf_evsel *evsel) ctx |=CTX_BIT_KERNEL ;if (evsel->attr.exclude_user) ctx |=CTX_BIT_USER ; +if (evsel->attr.exclude_hv) + ctx |=CTX_BIT_HV ;return ctx; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 49/64 perf stat: Add metrics support for exclude_(host|guest)
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Separating metrics values for guest and host, so we get proper values.
--- tools/perf/builtin-stat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +5 -1
@@ -251,7 +251,8 @@ enum {CTX_BIT_USER =1 <<0 ,CTX_BIT_KERNEL =1 <<1 ,CTX_BIT_HV =1 <<2 , - CTX_BIT_MAX = 1 << 3, +CTX_BIT_HOST =1 <<3 , + CTX_BIT_MAX = 1 << 4, };#define NUM_CTX CTX_BIT_MAX
@@ -282,6 +283,9 @@ static int evsel_context(struct perf_evsel *evsel) ctx |=CTX_BIT_USER ;if (evsel->attr.exclude_hv) ctx |=CTX_BIT_HV ; +if (evsel->attr.exclude_host) + ctx |=CTX_BIT_HOST ; +return ctx; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 50/64 perf stat: Add metrics support for exclude_idle
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Separating metrics values for exclude_idle bit.
--- tools/perf/builtin-stat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
@@ -252,7 +252,8 @@ enum {CTX_BIT_KERNEL =1 <<1 ,CTX_BIT_HV =1 <<2 ,CTX_BIT_HOST =1 <<3 , - CTX_BIT_MAX = 1 << 4, +CTX_BIT_IDLE =1 <<4 , + CTX_BIT_MAX = 1 << 5, };#define NUM_CTX CTX_BIT_MAX
@@ -285,6 +286,8 @@ static int evsel_context(struct perf_evsel *evsel) ctx |=CTX_BIT_HV ;if (evsel->attr.exclude_host) ctx |=CTX_BIT_HOST ; +if (evsel->attr.exclude_idle) + ctx |=CTX_BIT_IDLE ;return ctx; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 51/64 perf tools: Document --children option in more detail
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
As the --children option changes the output of perf report (and perf top) it sometimes confuses users. Add more words and examples to help understanding of the option's behavior - and how to disable it ;-).
--- .../callchain-overhead-calculation.txt | 108 +++++++++++++++++++++ tools/perf/Documentation/perf-report.txt | 4 + tools/perf/Documentation/perf-top.txt | 3 +- 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 tools/perf/Documentation/callchain-overhead-calculation.txt
tools/perf/Documentation/callchain-overhead-calculation.txt new file +108 -0
@@ -0,0 +1,108 @@ +Overhead calculation +-------------------- +The overhead can be shown in two columns as 'Children' and 'Self' when +perf collects callchains. The 'self' overhead is simply calculated by +adding all period values of the entry - usually a function (symbol). +This is the value that perf shows traditionally and sum of all the +'self' overhead values should be 100%. + +The 'children' overhead is calculated by adding all period values of +the child functions so that it can show the total overhead of the +higher level functions even if they don't directly execute much. +'Children' here means functions that are called from another (parent) +function. + +It might be confusing that the sum of all the 'children' overhead +values exceeds 100% since each of them is already an accumulation of +'self' overhead of its child functions. But with this enabled, users +can find which function has the most overhead even if samples are +spread over the children. + +Consider the following example; there are three functions like below. + +----------------------- +void foo(void) { + /* do something */ +} + +void bar(void) { + /* do something */ + foo(); +} + +int main(void) { + bar() + return 0; +} +----------------------- + +In this case 'foo' is a child of 'bar', and 'bar' is an immediate +child of 'main' so 'foo' also is a child of 'main'. In other words, +'main' is a parent of 'foo' and 'bar', and 'bar' is a parent of 'foo'. + +Suppose all samples are recorded in 'foo' and 'bar' only. When it's +recorded with callchains the output will show something like below +in the usual (self-overhead-only) output of perf report: + +---------------------------------- +Overhead Symbol +........ ..................... + 60.00% foo + | + --- foo + bar + main + __libc_start_main + + 40.00% bar + | + --- bar + main + __libc_start_main +---------------------------------- + +When the --children option is enabled, the 'self' overhead values of +child functions (i.e. 'foo' and 'bar') are added to the parents to +calculate the 'children' overhead. In this case the report could be +displayed as: + +------------------------------------------- +Children Self Symbol +........ ........ .................... + 100.00% 0.00% __libc_start_main + | + --- __libc_start_main + + 100.00% 0.00% main + | + --- main + __libc_start_main + + 100.00% 40.00% bar + | + --- bar + main + __libc_start_main + + 60.00% 60.00% foo + | + --- foo + bar + main + __libc_start_main +------------------------------------------- + +In the above output, the 'self' overhead of 'foo' (60%) was add to the +'children' overhead of 'bar', 'main' and '\_\_libc_start_main'. +Likewise, the 'self' overhead of 'bar' (40%) was added to the +'children' overhead of 'main' and '\_\_libc_start_main'. + +So '\_\_libc_start_main' and 'main' are shown first since they have +same (100%) 'children' overhead (even though they have zero 'self' +overhead) and they are the parents of 'foo' and 'bar'. + +Since v3.16 the 'children' overhead is shown by default and the output +is sorted by its values. The 'children' overhead is disabled by +specifying --no-children option on the command line or by adding +'report.children = false' or 'top.children = false' in the perf config +file.
tools/perf/Documentation/perf-report.txt +4 -0
@@ -193,6 +193,7 @@ OPTIONS Accumulate callchain of children to parent entry so that then can show up in the output. The output will have a new "Children" column and will be sorted on the data. It requires callchains are recorded. + See the `overhead calculation' section for more details. --max-stack:: Set the stack depth limit when parsing the callchain, anything
@@ -323,6 +324,9 @@ OPTIONS --header-only:: Show only perf.data header (forces --stdio). + +include::callchain-overhead-calculation.txt[] + SEE ALSO -------- linkperf:perf-stat[1], linkperf:perf-annotate[1]
tools/perf/Documentation/perf-top.txt +2 -1
@@ -168,7 +168,7 @@ Default is to monitor all CPUS. Accumulate callchain of children to parent entry so that then can show up in the output. The output will have a new "Children" column and will be sorted on the data. It requires -g/--call-graph option - enabled. + enabled. See the `overhead calculation' section for more details. --max-stack:: Set the stack depth limit when parsing the callchain, anything
@@ -234,6 +234,7 @@ INTERACTIVE PROMPTING KEYS Pressing any unmapped key displays a menu, and prompts for input. +include::callchain-overhead-calculation.txt[] SEE ALSO --------
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 52/64 perf tools: Move TUI-specific fields into unnamed union
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
Since perf diff only supports stdio output, TUI fields are only accessed from perf report (or perf top). So add a new unnamed union and move struct hist_entry_tui and those TUI-specific fields.
--- tools/perf/util/sort.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
tools/perf/util/sort.h +12 -6
@@ -93,18 +93,24 @@ struct hist_entry {s32 cpu;u8 cpumode; -struct hist_entry_diff diff; -/* We are added by hists__add_dummy_entry. */ bool dummy; -/* XXX These two should move to some tree widget lib */ -u16 row_offset; -u16 nr_rows; -bool init_have_children;char level;u8 filtered; +union { +/* +* Since perf diff only supports the stdio output, TUI +* fields are only accessed from perf report (or perf +* top). So make it an union to reduce memory usage. +*/ +struct hist_entry_diff diff; +struct /* for TUI */ { +u16 row_offset; +u16 nr_rows; + }; + };char *srcline;struct symbol *parent;struct rb_root sorted_chain;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 53/64 perf tools: Move init_have_children field to the unnamed union
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
The init_have_children is used to init callchain info only for TUI. So it'd be better to move it to the TUI-specific unnamed union member.
--- tools/perf/util/sort.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/sort.h +1 -1
@@ -96,7 +96,6 @@ struct hist_entry {/* We are added by hists__add_dummy_entry. */ bool dummy; -bool init_have_children;char level;u8 filtered;union {
@@ -109,6 +108,7 @@ struct hist_entry {struct /* for TUI */ {u16 row_offset;u16 nr_rows; +bool init_have_children; }; };char *srcline;
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 54/64 perf hists browser: Fix possible memory leak
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
The options array saves strings for each popup menu item. The number of items can be vary according to the currently selected item. So it can leak some memory if it's exited from a small item. Fix it by freeing all items when loop terminates.
--- tools/perf/ui/browsers/hists.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/ui/browsers/hists.c +5 -3
@@ -1424,7 +1424,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,struct hist_browser *browser =hist_browser__new (hists);struct branch_info *bi;struct pstack *fstack; -char *options[16 ]; +#define MAX_OPTIONS 16 +char *options[MAX_OPTIONS ];int nr_options =0 ;int key =-1 ;char buf[64 ];
@@ -1691,7 +1692,8 @@ skip_annotation: "Switch to another data file in PWD") > 0) switch_data = nr_options++; add_exit_option: - options[nr_options++] = (char *)"Exit" ; +if (asprintf (&options[nr_options],"Exit" ) >0 ) + nr_options++; retry_popup_menu: choice =ui__popup_menu (nr_options, options);
@@ -1812,7 +1814,7 @@ out_free_stack:pstack__delete (fstack); out:hist_browser__delete (browser); -free_popup_options (options, nr_options -1 ); +free_popup_options (options,MAX_OPTIONS );return key; }
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 55/64 perf hists browser: Save hist_browser_timer pointer in hist_browser
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
The struct hist_browser_timer is to carry perf-top related info throughout the hist browser code. So it'd be better to keep in the struct hist_browser. This is a preparation to later change.
--- tools/perf/ui/browsers/hists.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
tools/perf/ui/browsers/hists.c +8 -5
@@ -25,6 +25,7 @@ struct hist_browser {struct hists *hists;struct hist_entry *he_selection;struct map_symbol *selection; +struct hist_browser_timer *hbt;int print_seq;bool show_dso;bool show_headers;
@@ -406,11 +407,11 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser) "Or reduce the sampling frequency."); } -static int hist_browser__run (struct hist_browser *browser, -struct hist_browser_timer *hbt) +static int hist_browser__run (struct hist_browser *browser) {int key;char title[160 ]; +struct hist_browser_timer *hbt = browser->hbt;int delay_secs = hbt ? hbt->refresh :0 ; browser->b.entries = &browser->hists->entries;
@@ -1195,7 +1196,8 @@ static int hist_browser__dump(struct hist_browser *browser)return 0 ; } -static struct hist_browser *hist_browser__new (struct hists *hists) +static struct hist_browser *hist_browser__new (struct hists *hists, +struct hist_browser_timer *hbt) {struct hist_browser *browser =zalloc (sizeof (*browser));
@@ -1206,6 +1208,7 @@ static struct hist_browser *hist_browser__new(struct hists *hists) browser->b.seek = ui_browser__hists_seek; browser->b.use_navkeypressed = true; browser->show_headers = symbol_conf.show_hist_headers; + browser->hbt = hbt; }return browser;
@@ -1421,7 +1424,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, struct perf_session_env *env) {struct hists *hists =evsel__hists (evsel); -struct hist_browser *browser =hist_browser__new (hists); +struct hist_browser *browser =hist_browser__new (hists, hbt);struct branch_info *bi;struct pstack *fstack;#define MAX_OPTIONS 16
@@ -1499,7 +1502,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, nr_options =0 ; - key =hist_browser__run (browser, hbt); + key =hist_browser__run (browser);if (browser->he_selection !=NULL ) { thread =hist_browser__selected_thread (browser);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 56/64 perf hists browser: Save pstack in the hist_browser
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
The struct pstack is to save currently applied thread and/or dso filters in the browser. So it'd be better to keep in the struct hist_browser. This is a preparation to later change.
--- tools/perf/ui/browsers/hists.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
tools/perf/ui/browsers/hists.c +10 -10
@@ -26,6 +26,7 @@ struct hist_browser {struct hist_entry *he_selection;struct map_symbol *selection;struct hist_browser_timer *hbt; +struct pstack *pstack;int print_seq;bool show_dso;bool show_headers;
@@ -1426,7 +1427,6 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,struct hists *hists =evsel__hists (evsel);struct hist_browser *browser =hist_browser__new (hists, hbt);struct branch_info *bi; -struct pstack *fstack;#define MAX_OPTIONS 16char *options[MAX_OPTIONS ];int nr_options =0 ;
@@ -1477,8 +1477,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,hist_browser__update_nr_entries (browser); } - fstack =pstack__new (2 ); -if (fstack ==NULL ) + browser->pstack =pstack__new (2 ); +if (browser->pstack ==NULL ) goto out;ui_helpline__push (helpline);
@@ -1587,7 +1587,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,case K_LEFT : {const void *top; -if (pstack__empty (fstack)) { +if (pstack__empty (browser->pstack)) {/* * Go back to the perf_evsel_menu__run or other user */
@@ -1595,7 +1595,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, goto out_free_stack;continue ; } - top =pstack__pop (fstack); + top =pstack__pop (browser->pstack);if (top == &browser->hists->dso_filter) goto zoom_out_dso;if (top == &browser->hists->thread_filter)
@@ -1753,7 +1753,7 @@ do_annotate:else if (choice == zoom_dso) { zoom_dso:if (browser->hists->dso_filter) { -pstack__remove (fstack, &browser->hists->dso_filter); +pstack__remove (browser->pstack, &browser->hists->dso_filter); zoom_out_dso:ui_helpline__pop (); browser->hists->dso_filter =NULL ;
@@ -1765,14 +1765,14 @@ zoom_out_dso: dso->kernel ? "the Kernel" : dso->short_name); browser->hists->dso_filter = dso;perf_hpp__set_elide (HISTC_DSO , true); -pstack__push (fstack, &browser->hists->dso_filter); +pstack__push (browser->pstack, &browser->hists->dso_filter); }hists__filter_by_dso (hists);hist_browser__reset (browser); }else if (choice == zoom_thread) { zoom_thread:if (browser->hists->thread_filter) { -pstack__remove (fstack, &browser->hists->thread_filter); +pstack__remove (browser->pstack, &browser->hists->thread_filter); zoom_out_thread:ui_helpline__pop ();thread__zput (browser->hists->thread_filter);
@@ -1783,7 +1783,7 @@ zoom_out_thread: thread->tid); browser->hists->thread_filter =thread__get (thread);perf_hpp__set_elide (HISTC_THREAD , false); -pstack__push (fstack, &browser->hists->thread_filter); +pstack__push (browser->pstack, &browser->hists->thread_filter); }hists__filter_by_thread (hists);hist_browser__reset (browser);
@@ -1814,7 +1814,7 @@ do_data_switch: } } out_free_stack: -pstack__delete (fstack); +pstack__delete (browser->pstack); out:hist_browser__delete (browser);free_popup_options (options,MAX_OPTIONS );
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 57/64 perf hists browser: Save perf_session_env in the hist_browser
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
The perf_session_env is to save system informantion at the recording time to be refered in the hist browser. So it'd be better to keep in the struct hist_browser. This is a preparation to later change.
--- tools/perf/ui/browsers/hists.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/ui/browsers/hists.c +5 -2
@@ -27,6 +27,7 @@ struct hist_browser {struct map_symbol *selection;struct hist_browser_timer *hbt;struct pstack *pstack; +struct perf_session_env *env;int print_seq;bool show_dso;bool show_headers;
@@ -1198,7 +1199,8 @@ static int hist_browser__dump(struct hist_browser *browser) }static struct hist_browser *hist_browser__new (struct hists *hists, -struct hist_browser_timer *hbt) +struct hist_browser_timer *hbt, +struct perf_session_env *env) {struct hist_browser *browser =zalloc (sizeof (*browser));
@@ -1210,6 +1212,7 @@ static struct hist_browser *hist_browser__new(struct hists *hists, browser->b.use_navkeypressed = true; browser->show_headers = symbol_conf.show_hist_headers; browser->hbt = hbt; + browser->env = env; }return browser;
@@ -1425,7 +1428,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, struct perf_session_env *env) {struct hists *hists =evsel__hists (evsel); -struct hist_browser *browser =hist_browser__new (hists, hbt); +struct hist_browser *browser =hist_browser__new (hists, hbt, env);struct branch_info *bi;#define MAX_OPTIONS 16char *options[MAX_OPTIONS ];
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 58/64 perf hists browser: Split popup menu actions
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
Currently perf_evsel__hists_browse() function spins on a huge loop and handles many key actions. Since it's hard to read and modify, let's split it out into small helper functions.
This patch introduces do_XXX() functions which corresponds to each goto label. This way we can call such functions both from key press actions and popup menu actions.
No functional change intended.
--- tools/perf/ui/browsers/hists.c | 242 ++++++++++++++++++++++++++--------------- 1 file changed, 156 insertions(+), 86 deletions(-)
tools/perf/ui/browsers/hists.c +156 -86
@@ -1402,6 +1402,120 @@ close_file_and_continue:return ret; } +static int +do_annotate (struct hist_browser *browser,struct map_symbol *ms) +{ +struct perf_evsel *evsel; +struct annotation *notes; +struct hist_entry *he; +int err; + +if (!objdump_path &&perf_session_env__lookup_objdump (browser->env)) +return 0 ; + + notes =symbol__annotation (ms->sym); +if (!notes->src) +return 0 ; + + evsel =hists_to_evsel (browser->hists); + err =map_symbol__tui_annotate (ms, evsel, browser->hbt); + he =hist_browser__selected_entry (browser); +/* +* offer option to annotate the other branch source or target +* (if they exists) when returning from annotate +*/ +if ((err =='q' || err ==CTRL ('c' )) && he->branch_info) +return 1 ; + +ui_browser__update_nr_entries (&browser->b, browser->hists->nr_entries); +if (err) +ui_browser__handle_resize (&browser->b); +return 0 ; +} + +static int +do_zoom_thread (struct hist_browser *browser,struct thread *thread) +{ +if (browser->hists->thread_filter) { +pstack__remove (browser->pstack, &browser->hists->thread_filter); +perf_hpp__set_elide (HISTC_THREAD , false); +thread__zput (browser->hists->thread_filter); +ui_helpline__pop (); + }else { +ui_helpline__fpush ("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"" , + thread->comm_set ?thread__comm_str (thread) :"" , + thread->tid); + browser->hists->thread_filter =thread__get (thread); +perf_hpp__set_elide (HISTC_THREAD , false); +pstack__push (browser->pstack, &browser->hists->thread_filter); + } + +hists__filter_by_thread (browser->hists); +hist_browser__reset (browser); +return 0 ; +} + +static int +do_zoom_dso (struct hist_browser *browser,struct dso *dso) +{ +if (browser->hists->dso_filter) { +pstack__remove (browser->pstack, &browser->hists->dso_filter); +perf_hpp__set_elide (HISTC_DSO , false); + browser->hists->dso_filter =NULL ; +ui_helpline__pop (); + }else { +if (dso ==NULL ) +return 0 ; +ui_helpline__fpush ("To zoom out press <- or -> + \"Zoom out of %s DSO\"" , + dso->kernel ?"the Kernel" : dso->short_name); + browser->hists->dso_filter = dso; +perf_hpp__set_elide (HISTC_DSO , true); +pstack__push (browser->pstack, &browser->hists->dso_filter); + } + +hists__filter_by_dso (browser->hists); +hist_browser__reset (browser); +return 0 ; +} + +static int +do_browse_map (struct hist_browser *browser__maybe_unused ,struct map *map) +{ +map__browse (map); +return 0 ; +} + +static int +do_run_script (struct hist_browser *browser__maybe_unused , +struct thread *thread,struct symbol *sym) +{ +char script_opt[64 ]; +memset (script_opt,0 ,sizeof (script_opt)); + +if (thread) { +scnprintf (script_opt,sizeof (script_opt)," -c %s " , +thread__comm_str (thread)); + }else if (sym) { +scnprintf (script_opt,sizeof (script_opt)," -S %s " , + sym->name); + } + +script_browse (script_opt); +return 0 ; +} + +static int +do_switch_data (struct hist_browser *browser__maybe_unused ,int key) +{ +if (switch_data_file ()) { +ui__warning ("Won't switch the data files due to\n" +"no valid data file get selected!\n" ); +return key; + } + +return K_SWITCH_INPUT_DATA ; +} +static void hist_browser__update_nr_entries (struct hist_browser *hb) {u64 nr_entries =0 ;
@@ -1435,7 +1549,6 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,int nr_options =0 ;int key =-1 ;char buf[64 ]; -char script_opt[64 ];int delay_secs = hbt ? hbt->refresh :0 ;struct perf_hpp_fmt *fmt;
@@ -1496,7 +1609,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,while (1 ) {struct thread *thread =NULL ; -const struct dso *dso =NULL ; +struct dso *dso =NULL ; +struct map_symbol ms;int choice =0 , annotate =-2 , zoom_dso =-2 , zoom_thread =-2 , annotate_f =-2 , annotate_t =-2 , browse_map =-2 ;
@@ -1533,17 +1647,24 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, browser->selection->sym ==NULL || browser->selection->map->dso->annotate_warned) continue; - goto do_annotate; + + ms.map = browser->selection->map; + ms.sym = browser->selection->sym; + +do_annotate (browser, &ms); +continue ;case 'P' :hist_browser__dump (browser);continue ;case 'd' : - goto zoom_dso; +do_zoom_dso (browser, dso); +continue ;case 'V' : browser->show_dso = !browser->show_dso;continue ;case 't' : - goto zoom_thread; +do_zoom_thread (browser, thread); +continue ;case '/' : if (ui_browser__input_window("Symbol to show", "Please enter the name of symbol you want to see",
@@ -1556,11 +1677,14 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,continue ;case 'r' :if (is_report_browser (hbt)) - goto do_scripts; +do_run_script (browser,NULL ,NULL );continue ;case 's' : -if (is_report_browser (hbt)) - goto do_data_switch; +if (is_report_browser (hbt)) { + key =do_switch_data (browser, key); +if (key ==K_SWITCH_INPUT_DATA ) + goto out_free_stack; + }continue ;case 'i' :/* env->arch is NULL for live-mode (i.e. perf top) */
@@ -1599,10 +1723,18 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,continue ; } top =pstack__pop (browser->pstack); -if (top == &browser->hists->dso_filter) - goto zoom_out_dso; -if (top == &browser->hists->thread_filter) - goto zoom_out_thread; +if (top == &browser->hists->dso_filter) { +perf_hpp__set_elide (HISTC_DSO , false); + browser->hists->dso_filter =NULL ; +hists__filter_by_dso (browser->hists); + } +if (top == &browser->hists->thread_filter) { +perf_hpp__set_elide (HISTC_THREAD , false); +thread__zput (browser->hists->thread_filter); +hists__filter_by_thread (browser->hists); + } +ui_helpline__pop (); +hist_browser__reset (browser);continue ; }case K_ESC :
@@ -1713,12 +1845,6 @@ retry_popup_menu:if (choice == annotate || choice == annotate_t || choice == annotate_f) {struct hist_entry *he; -struct annotation *notes; -struct map_symbol ms; -int err; -do_annotate: -if (!objdump_path &&perf_session_env__lookup_objdump (env)) -continue ; he =hist_browser__selected_entry (browser);if (he ==NULL )
@@ -1734,86 +1860,30 @@ do_annotate: ms = *browser->selection; } - notes =symbol__annotation (ms.sym); -if (!notes->src) -continue ; - - err =map_symbol__tui_annotate (&ms, evsel, hbt); -/* -* offer option to annotate the other branch source or target -* (if they exists) when returning from annotate -*/ -if ((err =='q' || err ==CTRL ('c' )) - && annotate_t !=-2 && annotate_f !=-2 ) +if (do_annotate (browser, &ms) ==1 ) goto retry_popup_menu; - -ui_browser__update_nr_entries (&browser->b, browser->hists->nr_entries); -if (err) -ui_browser__handle_resize (&browser->b); - - }else if (choice == browse_map) -map__browse (browser->selection->map); -else if (choice == zoom_dso) { -zoom_dso: -if (browser->hists->dso_filter) { -pstack__remove (browser->pstack, &browser->hists->dso_filter); -zoom_out_dso: -ui_helpline__pop (); - browser->hists->dso_filter =NULL ; -perf_hpp__set_elide (HISTC_DSO , false); - }else { -if (dso ==NULL ) -continue ; -ui_helpline__fpush ("To zoom out press <- or -> + \"Zoom out of %s DSO\"" , - dso->kernel ?"the Kernel" : dso->short_name); - browser->hists->dso_filter = dso; -perf_hpp__set_elide (HISTC_DSO , true); -pstack__push (browser->pstack, &browser->hists->dso_filter); - } -hists__filter_by_dso (hists); -hist_browser__reset (browser); + }else if (choice == browse_map) { +do_browse_map (browser, browser->selection->map); + }else if (choice == zoom_dso) { +do_zoom_dso (browser, dso); }else if (choice == zoom_thread) { -zoom_thread: -if (browser->hists->thread_filter) { -pstack__remove (browser->pstack, &browser->hists->thread_filter); -zoom_out_thread: -ui_helpline__pop (); -thread__zput (browser->hists->thread_filter); -perf_hpp__set_elide (HISTC_THREAD , false); - }else { -ui_helpline__fpush ("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"" , - thread->comm_set ?thread__comm_str (thread) :"" , - thread->tid); - browser->hists->thread_filter =thread__get (thread); -perf_hpp__set_elide (HISTC_THREAD , false); -pstack__push (browser->pstack, &browser->hists->thread_filter); - } -hists__filter_by_thread (hists); -hist_browser__reset (browser); +do_zoom_thread (browser, thread); }/* perf scripts support */ else if (choice == scripts_all || choice == scripts_comm || choice == scripts_symbol) { -do_scripts: -memset (script_opt,0 ,64 ); -if (choice == scripts_comm) -sprintf (script_opt," -c %s " ,thread__comm_str (browser->he_selection->thread)); - +do_run_script (browser, browser->he_selection->thread,NULL );if (choice == scripts_symbol) -sprintf (script_opt," -S %s " , browser->he_selection->ms.sym->name); - -script_browse (script_opt); +do_run_script (browser,NULL , browser->he_selection->ms.sym); +if (choice == scripts_all) +do_run_script (browser,NULL ,NULL ); }/* Switch to another data file */ else if (choice == switch_data) { -do_data_switch: -if (!switch_data_file ()) { - key =K_SWITCH_INPUT_DATA ; + key =do_switch_data (browser, key); +if (key ==K_SWITCH_INPUT_DATA )break ; - }else -ui__warning ("Won't switch the data files due to\n" -"no valid data file get selected!\n" ); } } out_free_stack:
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 59/64 perf hists browser: Split popup menu actions - part 2
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
Currently perf_evsel__hists_browse() function spins on a huge loop and handles many key actions. Since it's hard to read and modify, let's split it out into small helper functions.
The add_XXX_opt() functions are to register popup menu item on the selected entry. When it adds an item, it also saves related data into struct popup_action and returns 1 so that it can increase the number of items (nr_options).
With this change, we can simplify the code just to call selected callback function without considering various conditions. A callback function named do_XXX is called with saved data when the item is selected by user.
No functional change intended.
--- tools/perf/ui/browsers/hists.c | 354 +++++++++++++++++++++++++---------------- 1 file changed, 214 insertions(+), 140 deletions(-)
tools/perf/ui/browsers/hists.c +214 -140
@@ -1402,8 +1402,16 @@ close_file_and_continue:return ret; } +struct popup_action { +struct thread *thread; +struct dso *dso; +struct map_symbol ms; + +int (*fn)(struct hist_browser *browser,struct popup_action *act); +}; +static int -do_annotate (struct hist_browser *browser,struct map_symbol *ms) +do_annotate (struct hist_browser *browser,struct popup_action *act) {struct perf_evsel *evsel;struct annotation *notes;
@@ -1413,12 +1421,12 @@ do_annotate(struct hist_browser *browser, struct map_symbol *ms)if (!objdump_path &&perf_session_env__lookup_objdump (browser->env))return 0 ; - notes =symbol__annotation (ms->sym); + notes =symbol__annotation (act->ms.sym);if (!notes->src)return 0 ; evsel =hists_to_evsel (browser->hists); - err =map_symbol__tui_annotate (ms, evsel, browser->hbt); + err =map_symbol__tui_annotate (&act->ms, evsel, browser->hbt); he =hist_browser__selected_entry (browser);/* * offer option to annotate the other branch source or target
@@ -1434,8 +1442,27 @@ do_annotate(struct hist_browser *browser, struct map_symbol *ms) }static int -do_zoom_thread (struct hist_browser *browser,struct thread *thread) +add_annotate_opt (struct hist_browser *browser__maybe_unused , +struct popup_action *act,char **optstr, +struct map *map,struct symbol *sym) { +if (sym ==NULL || map->dso->annotate_warned) +return 0 ; + +if (asprintf (optstr,"Annotate %s" , sym->name) <0 ) +return 0 ; + + act->ms.map = map; + act->ms.sym = sym; + act->fn = do_annotate; +return 1 ; +} + +static int +do_zoom_thread (struct hist_browser *browser,struct popup_action *act) +{ +struct thread *thread = act->thread; +if (browser->hists->thread_filter) {pstack__remove (browser->pstack, &browser->hists->thread_filter);perf_hpp__set_elide (HISTC_THREAD , false);
@@ -1456,8 +1483,28 @@ do_zoom_thread(struct hist_browser *browser, struct thread *thread) }static int -do_zoom_dso (struct hist_browser *browser,struct dso *dso) +add_thread_opt (struct hist_browser *browser,struct popup_action *act, +char **optstr,struct thread *thread) +{ +if (thread ==NULL ) +return 0 ; + +if (asprintf (optstr,"Zoom %s %s(%d) thread" , + browser->hists->thread_filter ?"out of" :"into" , + thread->comm_set ?thread__comm_str (thread) :"" , + thread->tid) <0 ) +return 0 ; + + act->thread = thread; + act->fn = do_zoom_thread; +return 1 ; +} + +static int +do_zoom_dso (struct hist_browser *browser,struct popup_action *act) { +struct dso *dso = act->dso; +if (browser->hists->dso_filter) {pstack__remove (browser->pstack, &browser->hists->dso_filter);perf_hpp__set_elide (HISTC_DSO , false);
@@ -1479,25 +1526,58 @@ do_zoom_dso(struct hist_browser *browser, struct dso *dso) }static int -do_browse_map (struct hist_browser *browser__maybe_unused ,struct map *map) +add_dso_opt (struct hist_browser *browser,struct popup_action *act, +char **optstr,struct dso *dso) { -map__browse (map); +if (dso ==NULL ) +return 0 ; + +if (asprintf (optstr,"Zoom %s %s DSO" , + browser->hists->dso_filter ?"out of" :"into" , + dso->kernel ?"the Kernel" : dso->short_name) <0 ) +return 0 ; + + act->dso = dso; + act->fn = do_zoom_dso; +return 1 ; +} + +static int +do_browse_map (struct hist_browser *browser__maybe_unused , +struct popup_action *act) +{ +map__browse (act->ms.map);return 0 ; }static int +add_map_opt (struct hist_browser *browser__maybe_unused , +struct popup_action *act,char **optstr,struct map *map) +{ +if (map ==NULL ) +return 0 ; + +if (asprintf (optstr,"Browse map details" ) <0 ) +return 0 ; + + act->ms.map = map; + act->fn = do_browse_map; +return 1 ; +} + +static int do_run_script (struct hist_browser *browser__maybe_unused , -struct thread *thread,struct symbol *sym) +struct popup_action *act) {char script_opt[64 ];memset (script_opt,0 ,sizeof (script_opt)); -if (thread) { +if (act->thread) {scnprintf (script_opt,sizeof (script_opt)," -c %s " , -thread__comm_str (thread)); - }else if (sym) { +thread__comm_str (act->thread)); + }else if (act->ms.sym) {scnprintf (script_opt,sizeof (script_opt)," -S %s " , - sym->name); + act->ms.sym->name); }script_browse (script_opt);
@@ -1505,17 +1585,74 @@ do_run_script(struct hist_browser *browser __maybe_unused, }static int -do_switch_data (struct hist_browser *browser__maybe_unused ,int key) +add_script_opt (struct hist_browser *browser__maybe_unused , +struct popup_action *act,char **optstr, +struct thread *thread,struct symbol *sym) +{ +if (thread) { +if (asprintf (optstr,"Run scripts for samples of thread [%s]" , +thread__comm_str (thread)) <0 ) +return 0 ; + }else if (sym) { +if (asprintf (optstr,"Run scripts for samples of symbol [%s]" , + sym->name) <0 ) +return 0 ; + }else { +if (asprintf (optstr,"Run scripts for all samples" ) <0 ) +return 0 ; + } + + act->thread = thread; + act->ms.sym = sym; + act->fn = do_run_script; +return 1 ; +} + +static int +do_switch_data (struct hist_browser *browser__maybe_unused , +struct popup_action *act__maybe_unused ) {if (switch_data_file ()) {ui__warning ("Won't switch the data files due to\n" "no valid data file get selected!\n" ); -return key; +return 0 ; }return K_SWITCH_INPUT_DATA ; } +static int +add_switch_opt (struct hist_browser *browser, +struct popup_action *act,char **optstr) +{ +if (!is_report_browser (browser->hbt)) +return 0 ; + +if (asprintf (optstr,"Switch to another data file in PWD" ) <0 ) +return 0 ; + + act->fn = do_switch_data; +return 1 ; +} + +static int +do_exit_browser (struct hist_browser *browser__maybe_unused , +struct popup_action *act__maybe_unused ) +{ +return 0 ; +} + +static int +add_exit_opt (struct hist_browser *browser__maybe_unused , +struct popup_action *act,char **optstr) +{ +if (asprintf (optstr,"Exit" ) <0 ) +return 0 ; + + act->fn = do_exit_browser; +return 1 ; +} +static void hist_browser__update_nr_entries (struct hist_browser *hb) {u64 nr_entries =0 ;
@@ -1546,6 +1683,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,struct branch_info *bi;#define MAX_OPTIONS 16char *options[MAX_OPTIONS ]; +struct popup_action actions[MAX_OPTIONS ];int nr_options =0 ;int key =-1 ;char buf[64 ];
@@ -1600,6 +1738,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,ui_helpline__push (helpline);memset (options,0 ,sizeof (options)); +memset (actions,0 ,sizeof (actions));perf_hpp__for_each_format (fmt)perf_hpp__reset_width (fmt, hists);
@@ -1610,12 +1749,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,while (1 ) {struct thread *thread =NULL ;struct dso *dso =NULL ; -struct map_symbol ms; -int choice =0 , - annotate =-2 , zoom_dso =-2 , zoom_thread =-2 , - annotate_f =-2 , annotate_t =-2 , browse_map =-2 ; -int scripts_comm =-2 , scripts_symbol =-2 , - scripts_all =-2 , switch_data =-2 ; +int choice =0 ; nr_options =0 ;
@@ -1648,22 +1782,23 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, browser->selection->map->dso->annotate_warned) continue; - ms.map = browser->selection->map; - ms.sym = browser->selection->sym; - -do_annotate (browser, &ms); + actions->ms.map = browser->selection->map; + actions->ms.sym = browser->selection->sym; +do_annotate (browser, actions);continue ;case 'P' :hist_browser__dump (browser);continue ;case 'd' : -do_zoom_dso (browser, dso); + actions->dso = dso; +do_zoom_dso (browser, actions);continue ;case 'V' : browser->show_dso = !browser->show_dso;continue ;case 't' : -do_zoom_thread (browser, thread); + actions->thread = thread; +do_zoom_thread (browser, actions);continue ;case '/' : if (ui_browser__input_window("Symbol to show",
@@ -1676,12 +1811,15 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, }continue ;case 'r' : -if (is_report_browser (hbt)) -do_run_script (browser,NULL ,NULL ); +if (is_report_browser (hbt)) { + actions->thread =NULL ; + actions->ms.sym =NULL ; +do_run_script (browser, actions); + }continue ;case 's' :if (is_report_browser (hbt)) { - key =do_switch_data (browser, key); + key =do_switch_data (browser, actions);if (key ==K_SWITCH_INPUT_DATA ) goto out_free_stack; }
@@ -1762,129 +1900,65 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,if (bi ==NULL ) goto skip_annotation; -if (bi->from.sym !=NULL && - !bi->from.map->dso->annotate_warned && -asprintf (&options[nr_options],"Annotate %s" , bi->from.sym->name) >0 ) { - annotate_f = nr_options++; - } - -if (bi->to.sym !=NULL && - !bi->to.map->dso->annotate_warned && - (bi->to.sym != bi->from.sym || - bi->to.map->dso != bi->from.map->dso) && -asprintf (&options[nr_options],"Annotate %s" , bi->to.sym->name) >0 ) { - annotate_t = nr_options++; - } + nr_options +=add_annotate_opt (browser, + &actions[nr_options], + &options[nr_options], + bi->from.map, + bi->from.sym); +if (bi->to.sym != bi->from.sym) + nr_options +=add_annotate_opt (browser, + &actions[nr_options], + &options[nr_options], + bi->to.map, + bi->to.sym); }else { -if (browser->selection->sym !=NULL && - !browser->selection->map->dso->annotate_warned) { -struct annotation *notes; - - notes =symbol__annotation (browser->selection->sym); - -if (notes->src && -asprintf (&options[nr_options],"Annotate %s" , - browser->selection->sym->name) >0 ) { - annotate = nr_options++; - } - } + nr_options +=add_annotate_opt (browser, + &actions[nr_options], + &options[nr_options], + browser->selection->map, + browser->selection->sym); } skip_annotation: -if (thread !=NULL && -asprintf (&options[nr_options],"Zoom %s %s(%d) thread" , - (browser->hists->thread_filter ?"out of" :"into" ), - (thread->comm_set ?thread__comm_str (thread) :"" ), - thread->tid) >0 ) - zoom_thread = nr_options++; - -if (dso !=NULL && -asprintf (&options[nr_options],"Zoom %s %s DSO" , - (browser->hists->dso_filter ?"out of" :"into" ), - (dso->kernel ?"the Kernel" : dso->short_name)) >0 ) - zoom_dso = nr_options++; - -if (browser->selection !=NULL && - browser->selection->map !=NULL && -asprintf (&options[nr_options],"Browse map details" ) >0 ) - browse_map = nr_options++; + nr_options +=add_thread_opt (browser, &actions[nr_options], + &options[nr_options], thread); + nr_options +=add_dso_opt (browser, &actions[nr_options], + &options[nr_options], dso); + nr_options +=add_map_opt (browser, &actions[nr_options], + &options[nr_options], + browser->selection->map);/* perf script support */ if (browser->he_selection) { -struct symbol *sym; - -if (asprintf (&options[nr_options],"Run scripts for samples of thread [%s]" , -thread__comm_str (browser->he_selection->thread)) >0 ) - scripts_comm = nr_options++; - - sym = browser->he_selection->ms.sym; -if (sym && sym->namelen && -asprintf (&options[nr_options],"Run scripts for samples of symbol [%s]" , - sym->name) >0 ) - scripts_symbol = nr_options++; + nr_options +=add_script_opt (browser, + &actions[nr_options], + &options[nr_options], + thread,NULL ); + nr_options +=add_script_opt (browser, + &actions[nr_options], + &options[nr_options], +NULL , browser->selection->sym); } - -if (asprintf (&options[nr_options],"Run scripts for all samples" ) >0 ) - scripts_all = nr_options++; - -if (is_report_browser (hbt) &&asprintf (&options[nr_options], -"Switch to another data file in PWD" ) >0 ) - switch_data = nr_options++; + nr_options +=add_script_opt (browser, &actions[nr_options], + &options[nr_options],NULL ,NULL ); + nr_options +=add_switch_opt (browser, &actions[nr_options], + &options[nr_options]); add_exit_option: -if (asprintf (&options[nr_options],"Exit" ) >0 ) - nr_options++; -retry_popup_menu: - choice =ui__popup_menu (nr_options, options); + nr_options +=add_exit_opt (browser, &actions[nr_options], + &options[nr_options]); -if (choice == nr_options -1 ) -break ; - -if (choice ==-1 ) { -free_popup_options (options, nr_options -1 ); -continue ; - } - -if (choice == annotate || choice == annotate_t || choice == annotate_f) { -struct hist_entry *he; +do { +struct popup_action *act; - he =hist_browser__selected_entry (browser); -if (he ==NULL ) -continue ; + choice =ui__popup_menu (nr_options, options); +if (choice ==-1 || choice >= nr_options) +break ; -if (choice == annotate_f) { - ms.map = he->branch_info->from.map; - ms.sym = he->branch_info->from.sym; - }else if (choice == annotate_t) { - ms.map = he->branch_info->to.map; - ms.sym = he->branch_info->to.sym; - }else { - ms = *browser->selection; - } + act = &actions[choice]; + key = act->fn (browser, act); + }while (key ==1 ); -if (do_annotate (browser, &ms) ==1 ) - goto retry_popup_menu; - }else if (choice == browse_map) { -do_browse_map (browser, browser->selection->map); - }else if (choice == zoom_dso) { -do_zoom_dso (browser, dso); - }else if (choice == zoom_thread) { -do_zoom_thread (browser, thread); - } -/* perf scripts support */ -else if (choice == scripts_all || choice == scripts_comm || - choice == scripts_symbol) { -if (choice == scripts_comm) -do_run_script (browser, browser->he_selection->thread,NULL ); -if (choice == scripts_symbol) -do_run_script (browser,NULL , browser->he_selection->ms.sym); -if (choice == scripts_all) -do_run_script (browser,NULL ,NULL ); - } -/* Switch to another data file */ -else if (choice == switch_data) { - key =do_switch_data (browser, key); -if (key ==K_SWITCH_INPUT_DATA ) -break ; - } +if (key ==K_SWITCH_INPUT_DATA ) +break ; } out_free_stack:pstack__delete (browser->pstack);
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 60/64 perf tools: Introduce pstack_peek()
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
The pstack_peek() is to get the topmost entry without removing it.
--- tools/perf/util/pstack.c | 7 +++++++ tools/perf/util/pstack.h | 1 + 2 files changed, 8 insertions(+)
tools/perf/util/pstack.c +7 -0
@@ -74,3 +74,10 @@ void *pstack__pop(struct pstack *pstack) pstack->entries[pstack->top] =NULL ;return ret; } + +void *pstack__peek (struct pstack *pstack) +{ +if (pstack->top ==0 ) +return NULL ; +return pstack->entries[pstack->top -1 ]; +}
tools/perf/util/pstack.h +1 -0
@@ -10,5 +10,6 @@ bool pstack__empty(const struct pstack *pstack);void pstack__remove (struct pstack *pstack,void *key);void pstack__push (struct pstack *pstack,void *key);void *pstack__pop (struct pstack *pstack); +void *pstack__peek (struct pstack *pstack);#endif /* _PERF_PSTACK_ */
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 61/64 perf hists browser: Simplify zooming code using pstack_peek()
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
Now LEFT key press action can just use do_zoom_dso/thread() code to get out of the current filter.
--- tools/perf/ui/browsers/hists.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
tools/perf/ui/browsers/hists.c +9 -11
@@ -1860,19 +1860,17 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, goto out_free_stack;continue ; } - top =pstack__pop (browser->pstack); + top =pstack__peek (browser->pstack);if (top == &browser->hists->dso_filter) { -perf_hpp__set_elide (HISTC_DSO , false); - browser->hists->dso_filter =NULL ; -hists__filter_by_dso (browser->hists); - } -if (top == &browser->hists->thread_filter) { -perf_hpp__set_elide (HISTC_THREAD , false); -thread__zput (browser->hists->thread_filter); -hists__filter_by_thread (browser->hists); +/* +* No need to set actions->dso here since +* it's just to remove the current filter. +* Ditto for thread below. +*/ +do_zoom_dso (browser, actions); } -ui_helpline__pop (); -hist_browser__reset (browser); +if (top == &browser->hists->thread_filter) +do_zoom_thread (browser, actions);continue ; }case K_ESC :
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 62/64 perf tools: Move TUI-specific fields out of map_symbol
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
The has_children and unfolded fields don't belong to struct map_symbol since they're used by TUI only. Move those fields out of map_symbol since the struct is also used by other places.
This will also help to compact the sizeof struct hist_entry.
--- tools/perf/ui/browsers/hists.c | 57 +++++++++++++++++++----------------------- tools/perf/util/callchain.h | 4 +++ tools/perf/util/hist.c | 2 +- tools/perf/util/sort.h | 2 ++ tools/perf/util/symbol.h | 2 -- 5 files changed, 33 insertions(+), 34 deletions(-)
tools/perf/ui/browsers/hists.c +26 -31
@@ -63,7 +63,7 @@ static int hist_browser__get_folding(struct hist_browser *browser)struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); -if (he->ms.unfolded) +if (he->unfolded) unfolded_rows += he->nr_rows; }return unfolded_rows;
@@ -139,24 +139,19 @@ static char tree__folded_sign(bool unfolded)return unfolded ?'-' :'+' ; } -static char map_symbol__folded (const struct map_symbol *ms) -{ -return ms->has_children ?tree__folded_sign (ms->unfolded) :' ' ; -} -static char hist_entry__folded (const struct hist_entry *he) { -return map_symbol__folded (&he->ms); +return he->has_children ?tree__folded_sign (he->unfolded) :' ' ; }static char callchain_list__folded (const struct callchain_list *cl) { -return map_symbol__folded (&cl->ms); +return cl->has_children ?tree__folded_sign (cl->unfolded) :' ' ; } -static void map_symbol__set_folding (struct map_symbol *ms,bool unfold) +static void callchain_list__set_folding (struct callchain_list *cl,bool unfold) { - ms->unfolded = unfold ? ms->has_children : false; + cl->unfolded = unfold ? cl->has_children : false; }static int callchain_node__count_rows_rb_tree (struct callchain_node *node)
@@ -192,7 +187,7 @@ static int callchain_node__count_rows(struct callchain_node *node)list_for_each_entry (chain, &node->val, list) { ++n; - unfolded = chain->ms.unfolded; + unfolded = chain->unfolded; }if (unfolded)
@@ -214,15 +209,15 @@ static int callchain__count_rows(struct rb_root *chain)return n; } -static bool map_symbol__toggle_fold (struct map_symbol *ms) +static bool hist_entry__toggle_fold (struct hist_entry *he) { -if (!ms) +if (!he)return false; -if (!ms->has_children) +if (!he->has_children)return false; - ms->unfolded = !ms->unfolded; + he->unfolded = !he->unfolded;return true; }
@@ -238,10 +233,10 @@ static void callchain_node__init_have_children_rb_tree(struct callchain_node *nolist_for_each_entry (chain, &child->val, list) {if (first) { first = false; - chain->ms.has_children = chain->list.next != &child->val || + chain->has_children = chain->list.next != &child->val || !RB_EMPTY_ROOT (&child->rb_root); }else - chain->ms.has_children = chain->list.next == &child->val && + chain->has_children = chain->list.next == &child->val && !RB_EMPTY_ROOT (&child->rb_root); }
@@ -255,11 +250,11 @@ static void callchain_node__init_have_children(struct callchain_node *node,struct callchain_list *chain; chain = list_entry(node->val.next, struct callchain_list, list); - chain->ms.has_children = has_sibling; + chain->has_children = has_sibling;if (!list_empty (&node->val)) { chain = list_entry(node->val.prev, struct callchain_list, list); - chain->ms.has_children = !RB_EMPTY_ROOT (&node->rb_root); + chain->has_children = !RB_EMPTY_ROOT (&node->rb_root); }callchain_node__init_have_children_rb_tree (node);
@@ -279,7 +274,7 @@ static void callchain__init_have_children(struct rb_root *root)static void hist_entry__init_have_children (struct hist_entry *he) {if (!he->init_have_children) { - he->ms.has_children = !RB_EMPTY_ROOT (&he->sorted_chain); + he->has_children = !RB_EMPTY_ROOT (&he->sorted_chain);callchain__init_have_children (&he->sorted_chain); he->init_have_children = true; }
@@ -287,14 +282,14 @@ static void hist_entry__init_have_children(struct hist_entry *he)static bool hist_browser__toggle_fold (struct hist_browser *browser) { -if (map_symbol__toggle_fold (browser->selection)) { +if (hist_entry__toggle_fold (browser->he_selection)) {struct hist_entry *he = browser->he_selection;hist_entry__init_have_children (he); browser->b.nr_entries -= he->nr_rows; browser->nr_callchain_rows -= he->nr_rows; -if (he->ms.unfolded) +if (he->unfolded) he->nr_rows =callchain__count_rows (&he->sorted_chain);else he->nr_rows =0 ;
@@ -321,8 +316,8 @@ static int callchain_node__set_folding_rb_tree(struct callchain_node *node, boollist_for_each_entry (chain, &child->val, list) { ++n; -map_symbol__set_folding (&chain->ms, unfold); - has_children = chain->ms.has_children; +callchain_list__set_folding (chain, unfold); + has_children = chain->has_children; }if (has_children)
@@ -340,8 +335,8 @@ static int callchain_node__set_folding(struct callchain_node *node, bool unfold)list_for_each_entry (chain, &node->val, list) { ++n; -map_symbol__set_folding (&chain->ms, unfold); - has_children = chain->ms.has_children; +callchain_list__set_folding (chain, unfold); + has_children = chain->has_children; }if (has_children)
@@ -366,9 +361,9 @@ static int callchain__set_folding(struct rb_root *chain, bool unfold)static void hist_entry__set_folding (struct hist_entry *he,bool unfold) {hist_entry__init_have_children (he); -map_symbol__set_folding (&he->ms, unfold); +hist_entry__set_folding (he, unfold); -if (he->ms.has_children) { +if (he->has_children) {int n =callchain__set_folding (&he->sorted_chain, unfold); he->nr_rows = unfold ? n :0 ; }else
@@ -1019,7 +1014,7 @@ do_offset:if (offset >0 ) { do { h = rb_entry(nd, struct hist_entry, rb_node); - if (h->ms.unfolded) { + if (h->unfolded) { u16 remaining = h->nr_rows - h->row_offset; if (offset > remaining) { offset -= remaining;
@@ -1040,7 +1035,7 @@ do_offset: }else if (offset <0 ) {while (1 ) { h = rb_entry(nd, struct hist_entry, rb_node); -if (h->ms.unfolded) { +if (h->unfolded) {if (first) {if (-offset > h->row_offset) { offset += h->row_offset;
@@ -1077,7 +1072,7 @@ do_offset:* row_offset at its last entry. */ h = rb_entry(nd, struct hist_entry, rb_node); -if (h->ms.unfolded) +if (h->unfolded) h->row_offset = h->nr_rows;break ; }
tools/perf/util/callchain.h +4 -0
@@ -72,6 +72,10 @@ extern struct callchain_param callchain_param;struct callchain_list {u64 ip;struct map_symbol ms; +struct /* for TUI */ { +bool unfolded; +bool has_children; + };char *srcline;struct list_head list; };
tools/perf/util/hist.c +1 -1
@@ -1163,7 +1163,7 @@ static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *hreturn ;/* force fold unfiltered entry for simplicity */ - h->ms.unfolded = false; + h->unfolded = false; h->row_offset =0 ; h->nr_rows =0 ;
tools/perf/util/sort.h +2 -0
@@ -109,6 +109,8 @@ struct hist_entry {u16 row_offset;u16 nr_rows;bool init_have_children; +bool unfolded; +bool has_children; }; };char *srcline;
tools/perf/util/symbol.h +0 -2
@@ -158,8 +158,6 @@ struct ref_reloc_sym {struct map_symbol {struct map *map;struct symbol *sym; -bool unfolded; -bool has_children; };struct addr_map_symbol {
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 63/64 perf tools: Use getconf to determine number of online CPUs
In reply to Arnaldo Carvalho de MeloFrom: Will Deacon <[email protected]>
Parsing /proc/cpuinfo is a fiddly, arch-dependent business and a recent change to get it working for Sparc broke arm and arm64 platforms.
Use sysconf to determine the number of online CPUs only parsing /proc/cpuinfo when sysconf is not available.
--- tools/perf/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile +1 -1
@@ -24,7 +24,7 @@ unexport MAKEFLAGS # (To override it, run 'make JOBS=1' and similar.) # ifeq ($(JOBS),) - JOBS := $(shell egrep -c '^processor|^CPU' /proc/cpuinfo 2>/dev/null) + JOBS := $(shell (getconf _NPROCESSORS_ONLN || egrep -c '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null) ifeq ($(JOBS),0) JOBS := 1 endif
Signature · 1 line
1.9.3
Arnaldo Carvalho de Melo
maintainerPATCH 64/64 perf bench numa: Show more stats of particular threads in verbose mode
In reply to Arnaldo Carvalho de MeloFrom: Petr Holasek <[email protected]>
In verbose mode perf bench numa shows also GB/s speed, system and user cpu time for each particular thread. Using of getrusage() can provide much more per process or per thread stats in future.
--- tools/perf/bench/numa.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
tools/perf/bench/numa.c +31 -1
@@ -23,6 +23,7 @@#include <pthread.h> #include <sys/mman.h> #include <sys/time.h> +#include <sys/resource.h> #include <sys/wait.h> #include <sys/prctl.h> #include <sys/types.h>
@@ -51,6 +52,9 @@ struct thread_data {unsigned int loops_done;u64 val;u64 runtime_ns; +u64 system_time_ns; +u64 user_time_ns; +double speed_gbs;pthread_mutex_t *process_lock; };
@@ -1034,6 +1038,7 @@ static void *worker_thread(void *__tdata)u64 bytes_done;long work_done;u32 l; +struct rusage usage;bind_to_cpumask (td->bind_cpumask);bind_to_memnode (td->bind_node);
@@ -1186,6 +1191,13 @@ static void *worker_thread(void *__tdata)timersub (&stop, &start0, &diff); td->runtime_ns = diff.tv_sec *1000000000ULL ; td->runtime_ns += diff.tv_usec *1000ULL ; + td->speed_gbs = bytes_done / (td->runtime_ns /1e9 ) /1e9 ; + +getrusage (RUSAGE_THREAD , &usage); + td->system_time_ns = usage.ru_stime.tv_sec *1000000000ULL ; + td->system_time_ns += usage.ru_stime.tv_usec *1000ULL ; + td->user_time_ns = usage.ru_utime.tv_sec *1000000000ULL ; + td->user_time_ns += usage.ru_utime.tv_usec *1000ULL ;free_data (thread_data, g->p.bytes_thread);
@@ -1412,7 +1424,7 @@ static int __bench_numa(const char *name)double runtime_sec_min;int wait_stat;double bytes; -int i, t; +int i, t, p;if (init ())return -1 ;
@@ -1548,6 +1560,24 @@ static int __bench_numa(const char *name)print_res (name, bytes / runtime_sec_max /1e9 ,"GB/sec," ,"total-speed" ,"GB/sec total speed" ); +if (g->p.show_details >=2 ) { +char tname[32 ]; +struct thread_data *td; +for (p =0 ; p < g->p.nr_proc; p++) { +for (t =0 ; t < g->p.nr_threads; t++) { +memset (tname,0 ,32 ); + td = g->threads + p*g->p.nr_threads + t; +snprintf (tname,32 ,"process%d:thread%d" , p, t); +print_res (tname, td->speed_gbs, +"GB/sec" ,"thread-speed" ,"GB/sec/thread speed" ); +print_res (tname, td->system_time_ns /1e9 , +"secs" ,"thread-system-time" ,"system CPU time/thread" ); +print_res (tname, td->user_time_ns /1e9 , +"secs" ,"thread-user-time" ,"user CPU time/thread" ); + } + } + } +free (pids);deinit ();
Signature · 1 line
1.9.3