[PATCH v1 4/4] perf annotate: Display multiple events for gtk mode

From: Jin Yao
Date: Tue Aug 15 2017 - 22:22:45 EST


For example:
perf record -e cycles,branches ./div
perf annotate main --gtk

Both the cycles and branches are displayed at the left column in
gtk window.

Signed-off-by: Jin Yao <yao.jin@xxxxxxxxxxxxxxx>
---
tools/perf/ui/gtk/annotate.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c
index 0217619..f314654 100644
--- a/tools/perf/ui/gtk/annotate.c
+++ b/tools/perf/ui/gtk/annotate.c
@@ -88,7 +88,8 @@ static int perf_gtk__get_line(char *buf, size_t size, struct disasm_line *dl)

static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,
struct map *map, struct perf_evsel *evsel,
- struct hist_browser_timer *hbt __maybe_unused)
+ struct hist_browser_timer *hbt __maybe_unused,
+ struct hist_entry *he)
{
struct disasm_line *pos, *n;
struct annotation *notes;
@@ -98,6 +99,7 @@ static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,
GtkWidget *view;
int i;
char s[512];
+ struct hist_event *hevt;

notes = symbol__annotation(sym);

@@ -124,17 +126,18 @@ static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,

gtk_list_store_append(store, &iter);

- if (perf_evsel__is_group_event(evsel)) {
- for (i = 0; i < evsel->nr_members; i++) {
+ if (evsel) {
+ ret = perf_gtk__get_percent(s, sizeof(s), sym, pos,
+ evsel->idx);
+ } else if (he) {
+ for (i = 0; i < he->event_nr; i++) {
+ hevt = &he->events[i];
ret += perf_gtk__get_percent(s + ret,
sizeof(s) - ret,
- sym, pos,
- evsel->idx + i);
+ hevt->ms.sym, pos,
+ hevt->idx);
ret += scnprintf(s + ret, sizeof(s) - ret, " ");
}
- } else {
- ret = perf_gtk__get_percent(s, sizeof(s), sym, pos,
- evsel->idx);
}

if (ret)
@@ -157,19 +160,25 @@ static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,

static int symbol__gtk_annotate(struct symbol *sym, struct map *map,
struct perf_evsel *evsel,
- struct hist_browser_timer *hbt)
+ struct hist_browser_timer *hbt,
+ struct hist_entry *he)
{
GtkWidget *window;
GtkWidget *notebook;
GtkWidget *scrolled_window;
GtkWidget *tab_label;
int err;
+ char *arch;
+
+ if (!evsel)
+ arch = perf_evsel__env_arch(he->events[0].evsel);
+ else
+ arch = perf_evsel__env_arch(evsel);

if (map->dso->annotate_warned)
return -1;

- err = symbol__disassemble(sym, map, perf_evsel__env_arch(evsel),
- 0, NULL, NULL);
+ err = symbol__disassemble(sym, map, arch, 0, NULL, NULL);
if (err) {
char msg[BUFSIZ];
symbol__strerror_disassemble(sym, map, err, msg, sizeof(msg));
@@ -228,7 +237,7 @@ static int symbol__gtk_annotate(struct symbol *sym, struct map *map,
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrolled_window,
tab_label);

- perf_gtk__annotate_symbol(scrolled_window, sym, map, evsel, hbt);
+ perf_gtk__annotate_symbol(scrolled_window, sym, map, evsel, hbt, he);
return 0;
}

@@ -236,7 +245,7 @@ int hist_entry__gtk_annotate(struct hist_entry *he,
struct perf_evsel *evsel,
struct hist_browser_timer *hbt)
{
- return symbol__gtk_annotate(he->ms.sym, he->ms.map, evsel, hbt);
+ return symbol__gtk_annotate(he->ms.sym, he->ms.map, evsel, hbt, he);
}

void perf_gtk__show_annotations(void)
--
2.7.4