diff options
Diffstat (limited to 'tools')
24 files changed, 971 insertions, 296 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-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/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-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/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/python/bin/netdev-times-record b/tools/perf/scripts/python/bin/netdev-times-record new file mode 100644 index 000000000000..d931a828126b --- /dev/null +++ b/tools/perf/scripts/python/bin/netdev-times-record | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | perf record -a -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..c3d0a638123d --- /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 ~/libexec/perf-core/scripts/python/netdev-times.py $@ | ||
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/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/hist.c b/tools/perf/util/hist.c index be22ae6ef055..2022e8740994 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 | } |
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/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/symbol.c b/tools/perf/util/symbol.c index b2f5ae97f33d..b39f499e575a 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
| @@ -388,6 +388,20 @@ size_t dso__fprintf_buildid(struct dso *self, FILE *fp) | |||
| 388 | return fprintf(fp, "%s", sbuild_id); | 388 | return fprintf(fp, "%s", sbuild_id); |
| 389 | } | 389 | } |
| 390 | 390 | ||
| 391 | size_t dso__fprintf_symbols_by_name(struct dso *self, enum map_type type, FILE *fp) | ||
| 392 | { | ||
| 393 | size_t ret = 0; | ||
| 394 | struct rb_node *nd; | ||
| 395 | struct symbol_name_rb_node *pos; | ||
| 396 | |||
| 397 | for (nd = rb_first(&self->symbol_names[type]); nd; nd = rb_next(nd)) { | ||
| 398 | pos = rb_entry(nd, struct symbol_name_rb_node, rb_node); | ||
| 399 | fprintf(fp, "%s\n", pos->sym.name); | ||
| 400 | } | ||
| 401 | |||
| 402 | return ret; | ||
| 403 | } | ||
| 404 | |||
| 391 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp) | 405 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp) |
| 392 | { | 406 | { |
| 393 | struct rb_node *nd; | 407 | struct rb_node *nd; |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index ea95c2756f05..038f2201ee09 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
| @@ -182,6 +182,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); | 182 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits); |
| 183 | 183 | ||
| 184 | size_t dso__fprintf_buildid(struct dso *self, FILE *fp); | 184 | size_t dso__fprintf_buildid(struct dso *self, FILE *fp); |
| 185 | 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); | 186 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp); |
| 186 | 187 | ||
| 187 | enum dso_origin { | 188 | enum dso_origin { |
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c index 66f2d583d8c4..6d0df809a2ed 100644 --- a/tools/perf/util/ui/browser.c +++ b/tools/perf/util/ui/browser.c | |||
| @@ -1,16 +1,6 @@ | |||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.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> | 1 | #include <slang.h> |
| 2 | #include "libslang.h" | ||
| 3 | #include <linux/compiler.h> | ||
| 14 | #include <linux/list.h> | 4 | #include <linux/list.h> |
| 15 | #include <linux/rbtree.h> | 5 | #include <linux/rbtree.h> |
| 16 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| @@ -19,17 +9,9 @@ | |||
| 19 | #include "helpline.h" | 9 | #include "helpline.h" |
| 20 | #include "../color.h" | 10 | #include "../color.h" |
| 21 | #include "../util.h" | 11 | #include "../util.h" |
| 12 | #include <stdio.h> | ||
| 22 | 13 | ||
| 23 | #if SLANG_VERSION < 20104 | 14 | 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 | { | 15 | { |
| 34 | if (current) | 16 | if (current) |
| 35 | return HE_COLORSET_SELECTED; | 17 | return HE_COLORSET_SELECTED; |
| @@ -40,6 +22,23 @@ int ui_browser__percent_color(double percent, bool current) | |||
| 40 | return HE_COLORSET_NORMAL; | 22 | return HE_COLORSET_NORMAL; |
| 41 | } | 23 | } |
| 42 | 24 | ||
| 25 | void ui_browser__set_color(struct ui_browser *self __used, int color) | ||
| 26 | { | ||
| 27 | SLsmg_set_color(color); | ||
| 28 | } | ||
| 29 | |||
| 30 | void ui_browser__set_percent_color(struct ui_browser *self, | ||
| 31 | double percent, bool current) | ||
| 32 | { | ||
| 33 | int color = ui_browser__percent_color(percent, current); | ||
| 34 | ui_browser__set_color(self, color); | ||
| 35 | } | ||
| 36 | |||
| 37 | void ui_browser__gotorc(struct ui_browser *self, int y, int x) | ||
| 38 | { | ||
| 39 | SLsmg_gotorc(self->y + y, self->x + x); | ||
| 40 | } | ||
| 41 | |||
| 43 | void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) | 42 | void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) |
| 44 | { | 43 | { |
| 45 | struct list_head *head = self->entries; | 44 | struct list_head *head = self->entries; |
| @@ -111,7 +110,7 @@ unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self) | |||
| 111 | nd = self->top; | 110 | nd = self->top; |
| 112 | 111 | ||
| 113 | while (nd != NULL) { | 112 | while (nd != NULL) { |
| 114 | SLsmg_gotorc(self->y + row, self->x); | 113 | ui_browser__gotorc(self, row, 0); |
| 115 | self->write(self, nd, row); | 114 | self->write(self, nd, row); |
| 116 | if (++row == self->height) | 115 | if (++row == self->height) |
| 117 | break; | 116 | break; |
| @@ -131,13 +130,10 @@ void ui_browser__refresh_dimensions(struct ui_browser *self) | |||
| 131 | int cols, rows; | 130 | int cols, rows; |
| 132 | newtGetScreenSize(&cols, &rows); | 131 | newtGetScreenSize(&cols, &rows); |
| 133 | 132 | ||
| 134 | if (self->width > cols - 4) | 133 | self->width = cols - 1; |
| 135 | self->width = cols - 4; | 134 | self->height = rows - 2; |
| 136 | self->height = rows - 5; | 135 | self->y = 1; |
| 137 | if (self->height > self->nr_entries) | 136 | self->x = 0; |
| 138 | self->height = self->nr_entries; | ||
| 139 | self->y = (rows - self->height) / 2; | ||
| 140 | self->x = (cols - self->width) / 2; | ||
| 141 | } | 137 | } |
| 142 | 138 | ||
| 143 | void ui_browser__reset_index(struct ui_browser *self) | 139 | void ui_browser__reset_index(struct ui_browser *self) |
| @@ -146,34 +142,48 @@ void ui_browser__reset_index(struct ui_browser *self) | |||
| 146 | self->seek(self, 0, SEEK_SET); | 142 | self->seek(self, 0, SEEK_SET); |
| 147 | } | 143 | } |
| 148 | 144 | ||
| 145 | void ui_browser__add_exit_key(struct ui_browser *self, int key) | ||
| 146 | { | ||
| 147 | newtFormAddHotKey(self->form, key); | ||
| 148 | } | ||
| 149 | |||
| 150 | void ui_browser__add_exit_keys(struct ui_browser *self, int keys[]) | ||
| 151 | { | ||
| 152 | int i = 0; | ||
| 153 | |||
| 154 | while (keys[i] && i < 64) { | ||
| 155 | ui_browser__add_exit_key(self, keys[i]); | ||
| 156 | ++i; | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 149 | int ui_browser__show(struct ui_browser *self, const char *title, | 160 | int ui_browser__show(struct ui_browser *self, const char *title, |
| 150 | const char *helpline, ...) | 161 | const char *helpline, ...) |
| 151 | { | 162 | { |
| 152 | va_list ap; | 163 | va_list ap; |
| 164 | int keys[] = { NEWT_KEY_UP, NEWT_KEY_DOWN, NEWT_KEY_PGUP, | ||
| 165 | NEWT_KEY_PGDN, NEWT_KEY_HOME, NEWT_KEY_END, ' ', | ||
| 166 | NEWT_KEY_LEFT, NEWT_KEY_ESCAPE, 'q', CTRL('c'), 0 }; | ||
| 153 | 167 | ||
| 154 | if (self->form != NULL) { | 168 | if (self->form != NULL) |
| 155 | newtFormDestroy(self->form); | 169 | newtFormDestroy(self->form); |
| 156 | newtPopWindow(); | 170 | |
| 157 | } | ||
| 158 | ui_browser__refresh_dimensions(self); | 171 | ui_browser__refresh_dimensions(self); |
| 159 | newtCenteredWindow(self->width, self->height, title); | 172 | self->form = newtForm(NULL, NULL, 0); |
| 160 | self->form = newt_form__new(); | ||
| 161 | if (self->form == NULL) | 173 | if (self->form == NULL) |
| 162 | return -1; | 174 | return -1; |
| 163 | 175 | ||
| 164 | self->sb = newtVerticalScrollbar(self->width, 0, self->height, | 176 | self->sb = newtVerticalScrollbar(self->width, 1, self->height, |
| 165 | HE_COLORSET_NORMAL, | 177 | HE_COLORSET_NORMAL, |
| 166 | HE_COLORSET_SELECTED); | 178 | HE_COLORSET_SELECTED); |
| 167 | if (self->sb == NULL) | 179 | if (self->sb == NULL) |
| 168 | return -1; | 180 | return -1; |
| 169 | 181 | ||
| 170 | newtFormAddHotKey(self->form, NEWT_KEY_UP); | 182 | SLsmg_gotorc(0, 0); |
| 171 | newtFormAddHotKey(self->form, NEWT_KEY_DOWN); | 183 | ui_browser__set_color(self, NEWT_COLORSET_ROOT); |
| 172 | newtFormAddHotKey(self->form, NEWT_KEY_PGUP); | 184 | slsmg_write_nstring(title, self->width); |
| 173 | newtFormAddHotKey(self->form, NEWT_KEY_PGDN); | 185 | |
| 174 | newtFormAddHotKey(self->form, NEWT_KEY_HOME); | 186 | ui_browser__add_exit_keys(self, keys); |
| 175 | newtFormAddHotKey(self->form, NEWT_KEY_END); | ||
| 176 | newtFormAddHotKey(self->form, ' '); | ||
| 177 | newtFormAddComponent(self->form, self->sb); | 187 | newtFormAddComponent(self->form, self->sb); |
| 178 | 188 | ||
| 179 | va_start(ap, helpline); | 189 | va_start(ap, helpline); |
| @@ -185,7 +195,6 @@ int ui_browser__show(struct ui_browser *self, const char *title, | |||
| 185 | void ui_browser__hide(struct ui_browser *self) | 195 | void ui_browser__hide(struct ui_browser *self) |
| 186 | { | 196 | { |
| 187 | newtFormDestroy(self->form); | 197 | newtFormDestroy(self->form); |
| 188 | newtPopWindow(); | ||
| 189 | self->form = NULL; | 198 | self->form = NULL; |
| 190 | ui_helpline__pop(); | 199 | ui_helpline__pop(); |
| 191 | } | 200 | } |
| @@ -196,28 +205,28 @@ int ui_browser__refresh(struct ui_browser *self) | |||
| 196 | 205 | ||
| 197 | newtScrollbarSet(self->sb, self->index, self->nr_entries - 1); | 206 | newtScrollbarSet(self->sb, self->index, self->nr_entries - 1); |
| 198 | row = self->refresh(self); | 207 | row = self->refresh(self); |
| 199 | SLsmg_set_color(HE_COLORSET_NORMAL); | 208 | ui_browser__set_color(self, HE_COLORSET_NORMAL); |
| 200 | SLsmg_fill_region(self->y + row, self->x, | 209 | SLsmg_fill_region(self->y + row, self->x, |
| 201 | self->height - row, self->width, ' '); | 210 | self->height - row, self->width, ' '); |
| 202 | 211 | ||
| 203 | return 0; | 212 | return 0; |
| 204 | } | 213 | } |
| 205 | 214 | ||
| 206 | int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es) | 215 | int ui_browser__run(struct ui_browser *self) |
| 207 | { | 216 | { |
| 217 | struct newtExitStruct es; | ||
| 218 | |||
| 208 | if (ui_browser__refresh(self) < 0) | 219 | if (ui_browser__refresh(self) < 0) |
| 209 | return -1; | 220 | return -1; |
| 210 | 221 | ||
| 211 | while (1) { | 222 | while (1) { |
| 212 | off_t offset; | 223 | off_t offset; |
| 213 | 224 | ||
| 214 | newtFormRun(self->form, es); | 225 | newtFormRun(self->form, &es); |
| 215 | 226 | ||
| 216 | if (es->reason != NEWT_EXIT_HOTKEY) | 227 | if (es.reason != NEWT_EXIT_HOTKEY) |
| 217 | break; | 228 | break; |
| 218 | if (is_exit_key(es->u.key)) | 229 | switch (es.u.key) { |
| 219 | return es->u.key; | ||
| 220 | switch (es->u.key) { | ||
| 221 | case NEWT_KEY_DOWN: | 230 | case NEWT_KEY_DOWN: |
| 222 | if (self->index == self->nr_entries - 1) | 231 | if (self->index == self->nr_entries - 1) |
| 223 | break; | 232 | break; |
| @@ -274,12 +283,12 @@ int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es) | |||
| 274 | self->seek(self, -offset, SEEK_END); | 283 | self->seek(self, -offset, SEEK_END); |
| 275 | break; | 284 | break; |
| 276 | default: | 285 | default: |
| 277 | return es->u.key; | 286 | return es.u.key; |
| 278 | } | 287 | } |
| 279 | if (ui_browser__refresh(self) < 0) | 288 | if (ui_browser__refresh(self) < 0) |
| 280 | return -1; | 289 | return -1; |
| 281 | } | 290 | } |
| 282 | return 0; | 291 | return -1; |
| 283 | } | 292 | } |
| 284 | 293 | ||
| 285 | unsigned int ui_browser__list_head_refresh(struct ui_browser *self) | 294 | unsigned int ui_browser__list_head_refresh(struct ui_browser *self) |
| @@ -294,7 +303,7 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *self) | |||
| 294 | pos = self->top; | 303 | pos = self->top; |
| 295 | 304 | ||
| 296 | list_for_each_from(pos, head) { | 305 | list_for_each_from(pos, head) { |
| 297 | SLsmg_gotorc(self->y + row, self->x); | 306 | ui_browser__gotorc(self, row, 0); |
| 298 | self->write(self, pos, row); | 307 | self->write(self, pos, row); |
| 299 | if (++row == self->height) | 308 | if (++row == self->height) |
| 300 | break; | 309 | 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..9706d9d40279 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) |
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 | ||
