perf annotate: Create a new '--tui-dump' option
cover perf annotate: Create a new '--tui-dump' option
There is a requirement to let perf annotate support displaying the IPC/Cycle. In previous patch, this is supported in TUI mode. While it's not convenient for users since they have to take screen shots and copy/paste data.
This patch series introduces a new option '--tui-dump' in perf annotate to dump the TUI output to stdio.
User can easily use the command line like:
'perf annotate --tui-dump > /tmp/log.txt'
For example:
$ perf annotate compute_flag --tui-dump
Percent IPC Cycle
Disassembly of section .text:
0000000000400640 <compute_flag>:
compute_flag():
volatile int count;
static unsigned int s_randseed;
__attribute__((noinline))
int compute_flag()
{
23.00 1.16 sub $0x8,%rsp
int i;
i = rand() % 2;
23.06 1.16 1 callq rand@plt
return i;
27.01 3.38 mov %eax,%edx
}
3.38 add $0x8,%rsp
{
int i;
i = rand() % 2;
return i;
3.38 shr $0x1f,%edx
3.38 add %edx,%eax
3.38 and $0x1,%eax
3.38 sub %edx,%eax
}
26.93 3.38 2 retqThe '--stdio' option is still kept now. Maybe in future, we can only maintain the TUI routines and drop the lagacy stdio code. But right now we'd better keep it until the '--tui-dump' option is good enough.
Jin Yao (4):
perf browser: Add a new 'dump' flag
perf browser: bypass ui_init if in tui dump mode perf annotate: Process the new switch flag tui_dump perf annotate: Enable the '--tui-dump' mode
tools/perf/Documentation/perf-annotate.txt | 3 +++ tools/perf/builtin-annotate.c | 12 +++++++-- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/ui/browser.c | 38 +++++++++++++++++++++++---- tools/perf/ui/browser.h | 1 + tools/perf/ui/browsers/annotate.c | 41 +++++++++++++++++++++--------- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/ui/setup.c | 9 +++++-- tools/perf/ui/ui.h | 2 +- tools/perf/util/annotate.h | 6 +++-- tools/perf/util/hist.h | 11 +++++--- 13 files changed, 99 insertions(+), 32 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/4 perf browser: Add a new 'dump' flag
We have a new requirement to provide the TUI output option for non-interactive mode. For example, write the TUI output to stdio directly.
This patch creates a new flag 'dump' in struct ui_browser. Once it's on, for the formatted buffer, we just print it on stdio.
--- tools/perf/ui/browser.c | 38 +++++++++++++++++++++++++++++++++----- tools/perf/ui/browser.h | 1 + 2 files changed, 34 insertions(+), 5 deletions(-)
tools/perf/ui/browser.c +33 -5
@@ -41,8 +41,13 @@ int ui_browser__set_color(struct ui_browser *browser, int color)void ui_browser__set_percent_color (struct ui_browser *browser,double percent,bool current) { -int color =ui_browser__percent_color (browser, percent, current); -ui_browser__set_color (browser, color); +int color; + +if (browser->dump) +return ; + + color =ui_browser__percent_color (browser, percent, current); +ui_browser__set_color (browser, color); }void ui_browser__gotorc (struct ui_browser *browser,int y,int x)
@@ -50,10 +55,27 @@ void ui_browser__gotorc(struct ui_browser *browser, int y, int x)SLsmg_gotorc (browser->y + y, browser->x + x); } +static void write_nstring (const char *msg,unsigned int width) +{ +unsigned int len =strlen (msg); +unsigned int i =0 ; + +while (i < len && i < width) { +putchar (msg[i]); + i++; + } + +while (i++ < width) +putchar (' ' ); +} +void ui_browser__write_nstring (struct ui_browser *browser__maybe_unused ,const char *msg,unsigned int width) { -slsmg_write_nstring (msg, width); +if (browser->dump) +write_nstring (msg, width); +else +slsmg_write_nstring (msg, width); }void ui_browser__printf (struct ui_browser *browser__maybe_unused ,const char *fmt, ...)
@@ -61,7 +83,10 @@ void ui_browser__printf(struct ui_browser *browser __maybe_unused, const char *fva_list args;va_start (args, fmt); -slsmg_vprintf (fmt, args); +if (browser->dump) +vprintf (fmt, args); +else +slsmg_vprintf (fmt, args);va_end (args); }
@@ -496,7 +521,10 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *browser)list_for_each_from (pos, head) {if (!browser->filter || !browser->filter (browser, pos)) { -ui_browser__gotorc (browser, row,0 ); +if (!browser->dump) +ui_browser__gotorc (browser, row,0 ); +else if (row >0 ) +printf ("\n" ); browser->write (browser, pos, row);if (++row == browser->rows)break ;
tools/perf/ui/browser.h +1 -0
@@ -28,6 +28,7 @@ struct ui_browser {u32 nr_entries;bool navkeypressed;bool use_navkeypressed; +bool dump; };int ui_browser__set_color (struct ui_browser *browser,int color);
Signature · 1 line
2.7.4
PATCH 2/4 perf browser: bypass ui_init if in tui dump mode
In reply to Jin YaoWe create a tui dump mode in previous patch. In tui dump mode, the output is written to stdio. We need to bypass ui_init() in setup_browser().
--- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/ui/setup.c | 9 +++++++-- tools/perf/ui/ui.h | 2 +- 6 files changed, 12 insertions(+), 7 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -576,7 +576,7 @@ int cmd_annotate(int argc, const char **argv)else if (annotate.use_gtk) use_browser =2 ; -setup_browser (true); +setup_browser (true, false);if (use_browser ==1 && annotate.has_br_stack) { sort__mode =SORT_MODE__BRANCH ;
tools/perf/builtin-c2c.c +1 -1
@@ -2618,7 +2618,7 @@ static int perf_c2c__report(int argc, const char **argv)else use_browser =1 ; -setup_browser (false); +setup_browser (false, false); err =perf_session__process_events (session);if (err) {
tools/perf/builtin-report.c +1 -1
@@ -1261,7 +1261,7 @@ int cmd_report(int argc, const char **argv) }if (strcmp (input_name,"-" ) !=0 ) -setup_browser (true); +setup_browser (true, false);else use_browser =0 ;
tools/perf/builtin-top.c +1 -1
@@ -1430,7 +1430,7 @@ int cmd_top(int argc, const char **argv)else if (top.use_tui) use_browser =1 ; -setup_browser (false); +setup_browser (false, false);if (setup_sorting (top.evlist) <0 ) {if (sort_order)
tools/perf/ui/setup.c +7 -2
@@ -73,9 +73,9 @@ int stdio__config_color(const struct option *opt __maybe_unused,return 0 ; } -void setup_browser (bool fallback_to_pager) +void setup_browser (bool fallback_to_pager,bool tui_dump) { -if (use_browser <2 && (!isatty (1 ) || dump_trace)) +if (use_browser <2 && (!isatty (1 ) || dump_trace) && !tui_dump) use_browser =0 ;/* default to TUI */
@@ -92,6 +92,11 @@ void setup_browser(bool fallback_to_pager)/* fall through */ case 1 : use_browser =1 ; +if (tui_dump) { +setup_pager (); +break ; + } +if (ui__init () ==0 )break ;/* fall through */
tools/perf/ui/ui.h +1 -1
@@ -11,7 +11,7 @@ extern void *perf_gtk_handle;extern int use_browser; -void setup_browser (bool fallback_to_pager); +void setup_browser (bool fallback_to_pager,bool tui_dump);void exit_browser (bool wait_for_ok);#ifdef HAVE_SLANG_SUPPORT
Signature · 1 line
2.7.4
PATCH 3/4 perf annotate: Process the new switch flag tui_dump
In reply to Jin YaoThe tui_dump is created as a parameter and it will be finally passed to symbol__tui_annotate() and be saved to browser.dump.
It's a switch for TUI routines to indicate if TUI output needs to be dumped to stdio.
--- tools/perf/builtin-annotate.c | 2 +- tools/perf/ui/browsers/annotate.c | 41 +++++++++++++++++++++++++++------------ tools/perf/ui/browsers/hists.c | 2 +- tools/perf/util/annotate.h | 6 ++++-- tools/perf/util/hist.h | 11 +++++++---- 5 files changed, 42 insertions(+), 20 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -334,7 +334,7 @@ static void hists__find_annotations(struct hists *hists,/* skip missing symbols */ nd =rb_next (nd); }else if (use_browser ==1 ) { - key =hist_entry__tui_annotate (he, evsel,NULL ); + key =hist_entry__tui_annotate (he, evsel,NULL , false);switch (key) {case -1 :
tools/perf/ui/browsers/annotate.c +29 -12
107 lines not on this page · raw message
tools/perf/ui/browsers/hists.c +1 -1
@@ -2418,7 +2418,7 @@ do_annotate(struct hist_browser *browser, struct popup_action *act)return 0 ; evsel =hists_to_evsel (browser->hists); - err =map_symbol__tui_annotate (&act->ms, evsel, browser->hbt); + err =map_symbol__tui_annotate (&act->ms, evsel, browser->hbt, false); he =hist_browser__selected_entry (browser);/* * offer option to annotate the other branch source or target
tools/perf/util/annotate.h +4 -2
@@ -218,13 +218,15 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map,#ifdef HAVE_SLANG_SUPPORT int symbol__tui_annotate (struct symbol *sym,struct map *map,struct perf_evsel *evsel, -struct hist_browser_timer *hbt); +struct hist_browser_timer *hbt, +bool tui_dump);#else static inline int symbol__tui_annotate (struct symbol *sym__maybe_unused ,struct map *map__maybe_unused ,struct perf_evsel *evsel__maybe_unused ,struct hist_browser_timer *hbt -__maybe_unused ) +__maybe_unused , +bool tui_dump) {return 0 ; }
tools/perf/util/hist.h +7 -4
@@ -421,10 +421,11 @@ struct hist_browser_timer {#ifdef HAVE_SLANG_SUPPORT #include "../ui/keysyms.h" int map_symbol__tui_annotate (struct map_symbol *ms,struct perf_evsel *evsel, -struct hist_browser_timer *hbt); +struct hist_browser_timer *hbt, +bool tui_dump);int hist_entry__tui_annotate (struct hist_entry *he,struct perf_evsel *evsel, -struct hist_browser_timer *hbt); +struct hist_browser_timer *hbt,bool tui_dump); int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, struct hist_browser_timer *hbt,
@@ -445,14 +446,16 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused, }static inline int map_symbol__tui_annotate (struct map_symbol *ms__maybe_unused ,struct perf_evsel *evsel__maybe_unused , -struct hist_browser_timer *hbt__maybe_unused ) +struct hist_browser_timer *hbt__maybe_unused , +bool tui_dump__maybe_unused ) {return 0 ; }static inline int hist_entry__tui_annotate (struct hist_entry *he__maybe_unused ,struct perf_evsel *evsel__maybe_unused , -struct hist_browser_timer *hbt__maybe_unused ) +struct hist_browser_timer *hbt__maybe_unused , +bool tui_dump__maybe_unused ) {return 0 ; }
Signature · 1 line
2.7.4
PATCH 4/4 perf annotate: Enable the '--tui-dump' mode
In reply to Jin YaoIt creates a new option '--tui-dump' in perf annotate command line.
With this option, for example, the perf annotate output:
$ perf annotate compute_flag --tui-dump
Percent IPC Cycle
Disassembly of section .text:
0000000000400640 <compute_flag>:
compute_flag():
volatile int count;
static unsigned int s_randseed;
__attribute__((noinline))
int compute_flag()
{
23.00 1.16 sub $0x8,%rsp
int i;
i = rand() % 2;23.06 1.16 1 callq rand@plt
return i;
27.01 3.38 mov %eax,%edx
}
3.38 add $0x8,%rsp
{
int i;
i = rand() % 2;
return i;
3.38 shr $0x1f,%edx
3.38 add %edx,%eax
3.38 and $0x1,%eax
3.38 sub %edx,%eax
}26.93 3.38 2 retq
Compared to TUI output,
$ perf annotate compute_flag
│ Disassembly of section .text:
│
│ 0000000000400640 <compute_flag>
│ compute_flag():
│ volatile int count;
│ static unsigned int s_randseed;
│
│ __attribute__((noinline))
│ int compute_flag()
│ {
23.00 │1.16 sub $0x8,%rsp
│ int i;
│
│ i = rand() % 2;
23.06 │1.16 1 → callq rand@plt
│
│ return i;
27.01 │3.38 mov %eax,%edx
│ }
│3.38 add $0x8,%rsp
│ {
│ int i;
│
│ i = rand() % 2;
│
│ return i;
│3.38 shr $0x1f,%edx
│3.38 add %edx,%eax
│3.38 and $0x1,%eax
│3.38 sub %edx,%eax
│ }
26.93 │3.38 2 ← retq--- tools/perf/Documentation/perf-annotate.txt | 3 +++ tools/perf/builtin-annotate.c | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-annotate.txt +3 -0
@@ -83,6 +83,9 @@ OPTIONS --gtk:: Use the GTK interface. +--tui-dump: Use the TUI interface. The TUI output is dumped to stdio + interface. + -C:: --cpu=<cpu>:: Only report samples for the list of CPUs provided. Multiple CPUs can be provided as a comma-separated list with no space: 0,1. Ranges of
tools/perf/builtin-annotate.c +10 -2
@@ -41,6 +41,7 @@ struct perf_annotate {struct perf_tool tool;struct perf_session *session;bool use_tui, use_stdio, use_gtk; +bool tui_dump;bool full_paths;bool print_line;bool skip_missing;
@@ -334,7 +335,10 @@ static void hists__find_annotations(struct hists *hists,/* skip missing symbols */ nd =rb_next (nd); }else if (use_browser ==1 ) { - key =hist_entry__tui_annotate (he, evsel,NULL , false); + key =hist_entry__tui_annotate (he, evsel,NULL , + ann->tui_dump); +if (ann->tui_dump) +return ;switch (key) {case -1 :
@@ -486,6 +490,7 @@ int cmd_annotate(int argc, const char **argv) "dump raw trace in ASCII"),OPT_BOOLEAN (0 ,"gtk" , &annotate.use_gtk,"Use the GTK interface" ),OPT_BOOLEAN (0 ,"tui" , &annotate.use_tui,"Use the TUI interface" ), +OPT_BOOLEAN (0 ,"tui-dump" , &annotate.tui_dump,"Dump TUI content" ),OPT_BOOLEAN (0 ,"stdio" , &annotate.use_stdio,"Use the stdio interface" ),OPT_STRING ('k' ,"vmlinux" , &symbol_conf.vmlinux_name, "file", "vmlinux pathname"),
@@ -576,7 +581,10 @@ int cmd_annotate(int argc, const char **argv)else if (annotate.use_gtk) use_browser =2 ; -setup_browser (true, false); +if (annotate.tui_dump) + use_browser =1 ; + +setup_browser (true, annotate.tui_dump);if (use_browser ==1 && annotate.has_br_stack) { sort__mode =SORT_MODE__BRANCH ;
Signature · 1 line
2.7.4
On 13/03/2018 15:16, Jin Yao wrote: [snip]
There seems to be something wonky about your system's clock?
The Date field in your messages:
Date: Tue, 13 Mar 2018 22:16:50 +0800
i.e. 14:16:50 GMT
Yet it was actually processed at 06:20:35 GMT
So it looks like your clock is 7h56 ahead of the actual time.
Regards.
Arnaldo Carvalho de Melo
maintainerEm Tue, Mar 13, 2018 at 10:16:50PM +0800, Jin Yao escreveu:
Quoted 9 lines
There is a requirement to let perf annotate support displaying the IPC/Cycle. In previous patch, this is supported in TUI mode. While it's not convenient for users since they have to take screen shots and copy/paste data.
This patch series introduces a new option '--tui-dump' in perf annotate to dump the TUI output to stdio.
User can easily use the command line like:
'perf annotate --tui-dump >/tmp/log.txt'
My first impression is that this pollutes the code with way too many ifs, I was thinking more of a:
while (read parsed objdump line) {
ins__fprintf();
}Going from the refresh routine, I started doing the conversion, but haven't completed it, there are opportunities for more __scnprintf like routines, also one to find the percent_max, etc then those would be used both in these two for --stdio2, that eventually would become --stdio with the old one becoming --stdio1, till we're satisfied with the new default.
static void annotation_line__fprintf(struct annotate_line *al, FILE *fp)
{
struct browser_line *bl = browser_line(al);
int i;
double percent_max = 0.0;
char bf[256];
for (i = 0; i < browser->nr_events; i++) {
if (al->samples[i].percent > percent_max)
percent_max = al->samples[i].percent;
}
/* the following if/else block should be transformed into a __scnprintf routine
that formats a buffer and then the TUI and --stdio2 use it */
if (al->offset != -1 && percent_max != 0.0) {
for (i = 0; i < ab->nr_events; i++) {
if (annotate_browser__opts.show_total_period) {
fprintf(fp, browser, "%11" PRIu64 " ", al->samples[i].he.period);
} else if (annotate_browser__opts.show_nr_samples) {
fprintf(fp, browser, "%6" PRIu64 " ", al->samples[i].he.nr_samples);
} else {
fprintf(fp, "%6.2f ", al->samples[i].percent);
}
}
} else {
ui_browser__printf(browser, "%*s", pcnt_width,
annotate_browser__opts.show_total_period ? "Period" :
annotate_browser__opts.show_nr_samples ? "Samples" : "Percent");
}
/* The ab->have_cycles should go to a separate struct, outside
* annotation_browser, and the rest should go to something that just does scnprintf on a buffer
* that then is printed on the TUI or with fprintf */
if (ab->have_cycles) {
if (al->ipc)
fprintf(fp, "%*.2f ", IPC_WIDTH - 1, al->ipc);
else if (show_title)
ui_browser__printf(browser, "%*s ", IPC_WIDTH - 1, "IPC");
if (al->cycles)
ui_browser__printf(browser, "%*" PRIu64 " ",
CYCLES_WIDTH - 1, al->cycles);
else if (!show_title)
ui_browser__write_nstring(browser, " ", CYCLES_WIDTH);
else
ui_browser__printf(browser, "%*s ", CYCLES_WIDTH - 1, "Cycle");
}
SLsmg_write_char(' ');
/* The scroll bar isn't being used */
if (!browser->navkeypressed)
width += 1;
if (!*al->line)
fprintf(fp, "\n");
else if (al->offset == -1) {
if (al->line_nr && annotate_browser__opts.show_linenr)
printed = scnprintf(bf, sizeof(bf), "%-*d ",
ab->addr_width + 1, al->line_nr);
else
printed = scnprintf(bf, sizeof(bf), "%*s ",
ab->addr_width, " ");
fprintf(fp, bf);
ui_browser__write_nstring(browser, al->line, width - printed - pcnt_width - cycles_width + 1);
} else {
u64 addr = al->offset;
int color = -1;
if (!annotate_browser__opts.use_offset)
addr += ab->start;
if (!annotate_browser__opts.use_offset) {
printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr);
} else {
if (bl->jump_sources) {
if (annotate_browser__opts.show_nr_jumps) {
int prev;
printed = scnprintf(bf, sizeof(bf), "%*d ",
ab->jumps_width,
bl->jump_sources);
prev = annotate_browser__set_jumps_percent_color(ab, bl->jump_sources,
current_entry);
ui_browser__write_nstring(browser, bf, printed);
ui_browser__set_color(browser, prev);
}
printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ",
ab->target_width, addr);
} else {
printed = scnprintf(bf, sizeof(bf), "%*s ",
ab->addr_width, " ");
}
}
fprintf(fp, bf);
disasm_line__write(disasm_line(al), browser, bf, sizeof(bf));
ui_browser__write_nstring(browser, bf, width - pcnt_width - cycles_width - 3 - printed);
}
}unsigned int annotation_lines__fprintf(struct list_head *lines, FILE *fp)
{
struct list_head *line;
struct annotation_line *al;
list_for_each(line, lines) {
struct annotation_line *al = list_entry(line, struct annotation_line, node);
annotation_line__fprintf(al, line);
}
return row;
}Then the main code would use the same code that creates the browser->b.entries and would pass it to annpotation_lines__fprintf().
i.e. we would disentanble the formatting of strings and auxiliary routines to obtain the max_percent, i.e. nothing of TUI is needed for --stdio2, just the formatting of strings.
- Arnaldo
Quoted 65 lines
For example:
$ perf annotate compute_flag --tui-dumpPercent IPC Cycle Disassembly of section .text: 0000000000400640 <compute_flag>: compute_flag(): volatile int count; static unsigned int s_randseed; __attribute__((noinline)) int compute_flag() { 23.00 1.16 sub $0x8,%rsp int i; i = rand() % 2; 23.06 1.16 1 callq rand@plt return i; 27.01 3.38 mov %eax,%edx } 3.38 add $0x8,%rsp { int i; i = rand() % 2; return i; 3.38 shr $0x1f,%edx 3.38 add %edx,%eax 3.38 and $0x1,%eax 3.38 sub %edx,%eax } 26.93 3.38 2 retqThe '--stdio' option is still kept now. Maybe in future, we can only maintain the TUI routines and drop the lagacy stdio code. But right now we'd better keep it until the '--tui-dump' option is good enough.
Jin Yao (4):
perf browser: Add a new 'dump' flag
perf browser: bypassui_initif in tui dump mode perf annotate: Process the new switch flagtui_dumpperf annotate: Enable the '--tui-dump' modetools/perf/Documentation/perf-annotate.txt | 3 +++ tools/perf/builtin-annotate.c | 12 +++++++-- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/ui/browser.c | 38 +++++++++++++++++++++++---- tools/perf/ui/browser.h | 1 + tools/perf/ui/browsers/annotate.c | 41 +++++++++++++++++++++--------- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/ui/setup.c | 9 +++++-- tools/perf/ui/ui.h | 2 +- tools/perf/util/annotate.h | 6 +++-- tools/perf/util/hist.h | 11 +++++--- 13 files changed, 99 insertions(+), 32 deletions(-)Signature · 1 line
2.7.4
Quoted 11 lines · Arnaldo Carvalho de Melo
Em Tue, Mar 13, 2018 at 10:16:50PM +0800, Jin Yao escreveu:
Quoted 9 lines
There is a requirement to let perf annotate support displaying the IPC/Cycle. In previous patch, this is supported in TUI mode. While it's not convenient for users since they have to take screen shots and copy/paste data.
This patch series introduces a new option '--tui-dump' in perf annotate to dump the TUI output to stdio.
User can easily use the command line like:
'perf annotate --tui-dump >/tmp/log.txt'
Quoted 7 lines
My first impression is that this pollutes the code with way too many ifs, I was thinking more of a:
while (read parsed objdump line) { ins__fprintf(); }
Yes, the issue in my patch is that it uses many 'if' to check if it's tui_dump(or called 'stdio2') or tui mode.
Quoted 6 lines
Going from the refresh routine, I started doing the conversion, but haven't completed it, there are opportunities for more
__scnprintflike routines, also one to find thepercent_max, etc then those would be used both in these two for --stdio2, that eventually would become --stdio with the old one becoming --stdio1, till we're satisfied with the new default.
I have some questions for the following code. Please correct me if I misunderstand anything.
Quoted 23 lines
static void
annotation_line__fprintf(struct annotate_line *al, FILE *fp){ struct browser_line *bl = browser_line(al); int i; double percent_max = 0.0; char bf[256]; for (i = 0; i < browser->nr_events; i++) { if (al->samples[i].percent > percent_max) percent_max = al->samples[i].percent; } /* the following if/else block should be transformed into a __scnprintf routine that formats a buffer and then the TUI and --stdio2 use it */ if (al->offset != -1 && percent_max != 0.0) { for (i = 0; i < ab->nr_events; i++) { if (annotate_browser__opts.show_total_period) { fprintf(fp, browser, "%11" PRIu64 " ", al->samples[i].he.period); } else if (annotate_browser__opts.show_nr_samples) { fprintf(fp, browser, "%6" PRIu64 " ", al->samples[i].he.nr_samples); } else { fprintf(fp, "%6.2f ", al->samples[i].percent);
Quoted 9 lines
}
}
} else {
ui_browser__printf(browser, "%*s", pcnt_width,
annotate_browser__opts.show_total_period ? "Period" :
annotate_browser__opts.show_nr_samples ? "Samples" : "Percent");
}I guess the above code has not been completed yet. My understanding for Arnaldo's idea is that the output should be written to a buffer via scnprintf and the buffer will be passed to TUI or stdio2 and printed out later.
One potential issue is how to process the color for TUI? For example, the call to ui_browser__set_percent_color. If we need to set color for TUI, it looks we still have to check if it's a TUI mode.
For example,
Suppose the bf[] has been written with the Percent string yet, next we need,
if (--tui) {
ui_browser__set_percent_color(...);
ui_browser__printf(bf, ...);
} else {
printf(..., bf);
}Is my understanding correct?
Quoted 48 lines
/* The ab->have_cycles should go to a separate struct, outside
* annotation_browser, and the rest should go to something that just does scnprintf on a buffer
* that then is printed on the TUI or with fprintf */
if (ab->have_cycles) {
if (al->ipc)
fprintf(fp, "%*.2f ", IPC_WIDTH - 1, al->ipc) > else if (show_title)
ui_browser__printf(browser, "%*s ", IPC_WIDTH - 1, "IPC");
if (al->cycles)
ui_browser__printf(browser, "%*" PRIu64 " ",
CYCLES_WIDTH - 1, al->cycles);
else if (!show_title)
ui_browser__write_nstring(browser, " ", CYCLES_WIDTH);
else
ui_browser__printf(browser, "%*s ", CYCLES_WIDTH - 1, "Cycle");
}
SLsmg_write_char(' ');
/* The scroll bar isn't being used */
if (!browser->navkeypressed)
width += 1;
if (!*al->line)
fprintf(fp, "\n");
else if (al->offset == -1) {
if (al->line_nr && annotate_browser__opts.show_linenr)
printed = scnprintf(bf, sizeof(bf), "%-*d ",
ab->addr_width + 1, al->line_nr);
else
printed = scnprintf(bf, sizeof(bf), "%*s ",
ab->addr_width, " ");
fprintf(fp, bf);
ui_browser__write_nstring(browser, al->line, width - printed - pcnt_width - cycles_width + 1);
} else {
u64 addr = al->offset;
int color = -1;
if (!annotate_browser__opts.use_offset)
addr += ab->start;
if (!annotate_browser__opts.use_offset) {
printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr);
} else {
if (bl->jump_sources) {
if (annotate_browser__opts.show_nr_jumps) {
int prev;Quoted 9 lines
printed = scnprintf(bf, sizeof(bf), "%*d ", ab->jumps_width, bl->jump_sources); prev = annotate_browser__set_jumps_percent_color(ab, bl->jump_sources, current_entry); ui_browser__write_nstring(browser, bf, printed); ui_browser__set_color(browser, prev); }
JUMP is another headache case. For TUI, we need to set color and write jump arrow. While for stdio2, we don't need that. So looks we also need to check if it's in TUI mode.
Quoted 29 lines
printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ", ab->target_width, addr); } else { printed = scnprintf(bf, sizeof(bf), "%*s ", ab->addr_width, " "); } } fprintf(fp, bf); disasm_line__write(disasm_line(al), browser, bf, sizeof(bf)); ui_browser__write_nstring(browser, bf, width - pcnt_width - cycles_width - 3 - printed); } }unsigned int
annotation_lines__fprintf(struct list_head *lines, FILE *fp){ struct list_head *line; struct annotation_line *al; list_for_each(line, lines) { struct annotation_line *al = list_entry(line, struct annotation_line, node); annotation_line__fprintf(al, line); } return row; }
Quoted 3 lines
Then the main code would use the same code that creates the
browser->b.entriesand would pass it toannpotation_lines__fprintf().
Is the main code mentioned here symbol__tui_annotate()?
struct annotate_browser browser = {
.b = {
.refresh = annotate_browser__refresh,
.write = annotate_browser__write,
....
},
};Remove the code line ".write = annotate_browser__write"? Don't need the browser op (write/refresh)? Sorry, I'm not very clear about this idea.
Quoted 6 lines
i.e. we would disentanble the formatting of strings and auxiliary routines to obtain the
max_percent, i.e. nothing of TUI is needed for --stdio2, just the formatting of strings.- Arnaldo
Will Arnaldo post your patch? Or do I need to improve my patch and post again?
Thanks
Jin Yao
Quoted 65 lines
Quoted 65 lines
For example:
$ perf annotate compute_flag --tui-dumpPercent IPC Cycle Disassembly of section .text: 0000000000400640 <compute_flag>: compute_flag(): volatile int count; static unsigned int s_randseed; __attribute__((noinline)) int compute_flag() { 23.00 1.16 sub $0x8,%rsp int i; i = rand() % 2; 23.06 1.16 1 callq rand@plt return i; 27.01 3.38 mov %eax,%edx } 3.38 add $0x8,%rsp { int i; i = rand() % 2; return i; 3.38 shr $0x1f,%edx 3.38 add %edx,%eax 3.38 and $0x1,%eax 3.38 sub %edx,%eax } 26.93 3.38 2 retqThe '--stdio' option is still kept now. Maybe in future, we can only maintain the TUI routines and drop the lagacy stdio code. But right now we'd better keep it until the '--tui-dump' option is good enough.
Jin Yao (4):
perf browser: Add a new 'dump' flag
perf browser: bypassui_initif in tui dump mode perf annotate: Process the new switch flagtui_dumpperf annotate: Enable the '--tui-dump' modetools/perf/Documentation/perf-annotate.txt | 3 +++ tools/perf/builtin-annotate.c | 12 +++++++-- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/ui/browser.c | 38 +++++++++++++++++++++++---- tools/perf/ui/browser.h | 1 + tools/perf/ui/browsers/annotate.c | 41 +++++++++++++++++++++--------- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/ui/setup.c | 9 +++++-- tools/perf/ui/ui.h | 2 +- tools/perf/util/annotate.h | 6 +++-- tools/perf/util/hist.h | 11 +++++--- 13 files changed, 99 insertions(+), 32 deletions(-)Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerEm Wed, Mar 14, 2018 at 10:04:49AM +0800, Jin, Yao escreveu:
Quoted 68 lines · Arnaldo Carvalho de Melo
Quoted 11 lines
Em Tue, Mar 13, 2018 at 10:16:50PM +0800, Jin Yao escreveu:
Quoted 9 lines
There is a requirement to let perf annotate support displaying the IPC/Cycle. In previous patch, this is supported in TUI mode. While it's not convenient for users since they have to take screen shots and copy/paste data.
This patch series introduces a new option '--tui-dump' in perf annotate to dump the TUI output to stdio.
User can easily use the command line like:
'perf annotate --tui-dump >/tmp/log.txt'Quoted 7 lines
My first impression is that this pollutes the code with way too many ifs, I was thinking more of a:
while (read parsed objdump line) { ins__fprintf(); }Yes, the issue in my patch is that it uses many 'if' to check if it's
tui_dump(or called 'stdio2')or tui mode.Quoted 6 lines
Going from the refresh routine, I started doing the conversion, but haven't completed it, there are opportunities for more
__scnprintflike routines, also one to find thepercent_max, etc then those would be used both in these two for --stdio2, that eventually would become --stdio with the old one becoming --stdio1, till we're satisfied with the new default.I have some questions for the following code. Please correct me if I misunderstand anything.
Quoted 23 lines
static void
annotation_line__fprintf(struct annotate_line *al, FILE *fp){ struct browser_line *bl = browser_line(al); int i; double percent_max = 0.0; char bf[256]; for (i = 0; i < browser->nr_events; i++) { if (al->samples[i].percent > percent_max) percent_max = al->samples[i].percent; } /* the following if/else block should be transformed into a __scnprintf routine that formats a buffer and then the TUI and --stdio2 use it */ if (al->offset != -1 && percent_max != 0.0) { for (i = 0; i < ab->nr_events; i++) { if (annotate_browser__opts.show_total_period) { fprintf(fp, browser, "%11" PRIu64 " ", al->samples[i].he.period); } else if (annotate_browser__opts.show_nr_samples) { fprintf(fp, browser, "%6" PRIu64 " ", al->samples[i].he.nr_samples); } else { fprintf(fp, "%6.2f ", al->samples[i].percent);Quoted 9 lines
} } } else { ui_browser__printf(browser, "%*s", pcnt_width, annotate_browser__opts.show_total_period ? "Period" : annotate_browser__opts.show_nr_samples ? "Samples" : "Percent"); }
Quoted 8 lines
I guess the above code has not been completed yet. My understanding for Arnaldo's idea is that the output should be written to a buffer via scnprintf and the buffer will be passed to TUI or stdio2 and printed out later.
One potential issue is how to process the color for TUI? For example, the call to
ui_browser__set_percent_color. If we need to set color for TUI, it looks we still have to check if it's a TUI mode.
That is part of the uncompleted code, if you want to show colors in --stdio2 (and I think it is worth) then use color_fprintf() like other stdio code.
For instance, 'perf top --stdio' uses red for hot lines, etc.
Quoted 4 lines
For example,
Suppose the bf[] has been written with the Percent string yet, next we need,
Quoted 8 lines
if (--tui) { ui_browser__set_percent_color(...); ui_browser__printf(bf, ...); } else { printf(..., bf); }Is my understanding correct?
The way I am suggesting there will be no if (tui), it will just reuse the scnprintf routines that are now used in the TUI code, but will only use fprintf/color_fprintf, etc.
The loop iterating over the annotation_lines you just lift from the tui code.
And parts that are useful for both and are not yet in __scnprintf form, then we need to make it so.
Quoted 58 lines
Quoted 48 lines
/* The ab->have_cycles should go to a separate struct, outside * annotation_browser, and the rest should go to something that just does scnprintf on a buffer * that then is printed on the TUI or with fprintf */ if (ab->have_cycles) { if (al->ipc) fprintf(fp, "%*.2f ", IPC_WIDTH - 1, al->ipc) > else if (show_title) ui_browser__printf(browser, "%*s ", IPC_WIDTH - 1, "IPC"); if (al->cycles) ui_browser__printf(browser, "%*" PRIu64 " ", CYCLES_WIDTH - 1, al->cycles); else if (!show_title) ui_browser__write_nstring(browser, " ", CYCLES_WIDTH); else ui_browser__printf(browser, "%*s ", CYCLES_WIDTH - 1, "Cycle"); } SLsmg_write_char(' '); /* The scroll bar isn't being used */ if (!browser->navkeypressed) width += 1; if (!*al->line) fprintf(fp, "\n"); else if (al->offset == -1) { if (al->line_nr && annotate_browser__opts.show_linenr) printed = scnprintf(bf, sizeof(bf), "%-*d ", ab->addr_width + 1, al->line_nr); else printed = scnprintf(bf, sizeof(bf), "%*s ", ab->addr_width, " "); fprintf(fp, bf); ui_browser__write_nstring(browser, al->line, width - printed - pcnt_width - cycles_width + 1); } else { u64 addr = al->offset; int color = -1; if (!annotate_browser__opts.use_offset) addr += ab->start; if (!annotate_browser__opts.use_offset) { printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr); } else { if (bl->jump_sources) { if (annotate_browser__opts.show_nr_jumps) { int prev;Quoted 9 lines
printed = scnprintf(bf, sizeof(bf), "%*d ", ab->jumps_width, bl->jump_sources); prev = annotate_browser__set_jumps_percent_color(ab, bl->jump_sources, current_entry); ui_browser__write_nstring(browser, bf, printed); ui_browser__set_color(browser, prev); }
Quoted 3 lines
JUMP is another headache case. For TUI, we need to set color and write jump arrow. While for stdio2, we don't need that. So looks we also need to check if it's in TUI mode.
No, when in --stdio2 case you either show no jump characters, or you show them if available, i.e. here are two stdio utilities showing those arrows:
[root@seventh ~]# cat a.txt
↑ jmp 3f0
[root@seventh ~]# head a.txt
↑ jmp 3f0
[root@seventh ~]#
You just don't need to print the arrows connecting jumps to its targets, because in a function with a lot of jumps, then it can get messy, but yeah, that could even be an option, perhaps not the default.
Quoted 43 lines
Quoted 29 lines
printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ", ab->target_width, addr); } else { printed = scnprintf(bf, sizeof(bf), "%*s ", ab->addr_width, " "); } } fprintf(fp, bf); disasm_line__write(disasm_line(al), browser, bf, sizeof(bf)); ui_browser__write_nstring(browser, bf, width - pcnt_width - cycles_width - 3 - printed); } }unsigned int
annotation_lines__fprintf(struct list_head *lines, FILE *fp){ struct list_head *line; struct annotation_line *al; list_for_each(line, lines) { struct annotation_line *al = list_entry(line, struct annotation_line, node); annotation_line__fprintf(al, line); } return row; }Quoted 3 lines
Then the main code would use the same code that creates the
browser->b.entriesand would pass it toannpotation_lines__fprintf().Is the main code mentioned here
symbol__tui_annotate()?struct annotate_browser browser = { .b = { .refresh = annotate_browser__refresh, .write = annotate_browser__write, .... }, };
Quoted 2 lines
Remove the code line ".write =
annotate_browser__write"? Don't need the
browser op (write/refresh)? Sorry, I'm not very clear about this idea.
You would have a symbol__stdio2_annotate(), and it would be something like:
int symbol__stdio2_annotate(FILE *fp)
{
struct annotation *notes;
symbol__annotate(sym, map, evsel, sizeof(struct annotatation_line), NULL);
symbol__calc_percent(sym, evsel);
notes = symbol__annotation(sym);
annotation_lines__fprintf(notes->src->source, fp);
}Something like that.
Quoted 6 lines
Quoted 3 lines
i.e. we would disentanble the formatting of strings and auxiliary routines to obtain the
max_percent, i.e. nothing of TUI is needed for --stdio2, just the formatting of strings.Will Arnaldo post your patch? Or do I need to improve my patch and post again?
We're still discussing what is the best way to implement this.
Quoted 68 lines
Thanks
Jin YaoQuoted 65 lines
Quoted 65 lines
For example:
$ perf annotate compute_flag --tui-dumpPercent IPC Cycle Disassembly of section .text: 0000000000400640 <compute_flag>: compute_flag(): volatile int count; static unsigned int s_randseed; __attribute__((noinline)) int compute_flag() { 23.00 1.16 sub $0x8,%rsp int i; i = rand() % 2; 23.06 1.16 1 callq rand@plt return i; 27.01 3.38 mov %eax,%edx } 3.38 add $0x8,%rsp { int i; i = rand() % 2; return i; 3.38 shr $0x1f,%edx 3.38 add %edx,%eax 3.38 and $0x1,%eax 3.38 sub %edx,%eax } 26.93 3.38 2 retqThe '--stdio' option is still kept now. Maybe in future, we can only maintain the TUI routines and drop the lagacy stdio code. But right now we'd better keep it until the '--tui-dump' option is good enough.
Jin Yao (4):
perf browser: Add a new 'dump' flag
perf browser: bypassui_initif in tui dump mode perf annotate: Process the new switch flagtui_dumpperf annotate: Enable the '--tui-dump' modetools/perf/Documentation/perf-annotate.txt | 3 +++ tools/perf/builtin-annotate.c | 12 +++++++-- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/ui/browser.c | 38 +++++++++++++++++++++++---- tools/perf/ui/browser.h | 1 + tools/perf/ui/browsers/annotate.c | 41 +++++++++++++++++++++--------- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/ui/setup.c | 9 +++++-- tools/perf/ui/ui.h | 2 +- tools/perf/util/annotate.h | 6 +++-- tools/perf/util/hist.h | 11 +++++--- 13 files changed, 99 insertions(+), 32 deletions(-)Signature · 1 line
2.7.4
Quoted 78 lines · Arnaldo Carvalho de Melo
Em Wed, Mar 14, 2018 at 10:04:49AM +0800, Jin, Yao escreveu:
Quoted 68 lines · Arnaldo Carvalho de Melo
Quoted 11 lines
Em Tue, Mar 13, 2018 at 10:16:50PM +0800, Jin Yao escreveu:
Quoted 9 lines
There is a requirement to let perf annotate support displaying the IPC/Cycle. In previous patch, this is supported in TUI mode. While it's not convenient for users since they have to take screen shots and copy/paste data.
This patch series introduces a new option '--tui-dump' in perf annotate to dump the TUI output to stdio.
User can easily use the command line like:
'perf annotate --tui-dump >/tmp/log.txt'Quoted 7 lines
My first impression is that this pollutes the code with way too many ifs, I was thinking more of a:
while (read parsed objdump line) { ins__fprintf(); }Yes, the issue in my patch is that it uses many 'if' to check if it's
tui_dump(or called 'stdio2')or tui mode.Quoted 6 lines
Going from the refresh routine, I started doing the conversion, but haven't completed it, there are opportunities for more
__scnprintflike routines, also one to find thepercent_max, etc then those would be used both in these two for --stdio2, that eventually would become --stdio with the old one becoming --stdio1, till we're satisfied with the new default.I have some questions for the following code. Please correct me if I misunderstand anything.
Quoted 23 lines
static void
annotation_line__fprintf(struct annotate_line *al, FILE *fp){ struct browser_line *bl = browser_line(al); int i; double percent_max = 0.0; char bf[256]; for (i = 0; i < browser->nr_events; i++) { if (al->samples[i].percent > percent_max) percent_max = al->samples[i].percent; } /* the following if/else block should be transformed into a __scnprintf routine that formats a buffer and then the TUI and --stdio2 use it */ if (al->offset != -1 && percent_max != 0.0) { for (i = 0; i < ab->nr_events; i++) { if (annotate_browser__opts.show_total_period) { fprintf(fp, browser, "%11" PRIu64 " ", al->samples[i].he.period); } else if (annotate_browser__opts.show_nr_samples) { fprintf(fp, browser, "%6" PRIu64 " ", al->samples[i].he.nr_samples); } else { fprintf(fp, "%6.2f ", al->samples[i].percent);Quoted 9 lines
} } } else { ui_browser__printf(browser, "%*s", pcnt_width, annotate_browser__opts.show_total_period ? "Period" : annotate_browser__opts.show_nr_samples ? "Samples" : "Percent"); }Quoted 8 lines
I guess the above code has not been completed yet. My understanding for Arnaldo's idea is that the output should be written to a buffer via scnprintf and the buffer will be passed to TUI or stdio2 and printed out later.
One potential issue is how to process the color for TUI? For example, the call to
ui_browser__set_percent_color. If we need to set color for TUI, it looks we still have to check if it's a TUI mode.
Quoted 6 lines
That is part of the uncompleted code, if you want to show colors in --stdio2 (and I think it is worth) then use
color_fprintf()like other stdio code.For instance, 'perf top --stdio' uses red for hot lines, etc.
Maybe we can support showing color in a followup patch after the basic function is ready.
Quoted 17 lines
Quoted 4 lines
For example,
Suppose the bf[] has been written with the Percent string yet, next we need,
Quoted 8 lines
if (--tui) { ui_browser__set_percent_color(...); ui_browser__printf(bf, ...); } else { printf(..., bf); }Is my understanding correct?
The way I am suggesting there will be no if (tui), it will just reuse the scnprintf routines that are now used in the TUI code, but will only use fprintf/color_fprintf, etc.
Quoted 6 lines
The loop iterating over the
annotation_linesyou just lift from the tui code.And parts that are useful for both and are not yet in
__scnprintfform, then we need to make it so.
OK, I understand, the key point is to avoid using if (tui).
So looks the code will be divided into 2 parts.
Part1: symbol__tui_annotate ->
annotate_browser__refresh/annotate_browser__write
It's current code-path and it's for TUI mode. We will not change it.
Part2:symbol__stdio2_annotate -> annotation_lines__fprintf -> annotation_line__fprintf
It's a new code-path and it's for --stdio2 only.
Is my understanding correct? If so, the good thing is we can avoid using if(tui), while maybe we can't easily reuse common code.
I just think what's the final target we want to reach. For me, I just wish we had better maintain only one mode (e.g. TUI mode) in future and for other modes (e.g. stdio), there will be no code work (or no much code work) for new added features.
If we create a new code-patch for stdio2, looks we have to maintain stdio2 code-path too when we add new feature to TUI mode.
If we use if(tui), since it's added in TUI code-path, though something ugly, but we don't need much code work to support stdio for new added feature.
That's my current thoughts. Correct me if my understanding is wrong.
Thanks
Jin Yao
Quoted 217 lines
Quoted 58 lines
Quoted 48 lines
/* The ab->have_cycles should go to a separate struct, outside * annotation_browser, and the rest should go to something that just does scnprintf on a buffer * that then is printed on the TUI or with fprintf */ if (ab->have_cycles) { if (al->ipc) fprintf(fp, "%*.2f ", IPC_WIDTH - 1, al->ipc) > else if (show_title) ui_browser__printf(browser, "%*s ", IPC_WIDTH - 1, "IPC"); if (al->cycles) ui_browser__printf(browser, "%*" PRIu64 " ", CYCLES_WIDTH - 1, al->cycles); else if (!show_title) ui_browser__write_nstring(browser, " ", CYCLES_WIDTH); else ui_browser__printf(browser, "%*s ", CYCLES_WIDTH - 1, "Cycle"); } SLsmg_write_char(' '); /* The scroll bar isn't being used */ if (!browser->navkeypressed) width += 1; if (!*al->line) fprintf(fp, "\n"); else if (al->offset == -1) { if (al->line_nr && annotate_browser__opts.show_linenr) printed = scnprintf(bf, sizeof(bf), "%-*d ", ab->addr_width + 1, al->line_nr); else printed = scnprintf(bf, sizeof(bf), "%*s ", ab->addr_width, " "); fprintf(fp, bf); ui_browser__write_nstring(browser, al->line, width - printed - pcnt_width - cycles_width + 1); } else { u64 addr = al->offset; int color = -1; if (!annotate_browser__opts.use_offset) addr += ab->start; if (!annotate_browser__opts.use_offset) { printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr); } else { if (bl->jump_sources) { if (annotate_browser__opts.show_nr_jumps) { int prev;Quoted 9 lines
printed = scnprintf(bf, sizeof(bf), "%*d ", ab->jumps_width, bl->jump_sources); prev = annotate_browser__set_jumps_percent_color(ab, bl->jump_sources, current_entry); ui_browser__write_nstring(browser, bf, printed); ui_browser__set_color(browser, prev); }Quoted 3 lines
JUMP is another headache case. For TUI, we need to set color and write jump arrow. While for stdio2, we don't need that. So looks we also need to check if it's in TUI mode.
No, when in --stdio2 case you either show no jump characters, or you show them if available, i.e. here are two stdio utilities showing those arrows:
[root@seventh ~]# cat a.txt
↑ jmp 3f0
[root@seventh ~]# head a.txt
↑ jmp 3f0
[root@seventh ~]#You just don't need to print the arrows connecting jumps to its targets, because in a function with a lot of jumps, then it can get messy, but yeah, that could even be an option, perhaps not the default.
Quoted 43 lines
Quoted 29 lines
printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ", ab->target_width, addr); } else { printed = scnprintf(bf, sizeof(bf), "%*s ", ab->addr_width, " "); } } fprintf(fp, bf); disasm_line__write(disasm_line(al), browser, bf, sizeof(bf)); ui_browser__write_nstring(browser, bf, width - pcnt_width - cycles_width - 3 - printed); } }unsigned int
annotation_lines__fprintf(struct list_head *lines, FILE *fp){ struct list_head *line; struct annotation_line *al; list_for_each(line, lines) { struct annotation_line *al = list_entry(line, struct annotation_line, node); annotation_line__fprintf(al, line); } return row; }Quoted 3 lines
Then the main code would use the same code that creates the
browser->b.entriesand would pass it toannpotation_lines__fprintf().Is the main code mentioned here
symbol__tui_annotate()?struct annotate_browser browser = { .b = { .refresh = annotate_browser__refresh, .write = annotate_browser__write, .... }, };Quoted 2 lines
Remove the code line ".write =
annotate_browser__write"? Don't need the
browser op (write/refresh)? Sorry, I'm not very clear about this idea.You would have a
symbol__stdio2_annotate(), and it would be something like:int
symbol__stdio2_annotate(FILE *fp){ struct annotation *notes; symbol__annotate(sym, map, evsel, sizeof(struct annotatation_line), NULL); symbol__calc_percent(sym, evsel); notes = symbol__annotation(sym); annotation_lines__fprintf(notes->src->source, fp); }Something like that.
Quoted 6 lines
Quoted 3 lines
i.e. we would disentanble the formatting of strings and auxiliary routines to obtain the
max_percent, i.e. nothing of TUI is needed for --stdio2, just the formatting of strings.Will Arnaldo post your patch? Or do I need to improve my patch and post again?
We're still discussing what is the best way to implement this.
Quoted 68 lines
Thanks
Jin YaoQuoted 65 lines
Quoted 65 lines
For example:
$ perf annotate compute_flag --tui-dumpPercent IPC Cycle Disassembly of section .text: 0000000000400640 <compute_flag>: compute_flag(): volatile int count; static unsigned int s_randseed; __attribute__((noinline)) int compute_flag() { 23.00 1.16 sub $0x8,%rsp int i; i = rand() % 2; 23.06 1.16 1 callq rand@plt return i; 27.01 3.38 mov %eax,%edx } 3.38 add $0x8,%rsp { int i; i = rand() % 2; return i; 3.38 shr $0x1f,%edx 3.38 add %edx,%eax 3.38 and $0x1,%eax 3.38 sub %edx,%eax } 26.93 3.38 2 retqThe '--stdio' option is still kept now. Maybe in future, we can only maintain the TUI routines and drop the lagacy stdio code. But right now we'd better keep it until the '--tui-dump' option is good enough.
Jin Yao (4):
perf browser: Add a new 'dump' flag
perf browser: bypassui_initif in tui dump mode perf annotate: Process the new switch flagtui_dumpperf annotate: Enable the '--tui-dump' modetools/perf/Documentation/perf-annotate.txt | 3 +++ tools/perf/builtin-annotate.c | 12 +++++++-- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/ui/browser.c | 38 +++++++++++++++++++++++---- tools/perf/ui/browser.h | 1 + tools/perf/ui/browsers/annotate.c | 41 +++++++++++++++++++++--------- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/ui/setup.c | 9 +++++-- tools/perf/ui/ui.h | 2 +- tools/perf/util/annotate.h | 6 +++-- tools/perf/util/hist.h | 11 +++++--- 13 files changed, 99 insertions(+), 32 deletions(-)Signature · 1 line
2.7.4