Skip to content

Commit ad83f3b

Browse files
TianyouLinamhyung
authored andcommitted
perf c2c annotate: Start from the contention line
Add support to highlight the contention line in the annotate browser, use 'TAB'/'UNTAB' to refocus to the contention line. Signed-off-by: Tianyou Li <[email protected]> Reviewed-by: Dapeng Mi <[email protected]> Reviewed-by: Thomas Falcon <[email protected]> Reviewed-by: Jiebin Sun <[email protected]> Reviewed-by: Pan Deng <[email protected]> Reviewed-by: Zhiguo Zhou <[email protected]> Reviewed-by: Wangyang Guo <[email protected]> Tested-by: Ravi Bangoria <[email protected]> Signed-off-by: Namhyung Kim <[email protected]>
1 parent cd3466c commit ad83f3b

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

tools/perf/builtin-annotate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static void hists__find_annotations(struct hists *hists,
519519
/* skip missing symbols */
520520
nd = rb_next(nd);
521521
} else if (use_browser == 1) {
522-
key = hist_entry__tui_annotate(he, evsel, NULL);
522+
key = hist_entry__tui_annotate(he, evsel, NULL, NO_ADDR);
523523

524524
switch (key) {
525525
case -1:

tools/perf/builtin-c2c.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,7 @@ static int perf_c2c__toggle_annotation(struct hist_browser *browser)
26042604
struct symbol *sym = NULL;
26052605
struct annotated_source *src = NULL;
26062606
struct c2c_hist_entry *c2c_he = NULL;
2607+
u64 al_addr = NO_ADDR;
26072608

26082609
if (!perf_c2c__has_annotation(he->hists->hpp_list)) {
26092610
ui_browser__help_window(&browser->b, "No annotation support");
@@ -2627,8 +2628,11 @@ static int perf_c2c__toggle_annotation(struct hist_browser *browser)
26272628
return 0;
26282629
}
26292630

2631+
if (he->mem_info)
2632+
al_addr = mem_info__iaddr(he->mem_info)->al_addr;
2633+
26302634
c2c_he = container_of(he, struct c2c_hist_entry, he);
2631-
return hist_entry__tui_annotate(he, c2c_he->evsel, NULL);
2635+
return hist_entry__tui_annotate(he, c2c_he->evsel, NULL, al_addr);
26322636
}
26332637

26342638
static void c2c_browser__update_nr_entries(struct hist_browser *hb)

tools/perf/ui/browsers/annotate.c

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
605605
target_ms.map = ms->map;
606606
target_ms.sym = dl->ops.target.sym;
607607
annotation__unlock(notes);
608-
__hist_entry__tui_annotate(browser->he, &target_ms, evsel, hbt);
608+
__hist_entry__tui_annotate(browser->he, &target_ms, evsel, hbt, NO_ADDR);
609609

610610
/*
611611
* The annotate_browser above changed the title with the target function
@@ -852,6 +852,16 @@ static void annotate_browser__debuginfo_warning(struct annotate_browser *browser
852852
}
853853
}
854854

855+
static s64 annotate_browser__curr_hot_offset(struct annotate_browser *browser)
856+
{
857+
struct annotation_line *al = NULL;
858+
859+
if (browser->curr_hot)
860+
al = rb_entry(browser->curr_hot, struct annotation_line, rb_node);
861+
862+
return al ? al->offset : 0;
863+
}
864+
855865
static int annotate_browser__run(struct annotate_browser *browser,
856866
struct evsel *evsel,
857867
struct hist_browser_timer *hbt)
@@ -873,6 +883,11 @@ static int annotate_browser__run(struct annotate_browser *browser,
873883

874884
annotate_browser__calc_percent(browser, evsel);
875885

886+
if (browser->selection != NULL) {
887+
browser->curr_hot = &browser->selection->rb_node;
888+
browser->b.use_navkeypressed = false;
889+
}
890+
876891
if (browser->curr_hot) {
877892
annotate_browser__set_rb_top(browser, browser->curr_hot);
878893
browser->b.navkeypressed = false;
@@ -969,8 +984,19 @@ static int annotate_browser__run(struct annotate_browser *browser,
969984
nd = browser->curr_hot;
970985
break;
971986
case 's':
987+
struct annotation_line *al = NULL;
988+
s64 offset = annotate_browser__curr_hot_offset(browser);
989+
972990
if (annotate_browser__toggle_source(browser, evsel))
973991
ui_helpline__puts(help);
992+
993+
/* Update the annotation browser's rb_tree, and reset the nd */
994+
annotate_browser__calc_percent(browser, evsel);
995+
/* Try to find the same asm line as before */
996+
al = annotated_source__get_line(notes->src, offset);
997+
browser->curr_hot = al ? &al->rb_node : NULL;
998+
nd = browser->curr_hot;
999+
9741000
annotate__scnprintf_title(hists, title, sizeof(title));
9751001
annotate_browser__show(browser, title, help);
9761002
continue;
@@ -1106,19 +1132,19 @@ static int annotate_browser__run(struct annotate_browser *browser,
11061132
}
11071133

11081134
int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel,
1109-
struct hist_browser_timer *hbt)
1135+
struct hist_browser_timer *hbt, u64 al_addr)
11101136
{
11111137
/* reset abort key so that it can get Ctrl-C as a key */
11121138
SLang_reset_tty();
11131139
SLang_init_tty(0, 0, 0);
11141140
SLtty_set_suspend_state(true);
11151141

1116-
return __hist_entry__tui_annotate(he, &he->ms, evsel, hbt);
1142+
return __hist_entry__tui_annotate(he, &he->ms, evsel, hbt, al_addr);
11171143
}
11181144

11191145
int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
11201146
struct evsel *evsel,
1121-
struct hist_browser_timer *hbt)
1147+
struct hist_browser_timer *hbt, u64 al_addr)
11221148
{
11231149
struct symbol *sym = ms->sym;
11241150
struct annotation *notes = symbol__annotation(sym);
@@ -1188,6 +1214,20 @@ int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
11881214
if (annotate_opts.hide_src_code)
11891215
ui_browser__init_asm_mode(&browser.b);
11901216

1217+
/*
1218+
* If al_addr is set, it means that there should be a line
1219+
* intentionally selected, not based on the percentages
1220+
* which caculated by the event sampling. In this case, we
1221+
* convey this information into the browser selection, where
1222+
* the selection in other cases should be empty.
1223+
*/
1224+
if (al_addr != NO_ADDR) {
1225+
struct annotation_line *al = annotated_source__get_line(notes->src,
1226+
al_addr - sym->start);
1227+
1228+
browser.selection = al;
1229+
}
1230+
11911231
ret = annotate_browser__run(&browser, evsel, hbt);
11921232

11931233
debuginfo__delete(browser.dbg);

tools/perf/ui/browsers/hists.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2485,7 +2485,7 @@ do_annotate(struct hist_browser *browser, struct popup_action *act)
24852485
evsel = hists_to_evsel(browser->hists);
24862486

24872487
he = hist_browser__selected_entry(browser);
2488-
err = __hist_entry__tui_annotate(he, &act->ms, evsel, browser->hbt);
2488+
err = __hist_entry__tui_annotate(he, &act->ms, evsel, browser->hbt, NO_ADDR);
24892489
/*
24902490
* offer option to annotate the other branch source or target
24912491
* (if they exists) when returning from annotate

tools/perf/util/hist.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,12 +713,14 @@ struct block_hist {
713713
#include "../ui/keysyms.h"
714714
void attr_to_script(char *buf, struct perf_event_attr *attr);
715715

716+
#define NO_ADDR 0
717+
716718
int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
717719
struct evsel *evsel,
718-
struct hist_browser_timer *hbt);
720+
struct hist_browser_timer *hbt, u64 al_addr);
719721

720722
int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel,
721-
struct hist_browser_timer *hbt);
723+
struct hist_browser_timer *hbt, u64 al_addr);
722724

723725
int evlist__tui_browse_hists(struct evlist *evlist, const char *help, struct hist_browser_timer *hbt,
724726
float min_pcnt, struct perf_env *env, bool warn_lost_event);

0 commit comments

Comments
 (0)