diff options
Diffstat (limited to 'tools')
75 files changed, 2744 insertions, 654 deletions
diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt index 5164a655c39f..b2c63309a651 100644 --- a/tools/perf/Documentation/perf-annotate.txt +++ b/tools/perf/Documentation/perf-annotate.txt | |||
@@ -8,7 +8,7 @@ perf-annotate - Read perf.data (created by perf record) and display annotated co | |||
8 | SYNOPSIS | 8 | SYNOPSIS |
9 | -------- | 9 | -------- |
10 | [verse] | 10 | [verse] |
11 | 'perf annotate' [-i <file> | --input=file] symbol_name | 11 | 'perf annotate' [-i <file> | --input=file] [symbol_name] |
12 | 12 | ||
13 | DESCRIPTION | 13 | DESCRIPTION |
14 | ----------- | 14 | ----------- |
@@ -24,6 +24,13 @@ OPTIONS | |||
24 | --input=:: | 24 | --input=:: |
25 | Input file name. (default: perf.data) | 25 | Input file name. (default: perf.data) |
26 | 26 | ||
27 | --stdio:: Use the stdio interface. | ||
28 | |||
29 | --tui:: Use the TUI interface Use of --tui requires a tty, if one is not | ||
30 | present, as when piping to other commands, the stdio interface is | ||
31 | used. This interfaces starts by centering on the line with more | ||
32 | samples, TAB/UNTAB cycles thru the lines with more samples. | ||
33 | |||
27 | SEE ALSO | 34 | SEE ALSO |
28 | -------- | 35 | -------- |
29 | linkperf:perf-record[1] | 36 | linkperf:perf-record[1], linkperf:perf-report[1] |
diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt index 43e3dd284b90..399751befeed 100644 --- a/tools/perf/Documentation/perf-list.txt +++ b/tools/perf/Documentation/perf-list.txt | |||
@@ -15,6 +15,23 @@ DESCRIPTION | |||
15 | This command displays the symbolic event types which can be selected in the | 15 | This command displays the symbolic event types which can be selected in the |
16 | various perf commands with the -e option. | 16 | various perf commands with the -e option. |
17 | 17 | ||
18 | EVENT MODIFIERS | ||
19 | --------------- | ||
20 | |||
21 | Events can optionally have a modifer by appending a colon and one or | ||
22 | more modifiers. Modifiers allow the user to restrict when events are | ||
23 | counted with 'u' for user-space, 'k' for kernel, 'h' for hypervisor. | ||
24 | |||
25 | The 'p' modifier can be used for specifying how precise the instruction | ||
26 | address should be. The 'p' modifier is currently only implemented for | ||
27 | Intel PEBS and can be specified multiple times: | ||
28 | 0 - SAMPLE_IP can have arbitrary skid | ||
29 | 1 - SAMPLE_IP must have constant skid | ||
30 | 2 - SAMPLE_IP requested to have 0 skid | ||
31 | 3 - SAMPLE_IP must have 0 skid | ||
32 | |||
33 | The PEBS implementation now supports up to 2. | ||
34 | |||
18 | RAW HARDWARE EVENT DESCRIPTOR | 35 | RAW HARDWARE EVENT DESCRIPTOR |
19 | ----------------------------- | 36 | ----------------------------- |
20 | Even when an event is not available in a symbolic form within perf right now, | 37 | Even when an event is not available in a symbolic form within perf right now, |
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt index 27d52dae5a43..62de1b7f4e76 100644 --- a/tools/perf/Documentation/perf-probe.txt +++ b/tools/perf/Documentation/perf-probe.txt | |||
@@ -16,7 +16,9 @@ or | |||
16 | or | 16 | or |
17 | 'perf probe' --list | 17 | 'perf probe' --list |
18 | or | 18 | or |
19 | 'perf probe' --line='FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]' | 19 | 'perf probe' [options] --line='FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]' |
20 | or | ||
21 | 'perf probe' [options] --vars='PROBEPOINT' | ||
20 | 22 | ||
21 | DESCRIPTION | 23 | DESCRIPTION |
22 | ----------- | 24 | ----------- |
@@ -31,6 +33,11 @@ OPTIONS | |||
31 | --vmlinux=PATH:: | 33 | --vmlinux=PATH:: |
32 | Specify vmlinux path which has debuginfo (Dwarf binary). | 34 | Specify vmlinux path which has debuginfo (Dwarf binary). |
33 | 35 | ||
36 | -m:: | ||
37 | --module=MODNAME:: | ||
38 | Specify module name in which perf-probe searches probe points | ||
39 | or lines. | ||
40 | |||
34 | -s:: | 41 | -s:: |
35 | --source=PATH:: | 42 | --source=PATH:: |
36 | Specify path to kernel source. | 43 | Specify path to kernel source. |
@@ -57,6 +64,15 @@ OPTIONS | |||
57 | Show source code lines which can be probed. This needs an argument | 64 | Show source code lines which can be probed. This needs an argument |
58 | which specifies a range of the source code. (see LINE SYNTAX for detail) | 65 | which specifies a range of the source code. (see LINE SYNTAX for detail) |
59 | 66 | ||
67 | -V:: | ||
68 | --vars=:: | ||
69 | Show available local variables at given probe point. The argument | ||
70 | syntax is same as PROBE SYNTAX, but NO ARGs. | ||
71 | |||
72 | --externs:: | ||
73 | (Only for --vars) Show external defined variables in addition to local | ||
74 | variables. | ||
75 | |||
60 | -f:: | 76 | -f:: |
61 | --force:: | 77 | --force:: |
62 | Forcibly add events with existing name. | 78 | Forcibly add events with existing name. |
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index 3ee27dccfde9..a91f9f9e6e5c 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt | |||
@@ -83,6 +83,10 @@ OPTIONS | |||
83 | --call-graph:: | 83 | --call-graph:: |
84 | Do call-graph (stack chain/backtrace) recording. | 84 | Do call-graph (stack chain/backtrace) recording. |
85 | 85 | ||
86 | -q:: | ||
87 | --quiet:: | ||
88 | Don't print any message, useful for scripting. | ||
89 | |||
86 | -v:: | 90 | -v:: |
87 | --verbose:: | 91 | --verbose:: |
88 | Be more verbose (show counter open errors, etc). | 92 | Be more verbose (show counter open errors, etc). |
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt index abfabe9147a4..12052c9ed0ba 100644 --- a/tools/perf/Documentation/perf-report.txt +++ b/tools/perf/Documentation/perf-report.txt | |||
@@ -65,6 +65,13 @@ OPTIONS | |||
65 | the tree is considered as a new profiled object. + | 65 | the tree is considered as a new profiled object. + |
66 | Default: fractal,0.5. | 66 | Default: fractal,0.5. |
67 | 67 | ||
68 | --stdio:: Use the stdio interface. | ||
69 | |||
70 | --tui:: Use the TUI interface, that is integrated with annotate and allows | ||
71 | zooming into DSOs or threads, among other features. Use of --tui | ||
72 | requires a tty, if one is not present, as when piping to other | ||
73 | commands, the stdio interface is used. | ||
74 | |||
68 | SEE ALSO | 75 | SEE ALSO |
69 | -------- | 76 | -------- |
70 | linkperf:perf-stat[1] | 77 | linkperf:perf-stat[1] |
diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt index 122ec9dc4853..26aff6bf9e50 100644 --- a/tools/perf/Documentation/perf-trace.txt +++ b/tools/perf/Documentation/perf-trace.txt | |||
@@ -8,7 +8,11 @@ perf-trace - Read perf.data (created by perf record) and display trace output | |||
8 | SYNOPSIS | 8 | SYNOPSIS |
9 | -------- | 9 | -------- |
10 | [verse] | 10 | [verse] |
11 | 'perf trace' {record <script> | report <script> [args] } | 11 | 'perf trace' [<options>] |
12 | 'perf trace' [<options>] record <script> [<record-options>] <command> | ||
13 | 'perf trace' [<options>] report <script> [script-args] | ||
14 | 'perf trace' [<options>] <script> <required-script-args> [<record-options>] <command> | ||
15 | 'perf trace' [<options>] <top-script> [script-args] | ||
12 | 16 | ||
13 | DESCRIPTION | 17 | DESCRIPTION |
14 | ----------- | 18 | ----------- |
@@ -24,23 +28,53 @@ There are several variants of perf trace: | |||
24 | available via 'perf trace -l'). The following variants allow you to | 28 | available via 'perf trace -l'). The following variants allow you to |
25 | record and run those scripts: | 29 | record and run those scripts: |
26 | 30 | ||
27 | 'perf trace record <script>' to record the events required for 'perf | 31 | 'perf trace record <script> <command>' to record the events required |
28 | trace report'. <script> is the name displayed in the output of | 32 | for 'perf trace report'. <script> is the name displayed in the |
29 | 'perf trace --list' i.e. the actual script name minus any language | 33 | output of 'perf trace --list' i.e. the actual script name minus any |
30 | extension. | 34 | language extension. If <command> is not specified, the events are |
35 | recorded using the -a (system-wide) 'perf record' option. | ||
31 | 36 | ||
32 | 'perf trace report <script>' to run and display the results of | 37 | 'perf trace report <script> [args]' to run and display the results |
33 | <script>. <script> is the name displayed in the output of 'perf | 38 | of <script>. <script> is the name displayed in the output of 'perf |
34 | trace --list' i.e. the actual script name minus any language | 39 | trace --list' i.e. the actual script name minus any language |
35 | extension. The perf.data output from a previous run of 'perf trace | 40 | extension. The perf.data output from a previous run of 'perf trace |
36 | record <script>' is used and should be present for this command to | 41 | record <script>' is used and should be present for this command to |
37 | succeed. | 42 | succeed. [args] refers to the (mainly optional) args expected by |
43 | the script. | ||
44 | |||
45 | 'perf trace <script> <required-script-args> <command>' to both | ||
46 | record the events required for <script> and to run the <script> | ||
47 | using 'live-mode' i.e. without writing anything to disk. <script> | ||
48 | is the name displayed in the output of 'perf trace --list' i.e. the | ||
49 | actual script name minus any language extension. If <command> is | ||
50 | not specified, the events are recorded using the -a (system-wide) | ||
51 | 'perf record' option. If <script> has any required args, they | ||
52 | should be specified before <command>. This mode doesn't allow for | ||
53 | optional script args to be specified; if optional script args are | ||
54 | desired, they can be specified using separate 'perf trace record' | ||
55 | and 'perf trace report' commands, with the stdout of the record step | ||
56 | piped to the stdin of the report script, using the '-o -' and '-i -' | ||
57 | options of the corresponding commands. | ||
58 | |||
59 | 'perf trace <top-script>' to both record the events required for | ||
60 | <top-script> and to run the <top-script> using 'live-mode' | ||
61 | i.e. without writing anything to disk. <top-script> is the name | ||
62 | displayed in the output of 'perf trace --list' i.e. the actual | ||
63 | script name minus any language extension; a <top-script> is defined | ||
64 | as any script name ending with the string 'top'. | ||
65 | |||
66 | [<record-options>] can be passed to the record steps of 'perf trace | ||
67 | record' and 'live-mode' variants; this isn't possible however for | ||
68 | <top-script> 'live-mode' or 'perf trace report' variants. | ||
38 | 69 | ||
39 | See the 'SEE ALSO' section for links to language-specific | 70 | See the 'SEE ALSO' section for links to language-specific |
40 | information on how to write and run your own trace scripts. | 71 | information on how to write and run your own trace scripts. |
41 | 72 | ||
42 | OPTIONS | 73 | OPTIONS |
43 | ------- | 74 | ------- |
75 | <command>...:: | ||
76 | Any command you can specify in a shell. | ||
77 | |||
44 | -D:: | 78 | -D:: |
45 | --dump-raw-trace=:: | 79 | --dump-raw-trace=:: |
46 | Display verbose dump of the trace data. | 80 | Display verbose dump of the trace data. |
@@ -64,6 +98,13 @@ OPTIONS | |||
64 | Generate perf-trace.[ext] starter script for given language, | 98 | Generate perf-trace.[ext] starter script for given language, |
65 | using current perf.data. | 99 | using current perf.data. |
66 | 100 | ||
101 | -a:: | ||
102 | Force system-wide collection. Scripts run without a <command> | ||
103 | normally use -a by default, while scripts run with a <command> | ||
104 | normally don't - this option allows the latter to be run in | ||
105 | system-wide mode. | ||
106 | |||
107 | |||
67 | SEE ALSO | 108 | SEE ALSO |
68 | -------- | 109 | -------- |
69 | linkperf:perf-record[1], linkperf:perf-trace-perl[1], | 110 | linkperf:perf-record[1], linkperf:perf-trace-perl[1], |
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 1950e19af1cf..d1db0f676a4b 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -313,6 +313,9 @@ TEST_PROGRAMS = | |||
313 | 313 | ||
314 | SCRIPT_SH += perf-archive.sh | 314 | SCRIPT_SH += perf-archive.sh |
315 | 315 | ||
316 | grep-libs = $(filter -l%,$(1)) | ||
317 | strip-libs = $(filter-out -l%,$(1)) | ||
318 | |||
316 | # | 319 | # |
317 | # No Perl scripts right now: | 320 | # No Perl scripts right now: |
318 | # | 321 | # |
@@ -588,14 +591,17 @@ endif | |||
588 | ifdef NO_LIBPERL | 591 | ifdef NO_LIBPERL |
589 | BASIC_CFLAGS += -DNO_LIBPERL | 592 | BASIC_CFLAGS += -DNO_LIBPERL |
590 | else | 593 | else |
591 | PERL_EMBED_LDOPTS = `perl -MExtUtils::Embed -e ldopts 2>/dev/null` | 594 | PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) |
595 | PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) | ||
596 | PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) | ||
592 | PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null` | 597 | PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null` |
593 | FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) | 598 | FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) |
594 | 599 | ||
595 | ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED)),y) | 600 | ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED)),y) |
596 | BASIC_CFLAGS += -DNO_LIBPERL | 601 | BASIC_CFLAGS += -DNO_LIBPERL |
597 | else | 602 | else |
598 | ALL_LDFLAGS += $(PERL_EMBED_LDOPTS) | 603 | ALL_LDFLAGS += $(PERL_EMBED_LDFLAGS) |
604 | EXTLIBS += $(PERL_EMBED_LIBADD) | ||
599 | LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o | 605 | LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o |
600 | LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o | 606 | LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o |
601 | endif | 607 | endif |
@@ -604,13 +610,16 @@ endif | |||
604 | ifdef NO_LIBPYTHON | 610 | ifdef NO_LIBPYTHON |
605 | BASIC_CFLAGS += -DNO_LIBPYTHON | 611 | BASIC_CFLAGS += -DNO_LIBPYTHON |
606 | else | 612 | else |
607 | PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null` | 613 | PYTHON_EMBED_LDOPTS = $(shell python-config --ldflags 2>/dev/null) |
614 | PYTHON_EMBED_LDFLAGS = $(call strip-libs,$(PYTHON_EMBED_LDOPTS)) | ||
615 | PYTHON_EMBED_LIBADD = $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) | ||
608 | PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null` | 616 | PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null` |
609 | FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS) | 617 | FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS) |
610 | ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y) | 618 | ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y) |
611 | BASIC_CFLAGS += -DNO_LIBPYTHON | 619 | BASIC_CFLAGS += -DNO_LIBPYTHON |
612 | else | 620 | else |
613 | ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS) | 621 | ALL_LDFLAGS += $(PYTHON_EMBED_LDFLAGS) |
622 | EXTLIBS += $(PYTHON_EMBED_LIBADD) | ||
614 | LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o | 623 | LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o |
615 | LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o | 624 | LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o |
616 | endif | 625 | endif |
@@ -653,6 +662,15 @@ else | |||
653 | endif | 662 | endif |
654 | endif | 663 | endif |
655 | 664 | ||
665 | |||
666 | ifdef NO_STRLCPY | ||
667 | BASIC_CFLAGS += -DNO_STRLCPY | ||
668 | else | ||
669 | ifneq ($(call try-cc,$(SOURCE_STRLCPY),),y) | ||
670 | BASIC_CFLAGS += -DNO_STRLCPY | ||
671 | endif | ||
672 | endif | ||
673 | |||
656 | ifndef CC_LD_DYNPATH | 674 | ifndef CC_LD_DYNPATH |
657 | ifdef NO_R_TO_GCC_LINKER | 675 | ifdef NO_R_TO_GCC_LINKER |
658 | # Some gcc does not accept and pass -R to the linker to specify | 676 | # Some gcc does not accept and pass -R to the linker to specify |
@@ -910,8 +928,8 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS | |||
910 | $(ALL_CFLAGS) -c $(filter %.c,$^) -o $@ | 928 | $(ALL_CFLAGS) -c $(filter %.c,$^) -o $@ |
911 | 929 | ||
912 | $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS) | 930 | $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS) |
913 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \ | 931 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \ |
914 | $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) | 932 | $(BUILTIN_OBJS) $(LIBS) -o $@ |
915 | 933 | ||
916 | $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS | 934 | $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS |
917 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ | 935 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ |
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 1478dc64bf15..6d5604d8df95 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -28,7 +28,7 @@ | |||
28 | 28 | ||
29 | static char const *input_name = "perf.data"; | 29 | static char const *input_name = "perf.data"; |
30 | 30 | ||
31 | static bool force; | 31 | static bool force, use_tui, use_stdio; |
32 | 32 | ||
33 | static bool full_paths; | 33 | static bool full_paths; |
34 | 34 | ||
@@ -321,7 +321,7 @@ static int hist_entry__tty_annotate(struct hist_entry *he) | |||
321 | 321 | ||
322 | static void hists__find_annotations(struct hists *self) | 322 | static void hists__find_annotations(struct hists *self) |
323 | { | 323 | { |
324 | struct rb_node *first = rb_first(&self->entries), *nd = first; | 324 | struct rb_node *nd = rb_first(&self->entries), *next; |
325 | int key = KEY_RIGHT; | 325 | int key = KEY_RIGHT; |
326 | 326 | ||
327 | while (nd) { | 327 | while (nd) { |
@@ -343,20 +343,19 @@ find_next: | |||
343 | 343 | ||
344 | if (use_browser > 0) { | 344 | if (use_browser > 0) { |
345 | key = hist_entry__tui_annotate(he); | 345 | key = hist_entry__tui_annotate(he); |
346 | if (is_exit_key(key)) | ||
347 | break; | ||
348 | switch (key) { | 346 | switch (key) { |
349 | case KEY_RIGHT: | 347 | case KEY_RIGHT: |
350 | case '\t': | 348 | next = rb_next(nd); |
351 | nd = rb_next(nd); | ||
352 | break; | 349 | break; |
353 | case KEY_LEFT: | 350 | case KEY_LEFT: |
354 | if (nd == first) | 351 | next = rb_prev(nd); |
355 | continue; | ||
356 | nd = rb_prev(nd); | ||
357 | default: | ||
358 | break; | 352 | break; |
353 | default: | ||
354 | return; | ||
359 | } | 355 | } |
356 | |||
357 | if (next != NULL) | ||
358 | nd = next; | ||
360 | } else { | 359 | } else { |
361 | hist_entry__tty_annotate(he); | 360 | hist_entry__tty_annotate(he); |
362 | nd = rb_next(nd); | 361 | nd = rb_next(nd); |
@@ -428,6 +427,8 @@ static const struct option options[] = { | |||
428 | "be more verbose (show symbol address, etc)"), | 427 | "be more verbose (show symbol address, etc)"), |
429 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 428 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
430 | "dump raw trace in ASCII"), | 429 | "dump raw trace in ASCII"), |
430 | OPT_BOOLEAN(0, "tui", &use_tui, "Use the TUI interface"), | ||
431 | OPT_BOOLEAN(0, "stdio", &use_stdio, "Use the stdio interface"), | ||
431 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, | 432 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
432 | "file", "vmlinux pathname"), | 433 | "file", "vmlinux pathname"), |
433 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, | 434 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, |
@@ -443,6 +444,11 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used) | |||
443 | { | 444 | { |
444 | argc = parse_options(argc, argv, options, annotate_usage, 0); | 445 | argc = parse_options(argc, argv, options, annotate_usage, 0); |
445 | 446 | ||
447 | if (use_stdio) | ||
448 | use_browser = 0; | ||
449 | else if (use_tui) | ||
450 | use_browser = 1; | ||
451 | |||
446 | setup_browser(); | 452 | setup_browser(); |
447 | 453 | ||
448 | symbol_conf.priv_size = sizeof(struct sym_priv); | 454 | symbol_conf.priv_size = sizeof(struct sym_priv); |
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c index 44a47e13bd67..c49837de7d3f 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c | |||
@@ -36,7 +36,6 @@ static const struct option options[] = { | |||
36 | 36 | ||
37 | static int __cmd_buildid_list(void) | 37 | static int __cmd_buildid_list(void) |
38 | { | 38 | { |
39 | int err = -1; | ||
40 | struct perf_session *session; | 39 | struct perf_session *session; |
41 | 40 | ||
42 | session = perf_session__new(input_name, O_RDONLY, force, false); | 41 | session = perf_session__new(input_name, O_RDONLY, force, false); |
@@ -49,7 +48,7 @@ static int __cmd_buildid_list(void) | |||
49 | perf_session__fprintf_dsos_buildid(session, stdout, with_hits); | 48 | perf_session__fprintf_dsos_buildid(session, stdout, with_hits); |
50 | 49 | ||
51 | perf_session__delete(session); | 50 | perf_session__delete(session); |
52 | return err; | 51 | return 0; |
53 | } | 52 | } |
54 | 53 | ||
55 | int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) | 54 | int cmd_buildid_list(int argc, const char **argv, const char *prefix __used) |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 199d5e19554f..add163c9f0e7 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -50,14 +50,17 @@ static struct { | |||
50 | bool list_events; | 50 | bool list_events; |
51 | bool force_add; | 51 | bool force_add; |
52 | bool show_lines; | 52 | bool show_lines; |
53 | bool show_vars; | ||
54 | bool show_ext_vars; | ||
55 | bool mod_events; | ||
53 | int nevents; | 56 | int nevents; |
54 | struct perf_probe_event events[MAX_PROBES]; | 57 | struct perf_probe_event events[MAX_PROBES]; |
55 | struct strlist *dellist; | 58 | struct strlist *dellist; |
56 | struct line_range line_range; | 59 | struct line_range line_range; |
60 | const char *target_module; | ||
57 | int max_probe_points; | 61 | int max_probe_points; |
58 | } params; | 62 | } params; |
59 | 63 | ||
60 | |||
61 | /* Parse an event definition. Note that any error must die. */ | 64 | /* Parse an event definition. Note that any error must die. */ |
62 | static int parse_probe_event(const char *str) | 65 | static int parse_probe_event(const char *str) |
63 | { | 66 | { |
@@ -92,6 +95,7 @@ static int parse_probe_event_argv(int argc, const char **argv) | |||
92 | len = 0; | 95 | len = 0; |
93 | for (i = 0; i < argc; i++) | 96 | for (i = 0; i < argc; i++) |
94 | len += sprintf(&buf[len], "%s ", argv[i]); | 97 | len += sprintf(&buf[len], "%s ", argv[i]); |
98 | params.mod_events = true; | ||
95 | ret = parse_probe_event(buf); | 99 | ret = parse_probe_event(buf); |
96 | free(buf); | 100 | free(buf); |
97 | return ret; | 101 | return ret; |
@@ -100,9 +104,10 @@ static int parse_probe_event_argv(int argc, const char **argv) | |||
100 | static int opt_add_probe_event(const struct option *opt __used, | 104 | static int opt_add_probe_event(const struct option *opt __used, |
101 | const char *str, int unset __used) | 105 | const char *str, int unset __used) |
102 | { | 106 | { |
103 | if (str) | 107 | if (str) { |
108 | params.mod_events = true; | ||
104 | return parse_probe_event(str); | 109 | return parse_probe_event(str); |
105 | else | 110 | } else |
106 | return 0; | 111 | return 0; |
107 | } | 112 | } |
108 | 113 | ||
@@ -110,6 +115,7 @@ static int opt_del_probe_event(const struct option *opt __used, | |||
110 | const char *str, int unset __used) | 115 | const char *str, int unset __used) |
111 | { | 116 | { |
112 | if (str) { | 117 | if (str) { |
118 | params.mod_events = true; | ||
113 | if (!params.dellist) | 119 | if (!params.dellist) |
114 | params.dellist = strlist__new(true, NULL); | 120 | params.dellist = strlist__new(true, NULL); |
115 | strlist__add(params.dellist, str); | 121 | strlist__add(params.dellist, str); |
@@ -130,6 +136,25 @@ static int opt_show_lines(const struct option *opt __used, | |||
130 | 136 | ||
131 | return ret; | 137 | return ret; |
132 | } | 138 | } |
139 | |||
140 | static int opt_show_vars(const struct option *opt __used, | ||
141 | const char *str, int unset __used) | ||
142 | { | ||
143 | struct perf_probe_event *pev = ¶ms.events[params.nevents]; | ||
144 | int ret; | ||
145 | |||
146 | if (!str) | ||
147 | return 0; | ||
148 | |||
149 | ret = parse_probe_event(str); | ||
150 | if (!ret && pev->nargs != 0) { | ||
151 | pr_err(" Error: '--vars' doesn't accept arguments.\n"); | ||
152 | return -EINVAL; | ||
153 | } | ||
154 | params.show_vars = true; | ||
155 | |||
156 | return ret; | ||
157 | } | ||
133 | #endif | 158 | #endif |
134 | 159 | ||
135 | static const char * const probe_usage[] = { | 160 | static const char * const probe_usage[] = { |
@@ -138,7 +163,8 @@ static const char * const probe_usage[] = { | |||
138 | "perf probe [<options>] --del '[GROUP:]EVENT' ...", | 163 | "perf probe [<options>] --del '[GROUP:]EVENT' ...", |
139 | "perf probe --list", | 164 | "perf probe --list", |
140 | #ifdef DWARF_SUPPORT | 165 | #ifdef DWARF_SUPPORT |
141 | "perf probe --line 'LINEDESC'", | 166 | "perf probe [<options>] --line 'LINEDESC'", |
167 | "perf probe [<options>] --vars 'PROBEPOINT'", | ||
142 | #endif | 168 | #endif |
143 | NULL | 169 | NULL |
144 | }; | 170 | }; |
@@ -180,10 +206,17 @@ static const struct option options[] = { | |||
180 | OPT_CALLBACK('L', "line", NULL, | 206 | OPT_CALLBACK('L', "line", NULL, |
181 | "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]", | 207 | "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]", |
182 | "Show source code lines.", opt_show_lines), | 208 | "Show source code lines.", opt_show_lines), |
209 | OPT_CALLBACK('V', "vars", NULL, | ||
210 | "FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT", | ||
211 | "Show accessible variables on PROBEDEF", opt_show_vars), | ||
212 | OPT_BOOLEAN('\0', "externs", ¶ms.show_ext_vars, | ||
213 | "Show external variables too (with --vars only)"), | ||
183 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, | 214 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
184 | "file", "vmlinux pathname"), | 215 | "file", "vmlinux pathname"), |
185 | OPT_STRING('s', "source", &symbol_conf.source_prefix, | 216 | OPT_STRING('s', "source", &symbol_conf.source_prefix, |
186 | "directory", "path to kernel source"), | 217 | "directory", "path to kernel source"), |
218 | OPT_STRING('m', "module", ¶ms.target_module, | ||
219 | "modname", "target module name"), | ||
187 | #endif | 220 | #endif |
188 | OPT__DRY_RUN(&probe_event_dry_run), | 221 | OPT__DRY_RUN(&probe_event_dry_run), |
189 | OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points, | 222 | OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points, |
@@ -216,8 +249,13 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
216 | !params.show_lines)) | 249 | !params.show_lines)) |
217 | usage_with_options(probe_usage, options); | 250 | usage_with_options(probe_usage, options); |
218 | 251 | ||
252 | /* | ||
253 | * Only consider the user's kernel image path if given. | ||
254 | */ | ||
255 | symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL); | ||
256 | |||
219 | if (params.list_events) { | 257 | if (params.list_events) { |
220 | if (params.nevents != 0 || params.dellist) { | 258 | if (params.mod_events) { |
221 | pr_err(" Error: Don't use --list with --add/--del.\n"); | 259 | pr_err(" Error: Don't use --list with --add/--del.\n"); |
222 | usage_with_options(probe_usage, options); | 260 | usage_with_options(probe_usage, options); |
223 | } | 261 | } |
@@ -225,6 +263,10 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
225 | pr_err(" Error: Don't use --list with --line.\n"); | 263 | pr_err(" Error: Don't use --list with --line.\n"); |
226 | usage_with_options(probe_usage, options); | 264 | usage_with_options(probe_usage, options); |
227 | } | 265 | } |
266 | if (params.show_vars) { | ||
267 | pr_err(" Error: Don't use --list with --vars.\n"); | ||
268 | usage_with_options(probe_usage, options); | ||
269 | } | ||
228 | ret = show_perf_probe_events(); | 270 | ret = show_perf_probe_events(); |
229 | if (ret < 0) | 271 | if (ret < 0) |
230 | pr_err(" Error: Failed to show event list. (%d)\n", | 272 | pr_err(" Error: Failed to show event list. (%d)\n", |
@@ -234,17 +276,35 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
234 | 276 | ||
235 | #ifdef DWARF_SUPPORT | 277 | #ifdef DWARF_SUPPORT |
236 | if (params.show_lines) { | 278 | if (params.show_lines) { |
237 | if (params.nevents != 0 || params.dellist) { | 279 | if (params.mod_events) { |
238 | pr_warning(" Error: Don't use --line with" | 280 | pr_err(" Error: Don't use --line with" |
239 | " --add/--del.\n"); | 281 | " --add/--del.\n"); |
282 | usage_with_options(probe_usage, options); | ||
283 | } | ||
284 | if (params.show_vars) { | ||
285 | pr_err(" Error: Don't use --line with --vars.\n"); | ||
240 | usage_with_options(probe_usage, options); | 286 | usage_with_options(probe_usage, options); |
241 | } | 287 | } |
242 | 288 | ||
243 | ret = show_line_range(¶ms.line_range); | 289 | ret = show_line_range(¶ms.line_range, params.target_module); |
244 | if (ret < 0) | 290 | if (ret < 0) |
245 | pr_err(" Error: Failed to show lines. (%d)\n", ret); | 291 | pr_err(" Error: Failed to show lines. (%d)\n", ret); |
246 | return ret; | 292 | return ret; |
247 | } | 293 | } |
294 | if (params.show_vars) { | ||
295 | if (params.mod_events) { | ||
296 | pr_err(" Error: Don't use --vars with" | ||
297 | " --add/--del.\n"); | ||
298 | usage_with_options(probe_usage, options); | ||
299 | } | ||
300 | ret = show_available_vars(params.events, params.nevents, | ||
301 | params.max_probe_points, | ||
302 | params.target_module, | ||
303 | params.show_ext_vars); | ||
304 | if (ret < 0) | ||
305 | pr_err(" Error: Failed to show vars. (%d)\n", ret); | ||
306 | return ret; | ||
307 | } | ||
248 | #endif | 308 | #endif |
249 | 309 | ||
250 | if (params.dellist) { | 310 | if (params.dellist) { |
@@ -258,8 +318,9 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
258 | 318 | ||
259 | if (params.nevents) { | 319 | if (params.nevents) { |
260 | ret = add_perf_probe_events(params.events, params.nevents, | 320 | ret = add_perf_probe_events(params.events, params.nevents, |
261 | params.force_add, | 321 | params.max_probe_points, |
262 | params.max_probe_points); | 322 | params.target_module, |
323 | params.force_add); | ||
263 | if (ret < 0) { | 324 | if (ret < 0) { |
264 | pr_err(" Error: Failed to add events. (%d)\n", ret); | 325 | pr_err(" Error: Failed to add events. (%d)\n", ret); |
265 | return ret; | 326 | return ret; |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index ff77b805de71..564491fa18b2 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -197,7 +197,7 @@ static void sig_atexit(void) | |||
197 | if (child_pid > 0) | 197 | if (child_pid > 0) |
198 | kill(child_pid, SIGTERM); | 198 | kill(child_pid, SIGTERM); |
199 | 199 | ||
200 | if (signr == -1) | 200 | if (signr == -1 || signr == SIGUSR1) |
201 | return; | 201 | return; |
202 | 202 | ||
203 | signal(signr, SIG_DFL); | 203 | signal(signr, SIG_DFL); |
@@ -353,7 +353,7 @@ try_again: | |||
353 | } | 353 | } |
354 | 354 | ||
355 | if (read(fd[nr_cpu][counter][thread_index], &read_data, sizeof(read_data)) == -1) { | 355 | if (read(fd[nr_cpu][counter][thread_index], &read_data, sizeof(read_data)) == -1) { |
356 | perror("Unable to read perf file descriptor\n"); | 356 | perror("Unable to read perf file descriptor"); |
357 | exit(-1); | 357 | exit(-1); |
358 | } | 358 | } |
359 | 359 | ||
@@ -515,6 +515,7 @@ static int __cmd_record(int argc, const char **argv) | |||
515 | atexit(sig_atexit); | 515 | atexit(sig_atexit); |
516 | signal(SIGCHLD, sig_handler); | 516 | signal(SIGCHLD, sig_handler); |
517 | signal(SIGINT, sig_handler); | 517 | signal(SIGINT, sig_handler); |
518 | signal(SIGUSR1, sig_handler); | ||
518 | 519 | ||
519 | if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) { | 520 | if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) { |
520 | perror("failed to create pipes"); | 521 | perror("failed to create pipes"); |
@@ -606,6 +607,7 @@ static int __cmd_record(int argc, const char **argv) | |||
606 | execvp(argv[0], (char **)argv); | 607 | execvp(argv[0], (char **)argv); |
607 | 608 | ||
608 | perror(argv[0]); | 609 | perror(argv[0]); |
610 | kill(getppid(), SIGUSR1); | ||
609 | exit(-1); | 611 | exit(-1); |
610 | } | 612 | } |
611 | 613 | ||
@@ -626,7 +628,7 @@ static int __cmd_record(int argc, const char **argv) | |||
626 | 628 | ||
627 | nr_cpus = read_cpu_map(cpu_list); | 629 | nr_cpus = read_cpu_map(cpu_list); |
628 | if (nr_cpus < 1) { | 630 | if (nr_cpus < 1) { |
629 | perror("failed to collect number of CPUs\n"); | 631 | perror("failed to collect number of CPUs"); |
630 | return -1; | 632 | return -1; |
631 | } | 633 | } |
632 | 634 | ||
@@ -697,17 +699,18 @@ static int __cmd_record(int argc, const char **argv) | |||
697 | if (err < 0) | 699 | if (err < 0) |
698 | err = event__synthesize_kernel_mmap(process_synthesized_event, | 700 | err = event__synthesize_kernel_mmap(process_synthesized_event, |
699 | session, machine, "_stext"); | 701 | session, machine, "_stext"); |
700 | if (err < 0) { | 702 | if (err < 0) |
701 | pr_err("Couldn't record kernel reference relocation symbol.\n"); | 703 | pr_err("Couldn't record kernel reference relocation symbol\n" |
702 | return err; | 704 | "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n" |
703 | } | 705 | "Check /proc/kallsyms permission or run as root.\n"); |
704 | 706 | ||
705 | err = event__synthesize_modules(process_synthesized_event, | 707 | err = event__synthesize_modules(process_synthesized_event, |
706 | session, machine); | 708 | session, machine); |
707 | if (err < 0) { | 709 | if (err < 0) |
708 | pr_err("Couldn't record kernel reference relocation symbol.\n"); | 710 | pr_err("Couldn't record kernel module information.\n" |
709 | return err; | 711 | "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n" |
710 | } | 712 | "Check /proc/modules permission or run as root.\n"); |
713 | |||
711 | if (perf_guest) | 714 | if (perf_guest) |
712 | perf_session__process_machines(session, event__synthesize_guest_os); | 715 | perf_session__process_machines(session, event__synthesize_guest_os); |
713 | 716 | ||
@@ -761,6 +764,9 @@ static int __cmd_record(int argc, const char **argv) | |||
761 | } | 764 | } |
762 | } | 765 | } |
763 | 766 | ||
767 | if (quiet || signr == SIGUSR1) | ||
768 | return 0; | ||
769 | |||
764 | fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking); | 770 | fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking); |
765 | 771 | ||
766 | /* | 772 | /* |
@@ -787,7 +793,7 @@ static const char * const record_usage[] = { | |||
787 | 793 | ||
788 | static bool force, append_file; | 794 | static bool force, append_file; |
789 | 795 | ||
790 | static const struct option options[] = { | 796 | const struct option record_options[] = { |
791 | OPT_CALLBACK('e', "event", NULL, "event", | 797 | OPT_CALLBACK('e', "event", NULL, "event", |
792 | "event selector. use 'perf list' to list available events", | 798 | "event selector. use 'perf list' to list available events", |
793 | parse_events), | 799 | parse_events), |
@@ -820,6 +826,7 @@ static const struct option options[] = { | |||
820 | "do call-graph (stack chain/backtrace) recording"), | 826 | "do call-graph (stack chain/backtrace) recording"), |
821 | OPT_INCR('v', "verbose", &verbose, | 827 | OPT_INCR('v', "verbose", &verbose, |
822 | "be more verbose (show counter open errors, etc)"), | 828 | "be more verbose (show counter open errors, etc)"), |
829 | OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"), | ||
823 | OPT_BOOLEAN('s', "stat", &inherit_stat, | 830 | OPT_BOOLEAN('s', "stat", &inherit_stat, |
824 | "per thread counts"), | 831 | "per thread counts"), |
825 | OPT_BOOLEAN('d', "data", &sample_address, | 832 | OPT_BOOLEAN('d', "data", &sample_address, |
@@ -835,16 +842,16 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
835 | { | 842 | { |
836 | int i, j, err = -ENOMEM; | 843 | int i, j, err = -ENOMEM; |
837 | 844 | ||
838 | argc = parse_options(argc, argv, options, record_usage, | 845 | argc = parse_options(argc, argv, record_options, record_usage, |
839 | PARSE_OPT_STOP_AT_NON_OPTION); | 846 | PARSE_OPT_STOP_AT_NON_OPTION); |
840 | if (!argc && target_pid == -1 && target_tid == -1 && | 847 | if (!argc && target_pid == -1 && target_tid == -1 && |
841 | !system_wide && !cpu_list) | 848 | !system_wide && !cpu_list) |
842 | usage_with_options(record_usage, options); | 849 | usage_with_options(record_usage, record_options); |
843 | 850 | ||
844 | if (force && append_file) { | 851 | if (force && append_file) { |
845 | fprintf(stderr, "Can't overwrite and append at the same time." | 852 | fprintf(stderr, "Can't overwrite and append at the same time." |
846 | " You need to choose between -f and -A"); | 853 | " You need to choose between -f and -A"); |
847 | usage_with_options(record_usage, options); | 854 | usage_with_options(record_usage, record_options); |
848 | } else if (append_file) { | 855 | } else if (append_file) { |
849 | write_mode = WRITE_APPEND; | 856 | write_mode = WRITE_APPEND; |
850 | } else { | 857 | } else { |
@@ -867,7 +874,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
867 | if (thread_num <= 0) { | 874 | if (thread_num <= 0) { |
868 | fprintf(stderr, "Can't find all threads of pid %d\n", | 875 | fprintf(stderr, "Can't find all threads of pid %d\n", |
869 | target_pid); | 876 | target_pid); |
870 | usage_with_options(record_usage, options); | 877 | usage_with_options(record_usage, record_options); |
871 | } | 878 | } |
872 | } else { | 879 | } else { |
873 | all_tids=malloc(sizeof(pid_t)); | 880 | all_tids=malloc(sizeof(pid_t)); |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 55fc1f46892a..5de405d45230 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -32,7 +32,7 @@ | |||
32 | 32 | ||
33 | static char const *input_name = "perf.data"; | 33 | static char const *input_name = "perf.data"; |
34 | 34 | ||
35 | static bool force; | 35 | static bool force, use_tui, use_stdio; |
36 | static bool hide_unresolved; | 36 | static bool hide_unresolved; |
37 | static bool dont_use_callchains; | 37 | static bool dont_use_callchains; |
38 | 38 | ||
@@ -107,7 +107,8 @@ static int perf_session__add_hist_entry(struct perf_session *self, | |||
107 | goto out_free_syms; | 107 | goto out_free_syms; |
108 | err = 0; | 108 | err = 0; |
109 | if (symbol_conf.use_callchain) { | 109 | if (symbol_conf.use_callchain) { |
110 | err = append_chain(he->callchain, data->callchain, syms, data->period); | 110 | err = callchain_append(he->callchain, data->callchain, syms, |
111 | data->period); | ||
111 | if (err) | 112 | if (err) |
112 | goto out_free_syms; | 113 | goto out_free_syms; |
113 | } | 114 | } |
@@ -450,6 +451,8 @@ static const struct option options[] = { | |||
450 | "Show per-thread event counters"), | 451 | "Show per-thread event counters"), |
451 | OPT_STRING(0, "pretty", &pretty_printing_style, "key", | 452 | OPT_STRING(0, "pretty", &pretty_printing_style, "key", |
452 | "pretty printing style key: normal raw"), | 453 | "pretty printing style key: normal raw"), |
454 | OPT_BOOLEAN(0, "tui", &use_tui, "Use the TUI interface"), | ||
455 | OPT_BOOLEAN(0, "stdio", &use_stdio, "Use the stdio interface"), | ||
453 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", | 456 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", |
454 | "sort by key(s): pid, comm, dso, symbol, parent"), | 457 | "sort by key(s): pid, comm, dso, symbol, parent"), |
455 | OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization, | 458 | OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization, |
@@ -482,8 +485,15 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) | |||
482 | { | 485 | { |
483 | argc = parse_options(argc, argv, options, report_usage, 0); | 486 | argc = parse_options(argc, argv, options, report_usage, 0); |
484 | 487 | ||
488 | if (use_stdio) | ||
489 | use_browser = 0; | ||
490 | else if (use_tui) | ||
491 | use_browser = 1; | ||
492 | |||
485 | if (strcmp(input_name, "-") != 0) | 493 | if (strcmp(input_name, "-") != 0) |
486 | setup_browser(); | 494 | setup_browser(); |
495 | else | ||
496 | use_browser = 0; | ||
487 | /* | 497 | /* |
488 | * Only in the newt browser we are doing integrated annotation, | 498 | * Only in the newt browser we are doing integrated annotation, |
489 | * so don't allocate extra space that won't be used in the stdio | 499 | * so don't allocate extra space that won't be used in the stdio |
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index b513e40974f4..dd625808c2a5 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -69,7 +69,6 @@ static int target_tid = -1; | |||
69 | static pid_t *all_tids = NULL; | 69 | static pid_t *all_tids = NULL; |
70 | static int thread_num = 0; | 70 | static int thread_num = 0; |
71 | static bool inherit = false; | 71 | static bool inherit = false; |
72 | static int profile_cpu = -1; | ||
73 | static int nr_cpus = 0; | 72 | static int nr_cpus = 0; |
74 | static int realtime_prio = 0; | 73 | static int realtime_prio = 0; |
75 | static bool group = false; | 74 | static bool group = false; |
@@ -558,13 +557,13 @@ static void print_sym_table(void) | |||
558 | else | 557 | else |
559 | printf(" (all"); | 558 | printf(" (all"); |
560 | 559 | ||
561 | if (profile_cpu != -1) | 560 | if (cpu_list) |
562 | printf(", cpu: %d)\n", profile_cpu); | 561 | printf(", CPU%s: %s)\n", nr_cpus > 1 ? "s" : "", cpu_list); |
563 | else { | 562 | else { |
564 | if (target_tid != -1) | 563 | if (target_tid != -1) |
565 | printf(")\n"); | 564 | printf(")\n"); |
566 | else | 565 | else |
567 | printf(", %d CPUs)\n", nr_cpus); | 566 | printf(", %d CPU%s)\n", nr_cpus, nr_cpus > 1 ? "s" : ""); |
568 | } | 567 | } |
569 | 568 | ||
570 | printf("%-*.*s\n", win_width, win_width, graph_dotted_line); | 569 | printf("%-*.*s\n", win_width, win_width, graph_dotted_line); |
@@ -1187,11 +1186,10 @@ int group_fd; | |||
1187 | static void start_counter(int i, int counter) | 1186 | static void start_counter(int i, int counter) |
1188 | { | 1187 | { |
1189 | struct perf_event_attr *attr; | 1188 | struct perf_event_attr *attr; |
1190 | int cpu; | 1189 | int cpu = -1; |
1191 | int thread_index; | 1190 | int thread_index; |
1192 | 1191 | ||
1193 | cpu = profile_cpu; | 1192 | if (target_tid == -1) |
1194 | if (target_tid == -1 && profile_cpu == -1) | ||
1195 | cpu = cpumap[i]; | 1193 | cpu = cpumap[i]; |
1196 | 1194 | ||
1197 | attr = attrs + counter; | 1195 | attr = attrs + counter; |
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 40a6a2992d15..86cfe3800e6b 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "util/symbol.h" | 10 | #include "util/symbol.h" |
11 | #include "util/thread.h" | 11 | #include "util/thread.h" |
12 | #include "util/trace-event.h" | 12 | #include "util/trace-event.h" |
13 | #include "util/parse-options.h" | ||
13 | #include "util/util.h" | 14 | #include "util/util.h" |
14 | 15 | ||
15 | static char const *script_name; | 16 | static char const *script_name; |
@@ -17,6 +18,7 @@ static char const *generate_script_lang; | |||
17 | static bool debug_mode; | 18 | static bool debug_mode; |
18 | static u64 last_timestamp; | 19 | static u64 last_timestamp; |
19 | static u64 nr_unordered; | 20 | static u64 nr_unordered; |
21 | extern const struct option record_options[]; | ||
20 | 22 | ||
21 | static int default_start_script(const char *script __unused, | 23 | static int default_start_script(const char *script __unused, |
22 | int argc __unused, | 24 | int argc __unused, |
@@ -46,9 +48,6 @@ static struct scripting_ops *scripting_ops; | |||
46 | 48 | ||
47 | static void setup_scripting(void) | 49 | static void setup_scripting(void) |
48 | { | 50 | { |
49 | /* make sure PERF_EXEC_PATH is set for scripts */ | ||
50 | perf_set_argv_exec_path(perf_exec_path()); | ||
51 | |||
52 | setup_perl_scripting(); | 51 | setup_perl_scripting(); |
53 | setup_python_scripting(); | 52 | setup_python_scripting(); |
54 | 53 | ||
@@ -285,7 +284,7 @@ static int parse_scriptname(const struct option *opt __used, | |||
285 | script++; | 284 | script++; |
286 | } else { | 285 | } else { |
287 | script = str; | 286 | script = str; |
288 | ext = strchr(script, '.'); | 287 | ext = strrchr(script, '.'); |
289 | if (!ext) { | 288 | if (!ext) { |
290 | fprintf(stderr, "invalid script extension"); | 289 | fprintf(stderr, "invalid script extension"); |
291 | return -1; | 290 | return -1; |
@@ -331,7 +330,7 @@ static struct script_desc *script_desc__new(const char *name) | |||
331 | { | 330 | { |
332 | struct script_desc *s = zalloc(sizeof(*s)); | 331 | struct script_desc *s = zalloc(sizeof(*s)); |
333 | 332 | ||
334 | if (s != NULL) | 333 | if (s != NULL && name) |
335 | s->name = strdup(name); | 334 | s->name = strdup(name); |
336 | 335 | ||
337 | return s; | 336 | return s; |
@@ -340,6 +339,8 @@ static struct script_desc *script_desc__new(const char *name) | |||
340 | static void script_desc__delete(struct script_desc *s) | 339 | static void script_desc__delete(struct script_desc *s) |
341 | { | 340 | { |
342 | free(s->name); | 341 | free(s->name); |
342 | free(s->half_liner); | ||
343 | free(s->args); | ||
343 | free(s); | 344 | free(s); |
344 | } | 345 | } |
345 | 346 | ||
@@ -540,8 +541,40 @@ static char *get_script_path(const char *script_root, const char *suffix) | |||
540 | return path; | 541 | return path; |
541 | } | 542 | } |
542 | 543 | ||
544 | static bool is_top_script(const char *script_path) | ||
545 | { | ||
546 | return ends_with((char *)script_path, "top") == NULL ? false : true; | ||
547 | } | ||
548 | |||
549 | static int has_required_arg(char *script_path) | ||
550 | { | ||
551 | struct script_desc *desc; | ||
552 | int n_args = 0; | ||
553 | char *p; | ||
554 | |||
555 | desc = script_desc__new(NULL); | ||
556 | |||
557 | if (read_script_info(desc, script_path)) | ||
558 | goto out; | ||
559 | |||
560 | if (!desc->args) | ||
561 | goto out; | ||
562 | |||
563 | for (p = desc->args; *p; p++) | ||
564 | if (*p == '<') | ||
565 | n_args++; | ||
566 | out: | ||
567 | script_desc__delete(desc); | ||
568 | |||
569 | return n_args; | ||
570 | } | ||
571 | |||
543 | static const char * const trace_usage[] = { | 572 | static const char * const trace_usage[] = { |
544 | "perf trace [<options>] <command>", | 573 | "perf trace [<options>]", |
574 | "perf trace [<options>] record <script> [<record-options>] <command>", | ||
575 | "perf trace [<options>] report <script> [script-args]", | ||
576 | "perf trace [<options>] <script> [<record-options>] <command>", | ||
577 | "perf trace [<options>] <top-script> [script-args]", | ||
545 | NULL | 578 | NULL |
546 | }; | 579 | }; |
547 | 580 | ||
@@ -567,47 +600,81 @@ static const struct option options[] = { | |||
567 | OPT_END() | 600 | OPT_END() |
568 | }; | 601 | }; |
569 | 602 | ||
603 | static bool have_cmd(int argc, const char **argv) | ||
604 | { | ||
605 | char **__argv = malloc(sizeof(const char *) * argc); | ||
606 | |||
607 | if (!__argv) | ||
608 | die("malloc"); | ||
609 | memcpy(__argv, argv, sizeof(const char *) * argc); | ||
610 | argc = parse_options(argc, (const char **)__argv, record_options, | ||
611 | NULL, PARSE_OPT_STOP_AT_NON_OPTION); | ||
612 | free(__argv); | ||
613 | |||
614 | return argc != 0; | ||
615 | } | ||
616 | |||
570 | int cmd_trace(int argc, const char **argv, const char *prefix __used) | 617 | int cmd_trace(int argc, const char **argv, const char *prefix __used) |
571 | { | 618 | { |
619 | char *rec_script_path = NULL; | ||
620 | char *rep_script_path = NULL; | ||
572 | struct perf_session *session; | 621 | struct perf_session *session; |
573 | const char *suffix = NULL; | 622 | char *script_path = NULL; |
574 | const char **__argv; | 623 | const char **__argv; |
575 | char *script_path; | 624 | bool system_wide; |
576 | int i, err; | 625 | int i, j, err; |
577 | 626 | ||
578 | if (argc >= 2 && strncmp(argv[1], "rec", strlen("rec")) == 0) { | 627 | setup_scripting(); |
579 | if (argc < 3) { | 628 | |
580 | fprintf(stderr, | 629 | argc = parse_options(argc, argv, options, trace_usage, |
581 | "Please specify a record script\n"); | 630 | PARSE_OPT_STOP_AT_NON_OPTION); |
582 | return -1; | 631 | |
583 | } | 632 | if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) { |
584 | suffix = RECORD_SUFFIX; | 633 | rec_script_path = get_script_path(argv[1], RECORD_SUFFIX); |
634 | if (!rec_script_path) | ||
635 | return cmd_record(argc, argv, NULL); | ||
585 | } | 636 | } |
586 | 637 | ||
587 | if (argc >= 2 && strncmp(argv[1], "rep", strlen("rep")) == 0) { | 638 | if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) { |
588 | if (argc < 3) { | 639 | rep_script_path = get_script_path(argv[1], REPORT_SUFFIX); |
640 | if (!rep_script_path) { | ||
589 | fprintf(stderr, | 641 | fprintf(stderr, |
590 | "Please specify a report script\n"); | 642 | "Please specify a valid report script" |
643 | "(see 'perf trace -l' for listing)\n"); | ||
591 | return -1; | 644 | return -1; |
592 | } | 645 | } |
593 | suffix = REPORT_SUFFIX; | ||
594 | } | 646 | } |
595 | 647 | ||
596 | if (!suffix && argc >= 2 && strncmp(argv[1], "-", strlen("-")) != 0) { | 648 | /* make sure PERF_EXEC_PATH is set for scripts */ |
597 | char *record_script_path, *report_script_path; | 649 | perf_set_argv_exec_path(perf_exec_path()); |
650 | |||
651 | if (argc && !script_name && !rec_script_path && !rep_script_path) { | ||
598 | int live_pipe[2]; | 652 | int live_pipe[2]; |
653 | int rep_args; | ||
599 | pid_t pid; | 654 | pid_t pid; |
600 | 655 | ||
601 | record_script_path = get_script_path(argv[1], RECORD_SUFFIX); | 656 | rec_script_path = get_script_path(argv[0], RECORD_SUFFIX); |
602 | if (!record_script_path) { | 657 | rep_script_path = get_script_path(argv[0], REPORT_SUFFIX); |
603 | fprintf(stderr, "record script not found\n"); | 658 | |
604 | return -1; | 659 | if (!rec_script_path && !rep_script_path) { |
660 | fprintf(stderr, " Couldn't find script %s\n\n See perf" | ||
661 | " trace -l for available scripts.\n", argv[0]); | ||
662 | usage_with_options(trace_usage, options); | ||
605 | } | 663 | } |
606 | 664 | ||
607 | report_script_path = get_script_path(argv[1], REPORT_SUFFIX); | 665 | if (is_top_script(argv[0])) { |
608 | if (!report_script_path) { | 666 | rep_args = argc - 1; |
609 | fprintf(stderr, "report script not found\n"); | 667 | } else { |
610 | return -1; | 668 | int rec_args; |
669 | |||
670 | rep_args = has_required_arg(rep_script_path); | ||
671 | rec_args = (argc - 1) - rep_args; | ||
672 | if (rec_args < 0) { | ||
673 | fprintf(stderr, " %s script requires options." | ||
674 | "\n\n See perf trace -l for available " | ||
675 | "scripts and options.\n", argv[0]); | ||
676 | usage_with_options(trace_usage, options); | ||
677 | } | ||
611 | } | 678 | } |
612 | 679 | ||
613 | if (pipe(live_pipe) < 0) { | 680 | if (pipe(live_pipe) < 0) { |
@@ -622,59 +689,84 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) | |||
622 | } | 689 | } |
623 | 690 | ||
624 | if (!pid) { | 691 | if (!pid) { |
692 | system_wide = true; | ||
693 | j = 0; | ||
694 | |||
625 | dup2(live_pipe[1], 1); | 695 | dup2(live_pipe[1], 1); |
626 | close(live_pipe[0]); | 696 | close(live_pipe[0]); |
627 | 697 | ||
628 | __argv = malloc(5 * sizeof(const char *)); | 698 | if (!is_top_script(argv[0])) |
629 | __argv[0] = "/bin/sh"; | 699 | system_wide = !have_cmd(argc - rep_args, |
630 | __argv[1] = record_script_path; | 700 | &argv[rep_args]); |
631 | __argv[2] = "-o"; | 701 | |
632 | __argv[3] = "-"; | 702 | __argv = malloc((argc + 6) * sizeof(const char *)); |
633 | __argv[4] = NULL; | 703 | if (!__argv) |
704 | die("malloc"); | ||
705 | |||
706 | __argv[j++] = "/bin/sh"; | ||
707 | __argv[j++] = rec_script_path; | ||
708 | if (system_wide) | ||
709 | __argv[j++] = "-a"; | ||
710 | __argv[j++] = "-q"; | ||
711 | __argv[j++] = "-o"; | ||
712 | __argv[j++] = "-"; | ||
713 | for (i = rep_args + 1; i < argc; i++) | ||
714 | __argv[j++] = argv[i]; | ||
715 | __argv[j++] = NULL; | ||
634 | 716 | ||
635 | execvp("/bin/sh", (char **)__argv); | 717 | execvp("/bin/sh", (char **)__argv); |
718 | free(__argv); | ||
636 | exit(-1); | 719 | exit(-1); |
637 | } | 720 | } |
638 | 721 | ||
639 | dup2(live_pipe[0], 0); | 722 | dup2(live_pipe[0], 0); |
640 | close(live_pipe[1]); | 723 | close(live_pipe[1]); |
641 | 724 | ||
642 | __argv = malloc((argc + 3) * sizeof(const char *)); | 725 | __argv = malloc((argc + 4) * sizeof(const char *)); |
643 | __argv[0] = "/bin/sh"; | 726 | if (!__argv) |
644 | __argv[1] = report_script_path; | 727 | die("malloc"); |
645 | for (i = 2; i < argc; i++) | 728 | j = 0; |
646 | __argv[i] = argv[i]; | 729 | __argv[j++] = "/bin/sh"; |
647 | __argv[i++] = "-i"; | 730 | __argv[j++] = rep_script_path; |
648 | __argv[i++] = "-"; | 731 | for (i = 1; i < rep_args + 1; i++) |
649 | __argv[i++] = NULL; | 732 | __argv[j++] = argv[i]; |
733 | __argv[j++] = "-i"; | ||
734 | __argv[j++] = "-"; | ||
735 | __argv[j++] = NULL; | ||
650 | 736 | ||
651 | execvp("/bin/sh", (char **)__argv); | 737 | execvp("/bin/sh", (char **)__argv); |
738 | free(__argv); | ||
652 | exit(-1); | 739 | exit(-1); |
653 | } | 740 | } |
654 | 741 | ||
655 | if (suffix) { | 742 | if (rec_script_path) |
656 | script_path = get_script_path(argv[2], suffix); | 743 | script_path = rec_script_path; |
657 | if (!script_path) { | 744 | if (rep_script_path) |
658 | fprintf(stderr, "script not found\n"); | 745 | script_path = rep_script_path; |
659 | return -1; | 746 | |
660 | } | 747 | if (script_path) { |
661 | 748 | system_wide = false; | |
662 | __argv = malloc((argc + 1) * sizeof(const char *)); | 749 | j = 0; |
663 | __argv[0] = "/bin/sh"; | 750 | |
664 | __argv[1] = script_path; | 751 | if (rec_script_path) |
665 | for (i = 3; i < argc; i++) | 752 | system_wide = !have_cmd(argc - 1, &argv[1]); |
666 | __argv[i - 1] = argv[i]; | 753 | |
667 | __argv[argc - 1] = NULL; | 754 | __argv = malloc((argc + 2) * sizeof(const char *)); |
755 | if (!__argv) | ||
756 | die("malloc"); | ||
757 | __argv[j++] = "/bin/sh"; | ||
758 | __argv[j++] = script_path; | ||
759 | if (system_wide) | ||
760 | __argv[j++] = "-a"; | ||
761 | for (i = 2; i < argc; i++) | ||
762 | __argv[j++] = argv[i]; | ||
763 | __argv[j++] = NULL; | ||
668 | 764 | ||
669 | execvp("/bin/sh", (char **)__argv); | 765 | execvp("/bin/sh", (char **)__argv); |
766 | free(__argv); | ||
670 | exit(-1); | 767 | exit(-1); |
671 | } | 768 | } |
672 | 769 | ||
673 | setup_scripting(); | ||
674 | |||
675 | argc = parse_options(argc, argv, options, trace_usage, | ||
676 | PARSE_OPT_STOP_AT_NON_OPTION); | ||
677 | |||
678 | if (symbol__init() < 0) | 770 | if (symbol__init() < 0) |
679 | return -1; | 771 | return -1; |
680 | if (!script_name) | 772 | if (!script_name) |
diff --git a/tools/perf/feature-tests.mak b/tools/perf/feature-tests.mak index 7a7b60859053..b253db634f04 100644 --- a/tools/perf/feature-tests.mak +++ b/tools/perf/feature-tests.mak | |||
@@ -110,6 +110,17 @@ int main(void) | |||
110 | } | 110 | } |
111 | endef | 111 | endef |
112 | 112 | ||
113 | define SOURCE_STRLCPY | ||
114 | #include <stdlib.h> | ||
115 | extern size_t strlcpy(char *dest, const char *src, size_t size); | ||
116 | |||
117 | int main(void) | ||
118 | { | ||
119 | strlcpy(NULL, NULL, 0); | ||
120 | return 0; | ||
121 | } | ||
122 | endef | ||
123 | |||
113 | # try-cc | 124 | # try-cc |
114 | # Usage: option = $(call try-cc, source-to-build, cc-options) | 125 | # Usage: option = $(call try-cc, source-to-build, cc-options) |
115 | try-cc = $(shell sh -c \ | 126 | try-cc = $(shell sh -c \ |
diff --git a/tools/perf/scripts/perl/bin/failed-syscalls-record b/tools/perf/scripts/perl/bin/failed-syscalls-record index eb5846bcb565..8104895a7b67 100644 --- a/tools/perf/scripts/perl/bin/failed-syscalls-record +++ b/tools/perf/scripts/perl/bin/failed-syscalls-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -a -e raw_syscalls:sys_exit $@ | 2 | perf record -e raw_syscalls:sys_exit $@ |
diff --git a/tools/perf/scripts/perl/bin/failed-syscalls-report b/tools/perf/scripts/perl/bin/failed-syscalls-report index e3a5e55d54ff..4028d92dc4ae 100644 --- a/tools/perf/scripts/perl/bin/failed-syscalls-report +++ b/tools/perf/scripts/perl/bin/failed-syscalls-report | |||
@@ -7,4 +7,4 @@ if [ $# -gt 0 ] ; then | |||
7 | shift | 7 | shift |
8 | fi | 8 | fi |
9 | fi | 9 | fi |
10 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/failed-syscalls.pl $comm | 10 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/failed-syscalls.pl $comm |
diff --git a/tools/perf/scripts/perl/bin/rw-by-file-record b/tools/perf/scripts/perl/bin/rw-by-file-record index 5bfaae5a6cba..33efc8673aae 100644 --- a/tools/perf/scripts/perl/bin/rw-by-file-record +++ b/tools/perf/scripts/perl/bin/rw-by-file-record | |||
@@ -1,3 +1,3 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -a -e syscalls:sys_enter_read -e syscalls:sys_enter_write $@ | 2 | perf record -e syscalls:sys_enter_read -e syscalls:sys_enter_write $@ |
3 | 3 | ||
diff --git a/tools/perf/scripts/perl/bin/rw-by-file-report b/tools/perf/scripts/perl/bin/rw-by-file-report index d83070b7eeb5..ba25f4d41fb0 100644 --- a/tools/perf/scripts/perl/bin/rw-by-file-report +++ b/tools/perf/scripts/perl/bin/rw-by-file-report | |||
@@ -7,7 +7,7 @@ if [ $# -lt 1 ] ; then | |||
7 | fi | 7 | fi |
8 | comm=$1 | 8 | comm=$1 |
9 | shift | 9 | shift |
10 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/rw-by-file.pl $comm | 10 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/rw-by-file.pl $comm |
11 | 11 | ||
12 | 12 | ||
13 | 13 | ||
diff --git a/tools/perf/scripts/perl/bin/rw-by-pid-record b/tools/perf/scripts/perl/bin/rw-by-pid-record index 6e0b2f7755ac..7cb9db230448 100644 --- a/tools/perf/scripts/perl/bin/rw-by-pid-record +++ b/tools/perf/scripts/perl/bin/rw-by-pid-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -a -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@ | 2 | perf record -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@ |
diff --git a/tools/perf/scripts/perl/bin/rw-by-pid-report b/tools/perf/scripts/perl/bin/rw-by-pid-report index 7ef46983f62f..641a3f5d085c 100644 --- a/tools/perf/scripts/perl/bin/rw-by-pid-report +++ b/tools/perf/scripts/perl/bin/rw-by-pid-report | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: system-wide r/w activity | 2 | # description: system-wide r/w activity |
3 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/rw-by-pid.pl | 3 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/rw-by-pid.pl |
4 | 4 | ||
5 | 5 | ||
6 | 6 | ||
diff --git a/tools/perf/scripts/perl/bin/rwtop-record b/tools/perf/scripts/perl/bin/rwtop-record index 6e0b2f7755ac..7cb9db230448 100644 --- a/tools/perf/scripts/perl/bin/rwtop-record +++ b/tools/perf/scripts/perl/bin/rwtop-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -a -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@ | 2 | perf record -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@ |
diff --git a/tools/perf/scripts/perl/bin/rwtop-report b/tools/perf/scripts/perl/bin/rwtop-report index 93e698cd3f38..4918dba77021 100644 --- a/tools/perf/scripts/perl/bin/rwtop-report +++ b/tools/perf/scripts/perl/bin/rwtop-report | |||
@@ -17,7 +17,7 @@ if [ "$n_args" -gt 0 ] ; then | |||
17 | interval=$1 | 17 | interval=$1 |
18 | shift | 18 | shift |
19 | fi | 19 | fi |
20 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/rwtop.pl $interval | 20 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/rwtop.pl $interval |
21 | 21 | ||
22 | 22 | ||
23 | 23 | ||
diff --git a/tools/perf/scripts/perl/bin/wakeup-latency-record b/tools/perf/scripts/perl/bin/wakeup-latency-record index 9f2acaaae9f0..464251a1bd7e 100644 --- a/tools/perf/scripts/perl/bin/wakeup-latency-record +++ b/tools/perf/scripts/perl/bin/wakeup-latency-record | |||
@@ -1,5 +1,5 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -a -e sched:sched_switch -e sched:sched_wakeup $@ | 2 | perf record -e sched:sched_switch -e sched:sched_wakeup $@ |
3 | 3 | ||
4 | 4 | ||
5 | 5 | ||
diff --git a/tools/perf/scripts/perl/bin/wakeup-latency-report b/tools/perf/scripts/perl/bin/wakeup-latency-report index a0d898f9ca1d..49052ebcb632 100644 --- a/tools/perf/scripts/perl/bin/wakeup-latency-report +++ b/tools/perf/scripts/perl/bin/wakeup-latency-report | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: system-wide min/max/avg wakeup latency | 2 | # description: system-wide min/max/avg wakeup latency |
3 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/wakeup-latency.pl | 3 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/wakeup-latency.pl |
4 | 4 | ||
5 | 5 | ||
6 | 6 | ||
diff --git a/tools/perf/scripts/perl/bin/workqueue-stats-record b/tools/perf/scripts/perl/bin/workqueue-stats-record index 85301f2471ff..8edda9078d5d 100644 --- a/tools/perf/scripts/perl/bin/workqueue-stats-record +++ b/tools/perf/scripts/perl/bin/workqueue-stats-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -a -e workqueue:workqueue_creation -e workqueue:workqueue_destruction -e workqueue:workqueue_execution -e workqueue:workqueue_insertion $@ | 2 | perf record -e workqueue:workqueue_creation -e workqueue:workqueue_destruction -e workqueue:workqueue_execution -e workqueue:workqueue_insertion $@ |
diff --git a/tools/perf/scripts/perl/bin/workqueue-stats-report b/tools/perf/scripts/perl/bin/workqueue-stats-report index 35081132ef97..df0c65f4ca93 100644 --- a/tools/perf/scripts/perl/bin/workqueue-stats-report +++ b/tools/perf/scripts/perl/bin/workqueue-stats-report | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: workqueue stats (ins/exe/create/destroy) | 2 | # description: workqueue stats (ins/exe/create/destroy) |
3 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/workqueue-stats.pl | 3 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/workqueue-stats.pl |
4 | 4 | ||
5 | 5 | ||
6 | 6 | ||
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py index 9689bc0acd9f..13cc02b5893a 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py | |||
@@ -6,6 +6,14 @@ | |||
6 | # Public License ("GPL") version 2 as published by the Free Software | 6 | # Public License ("GPL") version 2 as published by the Free Software |
7 | # Foundation. | 7 | # Foundation. |
8 | 8 | ||
9 | import errno, os | ||
10 | |||
11 | FUTEX_WAIT = 0 | ||
12 | FUTEX_WAKE = 1 | ||
13 | FUTEX_PRIVATE_FLAG = 128 | ||
14 | FUTEX_CLOCK_REALTIME = 256 | ||
15 | FUTEX_CMD_MASK = ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME) | ||
16 | |||
9 | NSECS_PER_SEC = 1000000000 | 17 | NSECS_PER_SEC = 1000000000 |
10 | 18 | ||
11 | def avg(total, n): | 19 | def avg(total, n): |
@@ -24,5 +32,55 @@ def nsecs_str(nsecs): | |||
24 | str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)), | 32 | str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)), |
25 | return str | 33 | return str |
26 | 34 | ||
35 | def add_stats(dict, key, value): | ||
36 | if not dict.has_key(key): | ||
37 | dict[key] = (value, value, value, 1) | ||
38 | else: | ||
39 | min, max, avg, count = dict[key] | ||
40 | if value < min: | ||
41 | min = value | ||
42 | if value > max: | ||
43 | max = value | ||
44 | avg = (avg + value) / 2 | ||
45 | dict[key] = (min, max, avg, count + 1) | ||
46 | |||
27 | def clear_term(): | 47 | def clear_term(): |
28 | print("\x1b[H\x1b[2J") | 48 | print("\x1b[H\x1b[2J") |
49 | |||
50 | audit_package_warned = False | ||
51 | |||
52 | try: | ||
53 | import audit | ||
54 | machine_to_id = { | ||
55 | 'x86_64': audit.MACH_86_64, | ||
56 | 'alpha' : audit.MACH_ALPHA, | ||
57 | 'ia64' : audit.MACH_IA64, | ||
58 | 'ppc' : audit.MACH_PPC, | ||
59 | 'ppc64' : audit.MACH_PPC64, | ||
60 | 's390' : audit.MACH_S390, | ||
61 | 's390x' : audit.MACH_S390X, | ||
62 | 'i386' : audit.MACH_X86, | ||
63 | 'i586' : audit.MACH_X86, | ||
64 | 'i686' : audit.MACH_X86, | ||
65 | } | ||
66 | try: | ||
67 | machine_to_id['armeb'] = audit.MACH_ARMEB | ||
68 | except: | ||
69 | pass | ||
70 | machine_id = machine_to_id[os.uname()[4]] | ||
71 | except: | ||
72 | if not audit_package_warned: | ||
73 | audit_package_warned = True | ||
74 | print "Install the audit-libs-python package to get syscall names" | ||
75 | |||
76 | def syscall_name(id): | ||
77 | try: | ||
78 | return audit.audit_syscall_to_name(id, machine_id) | ||
79 | except: | ||
80 | return str(id) | ||
81 | |||
82 | def strerror(nr): | ||
83 | try: | ||
84 | return errno.errorcode[abs(nr)] | ||
85 | except: | ||
86 | return "Unknown %d errno" % nr | ||
diff --git a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record index eb5846bcb565..8104895a7b67 100644 --- a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record +++ b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -a -e raw_syscalls:sys_exit $@ | 2 | perf record -e raw_syscalls:sys_exit $@ |
diff --git a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report index 30293545fcc2..03587021463d 100644 --- a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report +++ b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report | |||
@@ -7,4 +7,4 @@ if [ $# -gt 0 ] ; then | |||
7 | shift | 7 | shift |
8 | fi | 8 | fi |
9 | fi | 9 | fi |
10 | perf trace $@ -s ~/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py $comm | 10 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/failed-syscalls-by-pid.py $comm |
diff --git a/tools/perf/scripts/python/bin/futex-contention-record b/tools/perf/scripts/python/bin/futex-contention-record new file mode 100644 index 000000000000..b1495c9a9b20 --- /dev/null +++ b/tools/perf/scripts/python/bin/futex-contention-record | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/bash | ||
2 | perf record -e syscalls:sys_enter_futex -e syscalls:sys_exit_futex $@ | ||
diff --git a/tools/perf/scripts/python/bin/futex-contention-report b/tools/perf/scripts/python/bin/futex-contention-report new file mode 100644 index 000000000000..c8268138fb7e --- /dev/null +++ b/tools/perf/scripts/python/bin/futex-contention-report | |||
@@ -0,0 +1,4 @@ | |||
1 | #!/bin/bash | ||
2 | # description: futext contention measurement | ||
3 | |||
4 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/futex-contention.py | ||
diff --git a/tools/perf/scripts/python/bin/netdev-times-record b/tools/perf/scripts/python/bin/netdev-times-record new file mode 100644 index 000000000000..558754b840a9 --- /dev/null +++ b/tools/perf/scripts/python/bin/netdev-times-record | |||
@@ -0,0 +1,8 @@ | |||
1 | #!/bin/bash | ||
2 | perf record -e net:net_dev_xmit -e net:net_dev_queue \ | ||
3 | -e net:netif_receive_skb -e net:netif_rx \ | ||
4 | -e skb:consume_skb -e skb:kfree_skb \ | ||
5 | -e skb:skb_copy_datagram_iovec -e napi:napi_poll \ | ||
6 | -e irq:irq_handler_entry -e irq:irq_handler_exit \ | ||
7 | -e irq:softirq_entry -e irq:softirq_exit \ | ||
8 | -e irq:softirq_raise $@ | ||
diff --git a/tools/perf/scripts/python/bin/netdev-times-report b/tools/perf/scripts/python/bin/netdev-times-report new file mode 100644 index 000000000000..4ad361b31249 --- /dev/null +++ b/tools/perf/scripts/python/bin/netdev-times-report | |||
@@ -0,0 +1,5 @@ | |||
1 | #!/bin/bash | ||
2 | # description: display a process of packet and processing time | ||
3 | # args: [tx] [rx] [dev=] [debug] | ||
4 | |||
5 | perf trace -s "$PERF_EXEC_PATH"/scripts/python/netdev-times.py $@ | ||
diff --git a/tools/perf/scripts/python/bin/sched-migration-record b/tools/perf/scripts/python/bin/sched-migration-record index 17a3e9bd9e8f..7493fddbe995 100644 --- a/tools/perf/scripts/python/bin/sched-migration-record +++ b/tools/perf/scripts/python/bin/sched-migration-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -m 16384 -a -e sched:sched_wakeup -e sched:sched_wakeup_new -e sched:sched_switch -e sched:sched_migrate_task $@ | 2 | perf record -m 16384 -e sched:sched_wakeup -e sched:sched_wakeup_new -e sched:sched_switch -e sched:sched_migrate_task $@ |
diff --git a/tools/perf/scripts/python/bin/sched-migration-report b/tools/perf/scripts/python/bin/sched-migration-report index 61d05f72e443..df1791f07c24 100644 --- a/tools/perf/scripts/python/bin/sched-migration-report +++ b/tools/perf/scripts/python/bin/sched-migration-report | |||
@@ -1,3 +1,3 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: sched migration overview | 2 | # description: sched migration overview |
3 | perf trace $@ -s ~/libexec/perf-core/scripts/python/sched-migration.py | 3 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/sched-migration.py |
diff --git a/tools/perf/scripts/python/bin/sctop-record b/tools/perf/scripts/python/bin/sctop-record index 1fc5998b721d..4efbfaa7f6a5 100644 --- a/tools/perf/scripts/python/bin/sctop-record +++ b/tools/perf/scripts/python/bin/sctop-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -a -e raw_syscalls:sys_enter $@ | 2 | perf record -e raw_syscalls:sys_enter $@ |
diff --git a/tools/perf/scripts/python/bin/sctop-report b/tools/perf/scripts/python/bin/sctop-report index b01c842ae7b4..36b409c05e50 100644 --- a/tools/perf/scripts/python/bin/sctop-report +++ b/tools/perf/scripts/python/bin/sctop-report | |||
@@ -21,4 +21,4 @@ elif [ "$n_args" -gt 0 ] ; then | |||
21 | interval=$1 | 21 | interval=$1 |
22 | shift | 22 | shift |
23 | fi | 23 | fi |
24 | perf trace $@ -s ~/libexec/perf-core/scripts/python/sctop.py $comm $interval | 24 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/sctop.py $comm $interval |
diff --git a/tools/perf/scripts/python/bin/syscall-counts-by-pid-record b/tools/perf/scripts/python/bin/syscall-counts-by-pid-record index 1fc5998b721d..4efbfaa7f6a5 100644 --- a/tools/perf/scripts/python/bin/syscall-counts-by-pid-record +++ b/tools/perf/scripts/python/bin/syscall-counts-by-pid-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -a -e raw_syscalls:sys_enter $@ | 2 | perf record -e raw_syscalls:sys_enter $@ |
diff --git a/tools/perf/scripts/python/bin/syscall-counts-by-pid-report b/tools/perf/scripts/python/bin/syscall-counts-by-pid-report index 9e9d8ddd72ce..4eb88c9fc83c 100644 --- a/tools/perf/scripts/python/bin/syscall-counts-by-pid-report +++ b/tools/perf/scripts/python/bin/syscall-counts-by-pid-report | |||
@@ -7,4 +7,4 @@ if [ $# -gt 0 ] ; then | |||
7 | shift | 7 | shift |
8 | fi | 8 | fi |
9 | fi | 9 | fi |
10 | perf trace $@ -s ~/libexec/perf-core/scripts/python/syscall-counts-by-pid.py $comm | 10 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/syscall-counts-by-pid.py $comm |
diff --git a/tools/perf/scripts/python/bin/syscall-counts-record b/tools/perf/scripts/python/bin/syscall-counts-record index 1fc5998b721d..4efbfaa7f6a5 100644 --- a/tools/perf/scripts/python/bin/syscall-counts-record +++ b/tools/perf/scripts/python/bin/syscall-counts-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -a -e raw_syscalls:sys_enter $@ | 2 | perf record -e raw_syscalls:sys_enter $@ |
diff --git a/tools/perf/scripts/python/bin/syscall-counts-report b/tools/perf/scripts/python/bin/syscall-counts-report index dc076b618796..cb2f9c5cf17e 100644 --- a/tools/perf/scripts/python/bin/syscall-counts-report +++ b/tools/perf/scripts/python/bin/syscall-counts-report | |||
@@ -7,4 +7,4 @@ if [ $# -gt 0 ] ; then | |||
7 | shift | 7 | shift |
8 | fi | 8 | fi |
9 | fi | 9 | fi |
10 | perf trace $@ -s ~/libexec/perf-core/scripts/python/syscall-counts.py $comm | 10 | perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/syscall-counts.py $comm |
diff --git a/tools/perf/scripts/python/failed-syscalls-by-pid.py b/tools/perf/scripts/python/failed-syscalls-by-pid.py index 0ca02278fe69..acd7848717b3 100644 --- a/tools/perf/scripts/python/failed-syscalls-by-pid.py +++ b/tools/perf/scripts/python/failed-syscalls-by-pid.py | |||
@@ -13,21 +13,26 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | |||
13 | 13 | ||
14 | from perf_trace_context import * | 14 | from perf_trace_context import * |
15 | from Core import * | 15 | from Core import * |
16 | from Util import * | ||
16 | 17 | ||
17 | usage = "perf trace -s syscall-counts-by-pid.py [comm]\n"; | 18 | usage = "perf trace -s syscall-counts-by-pid.py [comm|pid]\n"; |
18 | 19 | ||
19 | for_comm = None | 20 | for_comm = None |
21 | for_pid = None | ||
20 | 22 | ||
21 | if len(sys.argv) > 2: | 23 | if len(sys.argv) > 2: |
22 | sys.exit(usage) | 24 | sys.exit(usage) |
23 | 25 | ||
24 | if len(sys.argv) > 1: | 26 | if len(sys.argv) > 1: |
25 | for_comm = sys.argv[1] | 27 | try: |
28 | for_pid = int(sys.argv[1]) | ||
29 | except: | ||
30 | for_comm = sys.argv[1] | ||
26 | 31 | ||
27 | syscalls = autodict() | 32 | syscalls = autodict() |
28 | 33 | ||
29 | def trace_begin(): | 34 | def trace_begin(): |
30 | pass | 35 | print "Press control+C to stop and show the summary" |
31 | 36 | ||
32 | def trace_end(): | 37 | def trace_end(): |
33 | print_error_totals() | 38 | print_error_totals() |
@@ -35,9 +40,9 @@ def trace_end(): | |||
35 | def raw_syscalls__sys_exit(event_name, context, common_cpu, | 40 | def raw_syscalls__sys_exit(event_name, context, common_cpu, |
36 | common_secs, common_nsecs, common_pid, common_comm, | 41 | common_secs, common_nsecs, common_pid, common_comm, |
37 | id, ret): | 42 | id, ret): |
38 | if for_comm is not None: | 43 | if (for_comm and common_comm != for_comm) or \ |
39 | if common_comm != for_comm: | 44 | (for_pid and common_pid != for_pid ): |
40 | return | 45 | return |
41 | 46 | ||
42 | if ret < 0: | 47 | if ret < 0: |
43 | try: | 48 | try: |
@@ -62,7 +67,7 @@ def print_error_totals(): | |||
62 | print "\n%s [%d]\n" % (comm, pid), | 67 | print "\n%s [%d]\n" % (comm, pid), |
63 | id_keys = syscalls[comm][pid].keys() | 68 | id_keys = syscalls[comm][pid].keys() |
64 | for id in id_keys: | 69 | for id in id_keys: |
65 | print " syscall: %-16d\n" % (id), | 70 | print " syscall: %-16s\n" % syscall_name(id), |
66 | ret_keys = syscalls[comm][pid][id].keys() | 71 | ret_keys = syscalls[comm][pid][id].keys() |
67 | for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True): | 72 | for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True): |
68 | print " err = %-20d %10d\n" % (ret, val), | 73 | print " err = %-20s %10d\n" % (strerror(ret), val), |
diff --git a/tools/perf/scripts/python/futex-contention.py b/tools/perf/scripts/python/futex-contention.py new file mode 100644 index 000000000000..11e70a388d41 --- /dev/null +++ b/tools/perf/scripts/python/futex-contention.py | |||
@@ -0,0 +1,50 @@ | |||
1 | # futex contention | ||
2 | # (c) 2010, Arnaldo Carvalho de Melo <acme@redhat.com> | ||
3 | # Licensed under the terms of the GNU GPL License version 2 | ||
4 | # | ||
5 | # Translation of: | ||
6 | # | ||
7 | # http://sourceware.org/systemtap/wiki/WSFutexContention | ||
8 | # | ||
9 | # to perf python scripting. | ||
10 | # | ||
11 | # Measures futex contention | ||
12 | |||
13 | import os, sys | ||
14 | sys.path.append(os.environ['PERF_EXEC_PATH'] + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
15 | from Util import * | ||
16 | |||
17 | process_names = {} | ||
18 | thread_thislock = {} | ||
19 | thread_blocktime = {} | ||
20 | |||
21 | lock_waits = {} # long-lived stats on (tid,lock) blockage elapsed time | ||
22 | process_names = {} # long-lived pid-to-execname mapping | ||
23 | |||
24 | def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm, | ||
25 | nr, uaddr, op, val, utime, uaddr2, val3): | ||
26 | cmd = op & FUTEX_CMD_MASK | ||
27 | if cmd != FUTEX_WAIT: | ||
28 | return # we don't care about originators of WAKE events | ||
29 | |||
30 | process_names[tid] = comm | ||
31 | thread_thislock[tid] = uaddr | ||
32 | thread_blocktime[tid] = nsecs(s, ns) | ||
33 | |||
34 | def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm, | ||
35 | nr, ret): | ||
36 | if thread_blocktime.has_key(tid): | ||
37 | elapsed = nsecs(s, ns) - thread_blocktime[tid] | ||
38 | add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed) | ||
39 | del thread_blocktime[tid] | ||
40 | del thread_thislock[tid] | ||
41 | |||
42 | def trace_begin(): | ||
43 | print "Press control+C to stop and show the summary" | ||
44 | |||
45 | def trace_end(): | ||
46 | for (tid, lock) in lock_waits: | ||
47 | min, max, avg, count = lock_waits[tid, lock] | ||
48 | print "%s[%d] lock %x contended %d times, %d avg ns" % \ | ||
49 | (process_names[tid], tid, lock, count, avg) | ||
50 | |||
diff --git a/tools/perf/scripts/python/netdev-times.py b/tools/perf/scripts/python/netdev-times.py new file mode 100644 index 000000000000..9aa0a32972e8 --- /dev/null +++ b/tools/perf/scripts/python/netdev-times.py | |||
@@ -0,0 +1,464 @@ | |||
1 | # Display a process of packets and processed time. | ||
2 | # It helps us to investigate networking or network device. | ||
3 | # | ||
4 | # options | ||
5 | # tx: show only tx chart | ||
6 | # rx: show only rx chart | ||
7 | # dev=: show only thing related to specified device | ||
8 | # debug: work with debug mode. It shows buffer status. | ||
9 | |||
10 | import os | ||
11 | import sys | ||
12 | |||
13 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
14 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
15 | |||
16 | from perf_trace_context import * | ||
17 | from Core import * | ||
18 | from Util import * | ||
19 | |||
20 | all_event_list = []; # insert all tracepoint event related with this script | ||
21 | irq_dic = {}; # key is cpu and value is a list which stacks irqs | ||
22 | # which raise NET_RX softirq | ||
23 | net_rx_dic = {}; # key is cpu and value include time of NET_RX softirq-entry | ||
24 | # and a list which stacks receive | ||
25 | receive_hunk_list = []; # a list which include a sequence of receive events | ||
26 | rx_skb_list = []; # received packet list for matching | ||
27 | # skb_copy_datagram_iovec | ||
28 | |||
29 | buffer_budget = 65536; # the budget of rx_skb_list, tx_queue_list and | ||
30 | # tx_xmit_list | ||
31 | of_count_rx_skb_list = 0; # overflow count | ||
32 | |||
33 | tx_queue_list = []; # list of packets which pass through dev_queue_xmit | ||
34 | of_count_tx_queue_list = 0; # overflow count | ||
35 | |||
36 | tx_xmit_list = []; # list of packets which pass through dev_hard_start_xmit | ||
37 | of_count_tx_xmit_list = 0; # overflow count | ||
38 | |||
39 | tx_free_list = []; # list of packets which is freed | ||
40 | |||
41 | # options | ||
42 | show_tx = 0; | ||
43 | show_rx = 0; | ||
44 | dev = 0; # store a name of device specified by option "dev=" | ||
45 | debug = 0; | ||
46 | |||
47 | # indices of event_info tuple | ||
48 | EINFO_IDX_NAME= 0 | ||
49 | EINFO_IDX_CONTEXT=1 | ||
50 | EINFO_IDX_CPU= 2 | ||
51 | EINFO_IDX_TIME= 3 | ||
52 | EINFO_IDX_PID= 4 | ||
53 | EINFO_IDX_COMM= 5 | ||
54 | |||
55 | # Calculate a time interval(msec) from src(nsec) to dst(nsec) | ||
56 | def diff_msec(src, dst): | ||
57 | return (dst - src) / 1000000.0 | ||
58 | |||
59 | # Display a process of transmitting a packet | ||
60 | def print_transmit(hunk): | ||
61 | if dev != 0 and hunk['dev'].find(dev) < 0: | ||
62 | return | ||
63 | print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \ | ||
64 | (hunk['dev'], hunk['len'], | ||
65 | nsecs_secs(hunk['queue_t']), | ||
66 | nsecs_nsecs(hunk['queue_t'])/1000, | ||
67 | diff_msec(hunk['queue_t'], hunk['xmit_t']), | ||
68 | diff_msec(hunk['xmit_t'], hunk['free_t'])) | ||
69 | |||
70 | # Format for displaying rx packet processing | ||
71 | PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)" | ||
72 | PF_SOFT_ENTRY=" softirq_entry(+%.3fmsec)" | ||
73 | PF_NAPI_POLL= " napi_poll_exit(+%.3fmsec %s)" | ||
74 | PF_JOINT= " |" | ||
75 | PF_WJOINT= " | |" | ||
76 | PF_NET_RECV= " |---netif_receive_skb(+%.3fmsec skb=%x len=%d)" | ||
77 | PF_NET_RX= " |---netif_rx(+%.3fmsec skb=%x)" | ||
78 | PF_CPY_DGRAM= " | skb_copy_datagram_iovec(+%.3fmsec %d:%s)" | ||
79 | PF_KFREE_SKB= " | kfree_skb(+%.3fmsec location=%x)" | ||
80 | PF_CONS_SKB= " | consume_skb(+%.3fmsec)" | ||
81 | |||
82 | # Display a process of received packets and interrputs associated with | ||
83 | # a NET_RX softirq | ||
84 | def print_receive(hunk): | ||
85 | show_hunk = 0 | ||
86 | irq_list = hunk['irq_list'] | ||
87 | cpu = irq_list[0]['cpu'] | ||
88 | base_t = irq_list[0]['irq_ent_t'] | ||
89 | # check if this hunk should be showed | ||
90 | if dev != 0: | ||
91 | for i in range(len(irq_list)): | ||
92 | if irq_list[i]['name'].find(dev) >= 0: | ||
93 | show_hunk = 1 | ||
94 | break | ||
95 | else: | ||
96 | show_hunk = 1 | ||
97 | if show_hunk == 0: | ||
98 | return | ||
99 | |||
100 | print "%d.%06dsec cpu=%d" % \ | ||
101 | (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu) | ||
102 | for i in range(len(irq_list)): | ||
103 | print PF_IRQ_ENTRY % \ | ||
104 | (diff_msec(base_t, irq_list[i]['irq_ent_t']), | ||
105 | irq_list[i]['irq'], irq_list[i]['name']) | ||
106 | print PF_JOINT | ||
107 | irq_event_list = irq_list[i]['event_list'] | ||
108 | for j in range(len(irq_event_list)): | ||
109 | irq_event = irq_event_list[j] | ||
110 | if irq_event['event'] == 'netif_rx': | ||
111 | print PF_NET_RX % \ | ||
112 | (diff_msec(base_t, irq_event['time']), | ||
113 | irq_event['skbaddr']) | ||
114 | print PF_JOINT | ||
115 | print PF_SOFT_ENTRY % \ | ||
116 | diff_msec(base_t, hunk['sirq_ent_t']) | ||
117 | print PF_JOINT | ||
118 | event_list = hunk['event_list'] | ||
119 | for i in range(len(event_list)): | ||
120 | event = event_list[i] | ||
121 | if event['event_name'] == 'napi_poll': | ||
122 | print PF_NAPI_POLL % \ | ||
123 | (diff_msec(base_t, event['event_t']), event['dev']) | ||
124 | if i == len(event_list) - 1: | ||
125 | print "" | ||
126 | else: | ||
127 | print PF_JOINT | ||
128 | else: | ||
129 | print PF_NET_RECV % \ | ||
130 | (diff_msec(base_t, event['event_t']), event['skbaddr'], | ||
131 | event['len']) | ||
132 | if 'comm' in event.keys(): | ||
133 | print PF_WJOINT | ||
134 | print PF_CPY_DGRAM % \ | ||
135 | (diff_msec(base_t, event['comm_t']), | ||
136 | event['pid'], event['comm']) | ||
137 | elif 'handle' in event.keys(): | ||
138 | print PF_WJOINT | ||
139 | if event['handle'] == "kfree_skb": | ||
140 | print PF_KFREE_SKB % \ | ||
141 | (diff_msec(base_t, | ||
142 | event['comm_t']), | ||
143 | event['location']) | ||
144 | elif event['handle'] == "consume_skb": | ||
145 | print PF_CONS_SKB % \ | ||
146 | diff_msec(base_t, | ||
147 | event['comm_t']) | ||
148 | print PF_JOINT | ||
149 | |||
150 | def trace_begin(): | ||
151 | global show_tx | ||
152 | global show_rx | ||
153 | global dev | ||
154 | global debug | ||
155 | |||
156 | for i in range(len(sys.argv)): | ||
157 | if i == 0: | ||
158 | continue | ||
159 | arg = sys.argv[i] | ||
160 | if arg == 'tx': | ||
161 | show_tx = 1 | ||
162 | elif arg =='rx': | ||
163 | show_rx = 1 | ||
164 | elif arg.find('dev=',0, 4) >= 0: | ||
165 | dev = arg[4:] | ||
166 | elif arg == 'debug': | ||
167 | debug = 1 | ||
168 | if show_tx == 0 and show_rx == 0: | ||
169 | show_tx = 1 | ||
170 | show_rx = 1 | ||
171 | |||
172 | def trace_end(): | ||
173 | # order all events in time | ||
174 | all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME], | ||
175 | b[EINFO_IDX_TIME])) | ||
176 | # process all events | ||
177 | for i in range(len(all_event_list)): | ||
178 | event_info = all_event_list[i] | ||
179 | name = event_info[EINFO_IDX_NAME] | ||
180 | if name == 'irq__softirq_exit': | ||
181 | handle_irq_softirq_exit(event_info) | ||
182 | elif name == 'irq__softirq_entry': | ||
183 | handle_irq_softirq_entry(event_info) | ||
184 | elif name == 'irq__softirq_raise': | ||
185 | handle_irq_softirq_raise(event_info) | ||
186 | elif name == 'irq__irq_handler_entry': | ||
187 | handle_irq_handler_entry(event_info) | ||
188 | elif name == 'irq__irq_handler_exit': | ||
189 | handle_irq_handler_exit(event_info) | ||
190 | elif name == 'napi__napi_poll': | ||
191 | handle_napi_poll(event_info) | ||
192 | elif name == 'net__netif_receive_skb': | ||
193 | handle_netif_receive_skb(event_info) | ||
194 | elif name == 'net__netif_rx': | ||
195 | handle_netif_rx(event_info) | ||
196 | elif name == 'skb__skb_copy_datagram_iovec': | ||
197 | handle_skb_copy_datagram_iovec(event_info) | ||
198 | elif name == 'net__net_dev_queue': | ||
199 | handle_net_dev_queue(event_info) | ||
200 | elif name == 'net__net_dev_xmit': | ||
201 | handle_net_dev_xmit(event_info) | ||
202 | elif name == 'skb__kfree_skb': | ||
203 | handle_kfree_skb(event_info) | ||
204 | elif name == 'skb__consume_skb': | ||
205 | handle_consume_skb(event_info) | ||
206 | # display receive hunks | ||
207 | if show_rx: | ||
208 | for i in range(len(receive_hunk_list)): | ||
209 | print_receive(receive_hunk_list[i]) | ||
210 | # display transmit hunks | ||
211 | if show_tx: | ||
212 | print " dev len Qdisc " \ | ||
213 | " netdevice free" | ||
214 | for i in range(len(tx_free_list)): | ||
215 | print_transmit(tx_free_list[i]) | ||
216 | if debug: | ||
217 | print "debug buffer status" | ||
218 | print "----------------------------" | ||
219 | print "xmit Qdisc:remain:%d overflow:%d" % \ | ||
220 | (len(tx_queue_list), of_count_tx_queue_list) | ||
221 | print "xmit netdevice:remain:%d overflow:%d" % \ | ||
222 | (len(tx_xmit_list), of_count_tx_xmit_list) | ||
223 | print "receive:remain:%d overflow:%d" % \ | ||
224 | (len(rx_skb_list), of_count_rx_skb_list) | ||
225 | |||
226 | # called from perf, when it finds a correspoinding event | ||
227 | def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, vec): | ||
228 | if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX": | ||
229 | return | ||
230 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec) | ||
231 | all_event_list.append(event_info) | ||
232 | |||
233 | def irq__softirq_exit(name, context, cpu, sec, nsec, pid, comm, vec): | ||
234 | if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX": | ||
235 | return | ||
236 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec) | ||
237 | all_event_list.append(event_info) | ||
238 | |||
239 | def irq__softirq_raise(name, context, cpu, sec, nsec, pid, comm, vec): | ||
240 | if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX": | ||
241 | return | ||
242 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec) | ||
243 | all_event_list.append(event_info) | ||
244 | |||
245 | def irq__irq_handler_entry(name, context, cpu, sec, nsec, pid, comm, | ||
246 | irq, irq_name): | ||
247 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, | ||
248 | irq, irq_name) | ||
249 | all_event_list.append(event_info) | ||
250 | |||
251 | def irq__irq_handler_exit(name, context, cpu, sec, nsec, pid, comm, irq, ret): | ||
252 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, irq, ret) | ||
253 | all_event_list.append(event_info) | ||
254 | |||
255 | def napi__napi_poll(name, context, cpu, sec, nsec, pid, comm, napi, dev_name): | ||
256 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, | ||
257 | napi, dev_name) | ||
258 | all_event_list.append(event_info) | ||
259 | |||
260 | def net__netif_receive_skb(name, context, cpu, sec, nsec, pid, comm, skbaddr, | ||
261 | skblen, dev_name): | ||
262 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, | ||
263 | skbaddr, skblen, dev_name) | ||
264 | all_event_list.append(event_info) | ||
265 | |||
266 | def net__netif_rx(name, context, cpu, sec, nsec, pid, comm, skbaddr, | ||
267 | skblen, dev_name): | ||
268 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, | ||
269 | skbaddr, skblen, dev_name) | ||
270 | all_event_list.append(event_info) | ||
271 | |||
272 | def net__net_dev_queue(name, context, cpu, sec, nsec, pid, comm, | ||
273 | skbaddr, skblen, dev_name): | ||
274 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, | ||
275 | skbaddr, skblen, dev_name) | ||
276 | all_event_list.append(event_info) | ||
277 | |||
278 | def net__net_dev_xmit(name, context, cpu, sec, nsec, pid, comm, | ||
279 | skbaddr, skblen, rc, dev_name): | ||
280 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, | ||
281 | skbaddr, skblen, rc ,dev_name) | ||
282 | all_event_list.append(event_info) | ||
283 | |||
284 | def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm, | ||
285 | skbaddr, protocol, location): | ||
286 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, | ||
287 | skbaddr, protocol, location) | ||
288 | all_event_list.append(event_info) | ||
289 | |||
290 | def skb__consume_skb(name, context, cpu, sec, nsec, pid, comm, skbaddr): | ||
291 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, | ||
292 | skbaddr) | ||
293 | all_event_list.append(event_info) | ||
294 | |||
295 | def skb__skb_copy_datagram_iovec(name, context, cpu, sec, nsec, pid, comm, | ||
296 | skbaddr, skblen): | ||
297 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, | ||
298 | skbaddr, skblen) | ||
299 | all_event_list.append(event_info) | ||
300 | |||
301 | def handle_irq_handler_entry(event_info): | ||
302 | (name, context, cpu, time, pid, comm, irq, irq_name) = event_info | ||
303 | if cpu not in irq_dic.keys(): | ||
304 | irq_dic[cpu] = [] | ||
305 | irq_record = {'irq':irq, 'name':irq_name, 'cpu':cpu, 'irq_ent_t':time} | ||
306 | irq_dic[cpu].append(irq_record) | ||
307 | |||
308 | def handle_irq_handler_exit(event_info): | ||
309 | (name, context, cpu, time, pid, comm, irq, ret) = event_info | ||
310 | if cpu not in irq_dic.keys(): | ||
311 | return | ||
312 | irq_record = irq_dic[cpu].pop() | ||
313 | if irq != irq_record['irq']: | ||
314 | return | ||
315 | irq_record.update({'irq_ext_t':time}) | ||
316 | # if an irq doesn't include NET_RX softirq, drop. | ||
317 | if 'event_list' in irq_record.keys(): | ||
318 | irq_dic[cpu].append(irq_record) | ||
319 | |||
320 | def handle_irq_softirq_raise(event_info): | ||
321 | (name, context, cpu, time, pid, comm, vec) = event_info | ||
322 | if cpu not in irq_dic.keys() \ | ||
323 | or len(irq_dic[cpu]) == 0: | ||
324 | return | ||
325 | irq_record = irq_dic[cpu].pop() | ||
326 | if 'event_list' in irq_record.keys(): | ||
327 | irq_event_list = irq_record['event_list'] | ||
328 | else: | ||
329 | irq_event_list = [] | ||
330 | irq_event_list.append({'time':time, 'event':'sirq_raise'}) | ||
331 | irq_record.update({'event_list':irq_event_list}) | ||
332 | irq_dic[cpu].append(irq_record) | ||
333 | |||
334 | def handle_irq_softirq_entry(event_info): | ||
335 | (name, context, cpu, time, pid, comm, vec) = event_info | ||
336 | net_rx_dic[cpu] = {'sirq_ent_t':time, 'event_list':[]} | ||
337 | |||
338 | def handle_irq_softirq_exit(event_info): | ||
339 | (name, context, cpu, time, pid, comm, vec) = event_info | ||
340 | irq_list = [] | ||
341 | event_list = 0 | ||
342 | if cpu in irq_dic.keys(): | ||
343 | irq_list = irq_dic[cpu] | ||
344 | del irq_dic[cpu] | ||
345 | if cpu in net_rx_dic.keys(): | ||
346 | sirq_ent_t = net_rx_dic[cpu]['sirq_ent_t'] | ||
347 | event_list = net_rx_dic[cpu]['event_list'] | ||
348 | del net_rx_dic[cpu] | ||
349 | if irq_list == [] or event_list == 0: | ||
350 | return | ||
351 | rec_data = {'sirq_ent_t':sirq_ent_t, 'sirq_ext_t':time, | ||
352 | 'irq_list':irq_list, 'event_list':event_list} | ||
353 | # merge information realted to a NET_RX softirq | ||
354 | receive_hunk_list.append(rec_data) | ||
355 | |||
356 | def handle_napi_poll(event_info): | ||
357 | (name, context, cpu, time, pid, comm, napi, dev_name) = event_info | ||
358 | if cpu in net_rx_dic.keys(): | ||
359 | event_list = net_rx_dic[cpu]['event_list'] | ||
360 | rec_data = {'event_name':'napi_poll', | ||
361 | 'dev':dev_name, 'event_t':time} | ||
362 | event_list.append(rec_data) | ||
363 | |||
364 | def handle_netif_rx(event_info): | ||
365 | (name, context, cpu, time, pid, comm, | ||
366 | skbaddr, skblen, dev_name) = event_info | ||
367 | if cpu not in irq_dic.keys() \ | ||
368 | or len(irq_dic[cpu]) == 0: | ||
369 | return | ||
370 | irq_record = irq_dic[cpu].pop() | ||
371 | if 'event_list' in irq_record.keys(): | ||
372 | irq_event_list = irq_record['event_list'] | ||
373 | else: | ||
374 | irq_event_list = [] | ||
375 | irq_event_list.append({'time':time, 'event':'netif_rx', | ||
376 | 'skbaddr':skbaddr, 'skblen':skblen, 'dev_name':dev_name}) | ||
377 | irq_record.update({'event_list':irq_event_list}) | ||
378 | irq_dic[cpu].append(irq_record) | ||
379 | |||
380 | def handle_netif_receive_skb(event_info): | ||
381 | global of_count_rx_skb_list | ||
382 | |||
383 | (name, context, cpu, time, pid, comm, | ||
384 | skbaddr, skblen, dev_name) = event_info | ||
385 | if cpu in net_rx_dic.keys(): | ||
386 | rec_data = {'event_name':'netif_receive_skb', | ||
387 | 'event_t':time, 'skbaddr':skbaddr, 'len':skblen} | ||
388 | event_list = net_rx_dic[cpu]['event_list'] | ||
389 | event_list.append(rec_data) | ||
390 | rx_skb_list.insert(0, rec_data) | ||
391 | if len(rx_skb_list) > buffer_budget: | ||
392 | rx_skb_list.pop() | ||
393 | of_count_rx_skb_list += 1 | ||
394 | |||
395 | def handle_net_dev_queue(event_info): | ||
396 | global of_count_tx_queue_list | ||
397 | |||
398 | (name, context, cpu, time, pid, comm, | ||
399 | skbaddr, skblen, dev_name) = event_info | ||
400 | skb = {'dev':dev_name, 'skbaddr':skbaddr, 'len':skblen, 'queue_t':time} | ||
401 | tx_queue_list.insert(0, skb) | ||
402 | if len(tx_queue_list) > buffer_budget: | ||
403 | tx_queue_list.pop() | ||
404 | of_count_tx_queue_list += 1 | ||
405 | |||
406 | def handle_net_dev_xmit(event_info): | ||
407 | global of_count_tx_xmit_list | ||
408 | |||
409 | (name, context, cpu, time, pid, comm, | ||
410 | skbaddr, skblen, rc, dev_name) = event_info | ||
411 | if rc == 0: # NETDEV_TX_OK | ||
412 | for i in range(len(tx_queue_list)): | ||
413 | skb = tx_queue_list[i] | ||
414 | if skb['skbaddr'] == skbaddr: | ||
415 | skb['xmit_t'] = time | ||
416 | tx_xmit_list.insert(0, skb) | ||
417 | del tx_queue_list[i] | ||
418 | if len(tx_xmit_list) > buffer_budget: | ||
419 | tx_xmit_list.pop() | ||
420 | of_count_tx_xmit_list += 1 | ||
421 | return | ||
422 | |||
423 | def handle_kfree_skb(event_info): | ||
424 | (name, context, cpu, time, pid, comm, | ||
425 | skbaddr, protocol, location) = event_info | ||
426 | for i in range(len(tx_queue_list)): | ||
427 | skb = tx_queue_list[i] | ||
428 | if skb['skbaddr'] == skbaddr: | ||
429 | del tx_queue_list[i] | ||
430 | return | ||
431 | for i in range(len(tx_xmit_list)): | ||
432 | skb = tx_xmit_list[i] | ||
433 | if skb['skbaddr'] == skbaddr: | ||
434 | skb['free_t'] = time | ||
435 | tx_free_list.append(skb) | ||
436 | del tx_xmit_list[i] | ||
437 | return | ||
438 | for i in range(len(rx_skb_list)): | ||
439 | rec_data = rx_skb_list[i] | ||
440 | if rec_data['skbaddr'] == skbaddr: | ||
441 | rec_data.update({'handle':"kfree_skb", | ||
442 | 'comm':comm, 'pid':pid, 'comm_t':time}) | ||
443 | del rx_skb_list[i] | ||
444 | return | ||
445 | |||
446 | def handle_consume_skb(event_info): | ||
447 | (name, context, cpu, time, pid, comm, skbaddr) = event_info | ||
448 | for i in range(len(tx_xmit_list)): | ||
449 | skb = tx_xmit_list[i] | ||
450 | if skb['skbaddr'] == skbaddr: | ||
451 | skb['free_t'] = time | ||
452 | tx_free_list.append(skb) | ||
453 | del tx_xmit_list[i] | ||
454 | return | ||
455 | |||
456 | def handle_skb_copy_datagram_iovec(event_info): | ||
457 | (name, context, cpu, time, pid, comm, skbaddr, skblen) = event_info | ||
458 | for i in range(len(rx_skb_list)): | ||
459 | rec_data = rx_skb_list[i] | ||
460 | if skbaddr == rec_data['skbaddr']: | ||
461 | rec_data.update({'handle':"skb_copy_datagram_iovec", | ||
462 | 'comm':comm, 'pid':pid, 'comm_t':time}) | ||
463 | del rx_skb_list[i] | ||
464 | return | ||
diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py index 6cafad40c296..7a6ec2c7d8ab 100644 --- a/tools/perf/scripts/python/sctop.py +++ b/tools/perf/scripts/python/sctop.py | |||
@@ -8,10 +8,7 @@ | |||
8 | # will be refreshed every [interval] seconds. The default interval is | 8 | # will be refreshed every [interval] seconds. The default interval is |
9 | # 3 seconds. | 9 | # 3 seconds. |
10 | 10 | ||
11 | import thread | 11 | import os, sys, thread, time |
12 | import time | ||
13 | import os | ||
14 | import sys | ||
15 | 12 | ||
16 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | 13 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ |
17 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | 14 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') |
@@ -20,7 +17,7 @@ from perf_trace_context import * | |||
20 | from Core import * | 17 | from Core import * |
21 | from Util import * | 18 | from Util import * |
22 | 19 | ||
23 | usage = "perf trace -s syscall-counts.py [comm] [interval]\n"; | 20 | usage = "perf trace -s sctop.py [comm] [interval]\n"; |
24 | 21 | ||
25 | for_comm = None | 22 | for_comm = None |
26 | default_interval = 3 | 23 | default_interval = 3 |
@@ -71,7 +68,7 @@ def print_syscall_totals(interval): | |||
71 | for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ | 68 | for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ |
72 | reverse = True): | 69 | reverse = True): |
73 | try: | 70 | try: |
74 | print "%-40d %10d\n" % (id, val), | 71 | print "%-40s %10d\n" % (syscall_name(id), val), |
75 | except TypeError: | 72 | except TypeError: |
76 | pass | 73 | pass |
77 | syscalls.clear() | 74 | syscalls.clear() |
diff --git a/tools/perf/scripts/python/syscall-counts-by-pid.py b/tools/perf/scripts/python/syscall-counts-by-pid.py index af722d6a4b3f..d1ee3ec10cf2 100644 --- a/tools/perf/scripts/python/syscall-counts-by-pid.py +++ b/tools/perf/scripts/python/syscall-counts-by-pid.py | |||
@@ -5,29 +5,33 @@ | |||
5 | # Displays system-wide system call totals, broken down by syscall. | 5 | # Displays system-wide system call totals, broken down by syscall. |
6 | # If a [comm] arg is specified, only syscalls called by [comm] are displayed. | 6 | # If a [comm] arg is specified, only syscalls called by [comm] are displayed. |
7 | 7 | ||
8 | import os | 8 | import os, sys |
9 | import sys | ||
10 | 9 | ||
11 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | 10 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ |
12 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | 11 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') |
13 | 12 | ||
14 | from perf_trace_context import * | 13 | from perf_trace_context import * |
15 | from Core import * | 14 | from Core import * |
15 | from Util import syscall_name | ||
16 | 16 | ||
17 | usage = "perf trace -s syscall-counts-by-pid.py [comm]\n"; | 17 | usage = "perf trace -s syscall-counts-by-pid.py [comm]\n"; |
18 | 18 | ||
19 | for_comm = None | 19 | for_comm = None |
20 | for_pid = None | ||
20 | 21 | ||
21 | if len(sys.argv) > 2: | 22 | if len(sys.argv) > 2: |
22 | sys.exit(usage) | 23 | sys.exit(usage) |
23 | 24 | ||
24 | if len(sys.argv) > 1: | 25 | if len(sys.argv) > 1: |
25 | for_comm = sys.argv[1] | 26 | try: |
27 | for_pid = int(sys.argv[1]) | ||
28 | except: | ||
29 | for_comm = sys.argv[1] | ||
26 | 30 | ||
27 | syscalls = autodict() | 31 | syscalls = autodict() |
28 | 32 | ||
29 | def trace_begin(): | 33 | def trace_begin(): |
30 | pass | 34 | print "Press control+C to stop and show the summary" |
31 | 35 | ||
32 | def trace_end(): | 36 | def trace_end(): |
33 | print_syscall_totals() | 37 | print_syscall_totals() |
@@ -35,9 +39,10 @@ def trace_end(): | |||
35 | def raw_syscalls__sys_enter(event_name, context, common_cpu, | 39 | def raw_syscalls__sys_enter(event_name, context, common_cpu, |
36 | common_secs, common_nsecs, common_pid, common_comm, | 40 | common_secs, common_nsecs, common_pid, common_comm, |
37 | id, args): | 41 | id, args): |
38 | if for_comm is not None: | 42 | |
39 | if common_comm != for_comm: | 43 | if (for_comm and common_comm != for_comm) or \ |
40 | return | 44 | (for_pid and common_pid != for_pid ): |
45 | return | ||
41 | try: | 46 | try: |
42 | syscalls[common_comm][common_pid][id] += 1 | 47 | syscalls[common_comm][common_pid][id] += 1 |
43 | except TypeError: | 48 | except TypeError: |
@@ -61,4 +66,4 @@ def print_syscall_totals(): | |||
61 | id_keys = syscalls[comm][pid].keys() | 66 | id_keys = syscalls[comm][pid].keys() |
62 | for id, val in sorted(syscalls[comm][pid].iteritems(), \ | 67 | for id, val in sorted(syscalls[comm][pid].iteritems(), \ |
63 | key = lambda(k, v): (v, k), reverse = True): | 68 | key = lambda(k, v): (v, k), reverse = True): |
64 | print " %-38d %10d\n" % (id, val), | 69 | print " %-38s %10d\n" % (syscall_name(id), val), |
diff --git a/tools/perf/scripts/python/syscall-counts.py b/tools/perf/scripts/python/syscall-counts.py index f977e85ff049..ea183dc82d29 100644 --- a/tools/perf/scripts/python/syscall-counts.py +++ b/tools/perf/scripts/python/syscall-counts.py | |||
@@ -13,6 +13,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | |||
13 | 13 | ||
14 | from perf_trace_context import * | 14 | from perf_trace_context import * |
15 | from Core import * | 15 | from Core import * |
16 | from Util import syscall_name | ||
16 | 17 | ||
17 | usage = "perf trace -s syscall-counts.py [comm]\n"; | 18 | usage = "perf trace -s syscall-counts.py [comm]\n"; |
18 | 19 | ||
@@ -27,7 +28,7 @@ if len(sys.argv) > 1: | |||
27 | syscalls = autodict() | 28 | syscalls = autodict() |
28 | 29 | ||
29 | def trace_begin(): | 30 | def trace_begin(): |
30 | pass | 31 | print "Press control+C to stop and show the summary" |
31 | 32 | ||
32 | def trace_end(): | 33 | def trace_end(): |
33 | print_syscall_totals() | 34 | print_syscall_totals() |
@@ -55,4 +56,4 @@ def print_syscall_totals(): | |||
55 | 56 | ||
56 | for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ | 57 | for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ |
57 | reverse = True): | 58 | reverse = True): |
58 | print "%-40d %10d\n" % (id, val), | 59 | print "%-40s %10d\n" % (syscall_name(id), val), |
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 27e9ebe4076e..a7729797fd96 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h | |||
@@ -82,6 +82,8 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2 | |||
82 | extern char *perf_pathdup(const char *fmt, ...) | 82 | extern char *perf_pathdup(const char *fmt, ...) |
83 | __attribute__((format (printf, 1, 2))); | 83 | __attribute__((format (printf, 1, 2))); |
84 | 84 | ||
85 | #ifdef NO_STRLCPY | ||
85 | extern size_t strlcpy(char *dest, const char *src, size_t size); | 86 | extern size_t strlcpy(char *dest, const char *src, size_t size); |
87 | #endif | ||
86 | 88 | ||
87 | #endif /* __PERF_CACHE_H */ | 89 | #endif /* __PERF_CACHE_H */ |
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index f231f43424d2..e12d539417b2 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
@@ -28,6 +28,9 @@ bool ip_callchain__valid(struct ip_callchain *chain, const event_t *event) | |||
28 | #define chain_for_each_child(child, parent) \ | 28 | #define chain_for_each_child(child, parent) \ |
29 | list_for_each_entry(child, &parent->children, brothers) | 29 | list_for_each_entry(child, &parent->children, brothers) |
30 | 30 | ||
31 | #define chain_for_each_child_safe(child, next, parent) \ | ||
32 | list_for_each_entry_safe(child, next, &parent->children, brothers) | ||
33 | |||
31 | static void | 34 | static void |
32 | rb_insert_callchain(struct rb_root *root, struct callchain_node *chain, | 35 | rb_insert_callchain(struct rb_root *root, struct callchain_node *chain, |
33 | enum chain_mode mode) | 36 | enum chain_mode mode) |
@@ -86,10 +89,10 @@ __sort_chain_flat(struct rb_root *rb_root, struct callchain_node *node, | |||
86 | * sort them by hit | 89 | * sort them by hit |
87 | */ | 90 | */ |
88 | static void | 91 | static void |
89 | sort_chain_flat(struct rb_root *rb_root, struct callchain_node *node, | 92 | sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root, |
90 | u64 min_hit, struct callchain_param *param __used) | 93 | u64 min_hit, struct callchain_param *param __used) |
91 | { | 94 | { |
92 | __sort_chain_flat(rb_root, node, min_hit); | 95 | __sort_chain_flat(rb_root, &root->node, min_hit); |
93 | } | 96 | } |
94 | 97 | ||
95 | static void __sort_chain_graph_abs(struct callchain_node *node, | 98 | static void __sort_chain_graph_abs(struct callchain_node *node, |
@@ -108,11 +111,11 @@ static void __sort_chain_graph_abs(struct callchain_node *node, | |||
108 | } | 111 | } |
109 | 112 | ||
110 | static void | 113 | static void |
111 | sort_chain_graph_abs(struct rb_root *rb_root, struct callchain_node *chain_root, | 114 | sort_chain_graph_abs(struct rb_root *rb_root, struct callchain_root *chain_root, |
112 | u64 min_hit, struct callchain_param *param __used) | 115 | u64 min_hit, struct callchain_param *param __used) |
113 | { | 116 | { |
114 | __sort_chain_graph_abs(chain_root, min_hit); | 117 | __sort_chain_graph_abs(&chain_root->node, min_hit); |
115 | rb_root->rb_node = chain_root->rb_root.rb_node; | 118 | rb_root->rb_node = chain_root->node.rb_root.rb_node; |
116 | } | 119 | } |
117 | 120 | ||
118 | static void __sort_chain_graph_rel(struct callchain_node *node, | 121 | static void __sort_chain_graph_rel(struct callchain_node *node, |
@@ -133,11 +136,11 @@ static void __sort_chain_graph_rel(struct callchain_node *node, | |||
133 | } | 136 | } |
134 | 137 | ||
135 | static void | 138 | static void |
136 | sort_chain_graph_rel(struct rb_root *rb_root, struct callchain_node *chain_root, | 139 | sort_chain_graph_rel(struct rb_root *rb_root, struct callchain_root *chain_root, |
137 | u64 min_hit __used, struct callchain_param *param) | 140 | u64 min_hit __used, struct callchain_param *param) |
138 | { | 141 | { |
139 | __sort_chain_graph_rel(chain_root, param->min_percent / 100.0); | 142 | __sort_chain_graph_rel(&chain_root->node, param->min_percent / 100.0); |
140 | rb_root->rb_node = chain_root->rb_root.rb_node; | 143 | rb_root->rb_node = chain_root->node.rb_root.rb_node; |
141 | } | 144 | } |
142 | 145 | ||
143 | int register_callchain_param(struct callchain_param *param) | 146 | int register_callchain_param(struct callchain_param *param) |
@@ -284,19 +287,18 @@ split_add_child(struct callchain_node *parent, struct resolved_chain *chain, | |||
284 | } | 287 | } |
285 | 288 | ||
286 | static int | 289 | static int |
287 | __append_chain(struct callchain_node *root, struct resolved_chain *chain, | 290 | append_chain(struct callchain_node *root, struct resolved_chain *chain, |
288 | unsigned int start, u64 period); | 291 | unsigned int start, u64 period); |
289 | 292 | ||
290 | static void | 293 | static void |
291 | __append_chain_children(struct callchain_node *root, | 294 | append_chain_children(struct callchain_node *root, struct resolved_chain *chain, |
292 | struct resolved_chain *chain, | 295 | unsigned int start, u64 period) |
293 | unsigned int start, u64 period) | ||
294 | { | 296 | { |
295 | struct callchain_node *rnode; | 297 | struct callchain_node *rnode; |
296 | 298 | ||
297 | /* lookup in childrens */ | 299 | /* lookup in childrens */ |
298 | chain_for_each_child(rnode, root) { | 300 | chain_for_each_child(rnode, root) { |
299 | unsigned int ret = __append_chain(rnode, chain, start, period); | 301 | unsigned int ret = append_chain(rnode, chain, start, period); |
300 | 302 | ||
301 | if (!ret) | 303 | if (!ret) |
302 | goto inc_children_hit; | 304 | goto inc_children_hit; |
@@ -309,8 +311,8 @@ inc_children_hit: | |||
309 | } | 311 | } |
310 | 312 | ||
311 | static int | 313 | static int |
312 | __append_chain(struct callchain_node *root, struct resolved_chain *chain, | 314 | append_chain(struct callchain_node *root, struct resolved_chain *chain, |
313 | unsigned int start, u64 period) | 315 | unsigned int start, u64 period) |
314 | { | 316 | { |
315 | struct callchain_list *cnode; | 317 | struct callchain_list *cnode; |
316 | unsigned int i = start; | 318 | unsigned int i = start; |
@@ -357,7 +359,7 @@ __append_chain(struct callchain_node *root, struct resolved_chain *chain, | |||
357 | } | 359 | } |
358 | 360 | ||
359 | /* We match the node and still have a part remaining */ | 361 | /* We match the node and still have a part remaining */ |
360 | __append_chain_children(root, chain, i, period); | 362 | append_chain_children(root, chain, i, period); |
361 | 363 | ||
362 | return 0; | 364 | return 0; |
363 | } | 365 | } |
@@ -380,8 +382,8 @@ static void filter_context(struct ip_callchain *old, struct resolved_chain *new, | |||
380 | } | 382 | } |
381 | 383 | ||
382 | 384 | ||
383 | int append_chain(struct callchain_node *root, struct ip_callchain *chain, | 385 | int callchain_append(struct callchain_root *root, struct ip_callchain *chain, |
384 | struct map_symbol *syms, u64 period) | 386 | struct map_symbol *syms, u64 period) |
385 | { | 387 | { |
386 | struct resolved_chain *filtered; | 388 | struct resolved_chain *filtered; |
387 | 389 | ||
@@ -398,9 +400,65 @@ int append_chain(struct callchain_node *root, struct ip_callchain *chain, | |||
398 | if (!filtered->nr) | 400 | if (!filtered->nr) |
399 | goto end; | 401 | goto end; |
400 | 402 | ||
401 | __append_chain_children(root, filtered, 0, period); | 403 | append_chain_children(&root->node, filtered, 0, period); |
404 | |||
405 | if (filtered->nr > root->max_depth) | ||
406 | root->max_depth = filtered->nr; | ||
402 | end: | 407 | end: |
403 | free(filtered); | 408 | free(filtered); |
404 | 409 | ||
405 | return 0; | 410 | return 0; |
406 | } | 411 | } |
412 | |||
413 | static int | ||
414 | merge_chain_branch(struct callchain_node *dst, struct callchain_node *src, | ||
415 | struct resolved_chain *chain) | ||
416 | { | ||
417 | struct callchain_node *child, *next_child; | ||
418 | struct callchain_list *list, *next_list; | ||
419 | int old_pos = chain->nr; | ||
420 | int err = 0; | ||
421 | |||
422 | list_for_each_entry_safe(list, next_list, &src->val, list) { | ||
423 | chain->ips[chain->nr].ip = list->ip; | ||
424 | chain->ips[chain->nr].ms = list->ms; | ||
425 | chain->nr++; | ||
426 | list_del(&list->list); | ||
427 | free(list); | ||
428 | } | ||
429 | |||
430 | if (src->hit) | ||
431 | append_chain_children(dst, chain, 0, src->hit); | ||
432 | |||
433 | chain_for_each_child_safe(child, next_child, src) { | ||
434 | err = merge_chain_branch(dst, child, chain); | ||
435 | if (err) | ||
436 | break; | ||
437 | |||
438 | list_del(&child->brothers); | ||
439 | free(child); | ||
440 | } | ||
441 | |||
442 | chain->nr = old_pos; | ||
443 | |||
444 | return err; | ||
445 | } | ||
446 | |||
447 | int callchain_merge(struct callchain_root *dst, struct callchain_root *src) | ||
448 | { | ||
449 | struct resolved_chain *chain; | ||
450 | int err; | ||
451 | |||
452 | chain = malloc(sizeof(*chain) + | ||
453 | src->max_depth * sizeof(struct resolved_ip)); | ||
454 | if (!chain) | ||
455 | return -ENOMEM; | ||
456 | |||
457 | chain->nr = 0; | ||
458 | |||
459 | err = merge_chain_branch(&dst->node, &src->node, chain); | ||
460 | |||
461 | free(chain); | ||
462 | |||
463 | return err; | ||
464 | } | ||
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 6de4313924fb..c15fb8c24ad2 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h | |||
@@ -26,9 +26,14 @@ struct callchain_node { | |||
26 | u64 children_hit; | 26 | u64 children_hit; |
27 | }; | 27 | }; |
28 | 28 | ||
29 | struct callchain_root { | ||
30 | u64 max_depth; | ||
31 | struct callchain_node node; | ||
32 | }; | ||
33 | |||
29 | struct callchain_param; | 34 | struct callchain_param; |
30 | 35 | ||
31 | typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_node *, | 36 | typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *, |
32 | u64, struct callchain_param *); | 37 | u64, struct callchain_param *); |
33 | 38 | ||
34 | struct callchain_param { | 39 | struct callchain_param { |
@@ -44,15 +49,16 @@ struct callchain_list { | |||
44 | struct list_head list; | 49 | struct list_head list; |
45 | }; | 50 | }; |
46 | 51 | ||
47 | static inline void callchain_init(struct callchain_node *node) | 52 | static inline void callchain_init(struct callchain_root *root) |
48 | { | 53 | { |
49 | INIT_LIST_HEAD(&node->brothers); | 54 | INIT_LIST_HEAD(&root->node.brothers); |
50 | INIT_LIST_HEAD(&node->children); | 55 | INIT_LIST_HEAD(&root->node.children); |
51 | INIT_LIST_HEAD(&node->val); | 56 | INIT_LIST_HEAD(&root->node.val); |
52 | 57 | ||
53 | node->children_hit = 0; | 58 | root->node.parent = NULL; |
54 | node->parent = NULL; | 59 | root->node.hit = 0; |
55 | node->hit = 0; | 60 | root->node.children_hit = 0; |
61 | root->max_depth = 0; | ||
56 | } | 62 | } |
57 | 63 | ||
58 | static inline u64 cumul_hits(struct callchain_node *node) | 64 | static inline u64 cumul_hits(struct callchain_node *node) |
@@ -61,8 +67,9 @@ static inline u64 cumul_hits(struct callchain_node *node) | |||
61 | } | 67 | } |
62 | 68 | ||
63 | int register_callchain_param(struct callchain_param *param); | 69 | int register_callchain_param(struct callchain_param *param); |
64 | int append_chain(struct callchain_node *root, struct ip_callchain *chain, | 70 | int callchain_append(struct callchain_root *root, struct ip_callchain *chain, |
65 | struct map_symbol *syms, u64 period); | 71 | struct map_symbol *syms, u64 period); |
72 | int callchain_merge(struct callchain_root *dst, struct callchain_root *src); | ||
66 | 73 | ||
67 | bool ip_callchain__valid(struct ip_callchain *chain, const event_t *event); | 74 | bool ip_callchain__valid(struct ip_callchain *chain, const event_t *event); |
68 | #endif /* __PERF_CALLCHAIN_H */ | 75 | #endif /* __PERF_CALLCHAIN_H */ |
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index f9c7e3ad1aa7..c8d81b00089d 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -12,8 +12,8 @@ | |||
12 | #include "debug.h" | 12 | #include "debug.h" |
13 | #include "util.h" | 13 | #include "util.h" |
14 | 14 | ||
15 | int verbose = 0; | 15 | int verbose; |
16 | bool dump_trace = false; | 16 | bool dump_trace = false, quiet = false; |
17 | 17 | ||
18 | int eprintf(int level, const char *fmt, ...) | 18 | int eprintf(int level, const char *fmt, ...) |
19 | { | 19 | { |
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 7a17ee061bcb..7b514082bbaf 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h | |||
@@ -6,7 +6,7 @@ | |||
6 | #include "event.h" | 6 | #include "event.h" |
7 | 7 | ||
8 | extern int verbose; | 8 | extern int verbose; |
9 | extern bool dump_trace; | 9 | extern bool quiet, dump_trace; |
10 | 10 | ||
11 | int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); | 11 | int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); |
12 | void trace_event(event_t *event); | 12 | void trace_event(event_t *event); |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index d7e67b167ea3..7cba0551a565 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -265,15 +265,16 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, | |||
265 | const char *name, bool is_kallsyms) | 265 | const char *name, bool is_kallsyms) |
266 | { | 266 | { |
267 | const size_t size = PATH_MAX; | 267 | const size_t size = PATH_MAX; |
268 | char *filename = malloc(size), | 268 | char *realname = realpath(name, NULL), |
269 | *filename = malloc(size), | ||
269 | *linkname = malloc(size), *targetname; | 270 | *linkname = malloc(size), *targetname; |
270 | int len, err = -1; | 271 | int len, err = -1; |
271 | 272 | ||
272 | if (filename == NULL || linkname == NULL) | 273 | if (realname == NULL || filename == NULL || linkname == NULL) |
273 | goto out_free; | 274 | goto out_free; |
274 | 275 | ||
275 | len = snprintf(filename, size, "%s%s%s", | 276 | len = snprintf(filename, size, "%s%s%s", |
276 | debugdir, is_kallsyms ? "/" : "", name); | 277 | debugdir, is_kallsyms ? "/" : "", realname); |
277 | if (mkdir_p(filename, 0755)) | 278 | if (mkdir_p(filename, 0755)) |
278 | goto out_free; | 279 | goto out_free; |
279 | 280 | ||
@@ -283,7 +284,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, | |||
283 | if (is_kallsyms) { | 284 | if (is_kallsyms) { |
284 | if (copyfile("/proc/kallsyms", filename)) | 285 | if (copyfile("/proc/kallsyms", filename)) |
285 | goto out_free; | 286 | goto out_free; |
286 | } else if (link(name, filename) && copyfile(name, filename)) | 287 | } else if (link(realname, filename) && copyfile(name, filename)) |
287 | goto out_free; | 288 | goto out_free; |
288 | } | 289 | } |
289 | 290 | ||
@@ -300,6 +301,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, | |||
300 | if (symlink(targetname, linkname) == 0) | 301 | if (symlink(targetname, linkname) == 0) |
301 | err = 0; | 302 | err = 0; |
302 | out_free: | 303 | out_free: |
304 | free(realname); | ||
303 | free(filename); | 305 | free(filename); |
304 | free(linkname); | 306 | free(linkname); |
305 | return err; | 307 | return err; |
@@ -946,11 +948,16 @@ perf_header__find_attr(u64 id, struct perf_header *header) | |||
946 | 948 | ||
947 | /* | 949 | /* |
948 | * We set id to -1 if the data file doesn't contain sample | 950 | * We set id to -1 if the data file doesn't contain sample |
949 | * ids. Check for this and avoid walking through the entire | 951 | * ids. This can happen when the data file contains one type |
950 | * list of ids which may be large. | 952 | * of event and in that case, the header can still store the |
953 | * event attribute information. Check for this and avoid | ||
954 | * walking through the entire list of ids which may be large. | ||
951 | */ | 955 | */ |
952 | if (id == -1ULL) | 956 | if (id == -1ULL) { |
957 | if (header->attrs > 0) | ||
958 | return &header->attr[0]->attr; | ||
953 | return NULL; | 959 | return NULL; |
960 | } | ||
954 | 961 | ||
955 | for (i = 0; i < header->attrs; i++) { | 962 | for (i = 0; i < header->attrs; i++) { |
956 | struct perf_header_attr *attr = header->attr[i]; | 963 | struct perf_header_attr *attr = header->attr[i]; |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index be22ae6ef055..76bcc35cf9b1 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -87,7 +87,7 @@ static void hist_entry__add_cpumode_period(struct hist_entry *self, | |||
87 | 87 | ||
88 | static struct hist_entry *hist_entry__new(struct hist_entry *template) | 88 | static struct hist_entry *hist_entry__new(struct hist_entry *template) |
89 | { | 89 | { |
90 | size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_node) : 0; | 90 | size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0; |
91 | struct hist_entry *self = malloc(sizeof(*self) + callchain_size); | 91 | struct hist_entry *self = malloc(sizeof(*self) + callchain_size); |
92 | 92 | ||
93 | if (self != NULL) { | 93 | if (self != NULL) { |
@@ -226,6 +226,8 @@ static bool collapse__insert_entry(struct rb_root *root, struct hist_entry *he) | |||
226 | 226 | ||
227 | if (!cmp) { | 227 | if (!cmp) { |
228 | iter->period += he->period; | 228 | iter->period += he->period; |
229 | if (symbol_conf.use_callchain) | ||
230 | callchain_merge(iter->callchain, he->callchain); | ||
229 | hist_entry__free(he); | 231 | hist_entry__free(he); |
230 | return false; | 232 | return false; |
231 | } | 233 | } |
@@ -354,7 +356,7 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, | |||
354 | 356 | ||
355 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, | 357 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, |
356 | int depth, int depth_mask, int period, | 358 | int depth, int depth_mask, int period, |
357 | u64 total_samples, int hits, | 359 | u64 total_samples, u64 hits, |
358 | int left_margin) | 360 | int left_margin) |
359 | { | 361 | { |
360 | int i; | 362 | int i; |
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 78575796d5f3..b397c0383728 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h | |||
@@ -215,6 +215,16 @@ struct symbol *map_groups__find_function_by_name(struct map_groups *self, | |||
215 | return map_groups__find_symbol_by_name(self, MAP__FUNCTION, name, mapp, filter); | 215 | return map_groups__find_symbol_by_name(self, MAP__FUNCTION, name, mapp, filter); |
216 | } | 216 | } |
217 | 217 | ||
218 | static inline | ||
219 | struct symbol *machine__find_kernel_function_by_name(struct machine *self, | ||
220 | const char *name, | ||
221 | struct map **mapp, | ||
222 | symbol_filter_t filter) | ||
223 | { | ||
224 | return map_groups__find_function_by_name(&self->kmaps, name, mapp, | ||
225 | filter); | ||
226 | } | ||
227 | |||
218 | int map_groups__fixup_overlappings(struct map_groups *self, struct map *map, | 228 | int map_groups__fixup_overlappings(struct map_groups *self, struct map *map, |
219 | int verbose, FILE *fp); | 229 | int verbose, FILE *fp); |
220 | 230 | ||
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index 58a470d036dd..bd7497711424 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c | |||
@@ -22,6 +22,7 @@ static const char *get_perf_dir(void) | |||
22 | return "."; | 22 | return "."; |
23 | } | 23 | } |
24 | 24 | ||
25 | #ifdef NO_STRLCPY | ||
25 | size_t strlcpy(char *dest, const char *src, size_t size) | 26 | size_t strlcpy(char *dest, const char *src, size_t size) |
26 | { | 27 | { |
27 | size_t ret = strlen(src); | 28 | size_t ret = strlen(src); |
@@ -33,7 +34,7 @@ size_t strlcpy(char *dest, const char *src, size_t size) | |||
33 | } | 34 | } |
34 | return ret; | 35 | return ret; |
35 | } | 36 | } |
36 | 37 | #endif | |
37 | 38 | ||
38 | static char *get_pathname(void) | 39 | static char *get_pathname(void) |
39 | { | 40 | { |
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index fcc16e4349df..61191c6cbe7a 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -74,10 +74,9 @@ static int e_snprintf(char *str, size_t size, const char *format, ...) | |||
74 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); | 74 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); |
75 | static struct machine machine; | 75 | static struct machine machine; |
76 | 76 | ||
77 | /* Initialize symbol maps and path of vmlinux */ | 77 | /* Initialize symbol maps and path of vmlinux/modules */ |
78 | static int init_vmlinux(void) | 78 | static int init_vmlinux(void) |
79 | { | 79 | { |
80 | struct dso *kernel; | ||
81 | int ret; | 80 | int ret; |
82 | 81 | ||
83 | symbol_conf.sort_by_name = true; | 82 | symbol_conf.sort_by_name = true; |
@@ -91,33 +90,70 @@ static int init_vmlinux(void) | |||
91 | goto out; | 90 | goto out; |
92 | } | 91 | } |
93 | 92 | ||
94 | ret = machine__init(&machine, "/", 0); | 93 | ret = machine__init(&machine, "", HOST_KERNEL_ID); |
95 | if (ret < 0) | 94 | if (ret < 0) |
96 | goto out; | 95 | goto out; |
97 | 96 | ||
98 | kernel = dso__new_kernel(symbol_conf.vmlinux_name); | 97 | if (machine__create_kernel_maps(&machine) < 0) { |
99 | if (kernel == NULL) | 98 | pr_debug("machine__create_kernel_maps "); |
100 | die("Failed to create kernel dso."); | 99 | goto out; |
101 | 100 | } | |
102 | ret = __machine__create_kernel_maps(&machine, kernel); | ||
103 | if (ret < 0) | ||
104 | pr_debug("Failed to create kernel maps.\n"); | ||
105 | |||
106 | out: | 101 | out: |
107 | if (ret < 0) | 102 | if (ret < 0) |
108 | pr_warning("Failed to init vmlinux path.\n"); | 103 | pr_warning("Failed to init vmlinux path.\n"); |
109 | return ret; | 104 | return ret; |
110 | } | 105 | } |
111 | 106 | ||
107 | static struct symbol *__find_kernel_function_by_name(const char *name, | ||
108 | struct map **mapp) | ||
109 | { | ||
110 | return machine__find_kernel_function_by_name(&machine, name, mapp, | ||
111 | NULL); | ||
112 | } | ||
113 | |||
114 | const char *kernel_get_module_path(const char *module) | ||
115 | { | ||
116 | struct dso *dso; | ||
117 | struct map *map; | ||
118 | const char *vmlinux_name; | ||
119 | |||
120 | if (module) { | ||
121 | list_for_each_entry(dso, &machine.kernel_dsos, node) { | ||
122 | if (strncmp(dso->short_name + 1, module, | ||
123 | dso->short_name_len - 2) == 0) | ||
124 | goto found; | ||
125 | } | ||
126 | pr_debug("Failed to find module %s.\n", module); | ||
127 | return NULL; | ||
128 | } | ||
129 | |||
130 | map = machine.vmlinux_maps[MAP__FUNCTION]; | ||
131 | dso = map->dso; | ||
132 | |||
133 | vmlinux_name = symbol_conf.vmlinux_name; | ||
134 | if (vmlinux_name) { | ||
135 | if (dso__load_vmlinux(dso, map, vmlinux_name, NULL) <= 0) | ||
136 | return NULL; | ||
137 | } else { | ||
138 | if (dso__load_vmlinux_path(dso, map, NULL) <= 0) { | ||
139 | pr_debug("Failed to load kernel map.\n"); | ||
140 | return NULL; | ||
141 | } | ||
142 | } | ||
143 | found: | ||
144 | return dso->long_name; | ||
145 | } | ||
146 | |||
112 | #ifdef DWARF_SUPPORT | 147 | #ifdef DWARF_SUPPORT |
113 | static int open_vmlinux(void) | 148 | static int open_vmlinux(const char *module) |
114 | { | 149 | { |
115 | if (map__load(machine.vmlinux_maps[MAP__FUNCTION], NULL) < 0) { | 150 | const char *path = kernel_get_module_path(module); |
116 | pr_debug("Failed to load kernel map.\n"); | 151 | if (!path) { |
117 | return -EINVAL; | 152 | pr_err("Failed to find path of %s module", module ?: "kernel"); |
153 | return -ENOENT; | ||
118 | } | 154 | } |
119 | pr_debug("Try to open %s\n", machine.vmlinux_maps[MAP__FUNCTION]->dso->long_name); | 155 | pr_debug("Try to open %s\n", path); |
120 | return open(machine.vmlinux_maps[MAP__FUNCTION]->dso->long_name, O_RDONLY); | 156 | return open(path, O_RDONLY); |
121 | } | 157 | } |
122 | 158 | ||
123 | /* | 159 | /* |
@@ -125,20 +161,19 @@ static int open_vmlinux(void) | |||
125 | * Currently only handles kprobes. | 161 | * Currently only handles kprobes. |
126 | */ | 162 | */ |
127 | static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, | 163 | static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, |
128 | struct perf_probe_point *pp) | 164 | struct perf_probe_point *pp) |
129 | { | 165 | { |
130 | struct symbol *sym; | 166 | struct symbol *sym; |
131 | int fd, ret = -ENOENT; | 167 | struct map *map; |
168 | u64 addr; | ||
169 | int ret = -ENOENT; | ||
132 | 170 | ||
133 | sym = map__find_symbol_by_name(machine.vmlinux_maps[MAP__FUNCTION], | 171 | sym = __find_kernel_function_by_name(tp->symbol, &map); |
134 | tp->symbol, NULL); | ||
135 | if (sym) { | 172 | if (sym) { |
136 | fd = open_vmlinux(); | 173 | addr = map->unmap_ip(map, sym->start + tp->offset); |
137 | if (fd >= 0) { | 174 | pr_debug("try to find %s+%ld@%llx\n", tp->symbol, |
138 | ret = find_perf_probe_point(fd, | 175 | tp->offset, addr); |
139 | sym->start + tp->offset, pp); | 176 | ret = find_perf_probe_point((unsigned long)addr, pp); |
140 | close(fd); | ||
141 | } | ||
142 | } | 177 | } |
143 | if (ret <= 0) { | 178 | if (ret <= 0) { |
144 | pr_debug("Failed to find corresponding probes from " | 179 | pr_debug("Failed to find corresponding probes from " |
@@ -156,12 +191,12 @@ static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, | |||
156 | /* Try to find perf_probe_event with debuginfo */ | 191 | /* Try to find perf_probe_event with debuginfo */ |
157 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, | 192 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, |
158 | struct probe_trace_event **tevs, | 193 | struct probe_trace_event **tevs, |
159 | int max_tevs) | 194 | int max_tevs, const char *module) |
160 | { | 195 | { |
161 | bool need_dwarf = perf_probe_event_need_dwarf(pev); | 196 | bool need_dwarf = perf_probe_event_need_dwarf(pev); |
162 | int fd, ntevs; | 197 | int fd, ntevs; |
163 | 198 | ||
164 | fd = open_vmlinux(); | 199 | fd = open_vmlinux(module); |
165 | if (fd < 0) { | 200 | if (fd < 0) { |
166 | if (need_dwarf) { | 201 | if (need_dwarf) { |
167 | pr_warning("Failed to open debuginfo file.\n"); | 202 | pr_warning("Failed to open debuginfo file.\n"); |
@@ -300,7 +335,7 @@ error: | |||
300 | * Show line-range always requires debuginfo to find source file and | 335 | * Show line-range always requires debuginfo to find source file and |
301 | * line number. | 336 | * line number. |
302 | */ | 337 | */ |
303 | int show_line_range(struct line_range *lr) | 338 | int show_line_range(struct line_range *lr, const char *module) |
304 | { | 339 | { |
305 | int l = 1; | 340 | int l = 1; |
306 | struct line_node *ln; | 341 | struct line_node *ln; |
@@ -313,7 +348,7 @@ int show_line_range(struct line_range *lr) | |||
313 | if (ret < 0) | 348 | if (ret < 0) |
314 | return ret; | 349 | return ret; |
315 | 350 | ||
316 | fd = open_vmlinux(); | 351 | fd = open_vmlinux(module); |
317 | if (fd < 0) { | 352 | if (fd < 0) { |
318 | pr_warning("Failed to open debuginfo file.\n"); | 353 | pr_warning("Failed to open debuginfo file.\n"); |
319 | return fd; | 354 | return fd; |
@@ -378,11 +413,84 @@ end: | |||
378 | return ret; | 413 | return ret; |
379 | } | 414 | } |
380 | 415 | ||
416 | static int show_available_vars_at(int fd, struct perf_probe_event *pev, | ||
417 | int max_vls, bool externs) | ||
418 | { | ||
419 | char *buf; | ||
420 | int ret, i; | ||
421 | struct str_node *node; | ||
422 | struct variable_list *vls = NULL, *vl; | ||
423 | |||
424 | buf = synthesize_perf_probe_point(&pev->point); | ||
425 | if (!buf) | ||
426 | return -EINVAL; | ||
427 | pr_debug("Searching variables at %s\n", buf); | ||
428 | |||
429 | ret = find_available_vars_at(fd, pev, &vls, max_vls, externs); | ||
430 | if (ret > 0) { | ||
431 | /* Some variables were found */ | ||
432 | fprintf(stdout, "Available variables at %s\n", buf); | ||
433 | for (i = 0; i < ret; i++) { | ||
434 | vl = &vls[i]; | ||
435 | /* | ||
436 | * A probe point might be converted to | ||
437 | * several trace points. | ||
438 | */ | ||
439 | fprintf(stdout, "\t@<%s+%lu>\n", vl->point.symbol, | ||
440 | vl->point.offset); | ||
441 | free(vl->point.symbol); | ||
442 | if (vl->vars) { | ||
443 | strlist__for_each(node, vl->vars) | ||
444 | fprintf(stdout, "\t\t%s\n", node->s); | ||
445 | strlist__delete(vl->vars); | ||
446 | } else | ||
447 | fprintf(stdout, "(No variables)\n"); | ||
448 | } | ||
449 | free(vls); | ||
450 | } else | ||
451 | pr_err("Failed to find variables at %s (%d)\n", buf, ret); | ||
452 | |||
453 | free(buf); | ||
454 | return ret; | ||
455 | } | ||
456 | |||
457 | /* Show available variables on given probe point */ | ||
458 | int show_available_vars(struct perf_probe_event *pevs, int npevs, | ||
459 | int max_vls, const char *module, bool externs) | ||
460 | { | ||
461 | int i, fd, ret = 0; | ||
462 | |||
463 | ret = init_vmlinux(); | ||
464 | if (ret < 0) | ||
465 | return ret; | ||
466 | |||
467 | fd = open_vmlinux(module); | ||
468 | if (fd < 0) { | ||
469 | pr_warning("Failed to open debuginfo file.\n"); | ||
470 | return fd; | ||
471 | } | ||
472 | |||
473 | setup_pager(); | ||
474 | |||
475 | for (i = 0; i < npevs && ret >= 0; i++) | ||
476 | ret = show_available_vars_at(fd, &pevs[i], max_vls, externs); | ||
477 | |||
478 | close(fd); | ||
479 | return ret; | ||
480 | } | ||
481 | |||
381 | #else /* !DWARF_SUPPORT */ | 482 | #else /* !DWARF_SUPPORT */ |
382 | 483 | ||
383 | static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, | 484 | static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, |
384 | struct perf_probe_point *pp) | 485 | struct perf_probe_point *pp) |
385 | { | 486 | { |
487 | struct symbol *sym; | ||
488 | |||
489 | sym = __find_kernel_function_by_name(tp->symbol, NULL); | ||
490 | if (!sym) { | ||
491 | pr_err("Failed to find symbol %s in kernel.\n", tp->symbol); | ||
492 | return -ENOENT; | ||
493 | } | ||
386 | pp->function = strdup(tp->symbol); | 494 | pp->function = strdup(tp->symbol); |
387 | if (pp->function == NULL) | 495 | if (pp->function == NULL) |
388 | return -ENOMEM; | 496 | return -ENOMEM; |
@@ -394,7 +502,7 @@ static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, | |||
394 | 502 | ||
395 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, | 503 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, |
396 | struct probe_trace_event **tevs __unused, | 504 | struct probe_trace_event **tevs __unused, |
397 | int max_tevs __unused) | 505 | int max_tevs __unused, const char *mod __unused) |
398 | { | 506 | { |
399 | if (perf_probe_event_need_dwarf(pev)) { | 507 | if (perf_probe_event_need_dwarf(pev)) { |
400 | pr_warning("Debuginfo-analysis is not supported.\n"); | 508 | pr_warning("Debuginfo-analysis is not supported.\n"); |
@@ -403,12 +511,19 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev, | |||
403 | return 0; | 511 | return 0; |
404 | } | 512 | } |
405 | 513 | ||
406 | int show_line_range(struct line_range *lr __unused) | 514 | int show_line_range(struct line_range *lr __unused, const char *module __unused) |
407 | { | 515 | { |
408 | pr_warning("Debuginfo-analysis is not supported.\n"); | 516 | pr_warning("Debuginfo-analysis is not supported.\n"); |
409 | return -ENOSYS; | 517 | return -ENOSYS; |
410 | } | 518 | } |
411 | 519 | ||
520 | int show_available_vars(struct perf_probe_event *pevs __unused, | ||
521 | int npevs __unused, int max_vls __unused, | ||
522 | const char *module __unused, bool externs __unused) | ||
523 | { | ||
524 | pr_warning("Debuginfo-analysis is not supported.\n"); | ||
525 | return -ENOSYS; | ||
526 | } | ||
412 | #endif | 527 | #endif |
413 | 528 | ||
414 | int parse_line_range_desc(const char *arg, struct line_range *lr) | 529 | int parse_line_range_desc(const char *arg, struct line_range *lr) |
@@ -1087,7 +1202,7 @@ error: | |||
1087 | } | 1202 | } |
1088 | 1203 | ||
1089 | static int convert_to_perf_probe_event(struct probe_trace_event *tev, | 1204 | static int convert_to_perf_probe_event(struct probe_trace_event *tev, |
1090 | struct perf_probe_event *pev) | 1205 | struct perf_probe_event *pev) |
1091 | { | 1206 | { |
1092 | char buf[64] = ""; | 1207 | char buf[64] = ""; |
1093 | int i, ret; | 1208 | int i, ret; |
@@ -1516,14 +1631,14 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, | |||
1516 | 1631 | ||
1517 | static int convert_to_probe_trace_events(struct perf_probe_event *pev, | 1632 | static int convert_to_probe_trace_events(struct perf_probe_event *pev, |
1518 | struct probe_trace_event **tevs, | 1633 | struct probe_trace_event **tevs, |
1519 | int max_tevs) | 1634 | int max_tevs, const char *module) |
1520 | { | 1635 | { |
1521 | struct symbol *sym; | 1636 | struct symbol *sym; |
1522 | int ret = 0, i; | 1637 | int ret = 0, i; |
1523 | struct probe_trace_event *tev; | 1638 | struct probe_trace_event *tev; |
1524 | 1639 | ||
1525 | /* Convert perf_probe_event with debuginfo */ | 1640 | /* Convert perf_probe_event with debuginfo */ |
1526 | ret = try_to_find_probe_trace_events(pev, tevs, max_tevs); | 1641 | ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, module); |
1527 | if (ret != 0) | 1642 | if (ret != 0) |
1528 | return ret; | 1643 | return ret; |
1529 | 1644 | ||
@@ -1572,8 +1687,7 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev, | |||
1572 | } | 1687 | } |
1573 | 1688 | ||
1574 | /* Currently just checking function name from symbol map */ | 1689 | /* Currently just checking function name from symbol map */ |
1575 | sym = map__find_symbol_by_name(machine.vmlinux_maps[MAP__FUNCTION], | 1690 | sym = __find_kernel_function_by_name(tev->point.symbol, NULL); |
1576 | tev->point.symbol, NULL); | ||
1577 | if (!sym) { | 1691 | if (!sym) { |
1578 | pr_warning("Kernel symbol \'%s\' not found.\n", | 1692 | pr_warning("Kernel symbol \'%s\' not found.\n", |
1579 | tev->point.symbol); | 1693 | tev->point.symbol); |
@@ -1596,7 +1710,7 @@ struct __event_package { | |||
1596 | }; | 1710 | }; |
1597 | 1711 | ||
1598 | int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, | 1712 | int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, |
1599 | bool force_add, int max_tevs) | 1713 | int max_tevs, const char *module, bool force_add) |
1600 | { | 1714 | { |
1601 | int i, j, ret; | 1715 | int i, j, ret; |
1602 | struct __event_package *pkgs; | 1716 | struct __event_package *pkgs; |
@@ -1617,7 +1731,9 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, | |||
1617 | pkgs[i].pev = &pevs[i]; | 1731 | pkgs[i].pev = &pevs[i]; |
1618 | /* Convert with or without debuginfo */ | 1732 | /* Convert with or without debuginfo */ |
1619 | ret = convert_to_probe_trace_events(pkgs[i].pev, | 1733 | ret = convert_to_probe_trace_events(pkgs[i].pev, |
1620 | &pkgs[i].tevs, max_tevs); | 1734 | &pkgs[i].tevs, |
1735 | max_tevs, | ||
1736 | module); | ||
1621 | if (ret < 0) | 1737 | if (ret < 0) |
1622 | goto end; | 1738 | goto end; |
1623 | pkgs[i].ntevs = ret; | 1739 | pkgs[i].ntevs = ret; |
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index 5af39243a25b..5accbedfea37 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h | |||
@@ -90,6 +90,12 @@ struct line_range { | |||
90 | struct list_head line_list; /* Visible lines */ | 90 | struct list_head line_list; /* Visible lines */ |
91 | }; | 91 | }; |
92 | 92 | ||
93 | /* List of variables */ | ||
94 | struct variable_list { | ||
95 | struct probe_trace_point point; /* Actual probepoint */ | ||
96 | struct strlist *vars; /* Available variables */ | ||
97 | }; | ||
98 | |||
93 | /* Command string to events */ | 99 | /* Command string to events */ |
94 | extern int parse_perf_probe_command(const char *cmd, | 100 | extern int parse_perf_probe_command(const char *cmd, |
95 | struct perf_probe_event *pev); | 101 | struct perf_probe_event *pev); |
@@ -109,12 +115,18 @@ extern void clear_perf_probe_event(struct perf_probe_event *pev); | |||
109 | /* Command string to line-range */ | 115 | /* Command string to line-range */ |
110 | extern int parse_line_range_desc(const char *cmd, struct line_range *lr); | 116 | extern int parse_line_range_desc(const char *cmd, struct line_range *lr); |
111 | 117 | ||
118 | /* Internal use: Return kernel/module path */ | ||
119 | extern const char *kernel_get_module_path(const char *module); | ||
112 | 120 | ||
113 | extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, | 121 | extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, |
114 | bool force_add, int max_probe_points); | 122 | int max_probe_points, const char *module, |
123 | bool force_add); | ||
115 | extern int del_perf_probe_events(struct strlist *dellist); | 124 | extern int del_perf_probe_events(struct strlist *dellist); |
116 | extern int show_perf_probe_events(void); | 125 | extern int show_perf_probe_events(void); |
117 | extern int show_line_range(struct line_range *lr); | 126 | extern int show_line_range(struct line_range *lr, const char *module); |
127 | extern int show_available_vars(struct perf_probe_event *pevs, int npevs, | ||
128 | int max_probe_points, const char *module, | ||
129 | bool externs); | ||
118 | 130 | ||
119 | 131 | ||
120 | /* Maximum index number of event-name postfix */ | 132 | /* Maximum index number of event-name postfix */ |
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 32b81f707ff5..ddf4d4556321 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
@@ -116,6 +116,126 @@ static void line_list__free(struct list_head *head) | |||
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | /* Dwarf FL wrappers */ | ||
120 | static char *debuginfo_path; /* Currently dummy */ | ||
121 | |||
122 | static const Dwfl_Callbacks offline_callbacks = { | ||
123 | .find_debuginfo = dwfl_standard_find_debuginfo, | ||
124 | .debuginfo_path = &debuginfo_path, | ||
125 | |||
126 | .section_address = dwfl_offline_section_address, | ||
127 | |||
128 | /* We use this table for core files too. */ | ||
129 | .find_elf = dwfl_build_id_find_elf, | ||
130 | }; | ||
131 | |||
132 | /* Get a Dwarf from offline image */ | ||
133 | static Dwarf *dwfl_init_offline_dwarf(int fd, Dwfl **dwflp, Dwarf_Addr *bias) | ||
134 | { | ||
135 | Dwfl_Module *mod; | ||
136 | Dwarf *dbg = NULL; | ||
137 | |||
138 | if (!dwflp) | ||
139 | return NULL; | ||
140 | |||
141 | *dwflp = dwfl_begin(&offline_callbacks); | ||
142 | if (!*dwflp) | ||
143 | return NULL; | ||
144 | |||
145 | mod = dwfl_report_offline(*dwflp, "", "", fd); | ||
146 | if (!mod) | ||
147 | goto error; | ||
148 | |||
149 | dbg = dwfl_module_getdwarf(mod, bias); | ||
150 | if (!dbg) { | ||
151 | error: | ||
152 | dwfl_end(*dwflp); | ||
153 | *dwflp = NULL; | ||
154 | } | ||
155 | return dbg; | ||
156 | } | ||
157 | |||
158 | #if _ELFUTILS_PREREQ(0, 148) | ||
159 | /* This method is buggy if elfutils is older than 0.148 */ | ||
160 | static int __linux_kernel_find_elf(Dwfl_Module *mod, | ||
161 | void **userdata, | ||
162 | const char *module_name, | ||
163 | Dwarf_Addr base, | ||
164 | char **file_name, Elf **elfp) | ||
165 | { | ||
166 | int fd; | ||
167 | const char *path = kernel_get_module_path(module_name); | ||
168 | |||
169 | pr_debug2("Use file %s for %s\n", path, module_name); | ||
170 | if (path) { | ||
171 | fd = open(path, O_RDONLY); | ||
172 | if (fd >= 0) { | ||
173 | *file_name = strdup(path); | ||
174 | return fd; | ||
175 | } | ||
176 | } | ||
177 | /* If failed, try to call standard method */ | ||
178 | return dwfl_linux_kernel_find_elf(mod, userdata, module_name, base, | ||
179 | file_name, elfp); | ||
180 | } | ||
181 | |||
182 | static const Dwfl_Callbacks kernel_callbacks = { | ||
183 | .find_debuginfo = dwfl_standard_find_debuginfo, | ||
184 | .debuginfo_path = &debuginfo_path, | ||
185 | |||
186 | .find_elf = __linux_kernel_find_elf, | ||
187 | .section_address = dwfl_linux_kernel_module_section_address, | ||
188 | }; | ||
189 | |||
190 | /* Get a Dwarf from live kernel image */ | ||
191 | static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr, Dwfl **dwflp, | ||
192 | Dwarf_Addr *bias) | ||
193 | { | ||
194 | Dwarf *dbg; | ||
195 | |||
196 | if (!dwflp) | ||
197 | return NULL; | ||
198 | |||
199 | *dwflp = dwfl_begin(&kernel_callbacks); | ||
200 | if (!*dwflp) | ||
201 | return NULL; | ||
202 | |||
203 | /* Load the kernel dwarves: Don't care the result here */ | ||
204 | dwfl_linux_kernel_report_kernel(*dwflp); | ||
205 | dwfl_linux_kernel_report_modules(*dwflp); | ||
206 | |||
207 | dbg = dwfl_addrdwarf(*dwflp, addr, bias); | ||
208 | /* Here, check whether we could get a real dwarf */ | ||
209 | if (!dbg) { | ||
210 | pr_debug("Failed to find kernel dwarf at %lx\n", | ||
211 | (unsigned long)addr); | ||
212 | dwfl_end(*dwflp); | ||
213 | *dwflp = NULL; | ||
214 | } | ||
215 | return dbg; | ||
216 | } | ||
217 | #else | ||
218 | /* With older elfutils, this just support kernel module... */ | ||
219 | static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr __used, Dwfl **dwflp, | ||
220 | Dwarf_Addr *bias) | ||
221 | { | ||
222 | int fd; | ||
223 | const char *path = kernel_get_module_path("kernel"); | ||
224 | |||
225 | if (!path) { | ||
226 | pr_err("Failed to find vmlinux path\n"); | ||
227 | return NULL; | ||
228 | } | ||
229 | |||
230 | pr_debug2("Use file %s for debuginfo\n", path); | ||
231 | fd = open(path, O_RDONLY); | ||
232 | if (fd < 0) | ||
233 | return NULL; | ||
234 | |||
235 | return dwfl_init_offline_dwarf(fd, dwflp, bias); | ||
236 | } | ||
237 | #endif | ||
238 | |||
119 | /* Dwarf wrappers */ | 239 | /* Dwarf wrappers */ |
120 | 240 | ||
121 | /* Find the realpath of the target file. */ | 241 | /* Find the realpath of the target file. */ |
@@ -160,26 +280,44 @@ static bool die_compare_name(Dwarf_Die *dw_die, const char *tname) | |||
160 | return name ? (strcmp(tname, name) == 0) : false; | 280 | return name ? (strcmp(tname, name) == 0) : false; |
161 | } | 281 | } |
162 | 282 | ||
163 | /* Get type die, but skip qualifiers and typedef */ | 283 | /* Get type die */ |
164 | static Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | 284 | static Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) |
165 | { | 285 | { |
166 | Dwarf_Attribute attr; | 286 | Dwarf_Attribute attr; |
287 | |||
288 | if (dwarf_attr_integrate(vr_die, DW_AT_type, &attr) && | ||
289 | dwarf_formref_die(&attr, die_mem)) | ||
290 | return die_mem; | ||
291 | else | ||
292 | return NULL; | ||
293 | } | ||
294 | |||
295 | /* Get a type die, but skip qualifiers */ | ||
296 | static Dwarf_Die *__die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | ||
297 | { | ||
167 | int tag; | 298 | int tag; |
168 | 299 | ||
169 | do { | 300 | do { |
170 | if (dwarf_attr(vr_die, DW_AT_type, &attr) == NULL || | 301 | vr_die = die_get_type(vr_die, die_mem); |
171 | dwarf_formref_die(&attr, die_mem) == NULL) | 302 | if (!vr_die) |
172 | return NULL; | 303 | break; |
173 | 304 | tag = dwarf_tag(vr_die); | |
174 | tag = dwarf_tag(die_mem); | ||
175 | vr_die = die_mem; | ||
176 | } while (tag == DW_TAG_const_type || | 305 | } while (tag == DW_TAG_const_type || |
177 | tag == DW_TAG_restrict_type || | 306 | tag == DW_TAG_restrict_type || |
178 | tag == DW_TAG_volatile_type || | 307 | tag == DW_TAG_volatile_type || |
179 | tag == DW_TAG_shared_type || | 308 | tag == DW_TAG_shared_type); |
180 | tag == DW_TAG_typedef); | 309 | |
310 | return vr_die; | ||
311 | } | ||
312 | |||
313 | /* Get a type die, but skip qualifiers and typedef */ | ||
314 | static Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | ||
315 | { | ||
316 | do { | ||
317 | vr_die = __die_get_real_type(vr_die, die_mem); | ||
318 | } while (vr_die && dwarf_tag(vr_die) == DW_TAG_typedef); | ||
181 | 319 | ||
182 | return die_mem; | 320 | return vr_die; |
183 | } | 321 | } |
184 | 322 | ||
185 | static bool die_is_signed_type(Dwarf_Die *tp_die) | 323 | static bool die_is_signed_type(Dwarf_Die *tp_die) |
@@ -320,25 +458,35 @@ static Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, | |||
320 | return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem); | 458 | return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem); |
321 | } | 459 | } |
322 | 460 | ||
461 | struct __find_variable_param { | ||
462 | const char *name; | ||
463 | Dwarf_Addr addr; | ||
464 | }; | ||
465 | |||
323 | static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data) | 466 | static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data) |
324 | { | 467 | { |
325 | const char *name = data; | 468 | struct __find_variable_param *fvp = data; |
326 | int tag; | 469 | int tag; |
327 | 470 | ||
328 | tag = dwarf_tag(die_mem); | 471 | tag = dwarf_tag(die_mem); |
329 | if ((tag == DW_TAG_formal_parameter || | 472 | if ((tag == DW_TAG_formal_parameter || |
330 | tag == DW_TAG_variable) && | 473 | tag == DW_TAG_variable) && |
331 | die_compare_name(die_mem, name)) | 474 | die_compare_name(die_mem, fvp->name)) |
332 | return DIE_FIND_CB_FOUND; | 475 | return DIE_FIND_CB_FOUND; |
333 | 476 | ||
334 | return DIE_FIND_CB_CONTINUE; | 477 | if (dwarf_haspc(die_mem, fvp->addr)) |
478 | return DIE_FIND_CB_CONTINUE; | ||
479 | else | ||
480 | return DIE_FIND_CB_SIBLING; | ||
335 | } | 481 | } |
336 | 482 | ||
337 | /* Find a variable called 'name' */ | 483 | /* Find a variable called 'name' at given address */ |
338 | static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name, | 484 | static Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name, |
339 | Dwarf_Die *die_mem) | 485 | Dwarf_Addr addr, Dwarf_Die *die_mem) |
340 | { | 486 | { |
341 | return die_find_child(sp_die, __die_find_variable_cb, (void *)name, | 487 | struct __find_variable_param fvp = { .name = name, .addr = addr}; |
488 | |||
489 | return die_find_child(sp_die, __die_find_variable_cb, (void *)&fvp, | ||
342 | die_mem); | 490 | die_mem); |
343 | } | 491 | } |
344 | 492 | ||
@@ -361,6 +509,60 @@ static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, | |||
361 | die_mem); | 509 | die_mem); |
362 | } | 510 | } |
363 | 511 | ||
512 | /* Get the name of given variable DIE */ | ||
513 | static int die_get_typename(Dwarf_Die *vr_die, char *buf, int len) | ||
514 | { | ||
515 | Dwarf_Die type; | ||
516 | int tag, ret, ret2; | ||
517 | const char *tmp = ""; | ||
518 | |||
519 | if (__die_get_real_type(vr_die, &type) == NULL) | ||
520 | return -ENOENT; | ||
521 | |||
522 | tag = dwarf_tag(&type); | ||
523 | if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type) | ||
524 | tmp = "*"; | ||
525 | else if (tag == DW_TAG_subroutine_type) { | ||
526 | /* Function pointer */ | ||
527 | ret = snprintf(buf, len, "(function_type)"); | ||
528 | return (ret >= len) ? -E2BIG : ret; | ||
529 | } else { | ||
530 | if (!dwarf_diename(&type)) | ||
531 | return -ENOENT; | ||
532 | if (tag == DW_TAG_union_type) | ||
533 | tmp = "union "; | ||
534 | else if (tag == DW_TAG_structure_type) | ||
535 | tmp = "struct "; | ||
536 | /* Write a base name */ | ||
537 | ret = snprintf(buf, len, "%s%s", tmp, dwarf_diename(&type)); | ||
538 | return (ret >= len) ? -E2BIG : ret; | ||
539 | } | ||
540 | ret = die_get_typename(&type, buf, len); | ||
541 | if (ret > 0) { | ||
542 | ret2 = snprintf(buf + ret, len - ret, "%s", tmp); | ||
543 | ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret; | ||
544 | } | ||
545 | return ret; | ||
546 | } | ||
547 | |||
548 | /* Get the name and type of given variable DIE, stored as "type\tname" */ | ||
549 | static int die_get_varname(Dwarf_Die *vr_die, char *buf, int len) | ||
550 | { | ||
551 | int ret, ret2; | ||
552 | |||
553 | ret = die_get_typename(vr_die, buf, len); | ||
554 | if (ret < 0) { | ||
555 | pr_debug("Failed to get type, make it unknown.\n"); | ||
556 | ret = snprintf(buf, len, "(unknown_type)"); | ||
557 | } | ||
558 | if (ret > 0) { | ||
559 | ret2 = snprintf(buf + ret, len - ret, "\t%s", | ||
560 | dwarf_diename(vr_die)); | ||
561 | ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret; | ||
562 | } | ||
563 | return ret; | ||
564 | } | ||
565 | |||
364 | /* | 566 | /* |
365 | * Probe finder related functions | 567 | * Probe finder related functions |
366 | */ | 568 | */ |
@@ -374,8 +576,13 @@ static struct probe_trace_arg_ref *alloc_trace_arg_ref(long offs) | |||
374 | return ref; | 576 | return ref; |
375 | } | 577 | } |
376 | 578 | ||
377 | /* Show a location */ | 579 | /* |
378 | static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf) | 580 | * Convert a location into trace_arg. |
581 | * If tvar == NULL, this just checks variable can be converted. | ||
582 | */ | ||
583 | static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr, | ||
584 | Dwarf_Op *fb_ops, | ||
585 | struct probe_trace_arg *tvar) | ||
379 | { | 586 | { |
380 | Dwarf_Attribute attr; | 587 | Dwarf_Attribute attr; |
381 | Dwarf_Op *op; | 588 | Dwarf_Op *op; |
@@ -384,20 +591,23 @@ static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf) | |||
384 | Dwarf_Word offs = 0; | 591 | Dwarf_Word offs = 0; |
385 | bool ref = false; | 592 | bool ref = false; |
386 | const char *regs; | 593 | const char *regs; |
387 | struct probe_trace_arg *tvar = pf->tvar; | ||
388 | int ret; | 594 | int ret; |
389 | 595 | ||
596 | if (dwarf_attr(vr_die, DW_AT_external, &attr) != NULL) | ||
597 | goto static_var; | ||
598 | |||
390 | /* TODO: handle more than 1 exprs */ | 599 | /* TODO: handle more than 1 exprs */ |
391 | if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL || | 600 | if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL || |
392 | dwarf_getlocation_addr(&attr, pf->addr, &op, &nops, 1) <= 0 || | 601 | dwarf_getlocation_addr(&attr, addr, &op, &nops, 1) <= 0 || |
393 | nops == 0) { | 602 | nops == 0) { |
394 | /* TODO: Support const_value */ | 603 | /* TODO: Support const_value */ |
395 | pr_err("Failed to find the location of %s at this address.\n" | ||
396 | " Perhaps, it has been optimized out.\n", pf->pvar->var); | ||
397 | return -ENOENT; | 604 | return -ENOENT; |
398 | } | 605 | } |
399 | 606 | ||
400 | if (op->atom == DW_OP_addr) { | 607 | if (op->atom == DW_OP_addr) { |
608 | static_var: | ||
609 | if (!tvar) | ||
610 | return 0; | ||
401 | /* Static variables on memory (not stack), make @varname */ | 611 | /* Static variables on memory (not stack), make @varname */ |
402 | ret = strlen(dwarf_diename(vr_die)); | 612 | ret = strlen(dwarf_diename(vr_die)); |
403 | tvar->value = zalloc(ret + 2); | 613 | tvar->value = zalloc(ret + 2); |
@@ -412,14 +622,11 @@ static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf) | |||
412 | 622 | ||
413 | /* If this is based on frame buffer, set the offset */ | 623 | /* If this is based on frame buffer, set the offset */ |
414 | if (op->atom == DW_OP_fbreg) { | 624 | if (op->atom == DW_OP_fbreg) { |
415 | if (pf->fb_ops == NULL) { | 625 | if (fb_ops == NULL) |
416 | pr_warning("The attribute of frame base is not " | ||
417 | "supported.\n"); | ||
418 | return -ENOTSUP; | 626 | return -ENOTSUP; |
419 | } | ||
420 | ref = true; | 627 | ref = true; |
421 | offs = op->number; | 628 | offs = op->number; |
422 | op = &pf->fb_ops[0]; | 629 | op = &fb_ops[0]; |
423 | } | 630 | } |
424 | 631 | ||
425 | if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) { | 632 | if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) { |
@@ -435,13 +642,18 @@ static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf) | |||
435 | } else if (op->atom == DW_OP_regx) { | 642 | } else if (op->atom == DW_OP_regx) { |
436 | regn = op->number; | 643 | regn = op->number; |
437 | } else { | 644 | } else { |
438 | pr_warning("DW_OP %x is not supported.\n", op->atom); | 645 | pr_debug("DW_OP %x is not supported.\n", op->atom); |
439 | return -ENOTSUP; | 646 | return -ENOTSUP; |
440 | } | 647 | } |
441 | 648 | ||
649 | if (!tvar) | ||
650 | return 0; | ||
651 | |||
442 | regs = get_arch_regstr(regn); | 652 | regs = get_arch_regstr(regn); |
443 | if (!regs) { | 653 | if (!regs) { |
444 | pr_warning("Mapping for DWARF register number %u missing on this architecture.", regn); | 654 | /* This should be a bug in DWARF or this tool */ |
655 | pr_warning("Mapping for DWARF register number %u " | ||
656 | "missing on this architecture.", regn); | ||
445 | return -ERANGE; | 657 | return -ERANGE; |
446 | } | 658 | } |
447 | 659 | ||
@@ -666,8 +878,14 @@ static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf) | |||
666 | pr_debug("Converting variable %s into trace event.\n", | 878 | pr_debug("Converting variable %s into trace event.\n", |
667 | dwarf_diename(vr_die)); | 879 | dwarf_diename(vr_die)); |
668 | 880 | ||
669 | ret = convert_variable_location(vr_die, pf); | 881 | ret = convert_variable_location(vr_die, pf->addr, pf->fb_ops, |
670 | if (ret == 0 && pf->pvar->field) { | 882 | pf->tvar); |
883 | if (ret == -ENOENT) | ||
884 | pr_err("Failed to find the location of %s at this address.\n" | ||
885 | " Perhaps, it has been optimized out.\n", pf->pvar->var); | ||
886 | else if (ret == -ENOTSUP) | ||
887 | pr_err("Sorry, we don't support this variable location yet.\n"); | ||
888 | else if (pf->pvar->field) { | ||
671 | ret = convert_variable_fields(vr_die, pf->pvar->var, | 889 | ret = convert_variable_fields(vr_die, pf->pvar->var, |
672 | pf->pvar->field, &pf->tvar->ref, | 890 | pf->pvar->field, &pf->tvar->ref, |
673 | &die_mem); | 891 | &die_mem); |
@@ -722,56 +940,39 @@ static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
722 | pr_debug("Searching '%s' variable in context.\n", | 940 | pr_debug("Searching '%s' variable in context.\n", |
723 | pf->pvar->var); | 941 | pf->pvar->var); |
724 | /* Search child die for local variables and parameters. */ | 942 | /* Search child die for local variables and parameters. */ |
725 | if (die_find_variable(sp_die, pf->pvar->var, &vr_die)) | 943 | if (die_find_variable_at(sp_die, pf->pvar->var, pf->addr, &vr_die)) |
726 | ret = convert_variable(&vr_die, pf); | 944 | ret = convert_variable(&vr_die, pf); |
727 | else { | 945 | else { |
728 | /* Search upper class */ | 946 | /* Search upper class */ |
729 | nscopes = dwarf_getscopes_die(sp_die, &scopes); | 947 | nscopes = dwarf_getscopes_die(sp_die, &scopes); |
730 | if (nscopes > 0) { | 948 | while (nscopes-- > 1) { |
731 | ret = dwarf_getscopevar(scopes, nscopes, pf->pvar->var, | 949 | pr_debug("Searching variables in %s\n", |
732 | 0, NULL, 0, 0, &vr_die); | 950 | dwarf_diename(&scopes[nscopes])); |
733 | if (ret >= 0) | 951 | /* We should check this scope, so give dummy address */ |
952 | if (die_find_variable_at(&scopes[nscopes], | ||
953 | pf->pvar->var, 0, | ||
954 | &vr_die)) { | ||
734 | ret = convert_variable(&vr_die, pf); | 955 | ret = convert_variable(&vr_die, pf); |
735 | else | 956 | goto found; |
736 | ret = -ENOENT; | 957 | } |
958 | } | ||
959 | if (scopes) | ||
737 | free(scopes); | 960 | free(scopes); |
738 | } else | 961 | ret = -ENOENT; |
739 | ret = -ENOENT; | ||
740 | } | 962 | } |
963 | found: | ||
741 | if (ret < 0) | 964 | if (ret < 0) |
742 | pr_warning("Failed to find '%s' in this function.\n", | 965 | pr_warning("Failed to find '%s' in this function.\n", |
743 | pf->pvar->var); | 966 | pf->pvar->var); |
744 | return ret; | 967 | return ret; |
745 | } | 968 | } |
746 | 969 | ||
747 | /* Show a probe point to output buffer */ | 970 | /* Convert subprogram DIE to trace point */ |
748 | static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | 971 | static int convert_to_trace_point(Dwarf_Die *sp_die, Dwarf_Addr paddr, |
972 | bool retprobe, struct probe_trace_point *tp) | ||
749 | { | 973 | { |
750 | struct probe_trace_event *tev; | ||
751 | Dwarf_Addr eaddr; | 974 | Dwarf_Addr eaddr; |
752 | Dwarf_Die die_mem; | ||
753 | const char *name; | 975 | const char *name; |
754 | int ret, i; | ||
755 | Dwarf_Attribute fb_attr; | ||
756 | size_t nops; | ||
757 | |||
758 | if (pf->ntevs == pf->max_tevs) { | ||
759 | pr_warning("Too many( > %d) probe point found.\n", | ||
760 | pf->max_tevs); | ||
761 | return -ERANGE; | ||
762 | } | ||
763 | tev = &pf->tevs[pf->ntevs++]; | ||
764 | |||
765 | /* If no real subprogram, find a real one */ | ||
766 | if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) { | ||
767 | sp_die = die_find_real_subprogram(&pf->cu_die, | ||
768 | pf->addr, &die_mem); | ||
769 | if (!sp_die) { | ||
770 | pr_warning("Failed to find probe point in any " | ||
771 | "functions.\n"); | ||
772 | return -ENOENT; | ||
773 | } | ||
774 | } | ||
775 | 976 | ||
776 | /* Copy the name of probe point */ | 977 | /* Copy the name of probe point */ |
777 | name = dwarf_diename(sp_die); | 978 | name = dwarf_diename(sp_die); |
@@ -781,26 +982,45 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
781 | dwarf_diename(sp_die)); | 982 | dwarf_diename(sp_die)); |
782 | return -ENOENT; | 983 | return -ENOENT; |
783 | } | 984 | } |
784 | tev->point.symbol = strdup(name); | 985 | tp->symbol = strdup(name); |
785 | if (tev->point.symbol == NULL) | 986 | if (tp->symbol == NULL) |
786 | return -ENOMEM; | 987 | return -ENOMEM; |
787 | tev->point.offset = (unsigned long)(pf->addr - eaddr); | 988 | tp->offset = (unsigned long)(paddr - eaddr); |
788 | } else | 989 | } else |
789 | /* This function has no name. */ | 990 | /* This function has no name. */ |
790 | tev->point.offset = (unsigned long)pf->addr; | 991 | tp->offset = (unsigned long)paddr; |
791 | 992 | ||
792 | /* Return probe must be on the head of a subprogram */ | 993 | /* Return probe must be on the head of a subprogram */ |
793 | if (pf->pev->point.retprobe) { | 994 | if (retprobe) { |
794 | if (tev->point.offset != 0) { | 995 | if (eaddr != paddr) { |
795 | pr_warning("Return probe must be on the head of" | 996 | pr_warning("Return probe must be on the head of" |
796 | " a real function\n"); | 997 | " a real function\n"); |
797 | return -EINVAL; | 998 | return -EINVAL; |
798 | } | 999 | } |
799 | tev->point.retprobe = true; | 1000 | tp->retprobe = true; |
800 | } | 1001 | } |
801 | 1002 | ||
802 | pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, | 1003 | return 0; |
803 | tev->point.offset); | 1004 | } |
1005 | |||
1006 | /* Call probe_finder callback with real subprogram DIE */ | ||
1007 | static int call_probe_finder(Dwarf_Die *sp_die, struct probe_finder *pf) | ||
1008 | { | ||
1009 | Dwarf_Die die_mem; | ||
1010 | Dwarf_Attribute fb_attr; | ||
1011 | size_t nops; | ||
1012 | int ret; | ||
1013 | |||
1014 | /* If no real subprogram, find a real one */ | ||
1015 | if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) { | ||
1016 | sp_die = die_find_real_subprogram(&pf->cu_die, | ||
1017 | pf->addr, &die_mem); | ||
1018 | if (!sp_die) { | ||
1019 | pr_warning("Failed to find probe point in any " | ||
1020 | "functions.\n"); | ||
1021 | return -ENOENT; | ||
1022 | } | ||
1023 | } | ||
804 | 1024 | ||
805 | /* Get the frame base attribute/ops */ | 1025 | /* Get the frame base attribute/ops */ |
806 | dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr); | 1026 | dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr); |
@@ -820,22 +1040,13 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
820 | #endif | 1040 | #endif |
821 | } | 1041 | } |
822 | 1042 | ||
823 | /* Find each argument */ | 1043 | /* Call finder's callback handler */ |
824 | tev->nargs = pf->pev->nargs; | 1044 | ret = pf->callback(sp_die, pf); |
825 | tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); | ||
826 | if (tev->args == NULL) | ||
827 | return -ENOMEM; | ||
828 | for (i = 0; i < pf->pev->nargs; i++) { | ||
829 | pf->pvar = &pf->pev->args[i]; | ||
830 | pf->tvar = &tev->args[i]; | ||
831 | ret = find_variable(sp_die, pf); | ||
832 | if (ret != 0) | ||
833 | return ret; | ||
834 | } | ||
835 | 1045 | ||
836 | /* *pf->fb_ops will be cached in libdw. Don't free it. */ | 1046 | /* *pf->fb_ops will be cached in libdw. Don't free it. */ |
837 | pf->fb_ops = NULL; | 1047 | pf->fb_ops = NULL; |
838 | return 0; | 1048 | |
1049 | return ret; | ||
839 | } | 1050 | } |
840 | 1051 | ||
841 | /* Find probe point from its line number */ | 1052 | /* Find probe point from its line number */ |
@@ -871,7 +1082,7 @@ static int find_probe_point_by_line(struct probe_finder *pf) | |||
871 | (int)i, lineno, (uintmax_t)addr); | 1082 | (int)i, lineno, (uintmax_t)addr); |
872 | pf->addr = addr; | 1083 | pf->addr = addr; |
873 | 1084 | ||
874 | ret = convert_probe_point(NULL, pf); | 1085 | ret = call_probe_finder(NULL, pf); |
875 | /* Continuing, because target line might be inlined. */ | 1086 | /* Continuing, because target line might be inlined. */ |
876 | } | 1087 | } |
877 | return ret; | 1088 | return ret; |
@@ -984,7 +1195,7 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
984 | (int)i, lineno, (unsigned long long)addr); | 1195 | (int)i, lineno, (unsigned long long)addr); |
985 | pf->addr = addr; | 1196 | pf->addr = addr; |
986 | 1197 | ||
987 | ret = convert_probe_point(sp_die, pf); | 1198 | ret = call_probe_finder(sp_die, pf); |
988 | /* Continuing, because target line might be inlined. */ | 1199 | /* Continuing, because target line might be inlined. */ |
989 | } | 1200 | } |
990 | /* TODO: deallocate lines, but how? */ | 1201 | /* TODO: deallocate lines, but how? */ |
@@ -1019,7 +1230,7 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) | |||
1019 | pr_debug("found inline addr: 0x%jx\n", | 1230 | pr_debug("found inline addr: 0x%jx\n", |
1020 | (uintmax_t)pf->addr); | 1231 | (uintmax_t)pf->addr); |
1021 | 1232 | ||
1022 | param->retval = convert_probe_point(in_die, pf); | 1233 | param->retval = call_probe_finder(in_die, pf); |
1023 | if (param->retval < 0) | 1234 | if (param->retval < 0) |
1024 | return DWARF_CB_ABORT; | 1235 | return DWARF_CB_ABORT; |
1025 | } | 1236 | } |
@@ -1057,7 +1268,7 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data) | |||
1057 | } | 1268 | } |
1058 | pf->addr += pp->offset; | 1269 | pf->addr += pp->offset; |
1059 | /* TODO: Check the address in this function */ | 1270 | /* TODO: Check the address in this function */ |
1060 | param->retval = convert_probe_point(sp_die, pf); | 1271 | param->retval = call_probe_finder(sp_die, pf); |
1061 | } | 1272 | } |
1062 | } else { | 1273 | } else { |
1063 | struct dwarf_callback_param _param = {.data = (void *)pf, | 1274 | struct dwarf_callback_param _param = {.data = (void *)pf, |
@@ -1079,90 +1290,276 @@ static int find_probe_point_by_func(struct probe_finder *pf) | |||
1079 | return _param.retval; | 1290 | return _param.retval; |
1080 | } | 1291 | } |
1081 | 1292 | ||
1082 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ | 1293 | /* Find probe points from debuginfo */ |
1083 | int find_probe_trace_events(int fd, struct perf_probe_event *pev, | 1294 | static int find_probes(int fd, struct probe_finder *pf) |
1084 | struct probe_trace_event **tevs, int max_tevs) | ||
1085 | { | 1295 | { |
1086 | struct probe_finder pf = {.pev = pev, .max_tevs = max_tevs}; | 1296 | struct perf_probe_point *pp = &pf->pev->point; |
1087 | struct perf_probe_point *pp = &pev->point; | ||
1088 | Dwarf_Off off, noff; | 1297 | Dwarf_Off off, noff; |
1089 | size_t cuhl; | 1298 | size_t cuhl; |
1090 | Dwarf_Die *diep; | 1299 | Dwarf_Die *diep; |
1091 | Dwarf *dbg; | 1300 | Dwarf *dbg = NULL; |
1301 | Dwfl *dwfl; | ||
1302 | Dwarf_Addr bias; /* Currently ignored */ | ||
1092 | int ret = 0; | 1303 | int ret = 0; |
1093 | 1304 | ||
1094 | pf.tevs = zalloc(sizeof(struct probe_trace_event) * max_tevs); | 1305 | dbg = dwfl_init_offline_dwarf(fd, &dwfl, &bias); |
1095 | if (pf.tevs == NULL) | ||
1096 | return -ENOMEM; | ||
1097 | *tevs = pf.tevs; | ||
1098 | pf.ntevs = 0; | ||
1099 | |||
1100 | dbg = dwarf_begin(fd, DWARF_C_READ); | ||
1101 | if (!dbg) { | 1306 | if (!dbg) { |
1102 | pr_warning("No dwarf info found in the vmlinux - " | 1307 | pr_warning("No dwarf info found in the vmlinux - " |
1103 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | 1308 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
1104 | free(pf.tevs); | ||
1105 | *tevs = NULL; | ||
1106 | return -EBADF; | 1309 | return -EBADF; |
1107 | } | 1310 | } |
1108 | 1311 | ||
1109 | #if _ELFUTILS_PREREQ(0, 142) | 1312 | #if _ELFUTILS_PREREQ(0, 142) |
1110 | /* Get the call frame information from this dwarf */ | 1313 | /* Get the call frame information from this dwarf */ |
1111 | pf.cfi = dwarf_getcfi(dbg); | 1314 | pf->cfi = dwarf_getcfi(dbg); |
1112 | #endif | 1315 | #endif |
1113 | 1316 | ||
1114 | off = 0; | 1317 | off = 0; |
1115 | line_list__init(&pf.lcache); | 1318 | line_list__init(&pf->lcache); |
1116 | /* Loop on CUs (Compilation Unit) */ | 1319 | /* Loop on CUs (Compilation Unit) */ |
1117 | while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) && | 1320 | while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) && |
1118 | ret >= 0) { | 1321 | ret >= 0) { |
1119 | /* Get the DIE(Debugging Information Entry) of this CU */ | 1322 | /* Get the DIE(Debugging Information Entry) of this CU */ |
1120 | diep = dwarf_offdie(dbg, off + cuhl, &pf.cu_die); | 1323 | diep = dwarf_offdie(dbg, off + cuhl, &pf->cu_die); |
1121 | if (!diep) | 1324 | if (!diep) |
1122 | continue; | 1325 | continue; |
1123 | 1326 | ||
1124 | /* Check if target file is included. */ | 1327 | /* Check if target file is included. */ |
1125 | if (pp->file) | 1328 | if (pp->file) |
1126 | pf.fname = cu_find_realpath(&pf.cu_die, pp->file); | 1329 | pf->fname = cu_find_realpath(&pf->cu_die, pp->file); |
1127 | else | 1330 | else |
1128 | pf.fname = NULL; | 1331 | pf->fname = NULL; |
1129 | 1332 | ||
1130 | if (!pp->file || pf.fname) { | 1333 | if (!pp->file || pf->fname) { |
1131 | if (pp->function) | 1334 | if (pp->function) |
1132 | ret = find_probe_point_by_func(&pf); | 1335 | ret = find_probe_point_by_func(pf); |
1133 | else if (pp->lazy_line) | 1336 | else if (pp->lazy_line) |
1134 | ret = find_probe_point_lazy(NULL, &pf); | 1337 | ret = find_probe_point_lazy(NULL, pf); |
1135 | else { | 1338 | else { |
1136 | pf.lno = pp->line; | 1339 | pf->lno = pp->line; |
1137 | ret = find_probe_point_by_line(&pf); | 1340 | ret = find_probe_point_by_line(pf); |
1138 | } | 1341 | } |
1139 | } | 1342 | } |
1140 | off = noff; | 1343 | off = noff; |
1141 | } | 1344 | } |
1142 | line_list__free(&pf.lcache); | 1345 | line_list__free(&pf->lcache); |
1143 | dwarf_end(dbg); | 1346 | if (dwfl) |
1347 | dwfl_end(dwfl); | ||
1348 | |||
1349 | return ret; | ||
1350 | } | ||
1351 | |||
1352 | /* Add a found probe point into trace event list */ | ||
1353 | static int add_probe_trace_event(Dwarf_Die *sp_die, struct probe_finder *pf) | ||
1354 | { | ||
1355 | struct trace_event_finder *tf = | ||
1356 | container_of(pf, struct trace_event_finder, pf); | ||
1357 | struct probe_trace_event *tev; | ||
1358 | int ret, i; | ||
1144 | 1359 | ||
1145 | return (ret < 0) ? ret : pf.ntevs; | 1360 | /* Check number of tevs */ |
1361 | if (tf->ntevs == tf->max_tevs) { | ||
1362 | pr_warning("Too many( > %d) probe point found.\n", | ||
1363 | tf->max_tevs); | ||
1364 | return -ERANGE; | ||
1365 | } | ||
1366 | tev = &tf->tevs[tf->ntevs++]; | ||
1367 | |||
1368 | ret = convert_to_trace_point(sp_die, pf->addr, pf->pev->point.retprobe, | ||
1369 | &tev->point); | ||
1370 | if (ret < 0) | ||
1371 | return ret; | ||
1372 | |||
1373 | pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, | ||
1374 | tev->point.offset); | ||
1375 | |||
1376 | /* Find each argument */ | ||
1377 | tev->nargs = pf->pev->nargs; | ||
1378 | tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs); | ||
1379 | if (tev->args == NULL) | ||
1380 | return -ENOMEM; | ||
1381 | for (i = 0; i < pf->pev->nargs; i++) { | ||
1382 | pf->pvar = &pf->pev->args[i]; | ||
1383 | pf->tvar = &tev->args[i]; | ||
1384 | ret = find_variable(sp_die, pf); | ||
1385 | if (ret != 0) | ||
1386 | return ret; | ||
1387 | } | ||
1388 | |||
1389 | return 0; | ||
1390 | } | ||
1391 | |||
1392 | /* Find probe_trace_events specified by perf_probe_event from debuginfo */ | ||
1393 | int find_probe_trace_events(int fd, struct perf_probe_event *pev, | ||
1394 | struct probe_trace_event **tevs, int max_tevs) | ||
1395 | { | ||
1396 | struct trace_event_finder tf = { | ||
1397 | .pf = {.pev = pev, .callback = add_probe_trace_event}, | ||
1398 | .max_tevs = max_tevs}; | ||
1399 | int ret; | ||
1400 | |||
1401 | /* Allocate result tevs array */ | ||
1402 | *tevs = zalloc(sizeof(struct probe_trace_event) * max_tevs); | ||
1403 | if (*tevs == NULL) | ||
1404 | return -ENOMEM; | ||
1405 | |||
1406 | tf.tevs = *tevs; | ||
1407 | tf.ntevs = 0; | ||
1408 | |||
1409 | ret = find_probes(fd, &tf.pf); | ||
1410 | if (ret < 0) { | ||
1411 | free(*tevs); | ||
1412 | *tevs = NULL; | ||
1413 | return ret; | ||
1414 | } | ||
1415 | |||
1416 | return (ret < 0) ? ret : tf.ntevs; | ||
1417 | } | ||
1418 | |||
1419 | #define MAX_VAR_LEN 64 | ||
1420 | |||
1421 | /* Collect available variables in this scope */ | ||
1422 | static int collect_variables_cb(Dwarf_Die *die_mem, void *data) | ||
1423 | { | ||
1424 | struct available_var_finder *af = data; | ||
1425 | struct variable_list *vl; | ||
1426 | char buf[MAX_VAR_LEN]; | ||
1427 | int tag, ret; | ||
1428 | |||
1429 | vl = &af->vls[af->nvls - 1]; | ||
1430 | |||
1431 | tag = dwarf_tag(die_mem); | ||
1432 | if (tag == DW_TAG_formal_parameter || | ||
1433 | tag == DW_TAG_variable) { | ||
1434 | ret = convert_variable_location(die_mem, af->pf.addr, | ||
1435 | af->pf.fb_ops, NULL); | ||
1436 | if (ret == 0) { | ||
1437 | ret = die_get_varname(die_mem, buf, MAX_VAR_LEN); | ||
1438 | pr_debug2("Add new var: %s\n", buf); | ||
1439 | if (ret > 0) | ||
1440 | strlist__add(vl->vars, buf); | ||
1441 | } | ||
1442 | } | ||
1443 | |||
1444 | if (af->child && dwarf_haspc(die_mem, af->pf.addr)) | ||
1445 | return DIE_FIND_CB_CONTINUE; | ||
1446 | else | ||
1447 | return DIE_FIND_CB_SIBLING; | ||
1448 | } | ||
1449 | |||
1450 | /* Add a found vars into available variables list */ | ||
1451 | static int add_available_vars(Dwarf_Die *sp_die, struct probe_finder *pf) | ||
1452 | { | ||
1453 | struct available_var_finder *af = | ||
1454 | container_of(pf, struct available_var_finder, pf); | ||
1455 | struct variable_list *vl; | ||
1456 | Dwarf_Die die_mem, *scopes = NULL; | ||
1457 | int ret, nscopes; | ||
1458 | |||
1459 | /* Check number of tevs */ | ||
1460 | if (af->nvls == af->max_vls) { | ||
1461 | pr_warning("Too many( > %d) probe point found.\n", af->max_vls); | ||
1462 | return -ERANGE; | ||
1463 | } | ||
1464 | vl = &af->vls[af->nvls++]; | ||
1465 | |||
1466 | ret = convert_to_trace_point(sp_die, pf->addr, pf->pev->point.retprobe, | ||
1467 | &vl->point); | ||
1468 | if (ret < 0) | ||
1469 | return ret; | ||
1470 | |||
1471 | pr_debug("Probe point found: %s+%lu\n", vl->point.symbol, | ||
1472 | vl->point.offset); | ||
1473 | |||
1474 | /* Find local variables */ | ||
1475 | vl->vars = strlist__new(true, NULL); | ||
1476 | if (vl->vars == NULL) | ||
1477 | return -ENOMEM; | ||
1478 | af->child = true; | ||
1479 | die_find_child(sp_die, collect_variables_cb, (void *)af, &die_mem); | ||
1480 | |||
1481 | /* Find external variables */ | ||
1482 | if (!af->externs) | ||
1483 | goto out; | ||
1484 | /* Don't need to search child DIE for externs. */ | ||
1485 | af->child = false; | ||
1486 | nscopes = dwarf_getscopes_die(sp_die, &scopes); | ||
1487 | while (nscopes-- > 1) | ||
1488 | die_find_child(&scopes[nscopes], collect_variables_cb, | ||
1489 | (void *)af, &die_mem); | ||
1490 | if (scopes) | ||
1491 | free(scopes); | ||
1492 | |||
1493 | out: | ||
1494 | if (strlist__empty(vl->vars)) { | ||
1495 | strlist__delete(vl->vars); | ||
1496 | vl->vars = NULL; | ||
1497 | } | ||
1498 | |||
1499 | return ret; | ||
1500 | } | ||
1501 | |||
1502 | /* Find available variables at given probe point */ | ||
1503 | int find_available_vars_at(int fd, struct perf_probe_event *pev, | ||
1504 | struct variable_list **vls, int max_vls, | ||
1505 | bool externs) | ||
1506 | { | ||
1507 | struct available_var_finder af = { | ||
1508 | .pf = {.pev = pev, .callback = add_available_vars}, | ||
1509 | .max_vls = max_vls, .externs = externs}; | ||
1510 | int ret; | ||
1511 | |||
1512 | /* Allocate result vls array */ | ||
1513 | *vls = zalloc(sizeof(struct variable_list) * max_vls); | ||
1514 | if (*vls == NULL) | ||
1515 | return -ENOMEM; | ||
1516 | |||
1517 | af.vls = *vls; | ||
1518 | af.nvls = 0; | ||
1519 | |||
1520 | ret = find_probes(fd, &af.pf); | ||
1521 | if (ret < 0) { | ||
1522 | /* Free vlist for error */ | ||
1523 | while (af.nvls--) { | ||
1524 | if (af.vls[af.nvls].point.symbol) | ||
1525 | free(af.vls[af.nvls].point.symbol); | ||
1526 | if (af.vls[af.nvls].vars) | ||
1527 | strlist__delete(af.vls[af.nvls].vars); | ||
1528 | } | ||
1529 | free(af.vls); | ||
1530 | *vls = NULL; | ||
1531 | return ret; | ||
1532 | } | ||
1533 | |||
1534 | return (ret < 0) ? ret : af.nvls; | ||
1146 | } | 1535 | } |
1147 | 1536 | ||
1148 | /* Reverse search */ | 1537 | /* Reverse search */ |
1149 | int find_perf_probe_point(int fd, unsigned long addr, | 1538 | int find_perf_probe_point(unsigned long addr, struct perf_probe_point *ppt) |
1150 | struct perf_probe_point *ppt) | ||
1151 | { | 1539 | { |
1152 | Dwarf_Die cudie, spdie, indie; | 1540 | Dwarf_Die cudie, spdie, indie; |
1153 | Dwarf *dbg; | 1541 | Dwarf *dbg = NULL; |
1542 | Dwfl *dwfl = NULL; | ||
1154 | Dwarf_Line *line; | 1543 | Dwarf_Line *line; |
1155 | Dwarf_Addr laddr, eaddr; | 1544 | Dwarf_Addr laddr, eaddr, bias = 0; |
1156 | const char *tmp; | 1545 | const char *tmp; |
1157 | int lineno, ret = 0; | 1546 | int lineno, ret = 0; |
1158 | bool found = false; | 1547 | bool found = false; |
1159 | 1548 | ||
1160 | dbg = dwarf_begin(fd, DWARF_C_READ); | 1549 | /* Open the live linux kernel */ |
1161 | if (!dbg) | 1550 | dbg = dwfl_init_live_kernel_dwarf(addr, &dwfl, &bias); |
1162 | return -EBADF; | 1551 | if (!dbg) { |
1552 | pr_warning("No dwarf info found in the vmlinux - " | ||
1553 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | ||
1554 | ret = -EINVAL; | ||
1555 | goto end; | ||
1556 | } | ||
1163 | 1557 | ||
1558 | /* Adjust address with bias */ | ||
1559 | addr += bias; | ||
1164 | /* Find cu die */ | 1560 | /* Find cu die */ |
1165 | if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr, &cudie)) { | 1561 | if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr - bias, &cudie)) { |
1562 | pr_warning("No CU DIE is found at %lx\n", addr); | ||
1166 | ret = -EINVAL; | 1563 | ret = -EINVAL; |
1167 | goto end; | 1564 | goto end; |
1168 | } | 1565 | } |
@@ -1225,7 +1622,8 @@ found: | |||
1225 | } | 1622 | } |
1226 | 1623 | ||
1227 | end: | 1624 | end: |
1228 | dwarf_end(dbg); | 1625 | if (dwfl) |
1626 | dwfl_end(dwfl); | ||
1229 | if (ret >= 0) | 1627 | if (ret >= 0) |
1230 | ret = found ? 1 : 0; | 1628 | ret = found ? 1 : 0; |
1231 | return ret; | 1629 | return ret; |
@@ -1358,6 +1756,9 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data) | |||
1358 | struct line_finder *lf = param->data; | 1756 | struct line_finder *lf = param->data; |
1359 | struct line_range *lr = lf->lr; | 1757 | struct line_range *lr = lf->lr; |
1360 | 1758 | ||
1759 | pr_debug("find (%llx) %s\n", | ||
1760 | (unsigned long long)dwarf_dieoffset(sp_die), | ||
1761 | dwarf_diename(sp_die)); | ||
1361 | if (dwarf_tag(sp_die) == DW_TAG_subprogram && | 1762 | if (dwarf_tag(sp_die) == DW_TAG_subprogram && |
1362 | die_compare_name(sp_die, lr->function)) { | 1763 | die_compare_name(sp_die, lr->function)) { |
1363 | lf->fname = dwarf_decl_file(sp_die); | 1764 | lf->fname = dwarf_decl_file(sp_die); |
@@ -1401,10 +1802,12 @@ int find_line_range(int fd, struct line_range *lr) | |||
1401 | Dwarf_Off off = 0, noff; | 1802 | Dwarf_Off off = 0, noff; |
1402 | size_t cuhl; | 1803 | size_t cuhl; |
1403 | Dwarf_Die *diep; | 1804 | Dwarf_Die *diep; |
1404 | Dwarf *dbg; | 1805 | Dwarf *dbg = NULL; |
1806 | Dwfl *dwfl; | ||
1807 | Dwarf_Addr bias; /* Currently ignored */ | ||
1405 | const char *comp_dir; | 1808 | const char *comp_dir; |
1406 | 1809 | ||
1407 | dbg = dwarf_begin(fd, DWARF_C_READ); | 1810 | dbg = dwfl_init_offline_dwarf(fd, &dwfl, &bias); |
1408 | if (!dbg) { | 1811 | if (!dbg) { |
1409 | pr_warning("No dwarf info found in the vmlinux - " | 1812 | pr_warning("No dwarf info found in the vmlinux - " |
1410 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | 1813 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
@@ -1450,8 +1853,7 @@ int find_line_range(int fd, struct line_range *lr) | |||
1450 | } | 1853 | } |
1451 | 1854 | ||
1452 | pr_debug("path: %s\n", lr->path); | 1855 | pr_debug("path: %s\n", lr->path); |
1453 | dwarf_end(dbg); | 1856 | dwfl_end(dwfl); |
1454 | |||
1455 | return (ret < 0) ? ret : lf.found; | 1857 | return (ret < 0) ? ret : lf.found; |
1456 | } | 1858 | } |
1457 | 1859 | ||
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index 4507d519f183..bba69d455699 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h | |||
@@ -22,20 +22,27 @@ extern int find_probe_trace_events(int fd, struct perf_probe_event *pev, | |||
22 | int max_tevs); | 22 | int max_tevs); |
23 | 23 | ||
24 | /* Find a perf_probe_point from debuginfo */ | 24 | /* Find a perf_probe_point from debuginfo */ |
25 | extern int find_perf_probe_point(int fd, unsigned long addr, | 25 | extern int find_perf_probe_point(unsigned long addr, |
26 | struct perf_probe_point *ppt); | 26 | struct perf_probe_point *ppt); |
27 | 27 | ||
28 | /* Find a line range */ | ||
28 | extern int find_line_range(int fd, struct line_range *lr); | 29 | extern int find_line_range(int fd, struct line_range *lr); |
29 | 30 | ||
31 | /* Find available variables */ | ||
32 | extern int find_available_vars_at(int fd, struct perf_probe_event *pev, | ||
33 | struct variable_list **vls, int max_points, | ||
34 | bool externs); | ||
35 | |||
30 | #include <dwarf.h> | 36 | #include <dwarf.h> |
31 | #include <libdw.h> | 37 | #include <libdw.h> |
38 | #include <libdwfl.h> | ||
32 | #include <version.h> | 39 | #include <version.h> |
33 | 40 | ||
34 | struct probe_finder { | 41 | struct probe_finder { |
35 | struct perf_probe_event *pev; /* Target probe event */ | 42 | struct perf_probe_event *pev; /* Target probe event */ |
36 | struct probe_trace_event *tevs; /* Result trace events */ | 43 | |
37 | int ntevs; /* Number of trace events */ | 44 | /* Callback when a probe point is found */ |
38 | int max_tevs; /* Max number of trace events */ | 45 | int (*callback)(Dwarf_Die *sp_die, struct probe_finder *pf); |
39 | 46 | ||
40 | /* For function searching */ | 47 | /* For function searching */ |
41 | int lno; /* Line number */ | 48 | int lno; /* Line number */ |
@@ -53,6 +60,22 @@ struct probe_finder { | |||
53 | struct probe_trace_arg *tvar; /* Current result variable */ | 60 | struct probe_trace_arg *tvar; /* Current result variable */ |
54 | }; | 61 | }; |
55 | 62 | ||
63 | struct trace_event_finder { | ||
64 | struct probe_finder pf; | ||
65 | struct probe_trace_event *tevs; /* Found trace events */ | ||
66 | int ntevs; /* Number of trace events */ | ||
67 | int max_tevs; /* Max number of trace events */ | ||
68 | }; | ||
69 | |||
70 | struct available_var_finder { | ||
71 | struct probe_finder pf; | ||
72 | struct variable_list *vls; /* Found variable lists */ | ||
73 | int nvls; /* Number of variable lists */ | ||
74 | int max_vls; /* Max no. of variable lists */ | ||
75 | bool externs; /* Find external vars too */ | ||
76 | bool child; /* Search child scopes */ | ||
77 | }; | ||
78 | |||
56 | struct line_finder { | 79 | struct line_finder { |
57 | struct line_range *lr; /* Target line range */ | 80 | struct line_range *lr; /* Target line range */ |
58 | 81 | ||
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index 46e531d09e8b..0b91053a7d11 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h | |||
@@ -70,7 +70,7 @@ struct hist_entry { | |||
70 | struct hist_entry *pair; | 70 | struct hist_entry *pair; |
71 | struct rb_root sorted_chain; | 71 | struct rb_root sorted_chain; |
72 | }; | 72 | }; |
73 | struct callchain_node callchain[0]; | 73 | struct callchain_root callchain[0]; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | enum sort_type { | 76 | enum sort_type { |
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index 0409fc7c0058..8fc0bd3a3a4a 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c | |||
@@ -259,7 +259,7 @@ static bool __match_glob(const char *str, const char *pat, bool ignore_space) | |||
259 | if (!*pat) /* Tail wild card matches all */ | 259 | if (!*pat) /* Tail wild card matches all */ |
260 | return true; | 260 | return true; |
261 | while (*str) | 261 | while (*str) |
262 | if (strglobmatch(str++, pat)) | 262 | if (__match_glob(str++, pat, ignore_space)) |
263 | return true; | 263 | return true; |
264 | } | 264 | } |
265 | return !*str && !*pat; | 265 | return !*str && !*pat; |
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index b2f5ae97f33d..439ab947daf4 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -295,7 +295,9 @@ static void symbols__insert_by_name(struct rb_root *self, struct symbol *sym) | |||
295 | { | 295 | { |
296 | struct rb_node **p = &self->rb_node; | 296 | struct rb_node **p = &self->rb_node; |
297 | struct rb_node *parent = NULL; | 297 | struct rb_node *parent = NULL; |
298 | struct symbol_name_rb_node *symn = ((void *)sym) - sizeof(*parent), *s; | 298 | struct symbol_name_rb_node *symn, *s; |
299 | |||
300 | symn = container_of(sym, struct symbol_name_rb_node, sym); | ||
299 | 301 | ||
300 | while (*p != NULL) { | 302 | while (*p != NULL) { |
301 | parent = *p; | 303 | parent = *p; |
@@ -388,6 +390,20 @@ size_t dso__fprintf_buildid(struct dso *self, FILE *fp) | |||
388 | return fprintf(fp, "%s", sbuild_id); | 390 | return fprintf(fp, "%s", sbuild_id); |
389 | } | 391 | } |
390 | 392 | ||
393 | size_t dso__fprintf_symbols_by_name(struct dso *self, enum map_type type, FILE *fp) | ||
394 | { | ||
395 | size_t ret = 0; | ||
396 | struct rb_node *nd; | ||
397 | struct symbol_name_rb_node *pos; | ||
398 | |||
399 | for (nd = rb_first(&self->symbol_names[type]); nd; nd = rb_next(nd)) { | ||
400 | pos = rb_entry(nd, struct symbol_name_rb_node, rb_node); | ||
401 | fprintf(fp, "%s\n", pos->sym.name); | ||
402 | } | ||
403 | |||
404 | return ret; | ||
405 | } | ||
406 | |||
391 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp) | 407 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp) |
392 | { | 408 | { |
393 | struct rb_node *nd; | 409 | struct rb_node *nd; |
@@ -516,7 +532,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map, | |||
516 | struct machine *machine = kmaps->machine; | 532 | struct machine *machine = kmaps->machine; |
517 | struct map *curr_map = map; | 533 | struct map *curr_map = map; |
518 | struct symbol *pos; | 534 | struct symbol *pos; |
519 | int count = 0; | 535 | int count = 0, moved = 0; |
520 | struct rb_root *root = &self->symbols[map->type]; | 536 | struct rb_root *root = &self->symbols[map->type]; |
521 | struct rb_node *next = rb_first(root); | 537 | struct rb_node *next = rb_first(root); |
522 | int kernel_range = 0; | 538 | int kernel_range = 0; |
@@ -574,6 +590,11 @@ static int dso__split_kallsyms(struct dso *self, struct map *map, | |||
574 | char dso_name[PATH_MAX]; | 590 | char dso_name[PATH_MAX]; |
575 | struct dso *dso; | 591 | struct dso *dso; |
576 | 592 | ||
593 | if (count == 0) { | ||
594 | curr_map = map; | ||
595 | goto filter_symbol; | ||
596 | } | ||
597 | |||
577 | if (self->kernel == DSO_TYPE_GUEST_KERNEL) | 598 | if (self->kernel == DSO_TYPE_GUEST_KERNEL) |
578 | snprintf(dso_name, sizeof(dso_name), | 599 | snprintf(dso_name, sizeof(dso_name), |
579 | "[guest.kernel].%d", | 600 | "[guest.kernel].%d", |
@@ -599,7 +620,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map, | |||
599 | map_groups__insert(kmaps, curr_map); | 620 | map_groups__insert(kmaps, curr_map); |
600 | ++kernel_range; | 621 | ++kernel_range; |
601 | } | 622 | } |
602 | 623 | filter_symbol: | |
603 | if (filter && filter(curr_map, pos)) { | 624 | if (filter && filter(curr_map, pos)) { |
604 | discard_symbol: rb_erase(&pos->rb_node, root); | 625 | discard_symbol: rb_erase(&pos->rb_node, root); |
605 | symbol__delete(pos); | 626 | symbol__delete(pos); |
@@ -607,8 +628,9 @@ discard_symbol: rb_erase(&pos->rb_node, root); | |||
607 | if (curr_map != map) { | 628 | if (curr_map != map) { |
608 | rb_erase(&pos->rb_node, root); | 629 | rb_erase(&pos->rb_node, root); |
609 | symbols__insert(&curr_map->dso->symbols[curr_map->type], pos); | 630 | symbols__insert(&curr_map->dso->symbols[curr_map->type], pos); |
610 | } | 631 | ++moved; |
611 | count++; | 632 | } else |
633 | ++count; | ||
612 | } | 634 | } |
613 | } | 635 | } |
614 | 636 | ||
@@ -618,7 +640,7 @@ discard_symbol: rb_erase(&pos->rb_node, root); | |||
618 | dso__set_loaded(curr_map->dso, curr_map->type); | 640 | dso__set_loaded(curr_map->dso, curr_map->type); |
619 | } | 641 | } |
620 | 642 | ||
621 | return count; | 643 | return count + moved; |
622 | } | 644 | } |
623 | 645 | ||
624 | int dso__load_kallsyms(struct dso *self, const char *filename, | 646 | int dso__load_kallsyms(struct dso *self, const char *filename, |
@@ -1758,8 +1780,8 @@ out_failure: | |||
1758 | return -1; | 1780 | return -1; |
1759 | } | 1781 | } |
1760 | 1782 | ||
1761 | static int dso__load_vmlinux(struct dso *self, struct map *map, | 1783 | int dso__load_vmlinux(struct dso *self, struct map *map, |
1762 | const char *vmlinux, symbol_filter_t filter) | 1784 | const char *vmlinux, symbol_filter_t filter) |
1763 | { | 1785 | { |
1764 | int err = -1, fd; | 1786 | int err = -1, fd; |
1765 | 1787 | ||
@@ -2109,14 +2131,55 @@ static struct dso *machine__create_kernel(struct machine *self) | |||
2109 | return kernel; | 2131 | return kernel; |
2110 | } | 2132 | } |
2111 | 2133 | ||
2134 | struct process_args { | ||
2135 | u64 start; | ||
2136 | }; | ||
2137 | |||
2138 | static int symbol__in_kernel(void *arg, const char *name, | ||
2139 | char type __used, u64 start) | ||
2140 | { | ||
2141 | struct process_args *args = arg; | ||
2142 | |||
2143 | if (strchr(name, '[')) | ||
2144 | return 0; | ||
2145 | |||
2146 | args->start = start; | ||
2147 | return 1; | ||
2148 | } | ||
2149 | |||
2150 | /* Figure out the start address of kernel map from /proc/kallsyms */ | ||
2151 | static u64 machine__get_kernel_start_addr(struct machine *machine) | ||
2152 | { | ||
2153 | const char *filename; | ||
2154 | char path[PATH_MAX]; | ||
2155 | struct process_args args; | ||
2156 | |||
2157 | if (machine__is_host(machine)) { | ||
2158 | filename = "/proc/kallsyms"; | ||
2159 | } else { | ||
2160 | if (machine__is_default_guest(machine)) | ||
2161 | filename = (char *)symbol_conf.default_guest_kallsyms; | ||
2162 | else { | ||
2163 | sprintf(path, "%s/proc/kallsyms", machine->root_dir); | ||
2164 | filename = path; | ||
2165 | } | ||
2166 | } | ||
2167 | |||
2168 | if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0) | ||
2169 | return 0; | ||
2170 | |||
2171 | return args.start; | ||
2172 | } | ||
2173 | |||
2112 | int __machine__create_kernel_maps(struct machine *self, struct dso *kernel) | 2174 | int __machine__create_kernel_maps(struct machine *self, struct dso *kernel) |
2113 | { | 2175 | { |
2114 | enum map_type type; | 2176 | enum map_type type; |
2177 | u64 start = machine__get_kernel_start_addr(self); | ||
2115 | 2178 | ||
2116 | for (type = 0; type < MAP__NR_TYPES; ++type) { | 2179 | for (type = 0; type < MAP__NR_TYPES; ++type) { |
2117 | struct kmap *kmap; | 2180 | struct kmap *kmap; |
2118 | 2181 | ||
2119 | self->vmlinux_maps[type] = map__new2(0, kernel, type); | 2182 | self->vmlinux_maps[type] = map__new2(start, kernel, type); |
2120 | if (self->vmlinux_maps[type] == NULL) | 2183 | if (self->vmlinux_maps[type] == NULL) |
2121 | return -1; | 2184 | return -1; |
2122 | 2185 | ||
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index ea95c2756f05..6c6eafdb932d 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -166,6 +166,8 @@ void dso__sort_by_name(struct dso *self, enum map_type type); | |||
166 | struct dso *__dsos__findnew(struct list_head *head, const char *name); | 166 | struct dso *__dsos__findnew(struct list_head *head, const char *name); |
167 | 167 | ||
168 | int dso__load(struct dso *self, struct map *map, symbol_filter_t filter); | 168 | int dso__load(struct dso *self, struct map *map, symbol_filter_t filter); |
169 | int dso__load_vmlinux(struct dso *self, struct map *map, | ||
170 | const char *vmlinux, symbol_filter_t filter); | ||
169 | int dso__load_vmlinux_path(struct dso *self, struct map *map, | 171 | int dso__load_vmlinux_path(struct dso *self, struct map *map, |
170 | symbol_filter_t filter); | 172 | symbol_filter_t filter); |
171 | int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map, | 173 | int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map, |
@@ -182,6 +184,7 @@ size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp); | |||
182 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits); | 184 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits); |
183 | 185 | ||
184 | size_t dso__fprintf_buildid(struct dso *self, FILE *fp); | 186 | size_t dso__fprintf_buildid(struct dso *self, FILE *fp); |
187 | size_t dso__fprintf_symbols_by_name(struct dso *self, enum map_type type, FILE *fp); | ||
185 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp); | 188 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp); |
186 | 189 | ||
187 | enum dso_origin { | 190 | enum dso_origin { |
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c index 66f2d583d8c4..8bc010edca25 100644 --- a/tools/perf/util/ui/browser.c +++ b/tools/perf/util/ui/browser.c | |||
@@ -1,16 +1,5 @@ | |||
1 | #define _GNU_SOURCE | 1 | #include "libslang.h" |
2 | #include <stdio.h> | 2 | #include <linux/compiler.h> |
3 | #undef _GNU_SOURCE | ||
4 | /* | ||
5 | * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks | ||
6 | * the build if it isn't defined. Use the equivalent one that glibc | ||
7 | * has on features.h. | ||
8 | */ | ||
9 | #include <features.h> | ||
10 | #ifndef HAVE_LONG_LONG | ||
11 | #define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG | ||
12 | #endif | ||
13 | #include <slang.h> | ||
14 | #include <linux/list.h> | 3 | #include <linux/list.h> |
15 | #include <linux/rbtree.h> | 4 | #include <linux/rbtree.h> |
16 | #include <stdlib.h> | 5 | #include <stdlib.h> |
@@ -19,17 +8,9 @@ | |||
19 | #include "helpline.h" | 8 | #include "helpline.h" |
20 | #include "../color.h" | 9 | #include "../color.h" |
21 | #include "../util.h" | 10 | #include "../util.h" |
11 | #include <stdio.h> | ||
22 | 12 | ||
23 | #if SLANG_VERSION < 20104 | 13 | static int ui_browser__percent_color(double percent, bool current) |
24 | #define sltt_set_color(obj, name, fg, bg) \ | ||
25 | SLtt_set_color(obj,(char *)name, (char *)fg, (char *)bg) | ||
26 | #else | ||
27 | #define sltt_set_color SLtt_set_color | ||
28 | #endif | ||
29 | |||
30 | newtComponent newt_form__new(void); | ||
31 | |||
32 | int ui_browser__percent_color(double percent, bool current) | ||
33 | { | 14 | { |
34 | if (current) | 15 | if (current) |
35 | return HE_COLORSET_SELECTED; | 16 | return HE_COLORSET_SELECTED; |
@@ -40,6 +21,23 @@ int ui_browser__percent_color(double percent, bool current) | |||
40 | return HE_COLORSET_NORMAL; | 21 | return HE_COLORSET_NORMAL; |
41 | } | 22 | } |
42 | 23 | ||
24 | void ui_browser__set_color(struct ui_browser *self __used, int color) | ||
25 | { | ||
26 | SLsmg_set_color(color); | ||
27 | } | ||
28 | |||
29 | void ui_browser__set_percent_color(struct ui_browser *self, | ||
30 | double percent, bool current) | ||
31 | { | ||
32 | int color = ui_browser__percent_color(percent, current); | ||
33 | ui_browser__set_color(self, color); | ||
34 | } | ||
35 | |||
36 | void ui_browser__gotorc(struct ui_browser *self, int y, int x) | ||
37 | { | ||
38 | SLsmg_gotorc(self->y + y, self->x + x); | ||
39 | } | ||
40 | |||
43 | void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) | 41 | void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) |
44 | { | 42 | { |
45 | struct list_head *head = self->entries; | 43 | struct list_head *head = self->entries; |
@@ -111,7 +109,7 @@ unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self) | |||
111 | nd = self->top; | 109 | nd = self->top; |
112 | 110 | ||
113 | while (nd != NULL) { | 111 | while (nd != NULL) { |
114 | SLsmg_gotorc(self->y + row, self->x); | 112 | ui_browser__gotorc(self, row, 0); |
115 | self->write(self, nd, row); | 113 | self->write(self, nd, row); |
116 | if (++row == self->height) | 114 | if (++row == self->height) |
117 | break; | 115 | break; |
@@ -131,13 +129,10 @@ void ui_browser__refresh_dimensions(struct ui_browser *self) | |||
131 | int cols, rows; | 129 | int cols, rows; |
132 | newtGetScreenSize(&cols, &rows); | 130 | newtGetScreenSize(&cols, &rows); |
133 | 131 | ||
134 | if (self->width > cols - 4) | 132 | self->width = cols - 1; |
135 | self->width = cols - 4; | 133 | self->height = rows - 2; |
136 | self->height = rows - 5; | 134 | self->y = 1; |
137 | if (self->height > self->nr_entries) | 135 | self->x = 0; |
138 | self->height = self->nr_entries; | ||
139 | self->y = (rows - self->height) / 2; | ||
140 | self->x = (cols - self->width) / 2; | ||
141 | } | 136 | } |
142 | 137 | ||
143 | void ui_browser__reset_index(struct ui_browser *self) | 138 | void ui_browser__reset_index(struct ui_browser *self) |
@@ -146,34 +141,48 @@ void ui_browser__reset_index(struct ui_browser *self) | |||
146 | self->seek(self, 0, SEEK_SET); | 141 | self->seek(self, 0, SEEK_SET); |
147 | } | 142 | } |
148 | 143 | ||
144 | void ui_browser__add_exit_key(struct ui_browser *self, int key) | ||
145 | { | ||
146 | newtFormAddHotKey(self->form, key); | ||
147 | } | ||
148 | |||
149 | void ui_browser__add_exit_keys(struct ui_browser *self, int keys[]) | ||
150 | { | ||
151 | int i = 0; | ||
152 | |||
153 | while (keys[i] && i < 64) { | ||
154 | ui_browser__add_exit_key(self, keys[i]); | ||
155 | ++i; | ||
156 | } | ||
157 | } | ||
158 | |||
149 | int ui_browser__show(struct ui_browser *self, const char *title, | 159 | int ui_browser__show(struct ui_browser *self, const char *title, |
150 | const char *helpline, ...) | 160 | const char *helpline, ...) |
151 | { | 161 | { |
152 | va_list ap; | 162 | va_list ap; |
163 | int keys[] = { NEWT_KEY_UP, NEWT_KEY_DOWN, NEWT_KEY_PGUP, | ||
164 | NEWT_KEY_PGDN, NEWT_KEY_HOME, NEWT_KEY_END, ' ', | ||
165 | NEWT_KEY_LEFT, NEWT_KEY_ESCAPE, 'q', CTRL('c'), 0 }; | ||
153 | 166 | ||
154 | if (self->form != NULL) { | 167 | if (self->form != NULL) |
155 | newtFormDestroy(self->form); | 168 | newtFormDestroy(self->form); |
156 | newtPopWindow(); | 169 | |
157 | } | ||
158 | ui_browser__refresh_dimensions(self); | 170 | ui_browser__refresh_dimensions(self); |
159 | newtCenteredWindow(self->width, self->height, title); | 171 | self->form = newtForm(NULL, NULL, 0); |
160 | self->form = newt_form__new(); | ||
161 | if (self->form == NULL) | 172 | if (self->form == NULL) |
162 | return -1; | 173 | return -1; |
163 | 174 | ||
164 | self->sb = newtVerticalScrollbar(self->width, 0, self->height, | 175 | self->sb = newtVerticalScrollbar(self->width, 1, self->height, |
165 | HE_COLORSET_NORMAL, | 176 | HE_COLORSET_NORMAL, |
166 | HE_COLORSET_SELECTED); | 177 | HE_COLORSET_SELECTED); |
167 | if (self->sb == NULL) | 178 | if (self->sb == NULL) |
168 | return -1; | 179 | return -1; |
169 | 180 | ||
170 | newtFormAddHotKey(self->form, NEWT_KEY_UP); | 181 | SLsmg_gotorc(0, 0); |
171 | newtFormAddHotKey(self->form, NEWT_KEY_DOWN); | 182 | ui_browser__set_color(self, NEWT_COLORSET_ROOT); |
172 | newtFormAddHotKey(self->form, NEWT_KEY_PGUP); | 183 | slsmg_write_nstring(title, self->width); |
173 | newtFormAddHotKey(self->form, NEWT_KEY_PGDN); | 184 | |
174 | newtFormAddHotKey(self->form, NEWT_KEY_HOME); | 185 | ui_browser__add_exit_keys(self, keys); |
175 | newtFormAddHotKey(self->form, NEWT_KEY_END); | ||
176 | newtFormAddHotKey(self->form, ' '); | ||
177 | newtFormAddComponent(self->form, self->sb); | 186 | newtFormAddComponent(self->form, self->sb); |
178 | 187 | ||
179 | va_start(ap, helpline); | 188 | va_start(ap, helpline); |
@@ -185,7 +194,6 @@ int ui_browser__show(struct ui_browser *self, const char *title, | |||
185 | void ui_browser__hide(struct ui_browser *self) | 194 | void ui_browser__hide(struct ui_browser *self) |
186 | { | 195 | { |
187 | newtFormDestroy(self->form); | 196 | newtFormDestroy(self->form); |
188 | newtPopWindow(); | ||
189 | self->form = NULL; | 197 | self->form = NULL; |
190 | ui_helpline__pop(); | 198 | ui_helpline__pop(); |
191 | } | 199 | } |
@@ -196,28 +204,28 @@ int ui_browser__refresh(struct ui_browser *self) | |||
196 | 204 | ||
197 | newtScrollbarSet(self->sb, self->index, self->nr_entries - 1); | 205 | newtScrollbarSet(self->sb, self->index, self->nr_entries - 1); |
198 | row = self->refresh(self); | 206 | row = self->refresh(self); |
199 | SLsmg_set_color(HE_COLORSET_NORMAL); | 207 | ui_browser__set_color(self, HE_COLORSET_NORMAL); |
200 | SLsmg_fill_region(self->y + row, self->x, | 208 | SLsmg_fill_region(self->y + row, self->x, |
201 | self->height - row, self->width, ' '); | 209 | self->height - row, self->width, ' '); |
202 | 210 | ||
203 | return 0; | 211 | return 0; |
204 | } | 212 | } |
205 | 213 | ||
206 | int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es) | 214 | int ui_browser__run(struct ui_browser *self) |
207 | { | 215 | { |
216 | struct newtExitStruct es; | ||
217 | |||
208 | if (ui_browser__refresh(self) < 0) | 218 | if (ui_browser__refresh(self) < 0) |
209 | return -1; | 219 | return -1; |
210 | 220 | ||
211 | while (1) { | 221 | while (1) { |
212 | off_t offset; | 222 | off_t offset; |
213 | 223 | ||
214 | newtFormRun(self->form, es); | 224 | newtFormRun(self->form, &es); |
215 | 225 | ||
216 | if (es->reason != NEWT_EXIT_HOTKEY) | 226 | if (es.reason != NEWT_EXIT_HOTKEY) |
217 | break; | 227 | break; |
218 | if (is_exit_key(es->u.key)) | 228 | switch (es.u.key) { |
219 | return es->u.key; | ||
220 | switch (es->u.key) { | ||
221 | case NEWT_KEY_DOWN: | 229 | case NEWT_KEY_DOWN: |
222 | if (self->index == self->nr_entries - 1) | 230 | if (self->index == self->nr_entries - 1) |
223 | break; | 231 | break; |
@@ -274,12 +282,12 @@ int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es) | |||
274 | self->seek(self, -offset, SEEK_END); | 282 | self->seek(self, -offset, SEEK_END); |
275 | break; | 283 | break; |
276 | default: | 284 | default: |
277 | return es->u.key; | 285 | return es.u.key; |
278 | } | 286 | } |
279 | if (ui_browser__refresh(self) < 0) | 287 | if (ui_browser__refresh(self) < 0) |
280 | return -1; | 288 | return -1; |
281 | } | 289 | } |
282 | return 0; | 290 | return -1; |
283 | } | 291 | } |
284 | 292 | ||
285 | unsigned int ui_browser__list_head_refresh(struct ui_browser *self) | 293 | unsigned int ui_browser__list_head_refresh(struct ui_browser *self) |
@@ -294,7 +302,7 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *self) | |||
294 | pos = self->top; | 302 | pos = self->top; |
295 | 303 | ||
296 | list_for_each_from(pos, head) { | 304 | list_for_each_from(pos, head) { |
297 | SLsmg_gotorc(self->y + row, self->x); | 305 | ui_browser__gotorc(self, row, 0); |
298 | self->write(self, pos, row); | 306 | self->write(self, pos, row); |
299 | if (++row == self->height) | 307 | if (++row == self->height) |
300 | break; | 308 | break; |
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h index 0b9f829214f7..0dc7e4da36f5 100644 --- a/tools/perf/util/ui/browser.h +++ b/tools/perf/util/ui/browser.h | |||
@@ -25,16 +25,21 @@ struct ui_browser { | |||
25 | }; | 25 | }; |
26 | 26 | ||
27 | 27 | ||
28 | int ui_browser__percent_color(double percent, bool current); | 28 | void ui_browser__set_color(struct ui_browser *self, int color); |
29 | void ui_browser__set_percent_color(struct ui_browser *self, | ||
30 | double percent, bool current); | ||
29 | bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row); | 31 | bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row); |
30 | void ui_browser__refresh_dimensions(struct ui_browser *self); | 32 | void ui_browser__refresh_dimensions(struct ui_browser *self); |
31 | void ui_browser__reset_index(struct ui_browser *self); | 33 | void ui_browser__reset_index(struct ui_browser *self); |
32 | 34 | ||
35 | void ui_browser__gotorc(struct ui_browser *self, int y, int x); | ||
36 | void ui_browser__add_exit_key(struct ui_browser *self, int key); | ||
37 | void ui_browser__add_exit_keys(struct ui_browser *self, int keys[]); | ||
33 | int ui_browser__show(struct ui_browser *self, const char *title, | 38 | int ui_browser__show(struct ui_browser *self, const char *title, |
34 | const char *helpline, ...); | 39 | const char *helpline, ...); |
35 | void ui_browser__hide(struct ui_browser *self); | 40 | void ui_browser__hide(struct ui_browser *self); |
36 | int ui_browser__refresh(struct ui_browser *self); | 41 | int ui_browser__refresh(struct ui_browser *self); |
37 | int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es); | 42 | int ui_browser__run(struct ui_browser *self); |
38 | 43 | ||
39 | void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence); | 44 | void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence); |
40 | unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self); | 45 | unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self); |
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c index a90273e63f4f..82b78f99251b 100644 --- a/tools/perf/util/ui/browsers/annotate.c +++ b/tools/perf/util/ui/browsers/annotate.c | |||
@@ -40,14 +40,12 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro | |||
40 | 40 | ||
41 | if (ol->offset != -1) { | 41 | if (ol->offset != -1) { |
42 | struct objdump_line_rb_node *olrb = objdump_line__rb(ol); | 42 | struct objdump_line_rb_node *olrb = objdump_line__rb(ol); |
43 | int color = ui_browser__percent_color(olrb->percent, current_entry); | 43 | ui_browser__set_percent_color(self, olrb->percent, current_entry); |
44 | SLsmg_set_color(color); | ||
45 | slsmg_printf(" %7.2f ", olrb->percent); | 44 | slsmg_printf(" %7.2f ", olrb->percent); |
46 | if (!current_entry) | 45 | if (!current_entry) |
47 | SLsmg_set_color(HE_COLORSET_CODE); | 46 | ui_browser__set_color(self, HE_COLORSET_CODE); |
48 | } else { | 47 | } else { |
49 | int color = ui_browser__percent_color(0, current_entry); | 48 | ui_browser__set_percent_color(self, 0, current_entry); |
50 | SLsmg_set_color(color); | ||
51 | slsmg_write_nstring(" ", 9); | 49 | slsmg_write_nstring(" ", 9); |
52 | } | 50 | } |
53 | 51 | ||
@@ -135,32 +133,31 @@ static void annotate_browser__set_top(struct annotate_browser *self, | |||
135 | self->curr_hot = nd; | 133 | self->curr_hot = nd; |
136 | } | 134 | } |
137 | 135 | ||
138 | static int annotate_browser__run(struct annotate_browser *self, | 136 | static int annotate_browser__run(struct annotate_browser *self) |
139 | struct newtExitStruct *es) | ||
140 | { | 137 | { |
141 | struct rb_node *nd; | 138 | struct rb_node *nd; |
142 | struct hist_entry *he = self->b.priv; | 139 | struct hist_entry *he = self->b.priv; |
140 | int key; | ||
143 | 141 | ||
144 | if (ui_browser__show(&self->b, he->ms.sym->name, | 142 | if (ui_browser__show(&self->b, he->ms.sym->name, |
145 | "<- or ESC: exit, TAB/shift+TAB: cycle thru samples") < 0) | 143 | "<-, -> or ESC: exit, TAB/shift+TAB: cycle thru samples") < 0) |
146 | return -1; | 144 | return -1; |
147 | 145 | /* | |
148 | newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); | 146 | * To allow builtin-annotate to cycle thru multiple symbols by |
149 | newtFormAddHotKey(self->b.form, NEWT_KEY_RIGHT); | 147 | * examining the exit key for this function. |
148 | */ | ||
149 | ui_browser__add_exit_key(&self->b, NEWT_KEY_RIGHT); | ||
150 | 150 | ||
151 | nd = self->curr_hot; | 151 | nd = self->curr_hot; |
152 | if (nd) { | 152 | if (nd) { |
153 | newtFormAddHotKey(self->b.form, NEWT_KEY_TAB); | 153 | int tabs[] = { NEWT_KEY_TAB, NEWT_KEY_UNTAB, 0 }; |
154 | newtFormAddHotKey(self->b.form, NEWT_KEY_UNTAB); | 154 | ui_browser__add_exit_keys(&self->b, tabs); |
155 | } | 155 | } |
156 | 156 | ||
157 | while (1) { | 157 | while (1) { |
158 | ui_browser__run(&self->b, es); | 158 | key = ui_browser__run(&self->b); |
159 | |||
160 | if (es->reason != NEWT_EXIT_HOTKEY) | ||
161 | break; | ||
162 | 159 | ||
163 | switch (es->u.key) { | 160 | switch (key) { |
164 | case NEWT_KEY_TAB: | 161 | case NEWT_KEY_TAB: |
165 | nd = rb_prev(nd); | 162 | nd = rb_prev(nd); |
166 | if (nd == NULL) | 163 | if (nd == NULL) |
@@ -179,12 +176,11 @@ static int annotate_browser__run(struct annotate_browser *self, | |||
179 | } | 176 | } |
180 | out: | 177 | out: |
181 | ui_browser__hide(&self->b); | 178 | ui_browser__hide(&self->b); |
182 | return es->u.key; | 179 | return key; |
183 | } | 180 | } |
184 | 181 | ||
185 | int hist_entry__tui_annotate(struct hist_entry *self) | 182 | int hist_entry__tui_annotate(struct hist_entry *self) |
186 | { | 183 | { |
187 | struct newtExitStruct es; | ||
188 | struct objdump_line *pos, *n; | 184 | struct objdump_line *pos, *n; |
189 | struct objdump_line_rb_node *rbpos; | 185 | struct objdump_line_rb_node *rbpos; |
190 | LIST_HEAD(head); | 186 | LIST_HEAD(head); |
@@ -232,7 +228,7 @@ int hist_entry__tui_annotate(struct hist_entry *self) | |||
232 | annotate_browser__set_top(&browser, browser.curr_hot); | 228 | annotate_browser__set_top(&browser, browser.curr_hot); |
233 | 229 | ||
234 | browser.b.width += 18; /* Percentage */ | 230 | browser.b.width += 18; /* Percentage */ |
235 | ret = annotate_browser__run(&browser, &es); | 231 | ret = annotate_browser__run(&browser); |
236 | list_for_each_entry_safe(pos, n, &head, node) { | 232 | list_for_each_entry_safe(pos, n, &head, node) { |
237 | list_del(&pos->node); | 233 | list_del(&pos->node); |
238 | objdump_line__free(pos); | 234 | objdump_line__free(pos); |
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c index 6866aa4c41e0..ebda8c3fde9e 100644 --- a/tools/perf/util/ui/browsers/hists.c +++ b/tools/perf/util/ui/browsers/hists.c | |||
@@ -58,6 +58,11 @@ static char callchain_list__folded(const struct callchain_list *self) | |||
58 | return map_symbol__folded(&self->ms); | 58 | return map_symbol__folded(&self->ms); |
59 | } | 59 | } |
60 | 60 | ||
61 | static void map_symbol__set_folding(struct map_symbol *self, bool unfold) | ||
62 | { | ||
63 | self->unfolded = unfold ? self->has_children : false; | ||
64 | } | ||
65 | |||
61 | static int callchain_node__count_rows_rb_tree(struct callchain_node *self) | 66 | static int callchain_node__count_rows_rb_tree(struct callchain_node *self) |
62 | { | 67 | { |
63 | int n = 0; | 68 | int n = 0; |
@@ -129,16 +134,16 @@ static void callchain_node__init_have_children_rb_tree(struct callchain_node *se | |||
129 | for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) { | 134 | for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) { |
130 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); | 135 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); |
131 | struct callchain_list *chain; | 136 | struct callchain_list *chain; |
132 | int first = true; | 137 | bool first = true; |
133 | 138 | ||
134 | list_for_each_entry(chain, &child->val, list) { | 139 | list_for_each_entry(chain, &child->val, list) { |
135 | if (first) { | 140 | if (first) { |
136 | first = false; | 141 | first = false; |
137 | chain->ms.has_children = chain->list.next != &child->val || | 142 | chain->ms.has_children = chain->list.next != &child->val || |
138 | rb_first(&child->rb_root) != NULL; | 143 | !RB_EMPTY_ROOT(&child->rb_root); |
139 | } else | 144 | } else |
140 | chain->ms.has_children = chain->list.next == &child->val && | 145 | chain->ms.has_children = chain->list.next == &child->val && |
141 | rb_first(&child->rb_root) != NULL; | 146 | !RB_EMPTY_ROOT(&child->rb_root); |
142 | } | 147 | } |
143 | 148 | ||
144 | callchain_node__init_have_children_rb_tree(child); | 149 | callchain_node__init_have_children_rb_tree(child); |
@@ -150,7 +155,7 @@ static void callchain_node__init_have_children(struct callchain_node *self) | |||
150 | struct callchain_list *chain; | 155 | struct callchain_list *chain; |
151 | 156 | ||
152 | list_for_each_entry(chain, &self->val, list) | 157 | list_for_each_entry(chain, &self->val, list) |
153 | chain->ms.has_children = rb_first(&self->rb_root) != NULL; | 158 | chain->ms.has_children = !RB_EMPTY_ROOT(&self->rb_root); |
154 | 159 | ||
155 | callchain_node__init_have_children_rb_tree(self); | 160 | callchain_node__init_have_children_rb_tree(self); |
156 | } | 161 | } |
@@ -168,6 +173,7 @@ static void callchain__init_have_children(struct rb_root *self) | |||
168 | static void hist_entry__init_have_children(struct hist_entry *self) | 173 | static void hist_entry__init_have_children(struct hist_entry *self) |
169 | { | 174 | { |
170 | if (!self->init_have_children) { | 175 | if (!self->init_have_children) { |
176 | self->ms.has_children = !RB_EMPTY_ROOT(&self->sorted_chain); | ||
171 | callchain__init_have_children(&self->sorted_chain); | 177 | callchain__init_have_children(&self->sorted_chain); |
172 | self->init_have_children = true; | 178 | self->init_have_children = true; |
173 | } | 179 | } |
@@ -195,43 +201,114 @@ static bool hist_browser__toggle_fold(struct hist_browser *self) | |||
195 | return false; | 201 | return false; |
196 | } | 202 | } |
197 | 203 | ||
198 | static int hist_browser__run(struct hist_browser *self, const char *title, | 204 | static int callchain_node__set_folding_rb_tree(struct callchain_node *self, bool unfold) |
199 | struct newtExitStruct *es) | 205 | { |
206 | int n = 0; | ||
207 | struct rb_node *nd; | ||
208 | |||
209 | for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) { | ||
210 | struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node); | ||
211 | struct callchain_list *chain; | ||
212 | bool has_children = false; | ||
213 | |||
214 | list_for_each_entry(chain, &child->val, list) { | ||
215 | ++n; | ||
216 | map_symbol__set_folding(&chain->ms, unfold); | ||
217 | has_children = chain->ms.has_children; | ||
218 | } | ||
219 | |||
220 | if (has_children) | ||
221 | n += callchain_node__set_folding_rb_tree(child, unfold); | ||
222 | } | ||
223 | |||
224 | return n; | ||
225 | } | ||
226 | |||
227 | static int callchain_node__set_folding(struct callchain_node *node, bool unfold) | ||
228 | { | ||
229 | struct callchain_list *chain; | ||
230 | bool has_children = false; | ||
231 | int n = 0; | ||
232 | |||
233 | list_for_each_entry(chain, &node->val, list) { | ||
234 | ++n; | ||
235 | map_symbol__set_folding(&chain->ms, unfold); | ||
236 | has_children = chain->ms.has_children; | ||
237 | } | ||
238 | |||
239 | if (has_children) | ||
240 | n += callchain_node__set_folding_rb_tree(node, unfold); | ||
241 | |||
242 | return n; | ||
243 | } | ||
244 | |||
245 | static int callchain__set_folding(struct rb_root *chain, bool unfold) | ||
246 | { | ||
247 | struct rb_node *nd; | ||
248 | int n = 0; | ||
249 | |||
250 | for (nd = rb_first(chain); nd; nd = rb_next(nd)) { | ||
251 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); | ||
252 | n += callchain_node__set_folding(node, unfold); | ||
253 | } | ||
254 | |||
255 | return n; | ||
256 | } | ||
257 | |||
258 | static void hist_entry__set_folding(struct hist_entry *self, bool unfold) | ||
259 | { | ||
260 | hist_entry__init_have_children(self); | ||
261 | map_symbol__set_folding(&self->ms, unfold); | ||
262 | |||
263 | if (self->ms.has_children) { | ||
264 | int n = callchain__set_folding(&self->sorted_chain, unfold); | ||
265 | self->nr_rows = unfold ? n : 0; | ||
266 | } else | ||
267 | self->nr_rows = 0; | ||
268 | } | ||
269 | |||
270 | static void hists__set_folding(struct hists *self, bool unfold) | ||
271 | { | ||
272 | struct rb_node *nd; | ||
273 | |||
274 | self->nr_entries = 0; | ||
275 | |||
276 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { | ||
277 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); | ||
278 | hist_entry__set_folding(he, unfold); | ||
279 | self->nr_entries += 1 + he->nr_rows; | ||
280 | } | ||
281 | } | ||
282 | |||
283 | static void hist_browser__set_folding(struct hist_browser *self, bool unfold) | ||
284 | { | ||
285 | hists__set_folding(self->hists, unfold); | ||
286 | self->b.nr_entries = self->hists->nr_entries; | ||
287 | /* Go to the start, we may be way after valid entries after a collapse */ | ||
288 | ui_browser__reset_index(&self->b); | ||
289 | } | ||
290 | |||
291 | static int hist_browser__run(struct hist_browser *self, const char *title) | ||
200 | { | 292 | { |
201 | char str[256], unit; | 293 | int key; |
202 | unsigned long nr_events = self->hists->stats.nr_events[PERF_RECORD_SAMPLE]; | 294 | int exit_keys[] = { 'a', '?', 'h', 'C', 'd', 'D', 'E', 't', |
295 | NEWT_KEY_ENTER, NEWT_KEY_RIGHT, NEWT_KEY_LEFT, 0, }; | ||
203 | 296 | ||
204 | self->b.entries = &self->hists->entries; | 297 | self->b.entries = &self->hists->entries; |
205 | self->b.nr_entries = self->hists->nr_entries; | 298 | self->b.nr_entries = self->hists->nr_entries; |
206 | 299 | ||
207 | hist_browser__refresh_dimensions(self); | 300 | hist_browser__refresh_dimensions(self); |
208 | 301 | ||
209 | nr_events = convert_unit(nr_events, &unit); | ||
210 | snprintf(str, sizeof(str), "Events: %lu%c ", | ||
211 | nr_events, unit); | ||
212 | newtDrawRootText(0, 0, str); | ||
213 | |||
214 | if (ui_browser__show(&self->b, title, | 302 | if (ui_browser__show(&self->b, title, |
215 | "Press '?' for help on key bindings") < 0) | 303 | "Press '?' for help on key bindings") < 0) |
216 | return -1; | 304 | return -1; |
217 | 305 | ||
218 | newtFormAddHotKey(self->b.form, 'a'); | 306 | ui_browser__add_exit_keys(&self->b, exit_keys); |
219 | newtFormAddHotKey(self->b.form, '?'); | ||
220 | newtFormAddHotKey(self->b.form, 'h'); | ||
221 | newtFormAddHotKey(self->b.form, 'd'); | ||
222 | newtFormAddHotKey(self->b.form, 'D'); | ||
223 | newtFormAddHotKey(self->b.form, 't'); | ||
224 | |||
225 | newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); | ||
226 | newtFormAddHotKey(self->b.form, NEWT_KEY_RIGHT); | ||
227 | newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER); | ||
228 | 307 | ||
229 | while (1) { | 308 | while (1) { |
230 | ui_browser__run(&self->b, es); | 309 | key = ui_browser__run(&self->b); |
231 | 310 | ||
232 | if (es->reason != NEWT_EXIT_HOTKEY) | 311 | switch (key) { |
233 | break; | ||
234 | switch (es->u.key) { | ||
235 | case 'D': { /* Debug */ | 312 | case 'D': { /* Debug */ |
236 | static int seq; | 313 | static int seq; |
237 | struct hist_entry *h = rb_entry(self->b.top, | 314 | struct hist_entry *h = rb_entry(self->b.top, |
@@ -245,18 +322,26 @@ static int hist_browser__run(struct hist_browser *self, const char *title, | |||
245 | self->b.top_idx, | 322 | self->b.top_idx, |
246 | h->row_offset, h->nr_rows); | 323 | h->row_offset, h->nr_rows); |
247 | } | 324 | } |
248 | continue; | 325 | break; |
326 | case 'C': | ||
327 | /* Collapse the whole world. */ | ||
328 | hist_browser__set_folding(self, false); | ||
329 | break; | ||
330 | case 'E': | ||
331 | /* Expand the whole world. */ | ||
332 | hist_browser__set_folding(self, true); | ||
333 | break; | ||
249 | case NEWT_KEY_ENTER: | 334 | case NEWT_KEY_ENTER: |
250 | if (hist_browser__toggle_fold(self)) | 335 | if (hist_browser__toggle_fold(self)) |
251 | break; | 336 | break; |
252 | /* fall thru */ | 337 | /* fall thru */ |
253 | default: | 338 | default: |
254 | return 0; | 339 | goto out; |
255 | } | 340 | } |
256 | } | 341 | } |
257 | 342 | out: | |
258 | ui_browser__hide(&self->b); | 343 | ui_browser__hide(&self->b); |
259 | return 0; | 344 | return key; |
260 | } | 345 | } |
261 | 346 | ||
262 | static char *callchain_list__sym_name(struct callchain_list *self, | 347 | static char *callchain_list__sym_name(struct callchain_list *self, |
@@ -306,15 +391,10 @@ static int hist_browser__show_callchain_node_rb_tree(struct hist_browser *self, | |||
306 | int color; | 391 | int color; |
307 | bool was_first = first; | 392 | bool was_first = first; |
308 | 393 | ||
309 | if (first) { | 394 | if (first) |
310 | first = false; | 395 | first = false; |
311 | chain->ms.has_children = chain->list.next != &child->val || | 396 | else |
312 | rb_first(&child->rb_root) != NULL; | ||
313 | } else { | ||
314 | extra_offset = LEVEL_OFFSET_STEP; | 397 | extra_offset = LEVEL_OFFSET_STEP; |
315 | chain->ms.has_children = chain->list.next == &child->val && | ||
316 | rb_first(&child->rb_root) != NULL; | ||
317 | } | ||
318 | 398 | ||
319 | folded_sign = callchain_list__folded(chain); | 399 | folded_sign = callchain_list__folded(chain); |
320 | if (*row_offset != 0) { | 400 | if (*row_offset != 0) { |
@@ -341,8 +421,8 @@ static int hist_browser__show_callchain_node_rb_tree(struct hist_browser *self, | |||
341 | *is_current_entry = true; | 421 | *is_current_entry = true; |
342 | } | 422 | } |
343 | 423 | ||
344 | SLsmg_set_color(color); | 424 | ui_browser__set_color(&self->b, color); |
345 | SLsmg_gotorc(self->b.y + row, self->b.x); | 425 | ui_browser__gotorc(&self->b, row, 0); |
346 | slsmg_write_nstring(" ", offset + extra_offset); | 426 | slsmg_write_nstring(" ", offset + extra_offset); |
347 | slsmg_printf("%c ", folded_sign); | 427 | slsmg_printf("%c ", folded_sign); |
348 | slsmg_write_nstring(str, width); | 428 | slsmg_write_nstring(str, width); |
@@ -384,12 +464,7 @@ static int hist_browser__show_callchain_node(struct hist_browser *self, | |||
384 | list_for_each_entry(chain, &node->val, list) { | 464 | list_for_each_entry(chain, &node->val, list) { |
385 | char ipstr[BITS_PER_LONG / 4 + 1], *s; | 465 | char ipstr[BITS_PER_LONG / 4 + 1], *s; |
386 | int color; | 466 | int color; |
387 | /* | 467 | |
388 | * FIXME: This should be moved to somewhere else, | ||
389 | * probably when the callchain is created, so as not to | ||
390 | * traverse it all over again | ||
391 | */ | ||
392 | chain->ms.has_children = rb_first(&node->rb_root) != NULL; | ||
393 | folded_sign = callchain_list__folded(chain); | 468 | folded_sign = callchain_list__folded(chain); |
394 | 469 | ||
395 | if (*row_offset != 0) { | 470 | if (*row_offset != 0) { |
@@ -405,8 +480,8 @@ static int hist_browser__show_callchain_node(struct hist_browser *self, | |||
405 | } | 480 | } |
406 | 481 | ||
407 | s = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); | 482 | s = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); |
408 | SLsmg_gotorc(self->b.y + row, self->b.x); | 483 | ui_browser__gotorc(&self->b, row, 0); |
409 | SLsmg_set_color(color); | 484 | ui_browser__set_color(&self->b, color); |
410 | slsmg_write_nstring(" ", offset); | 485 | slsmg_write_nstring(" ", offset); |
411 | slsmg_printf("%c ", folded_sign); | 486 | slsmg_printf("%c ", folded_sign); |
412 | slsmg_write_nstring(s, width - 2); | 487 | slsmg_write_nstring(s, width - 2); |
@@ -465,7 +540,7 @@ static int hist_browser__show_entry(struct hist_browser *self, | |||
465 | } | 540 | } |
466 | 541 | ||
467 | if (symbol_conf.use_callchain) { | 542 | if (symbol_conf.use_callchain) { |
468 | entry->ms.has_children = !RB_EMPTY_ROOT(&entry->sorted_chain); | 543 | hist_entry__init_have_children(entry); |
469 | folded_sign = hist_entry__folded(entry); | 544 | folded_sign = hist_entry__folded(entry); |
470 | } | 545 | } |
471 | 546 | ||
@@ -484,8 +559,8 @@ static int hist_browser__show_entry(struct hist_browser *self, | |||
484 | color = HE_COLORSET_NORMAL; | 559 | color = HE_COLORSET_NORMAL; |
485 | } | 560 | } |
486 | 561 | ||
487 | SLsmg_set_color(color); | 562 | ui_browser__set_color(&self->b, color); |
488 | SLsmg_gotorc(self->b.y + row, self->b.x); | 563 | ui_browser__gotorc(&self->b, row, 0); |
489 | if (symbol_conf.use_callchain) { | 564 | if (symbol_conf.use_callchain) { |
490 | slsmg_printf("%c ", folded_sign); | 565 | slsmg_printf("%c ", folded_sign); |
491 | width -= 2; | 566 | width -= 2; |
@@ -687,8 +762,6 @@ static struct hist_browser *hist_browser__new(struct hists *hists) | |||
687 | 762 | ||
688 | static void hist_browser__delete(struct hist_browser *self) | 763 | static void hist_browser__delete(struct hist_browser *self) |
689 | { | 764 | { |
690 | newtFormDestroy(self->b.form); | ||
691 | newtPopWindow(); | ||
692 | free(self); | 765 | free(self); |
693 | } | 766 | } |
694 | 767 | ||
@@ -702,21 +775,26 @@ static struct thread *hist_browser__selected_thread(struct hist_browser *self) | |||
702 | return self->he_selection->thread; | 775 | return self->he_selection->thread; |
703 | } | 776 | } |
704 | 777 | ||
705 | static int hist_browser__title(char *bf, size_t size, const char *ev_name, | 778 | static int hists__browser_title(struct hists *self, char *bf, size_t size, |
706 | const struct dso *dso, const struct thread *thread) | 779 | const char *ev_name, const struct dso *dso, |
780 | const struct thread *thread) | ||
707 | { | 781 | { |
708 | int printed = 0; | 782 | char unit; |
783 | int printed; | ||
784 | unsigned long nr_events = self->stats.nr_events[PERF_RECORD_SAMPLE]; | ||
785 | |||
786 | nr_events = convert_unit(nr_events, &unit); | ||
787 | printed = snprintf(bf, size, "Events: %lu%c %s", nr_events, unit, ev_name); | ||
709 | 788 | ||
710 | if (thread) | 789 | if (thread) |
711 | printed += snprintf(bf + printed, size - printed, | 790 | printed += snprintf(bf + printed, size - printed, |
712 | "Thread: %s(%d)", | 791 | ", Thread: %s(%d)", |
713 | (thread->comm_set ? thread->comm : ""), | 792 | (thread->comm_set ? thread->comm : ""), |
714 | thread->pid); | 793 | thread->pid); |
715 | if (dso) | 794 | if (dso) |
716 | printed += snprintf(bf + printed, size - printed, | 795 | printed += snprintf(bf + printed, size - printed, |
717 | "%sDSO: %s", thread ? " " : "", | 796 | ", DSO: %s", dso->short_name); |
718 | dso->short_name); | 797 | return printed; |
719 | return printed ?: snprintf(bf, size, "Event: %s", ev_name); | ||
720 | } | 798 | } |
721 | 799 | ||
722 | int hists__browse(struct hists *self, const char *helpline, const char *ev_name) | 800 | int hists__browse(struct hists *self, const char *helpline, const char *ev_name) |
@@ -725,7 +803,6 @@ int hists__browse(struct hists *self, const char *helpline, const char *ev_name) | |||
725 | struct pstack *fstack; | 803 | struct pstack *fstack; |
726 | const struct thread *thread_filter = NULL; | 804 | const struct thread *thread_filter = NULL; |
727 | const struct dso *dso_filter = NULL; | 805 | const struct dso *dso_filter = NULL; |
728 | struct newtExitStruct es; | ||
729 | char msg[160]; | 806 | char msg[160]; |
730 | int key = -1; | 807 | int key = -1; |
731 | 808 | ||
@@ -738,9 +815,8 @@ int hists__browse(struct hists *self, const char *helpline, const char *ev_name) | |||
738 | 815 | ||
739 | ui_helpline__push(helpline); | 816 | ui_helpline__push(helpline); |
740 | 817 | ||
741 | hist_browser__title(msg, sizeof(msg), ev_name, | 818 | hists__browser_title(self, msg, sizeof(msg), ev_name, |
742 | dso_filter, thread_filter); | 819 | dso_filter, thread_filter); |
743 | |||
744 | while (1) { | 820 | while (1) { |
745 | const struct thread *thread; | 821 | const struct thread *thread; |
746 | const struct dso *dso; | 822 | const struct dso *dso; |
@@ -749,70 +825,63 @@ int hists__browse(struct hists *self, const char *helpline, const char *ev_name) | |||
749 | annotate = -2, zoom_dso = -2, zoom_thread = -2, | 825 | annotate = -2, zoom_dso = -2, zoom_thread = -2, |
750 | browse_map = -2; | 826 | browse_map = -2; |
751 | 827 | ||
752 | if (hist_browser__run(browser, msg, &es)) | 828 | key = hist_browser__run(browser, msg); |
753 | break; | ||
754 | 829 | ||
755 | thread = hist_browser__selected_thread(browser); | 830 | thread = hist_browser__selected_thread(browser); |
756 | dso = browser->selection->map ? browser->selection->map->dso : NULL; | 831 | dso = browser->selection->map ? browser->selection->map->dso : NULL; |
757 | 832 | ||
758 | if (es.reason == NEWT_EXIT_HOTKEY) { | 833 | switch (key) { |
759 | key = es.u.key; | 834 | case NEWT_KEY_TAB: |
760 | 835 | case NEWT_KEY_UNTAB: | |
761 | switch (key) { | 836 | /* |
762 | case NEWT_KEY_F1: | 837 | * Exit the browser, let hists__browser_tree |
763 | goto do_help; | 838 | * go to the next or previous |
764 | case NEWT_KEY_TAB: | 839 | */ |
765 | case NEWT_KEY_UNTAB: | 840 | goto out_free_stack; |
766 | /* | 841 | case 'a': |
767 | * Exit the browser, let hists__browser_tree | 842 | if (browser->selection->map == NULL && |
768 | * go to the next or previous | 843 | browser->selection->map->dso->annotate_warned) |
769 | */ | ||
770 | goto out_free_stack; | ||
771 | default:; | ||
772 | } | ||
773 | |||
774 | switch (key) { | ||
775 | case 'a': | ||
776 | if (browser->selection->map == NULL || | ||
777 | browser->selection->map->dso->annotate_warned) | ||
778 | continue; | ||
779 | goto do_annotate; | ||
780 | case 'd': | ||
781 | goto zoom_dso; | ||
782 | case 't': | ||
783 | goto zoom_thread; | ||
784 | case 'h': | ||
785 | case '?': | ||
786 | do_help: | ||
787 | ui__help_window("-> Zoom into DSO/Threads & Annotate current symbol\n" | ||
788 | "<- Zoom out\n" | ||
789 | "a Annotate current symbol\n" | ||
790 | "h/?/F1 Show this window\n" | ||
791 | "d Zoom into current DSO\n" | ||
792 | "t Zoom into current Thread\n" | ||
793 | "q/CTRL+C Exit browser"); | ||
794 | continue; | 844 | continue; |
795 | default:; | 845 | goto do_annotate; |
796 | } | 846 | case 'd': |
797 | if (is_exit_key(key)) { | 847 | goto zoom_dso; |
798 | if (key == NEWT_KEY_ESCAPE && | 848 | case 't': |
799 | !ui__dialog_yesno("Do you really want to exit?")) | 849 | goto zoom_thread; |
800 | continue; | 850 | case NEWT_KEY_F1: |
801 | break; | 851 | case 'h': |
802 | } | 852 | case '?': |
803 | 853 | ui__help_window("-> Zoom into DSO/Threads & Annotate current symbol\n" | |
804 | if (es.u.key == NEWT_KEY_LEFT) { | 854 | "<- Zoom out\n" |
805 | const void *top; | 855 | "a Annotate current symbol\n" |
856 | "h/?/F1 Show this window\n" | ||
857 | "C Collapse all callchains\n" | ||
858 | "E Expand all callchains\n" | ||
859 | "d Zoom into current DSO\n" | ||
860 | "t Zoom into current Thread\n" | ||
861 | "q/CTRL+C Exit browser"); | ||
862 | continue; | ||
863 | case NEWT_KEY_ENTER: | ||
864 | case NEWT_KEY_RIGHT: | ||
865 | /* menu */ | ||
866 | break; | ||
867 | case NEWT_KEY_LEFT: { | ||
868 | const void *top; | ||
806 | 869 | ||
807 | if (pstack__empty(fstack)) | 870 | if (pstack__empty(fstack)) |
808 | continue; | ||
809 | top = pstack__pop(fstack); | ||
810 | if (top == &dso_filter) | ||
811 | goto zoom_out_dso; | ||
812 | if (top == &thread_filter) | ||
813 | goto zoom_out_thread; | ||
814 | continue; | 871 | continue; |
815 | } | 872 | top = pstack__pop(fstack); |
873 | if (top == &dso_filter) | ||
874 | goto zoom_out_dso; | ||
875 | if (top == &thread_filter) | ||
876 | goto zoom_out_thread; | ||
877 | continue; | ||
878 | } | ||
879 | case NEWT_KEY_ESCAPE: | ||
880 | if (!ui__dialog_yesno("Do you really want to exit?")) | ||
881 | continue; | ||
882 | /* Fall thru */ | ||
883 | default: | ||
884 | goto out_free_stack; | ||
816 | } | 885 | } |
817 | 886 | ||
818 | if (browser->selection->sym != NULL && | 887 | if (browser->selection->sym != NULL && |
@@ -885,8 +954,8 @@ zoom_out_dso: | |||
885 | pstack__push(fstack, &dso_filter); | 954 | pstack__push(fstack, &dso_filter); |
886 | } | 955 | } |
887 | hists__filter_by_dso(self, dso_filter); | 956 | hists__filter_by_dso(self, dso_filter); |
888 | hist_browser__title(msg, sizeof(msg), ev_name, | 957 | hists__browser_title(self, msg, sizeof(msg), ev_name, |
889 | dso_filter, thread_filter); | 958 | dso_filter, thread_filter); |
890 | hist_browser__reset(browser); | 959 | hist_browser__reset(browser); |
891 | } else if (choice == zoom_thread) { | 960 | } else if (choice == zoom_thread) { |
892 | zoom_thread: | 961 | zoom_thread: |
@@ -903,8 +972,8 @@ zoom_out_thread: | |||
903 | pstack__push(fstack, &thread_filter); | 972 | pstack__push(fstack, &thread_filter); |
904 | } | 973 | } |
905 | hists__filter_by_thread(self, thread_filter); | 974 | hists__filter_by_thread(self, thread_filter); |
906 | hist_browser__title(msg, sizeof(msg), ev_name, | 975 | hists__browser_title(self, msg, sizeof(msg), ev_name, |
907 | dso_filter, thread_filter); | 976 | dso_filter, thread_filter); |
908 | hist_browser__reset(browser); | 977 | hist_browser__reset(browser); |
909 | } | 978 | } |
910 | } | 979 | } |
@@ -925,10 +994,6 @@ int hists__tui_browse_tree(struct rb_root *self, const char *help) | |||
925 | const char *ev_name = __event_name(hists->type, hists->config); | 994 | const char *ev_name = __event_name(hists->type, hists->config); |
926 | 995 | ||
927 | key = hists__browse(hists, help, ev_name); | 996 | key = hists__browse(hists, help, ev_name); |
928 | |||
929 | if (is_exit_key(key)) | ||
930 | break; | ||
931 | |||
932 | switch (key) { | 997 | switch (key) { |
933 | case NEWT_KEY_TAB: | 998 | case NEWT_KEY_TAB: |
934 | next = rb_next(nd); | 999 | next = rb_next(nd); |
@@ -940,7 +1005,7 @@ int hists__tui_browse_tree(struct rb_root *self, const char *help) | |||
940 | continue; | 1005 | continue; |
941 | nd = rb_prev(nd); | 1006 | nd = rb_prev(nd); |
942 | default: | 1007 | default: |
943 | break; | 1008 | return key; |
944 | } | 1009 | } |
945 | } | 1010 | } |
946 | 1011 | ||
diff --git a/tools/perf/util/ui/browsers/map.c b/tools/perf/util/ui/browsers/map.c index 142b825b42bf..e35437dfa5b4 100644 --- a/tools/perf/util/ui/browsers/map.c +++ b/tools/perf/util/ui/browsers/map.c | |||
@@ -1,6 +1,5 @@ | |||
1 | #include "../libslang.h" | 1 | #include "../libslang.h" |
2 | #include <elf.h> | 2 | #include <elf.h> |
3 | #include <newt.h> | ||
4 | #include <sys/ttydefaults.h> | 3 | #include <sys/ttydefaults.h> |
5 | #include <ctype.h> | 4 | #include <ctype.h> |
6 | #include <string.h> | 5 | #include <string.h> |
@@ -47,7 +46,6 @@ out_free_form: | |||
47 | struct map_browser { | 46 | struct map_browser { |
48 | struct ui_browser b; | 47 | struct ui_browser b; |
49 | struct map *map; | 48 | struct map *map; |
50 | u16 namelen; | ||
51 | u8 addrlen; | 49 | u8 addrlen; |
52 | }; | 50 | }; |
53 | 51 | ||
@@ -56,14 +54,16 @@ static void map_browser__write(struct ui_browser *self, void *nd, int row) | |||
56 | struct symbol *sym = rb_entry(nd, struct symbol, rb_node); | 54 | struct symbol *sym = rb_entry(nd, struct symbol, rb_node); |
57 | struct map_browser *mb = container_of(self, struct map_browser, b); | 55 | struct map_browser *mb = container_of(self, struct map_browser, b); |
58 | bool current_entry = ui_browser__is_current_entry(self, row); | 56 | bool current_entry = ui_browser__is_current_entry(self, row); |
59 | int color = ui_browser__percent_color(0, current_entry); | 57 | int width; |
60 | 58 | ||
61 | SLsmg_set_color(color); | 59 | ui_browser__set_percent_color(self, 0, current_entry); |
62 | slsmg_printf("%*llx %*llx %c ", | 60 | slsmg_printf("%*llx %*llx %c ", |
63 | mb->addrlen, sym->start, mb->addrlen, sym->end, | 61 | mb->addrlen, sym->start, mb->addrlen, sym->end, |
64 | sym->binding == STB_GLOBAL ? 'g' : | 62 | sym->binding == STB_GLOBAL ? 'g' : |
65 | sym->binding == STB_LOCAL ? 'l' : 'w'); | 63 | sym->binding == STB_LOCAL ? 'l' : 'w'); |
66 | slsmg_write_nstring(sym->name, mb->namelen); | 64 | width = self->width - ((mb->addrlen * 2) + 4); |
65 | if (width > 0) | ||
66 | slsmg_write_nstring(sym->name, width); | ||
67 | } | 67 | } |
68 | 68 | ||
69 | /* FIXME uber-kludgy, see comment on cmd_report... */ | 69 | /* FIXME uber-kludgy, see comment on cmd_report... */ |
@@ -98,31 +98,29 @@ static int map_browser__search(struct map_browser *self) | |||
98 | return 0; | 98 | return 0; |
99 | } | 99 | } |
100 | 100 | ||
101 | static int map_browser__run(struct map_browser *self, struct newtExitStruct *es) | 101 | static int map_browser__run(struct map_browser *self) |
102 | { | 102 | { |
103 | int key; | ||
104 | |||
103 | if (ui_browser__show(&self->b, self->map->dso->long_name, | 105 | if (ui_browser__show(&self->b, self->map->dso->long_name, |
104 | "Press <- or ESC to exit, %s / to search", | 106 | "Press <- or ESC to exit, %s / to search", |
105 | verbose ? "" : "restart with -v to use") < 0) | 107 | verbose ? "" : "restart with -v to use") < 0) |
106 | return -1; | 108 | return -1; |
107 | 109 | ||
108 | newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); | ||
109 | newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER); | ||
110 | if (verbose) | 110 | if (verbose) |
111 | newtFormAddHotKey(self->b.form, '/'); | 111 | ui_browser__add_exit_key(&self->b, '/'); |
112 | 112 | ||
113 | while (1) { | 113 | while (1) { |
114 | ui_browser__run(&self->b, es); | 114 | key = ui_browser__run(&self->b); |
115 | 115 | ||
116 | if (es->reason != NEWT_EXIT_HOTKEY) | 116 | if (verbose && key == '/') |
117 | break; | ||
118 | if (verbose && es->u.key == '/') | ||
119 | map_browser__search(self); | 117 | map_browser__search(self); |
120 | else | 118 | else |
121 | break; | 119 | break; |
122 | } | 120 | } |
123 | 121 | ||
124 | ui_browser__hide(&self->b); | 122 | ui_browser__hide(&self->b); |
125 | return 0; | 123 | return key; |
126 | } | 124 | } |
127 | 125 | ||
128 | int map__browse(struct map *self) | 126 | int map__browse(struct map *self) |
@@ -136,7 +134,6 @@ int map__browse(struct map *self) | |||
136 | }, | 134 | }, |
137 | .map = self, | 135 | .map = self, |
138 | }; | 136 | }; |
139 | struct newtExitStruct es; | ||
140 | struct rb_node *nd; | 137 | struct rb_node *nd; |
141 | char tmp[BITS_PER_LONG / 4]; | 138 | char tmp[BITS_PER_LONG / 4]; |
142 | u64 maxaddr = 0; | 139 | u64 maxaddr = 0; |
@@ -144,8 +141,6 @@ int map__browse(struct map *self) | |||
144 | for (nd = rb_first(mb.b.entries); nd; nd = rb_next(nd)) { | 141 | for (nd = rb_first(mb.b.entries); nd; nd = rb_next(nd)) { |
145 | struct symbol *pos = rb_entry(nd, struct symbol, rb_node); | 142 | struct symbol *pos = rb_entry(nd, struct symbol, rb_node); |
146 | 143 | ||
147 | if (mb.namelen < pos->namelen) | ||
148 | mb.namelen = pos->namelen; | ||
149 | if (maxaddr < pos->end) | 144 | if (maxaddr < pos->end) |
150 | maxaddr = pos->end; | 145 | maxaddr = pos->end; |
151 | if (verbose) { | 146 | if (verbose) { |
@@ -156,6 +151,5 @@ int map__browse(struct map *self) | |||
156 | } | 151 | } |
157 | 152 | ||
158 | mb.addrlen = snprintf(tmp, sizeof(tmp), "%llx", maxaddr); | 153 | mb.addrlen = snprintf(tmp, sizeof(tmp), "%llx", maxaddr); |
159 | mb.b.width += mb.addrlen * 2 + 4 + mb.namelen; | 154 | return map_browser__run(&mb); |
160 | return map_browser__run(&mb, &es); | ||
161 | } | 155 | } |
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c index 04600e26ceea..056c69521a38 100644 --- a/tools/perf/util/ui/util.c +++ b/tools/perf/util/ui/util.c | |||
@@ -11,8 +11,6 @@ | |||
11 | #include "helpline.h" | 11 | #include "helpline.h" |
12 | #include "util.h" | 12 | #include "util.h" |
13 | 13 | ||
14 | newtComponent newt_form__new(void); | ||
15 | |||
16 | static void newt_form__set_exit_keys(newtComponent self) | 14 | static void newt_form__set_exit_keys(newtComponent self) |
17 | { | 15 | { |
18 | newtFormAddHotKey(self, NEWT_KEY_LEFT); | 16 | newtFormAddHotKey(self, NEWT_KEY_LEFT); |
@@ -22,7 +20,7 @@ static void newt_form__set_exit_keys(newtComponent self) | |||
22 | newtFormAddHotKey(self, CTRL('c')); | 20 | newtFormAddHotKey(self, CTRL('c')); |
23 | } | 21 | } |
24 | 22 | ||
25 | newtComponent newt_form__new(void) | 23 | static newtComponent newt_form__new(void) |
26 | { | 24 | { |
27 | newtComponent self = newtForm(NULL, NULL, 0); | 25 | newtComponent self = newtForm(NULL, NULL, 0); |
28 | if (self) | 26 | if (self) |
@@ -106,9 +104,10 @@ out_destroy_form: | |||
106 | return rc; | 104 | return rc; |
107 | } | 105 | } |
108 | 106 | ||
107 | static const char yes[] = "Yes", no[] = "No"; | ||
108 | |||
109 | bool ui__dialog_yesno(const char *msg) | 109 | bool ui__dialog_yesno(const char *msg) |
110 | { | 110 | { |
111 | /* newtWinChoice should really be accepting const char pointers... */ | 111 | /* newtWinChoice should really be accepting const char pointers... */ |
112 | char yes[] = "Yes", no[] = "No"; | 112 | return newtWinChoice(NULL, (char *)yes, (char *)no, (char *)msg) == 1; |
113 | return newtWinChoice(NULL, yes, no, (char *)msg) == 1; | ||
114 | } | 113 | } |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index f380fed74359..7562707ddd1c 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -266,19 +266,6 @@ bool strglobmatch(const char *str, const char *pat); | |||
266 | bool strlazymatch(const char *str, const char *pat); | 266 | bool strlazymatch(const char *str, const char *pat); |
267 | unsigned long convert_unit(unsigned long value, char *unit); | 267 | unsigned long convert_unit(unsigned long value, char *unit); |
268 | 268 | ||
269 | #ifndef ESC | ||
270 | #define ESC 27 | ||
271 | #endif | ||
272 | |||
273 | static inline bool is_exit_key(int key) | ||
274 | { | ||
275 | char up; | ||
276 | if (key == CTRL('c') || key == ESC) | ||
277 | return true; | ||
278 | up = toupper(key); | ||
279 | return up == 'Q'; | ||
280 | } | ||
281 | |||
282 | #define _STR(x) #x | 269 | #define _STR(x) #x |
283 | #define STR(x) _STR(x) | 270 | #define STR(x) _STR(x) |
284 | 271 | ||
diff --git a/tools/power/x86/x86_energy_perf_policy/Makefile b/tools/power/x86/x86_energy_perf_policy/Makefile new file mode 100644 index 000000000000..f458237fdd79 --- /dev/null +++ b/tools/power/x86/x86_energy_perf_policy/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | x86_energy_perf_policy : x86_energy_perf_policy.c | ||
2 | |||
3 | clean : | ||
4 | rm -f x86_energy_perf_policy | ||
5 | |||
6 | install : | ||
7 | install x86_energy_perf_policy /usr/bin/ | ||
8 | install x86_energy_perf_policy.8 /usr/share/man/man8/ | ||
diff --git a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.8 b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.8 new file mode 100644 index 000000000000..8eaaad648cdb --- /dev/null +++ b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.8 | |||
@@ -0,0 +1,104 @@ | |||
1 | .\" This page Copyright (C) 2010 Len Brown <len.brown@intel.com> | ||
2 | .\" Distributed under the GPL, Copyleft 1994. | ||
3 | .TH X86_ENERGY_PERF_POLICY 8 | ||
4 | .SH NAME | ||
5 | x86_energy_perf_policy \- read or write MSR_IA32_ENERGY_PERF_BIAS | ||
6 | .SH SYNOPSIS | ||
7 | .ft B | ||
8 | .B x86_energy_perf_policy | ||
9 | .RB [ "\-c cpu" ] | ||
10 | .RB [ "\-v" ] | ||
11 | .RB "\-r" | ||
12 | .br | ||
13 | .B x86_energy_perf_policy | ||
14 | .RB [ "\-c cpu" ] | ||
15 | .RB [ "\-v" ] | ||
16 | .RB 'performance' | ||
17 | .br | ||
18 | .B x86_energy_perf_policy | ||
19 | .RB [ "\-c cpu" ] | ||
20 | .RB [ "\-v" ] | ||
21 | .RB 'normal' | ||
22 | .br | ||
23 | .B x86_energy_perf_policy | ||
24 | .RB [ "\-c cpu" ] | ||
25 | .RB [ "\-v" ] | ||
26 | .RB 'powersave' | ||
27 | .br | ||
28 | .B x86_energy_perf_policy | ||
29 | .RB [ "\-c cpu" ] | ||
30 | .RB [ "\-v" ] | ||
31 | .RB n | ||
32 | .br | ||
33 | .SH DESCRIPTION | ||
34 | \fBx86_energy_perf_policy\fP | ||
35 | allows software to convey | ||
36 | its policy for the relative importance of performance | ||
37 | versus energy savings to the processor. | ||
38 | |||
39 | The processor uses this information in model-specific ways | ||
40 | when it must select trade-offs between performance and | ||
41 | energy efficiency. | ||
42 | |||
43 | This policy hint does not supersede Processor Performance states | ||
44 | (P-states) or CPU Idle power states (C-states), but allows | ||
45 | software to have influence where it would otherwise be unable | ||
46 | to express a preference. | ||
47 | |||
48 | For example, this setting may tell the hardware how | ||
49 | aggressively or conservatively to control frequency | ||
50 | in the "turbo range" above the explicitly OS-controlled | ||
51 | P-state frequency range. It may also tell the hardware | ||
52 | how aggressively is should enter the OS requested C-states. | ||
53 | |||
54 | Support for this feature is indicated by CPUID.06H.ECX.bit3 | ||
55 | per the Intel Architectures Software Developer's Manual. | ||
56 | |||
57 | .SS Options | ||
58 | \fB-c\fP limits operation to a single CPU. | ||
59 | The default is to operate on all CPUs. | ||
60 | Note that MSR_IA32_ENERGY_PERF_BIAS is defined per | ||
61 | logical processor, but that the initial implementations | ||
62 | of the MSR were shared among all processors in each package. | ||
63 | .PP | ||
64 | \fB-v\fP increases verbosity. By default | ||
65 | x86_energy_perf_policy is silent. | ||
66 | .PP | ||
67 | \fB-r\fP is for "read-only" mode - the unchanged state | ||
68 | is read and displayed. | ||
69 | .PP | ||
70 | .I performance | ||
71 | Set a policy where performance is paramount. | ||
72 | The processor will be unwilling to sacrifice any performance | ||
73 | for the sake of energy saving. This is the hardware default. | ||
74 | .PP | ||
75 | .I normal | ||
76 | Set a policy with a normal balance between performance and energy efficiency. | ||
77 | The processor will tolerate minor performance compromise | ||
78 | for potentially significant energy savings. | ||
79 | This reasonable default for most desktops and servers. | ||
80 | .PP | ||
81 | .I powersave | ||
82 | Set a policy where the processor can accept | ||
83 | a measurable performance hit to maximize energy efficiency. | ||
84 | .PP | ||
85 | .I n | ||
86 | Set MSR_IA32_ENERGY_PERF_BIAS to the specified number. | ||
87 | The range of valid numbers is 0-15, where 0 is maximum | ||
88 | performance and 15 is maximum energy efficiency. | ||
89 | |||
90 | .SH NOTES | ||
91 | .B "x86_energy_perf_policy " | ||
92 | runs only as root. | ||
93 | .SH FILES | ||
94 | .ta | ||
95 | .nf | ||
96 | /dev/cpu/*/msr | ||
97 | .fi | ||
98 | |||
99 | .SH "SEE ALSO" | ||
100 | msr(4) | ||
101 | .PP | ||
102 | .SH AUTHORS | ||
103 | .nf | ||
104 | Written by Len Brown <len.brown@intel.com> | ||
diff --git a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c new file mode 100644 index 000000000000..d9678a34dd70 --- /dev/null +++ b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | |||
@@ -0,0 +1,325 @@ | |||
1 | /* | ||
2 | * x86_energy_perf_policy -- set the energy versus performance | ||
3 | * policy preference bias on recent X86 processors. | ||
4 | */ | ||
5 | /* | ||
6 | * Copyright (c) 2010, Intel Corporation. | ||
7 | * Len Brown <len.brown@intel.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms and conditions of the GNU General Public License, | ||
11 | * version 2, as published by the Free Software Foundation. | ||
12 | * | ||
13 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
16 | * more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License along with | ||
19 | * this program; if not, write to the Free Software Foundation, Inc., | ||
20 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
21 | */ | ||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <unistd.h> | ||
25 | #include <sys/types.h> | ||
26 | #include <sys/stat.h> | ||
27 | #include <sys/resource.h> | ||
28 | #include <fcntl.h> | ||
29 | #include <signal.h> | ||
30 | #include <sys/time.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <string.h> | ||
33 | |||
34 | unsigned int verbose; /* set with -v */ | ||
35 | unsigned int read_only; /* set with -r */ | ||
36 | char *progname; | ||
37 | unsigned long long new_bias; | ||
38 | int cpu = -1; | ||
39 | |||
40 | /* | ||
41 | * Usage: | ||
42 | * | ||
43 | * -c cpu: limit action to a single CPU (default is all CPUs) | ||
44 | * -v: verbose output (can invoke more than once) | ||
45 | * -r: read-only, don't change any settings | ||
46 | * | ||
47 | * performance | ||
48 | * Performance is paramount. | ||
49 | * Unwilling to sacrafice any performance | ||
50 | * for the sake of energy saving. (hardware default) | ||
51 | * | ||
52 | * normal | ||
53 | * Can tolerate minor performance compromise | ||
54 | * for potentially significant energy savings. | ||
55 | * (reasonable default for most desktops and servers) | ||
56 | * | ||
57 | * powersave | ||
58 | * Can tolerate significant performance hit | ||
59 | * to maximize energy savings. | ||
60 | * | ||
61 | * n | ||
62 | * a numerical value to write to the underlying MSR. | ||
63 | */ | ||
64 | void usage(void) | ||
65 | { | ||
66 | printf("%s: [-c cpu] [-v] " | ||
67 | "(-r | 'performance' | 'normal' | 'powersave' | n)\n", | ||
68 | progname); | ||
69 | exit(1); | ||
70 | } | ||
71 | |||
72 | #define MSR_IA32_ENERGY_PERF_BIAS 0x000001b0 | ||
73 | |||
74 | #define BIAS_PERFORMANCE 0 | ||
75 | #define BIAS_BALANCE 6 | ||
76 | #define BIAS_POWERSAVE 15 | ||
77 | |||
78 | void cmdline(int argc, char **argv) | ||
79 | { | ||
80 | int opt; | ||
81 | |||
82 | progname = argv[0]; | ||
83 | |||
84 | while ((opt = getopt(argc, argv, "+rvc:")) != -1) { | ||
85 | switch (opt) { | ||
86 | case 'c': | ||
87 | cpu = atoi(optarg); | ||
88 | break; | ||
89 | case 'r': | ||
90 | read_only = 1; | ||
91 | break; | ||
92 | case 'v': | ||
93 | verbose++; | ||
94 | break; | ||
95 | default: | ||
96 | usage(); | ||
97 | } | ||
98 | } | ||
99 | /* if -r, then should be no additional optind */ | ||
100 | if (read_only && (argc > optind)) | ||
101 | usage(); | ||
102 | |||
103 | /* | ||
104 | * if no -r , then must be one additional optind | ||
105 | */ | ||
106 | if (!read_only) { | ||
107 | |||
108 | if (argc != optind + 1) { | ||
109 | printf("must supply -r or policy param\n"); | ||
110 | usage(); | ||
111 | } | ||
112 | |||
113 | if (!strcmp("performance", argv[optind])) { | ||
114 | new_bias = BIAS_PERFORMANCE; | ||
115 | } else if (!strcmp("normal", argv[optind])) { | ||
116 | new_bias = BIAS_BALANCE; | ||
117 | } else if (!strcmp("powersave", argv[optind])) { | ||
118 | new_bias = BIAS_POWERSAVE; | ||
119 | } else { | ||
120 | char *endptr; | ||
121 | |||
122 | new_bias = strtoull(argv[optind], &endptr, 0); | ||
123 | if (endptr == argv[optind] || | ||
124 | new_bias > BIAS_POWERSAVE) { | ||
125 | fprintf(stderr, "invalid value: %s\n", | ||
126 | argv[optind]); | ||
127 | usage(); | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | } | ||
132 | |||
133 | /* | ||
134 | * validate_cpuid() | ||
135 | * returns on success, quietly exits on failure (make verbose with -v) | ||
136 | */ | ||
137 | void validate_cpuid(void) | ||
138 | { | ||
139 | unsigned int eax, ebx, ecx, edx, max_level; | ||
140 | char brand[16]; | ||
141 | unsigned int fms, family, model, stepping; | ||
142 | |||
143 | eax = ebx = ecx = edx = 0; | ||
144 | |||
145 | asm("cpuid" : "=a" (max_level), "=b" (ebx), "=c" (ecx), | ||
146 | "=d" (edx) : "a" (0)); | ||
147 | |||
148 | if (ebx != 0x756e6547 || edx != 0x49656e69 || ecx != 0x6c65746e) { | ||
149 | if (verbose) | ||
150 | fprintf(stderr, "%.4s%.4s%.4s != GenuineIntel", | ||
151 | (char *)&ebx, (char *)&edx, (char *)&ecx); | ||
152 | exit(1); | ||
153 | } | ||
154 | |||
155 | asm("cpuid" : "=a" (fms), "=c" (ecx), "=d" (edx) : "a" (1) : "ebx"); | ||
156 | family = (fms >> 8) & 0xf; | ||
157 | model = (fms >> 4) & 0xf; | ||
158 | stepping = fms & 0xf; | ||
159 | if (family == 6 || family == 0xf) | ||
160 | model += ((fms >> 16) & 0xf) << 4; | ||
161 | |||
162 | if (verbose > 1) | ||
163 | printf("CPUID %s %d levels family:model:stepping " | ||
164 | "0x%x:%x:%x (%d:%d:%d)\n", brand, max_level, | ||
165 | family, model, stepping, family, model, stepping); | ||
166 | |||
167 | if (!(edx & (1 << 5))) { | ||
168 | if (verbose) | ||
169 | printf("CPUID: no MSR\n"); | ||
170 | exit(1); | ||
171 | } | ||
172 | |||
173 | /* | ||
174 | * Support for MSR_IA32_ENERGY_PERF_BIAS | ||
175 | * is indicated by CPUID.06H.ECX.bit3 | ||
176 | */ | ||
177 | asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (6)); | ||
178 | if (verbose) | ||
179 | printf("CPUID.06H.ECX: 0x%x\n", ecx); | ||
180 | if (!(ecx & (1 << 3))) { | ||
181 | if (verbose) | ||
182 | printf("CPUID: No MSR_IA32_ENERGY_PERF_BIAS\n"); | ||
183 | exit(1); | ||
184 | } | ||
185 | return; /* success */ | ||
186 | } | ||
187 | |||
188 | unsigned long long get_msr(int cpu, int offset) | ||
189 | { | ||
190 | unsigned long long msr; | ||
191 | char msr_path[32]; | ||
192 | int retval; | ||
193 | int fd; | ||
194 | |||
195 | sprintf(msr_path, "/dev/cpu/%d/msr", cpu); | ||
196 | fd = open(msr_path, O_RDONLY); | ||
197 | if (fd < 0) { | ||
198 | printf("Try \"# modprobe msr\"\n"); | ||
199 | perror(msr_path); | ||
200 | exit(1); | ||
201 | } | ||
202 | |||
203 | retval = pread(fd, &msr, sizeof msr, offset); | ||
204 | |||
205 | if (retval != sizeof msr) { | ||
206 | printf("pread cpu%d 0x%x = %d\n", cpu, offset, retval); | ||
207 | exit(-2); | ||
208 | } | ||
209 | close(fd); | ||
210 | return msr; | ||
211 | } | ||
212 | |||
213 | unsigned long long put_msr(int cpu, unsigned long long new_msr, int offset) | ||
214 | { | ||
215 | unsigned long long old_msr; | ||
216 | char msr_path[32]; | ||
217 | int retval; | ||
218 | int fd; | ||
219 | |||
220 | sprintf(msr_path, "/dev/cpu/%d/msr", cpu); | ||
221 | fd = open(msr_path, O_RDWR); | ||
222 | if (fd < 0) { | ||
223 | perror(msr_path); | ||
224 | exit(1); | ||
225 | } | ||
226 | |||
227 | retval = pread(fd, &old_msr, sizeof old_msr, offset); | ||
228 | if (retval != sizeof old_msr) { | ||
229 | perror("pwrite"); | ||
230 | printf("pread cpu%d 0x%x = %d\n", cpu, offset, retval); | ||
231 | exit(-2); | ||
232 | } | ||
233 | |||
234 | retval = pwrite(fd, &new_msr, sizeof new_msr, offset); | ||
235 | if (retval != sizeof new_msr) { | ||
236 | perror("pwrite"); | ||
237 | printf("pwrite cpu%d 0x%x = %d\n", cpu, offset, retval); | ||
238 | exit(-2); | ||
239 | } | ||
240 | |||
241 | close(fd); | ||
242 | |||
243 | return old_msr; | ||
244 | } | ||
245 | |||
246 | void print_msr(int cpu) | ||
247 | { | ||
248 | printf("cpu%d: 0x%016llx\n", | ||
249 | cpu, get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS)); | ||
250 | } | ||
251 | |||
252 | void update_msr(int cpu) | ||
253 | { | ||
254 | unsigned long long previous_msr; | ||
255 | |||
256 | previous_msr = put_msr(cpu, new_bias, MSR_IA32_ENERGY_PERF_BIAS); | ||
257 | |||
258 | if (verbose) | ||
259 | printf("cpu%d msr0x%x 0x%016llx -> 0x%016llx\n", | ||
260 | cpu, MSR_IA32_ENERGY_PERF_BIAS, previous_msr, new_bias); | ||
261 | |||
262 | return; | ||
263 | } | ||
264 | |||
265 | char *proc_stat = "/proc/stat"; | ||
266 | /* | ||
267 | * run func() on every cpu in /dev/cpu | ||
268 | */ | ||
269 | void for_every_cpu(void (func)(int)) | ||
270 | { | ||
271 | FILE *fp; | ||
272 | int retval; | ||
273 | |||
274 | fp = fopen(proc_stat, "r"); | ||
275 | if (fp == NULL) { | ||
276 | perror(proc_stat); | ||
277 | exit(1); | ||
278 | } | ||
279 | |||
280 | retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n"); | ||
281 | if (retval != 0) { | ||
282 | perror("/proc/stat format"); | ||
283 | exit(1); | ||
284 | } | ||
285 | |||
286 | while (1) { | ||
287 | int cpu; | ||
288 | |||
289 | retval = fscanf(fp, | ||
290 | "cpu%u %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n", | ||
291 | &cpu); | ||
292 | if (retval != 1) | ||
293 | return; | ||
294 | |||
295 | func(cpu); | ||
296 | } | ||
297 | fclose(fp); | ||
298 | } | ||
299 | |||
300 | int main(int argc, char **argv) | ||
301 | { | ||
302 | cmdline(argc, argv); | ||
303 | |||
304 | if (verbose > 1) | ||
305 | printf("x86_energy_perf_policy Nov 24, 2010" | ||
306 | " - Len Brown <lenb@kernel.org>\n"); | ||
307 | if (verbose > 1 && !read_only) | ||
308 | printf("new_bias %lld\n", new_bias); | ||
309 | |||
310 | validate_cpuid(); | ||
311 | |||
312 | if (cpu != -1) { | ||
313 | if (read_only) | ||
314 | print_msr(cpu); | ||
315 | else | ||
316 | update_msr(cpu); | ||
317 | } else { | ||
318 | if (read_only) | ||
319 | for_every_cpu(print_msr); | ||
320 | else | ||
321 | for_every_cpu(update_msr); | ||
322 | } | ||
323 | |||
324 | return 0; | ||
325 | } | ||