aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/ui
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-08-10 13:54:09 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-08-10 15:09:41 -0400
commit211ef12771e759a08e10c3c606e6a8b1663519e7 (patch)
treef9881f574f9a7508ce47d125daad0a089bef5add /tools/perf/util/ui
parent34cea7f7c0620c964676eece258ef431a6608bce (diff)
perf ui: Move annotate browser to util/ui/browsers/
LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/ui')
-rw-r--r--tools/perf/util/ui/browser.h1
-rw-r--r--tools/perf/util/ui/browsers/annotate.c114
-rw-r--r--tools/perf/util/ui/libslang.h27
3 files changed, 142 insertions, 0 deletions
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h
index 8eed24cf2854..856e34361729 100644
--- a/tools/perf/util/ui/browser.h
+++ b/tools/perf/util/ui/browser.h
@@ -3,6 +3,7 @@
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include <newt.h> 5#include <newt.h>
6#include <sys/types.h>
6#include "../types.h" 7#include "../types.h"
7 8
8#define HE_COLORSET_TOP 50 9#define HE_COLORSET_TOP 50
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c
new file mode 100644
index 000000000000..783d277f2190
--- /dev/null
+++ b/tools/perf/util/ui/browsers/annotate.c
@@ -0,0 +1,114 @@
1#include "../browser.h"
2#include "../helpline.h"
3#include "../libslang.h"
4#include "../../hist.h"
5#include "../../sort.h"
6#include "../../symbol.h"
7
8static void ui__error_window(const char *fmt, ...)
9{
10 va_list ap;
11
12 va_start(ap, fmt);
13 newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap);
14 va_end(ap);
15}
16
17static void annotate_browser__write(struct ui_browser *self, void *entry, int row)
18{
19 struct objdump_line *ol = rb_entry(entry, struct objdump_line, node);
20 bool current_entry = ui_browser__is_current_entry(self, row);
21 int width = self->width;
22
23 if (ol->offset != -1) {
24 struct hist_entry *he = self->priv;
25 struct symbol *sym = he->ms.sym;
26 int len = he->ms.sym->end - he->ms.sym->start;
27 unsigned int hits = 0;
28 double percent = 0.0;
29 int color;
30 struct sym_priv *priv = symbol__priv(sym);
31 struct sym_ext *sym_ext = priv->ext;
32 struct sym_hist *h = priv->hist;
33 s64 offset = ol->offset;
34 struct objdump_line *next = objdump__get_next_ip_line(self->entries, ol);
35
36 while (offset < (s64)len &&
37 (next == NULL || offset < next->offset)) {
38 if (sym_ext) {
39 percent += sym_ext[offset].percent;
40 } else
41 hits += h->ip[offset];
42
43 ++offset;
44 }
45
46 if (sym_ext == NULL && h->sum)
47 percent = 100.0 * hits / h->sum;
48
49 color = ui_browser__percent_color(percent, current_entry);
50 SLsmg_set_color(color);
51 slsmg_printf(" %7.2f ", percent);
52 if (!current_entry)
53 SLsmg_set_color(HE_COLORSET_CODE);
54 } else {
55 int color = ui_browser__percent_color(0, current_entry);
56 SLsmg_set_color(color);
57 slsmg_write_nstring(" ", 9);
58 }
59
60 SLsmg_write_char(':');
61 slsmg_write_nstring(" ", 8);
62 if (!*ol->line)
63 slsmg_write_nstring(" ", width - 18);
64 else
65 slsmg_write_nstring(ol->line, width - 18);
66}
67
68int hist_entry__tui_annotate(struct hist_entry *self)
69{
70 struct newtExitStruct es;
71 struct objdump_line *pos, *n;
72 LIST_HEAD(head);
73 struct ui_browser browser = {
74 .entries = &head,
75 .refresh = ui_browser__list_head_refresh,
76 .seek = ui_browser__list_head_seek,
77 .write = annotate_browser__write,
78 .priv = self,
79 };
80 int ret;
81
82 if (self->ms.sym == NULL)
83 return -1;
84
85 if (self->ms.map->dso->annotate_warned)
86 return -1;
87
88 if (hist_entry__annotate(self, &head) < 0) {
89 ui__error_window(browser__last_msg);
90 return -1;
91 }
92
93 ui_helpline__push("Press <- or ESC to exit");
94
95 list_for_each_entry(pos, &head, node) {
96 size_t line_len = strlen(pos->line);
97 if (browser.width < line_len)
98 browser.width = line_len;
99 ++browser.nr_entries;
100 }
101
102 browser.width += 18; /* Percentage */
103 ui_browser__show(&browser, self->ms.sym->name);
104 newtFormAddHotKey(browser.form, ' ');
105 ret = ui_browser__run(&browser, &es);
106 newtFormDestroy(browser.form);
107 newtPopWindow();
108 list_for_each_entry_safe(pos, n, &head, node) {
109 list_del(&pos->node);
110 objdump_line__free(pos);
111 }
112 ui_helpline__pop();
113 return ret;
114}
diff --git a/tools/perf/util/ui/libslang.h b/tools/perf/util/ui/libslang.h
new file mode 100644
index 000000000000..5623da8e8080
--- /dev/null
+++ b/tools/perf/util/ui/libslang.h
@@ -0,0 +1,27 @@
1#ifndef _PERF_UI_SLANG_H_
2#define _PERF_UI_SLANG_H_ 1
3/*
4 * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks
5 * the build if it isn't defined. Use the equivalent one that glibc
6 * has on features.h.
7 */
8#include <features.h>
9#ifndef HAVE_LONG_LONG
10#define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG
11#endif
12#include <slang.h>
13
14#if SLANG_VERSION < 20104
15#define slsmg_printf(msg, args...) \
16 SLsmg_printf((char *)msg, ##args)
17#define slsmg_write_nstring(msg, len) \
18 SLsmg_write_nstring((char *)msg, len)
19#define sltt_set_color(obj, name, fg, bg) \
20 SLtt_set_color(obj,(char *)name, (char *)fg, (char *)bg)
21#else
22#define slsmg_printf SLsmg_printf
23#define slsmg_write_nstring SLsmg_write_nstring
24#define sltt_set_color SLtt_set_color
25#endif
26
27#endif /* _PERF_UI_SLANG_H_ */