diff options
-rw-r--r-- | tools/perf/ui/browsers/annotate.c | 97 | ||||
-rw-r--r-- | tools/perf/util/annotate.c | 113 | ||||
-rw-r--r-- | tools/perf/util/annotate.h | 13 |
3 files changed, 127 insertions, 96 deletions
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 9b77a016e299..2b18c462b882 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c | |||
@@ -71,38 +71,20 @@ static int ui_browser__jumps_percent_color(struct ui_browser *browser, int nr, b | |||
71 | return HE_COLORSET_NORMAL; | 71 | return HE_COLORSET_NORMAL; |
72 | } | 72 | } |
73 | 73 | ||
74 | static int ui_browser__set_jumps_percent_color(struct ui_browser *browser, int nr, bool current) | 74 | static int ui_browser__set_jumps_percent_color(void *browser, int nr, bool current) |
75 | { | 75 | { |
76 | int color = ui_browser__jumps_percent_color(browser, nr, current); | 76 | int color = ui_browser__jumps_percent_color(browser, nr, current); |
77 | return ui_browser__set_color(browser, color); | 77 | return ui_browser__set_color(browser, color); |
78 | } | 78 | } |
79 | 79 | ||
80 | static void disasm_line__write(struct disasm_line *dl, struct ui_browser *browser, | 80 | static int annotate_browser__set_color(void *browser, int color) |
81 | char *bf, size_t size) | ||
82 | { | 81 | { |
83 | struct annotation *notes = browser__annotation(browser); | 82 | return ui_browser__set_color(browser, color); |
84 | 83 | } | |
85 | if (dl->ins.ops && dl->ins.ops->scnprintf) { | ||
86 | if (ins__is_jump(&dl->ins)) { | ||
87 | bool fwd = dl->ops.target.offset > dl->al.offset; | ||
88 | |||
89 | ui_browser__write_graph(browser, fwd ? SLSMG_DARROW_CHAR : | ||
90 | SLSMG_UARROW_CHAR); | ||
91 | SLsmg_write_char(' '); | ||
92 | } else if (ins__is_call(&dl->ins)) { | ||
93 | ui_browser__write_graph(browser, SLSMG_RARROW_CHAR); | ||
94 | SLsmg_write_char(' '); | ||
95 | } else if (ins__is_ret(&dl->ins)) { | ||
96 | ui_browser__write_graph(browser, SLSMG_LARROW_CHAR); | ||
97 | SLsmg_write_char(' '); | ||
98 | } else { | ||
99 | ui_browser__write_nstring(browser, " ", 2); | ||
100 | } | ||
101 | } else { | ||
102 | ui_browser__write_nstring(browser, " ", 2); | ||
103 | } | ||
104 | 84 | ||
105 | disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset); | 85 | static void annotate_browser__write_graph(void *browser, int graph) |
86 | { | ||
87 | ui_browser__write_graph(browser, graph); | ||
106 | } | 88 | } |
107 | 89 | ||
108 | static void annotate_browser__set_percent_color(void *browser, double percent, bool current) | 90 | static void annotate_browser__set_percent_color(void *browser, double percent, bool current) |
@@ -128,68 +110,19 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int | |||
128 | bool change_color = (!notes->options->hide_src_code && | 110 | bool change_color = (!notes->options->hide_src_code && |
129 | (!current_entry || (browser->use_navkeypressed && | 111 | (!current_entry || (browser->use_navkeypressed && |
130 | !browser->navkeypressed))); | 112 | !browser->navkeypressed))); |
131 | int width = browser->width, printed; | 113 | int width = browser->width; |
132 | int pcnt_width = annotation__pcnt_width(notes), | ||
133 | cycles_width = annotation__cycles_width(notes); | ||
134 | char bf[256]; | ||
135 | |||
136 | annotation_line__print_start(al, notes, row == 0, current_entry, browser, | ||
137 | annotate_browser__set_percent_color, | ||
138 | annotate_browser__printf); | ||
139 | 114 | ||
140 | /* The scroll bar isn't being used */ | 115 | /* The scroll bar isn't being used */ |
141 | if (!browser->navkeypressed) | 116 | if (!browser->navkeypressed) |
142 | width += 1; | 117 | width += 1; |
143 | 118 | ||
144 | if (!*al->line) | 119 | annotation_line__write(al, notes, row == 0, current_entry, change_color, |
145 | ui_browser__write_nstring(browser, " ", width - pcnt_width - cycles_width); | 120 | width, browser, |
146 | else if (al->offset == -1) { | 121 | annotate_browser__set_color, |
147 | if (al->line_nr && notes->options->show_linenr) | 122 | annotate_browser__set_percent_color, |
148 | printed = scnprintf(bf, sizeof(bf), "%-*d ", notes->widths.addr + 1, al->line_nr); | 123 | ui_browser__set_jumps_percent_color, |
149 | else | 124 | annotate_browser__printf, |
150 | printed = scnprintf(bf, sizeof(bf), "%*s ", notes->widths.addr, " "); | 125 | annotate_browser__write_graph); |
151 | ui_browser__write_nstring(browser, bf, printed); | ||
152 | ui_browser__write_nstring(browser, al->line, width - printed - pcnt_width - cycles_width + 1); | ||
153 | } else { | ||
154 | u64 addr = al->offset; | ||
155 | int color = -1; | ||
156 | |||
157 | if (!notes->options->use_offset) | ||
158 | addr += notes->start; | ||
159 | |||
160 | if (!notes->options->use_offset) { | ||
161 | printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr); | ||
162 | } else { | ||
163 | if (al->jump_sources) { | ||
164 | if (notes->options->show_nr_jumps) { | ||
165 | int prev; | ||
166 | printed = scnprintf(bf, sizeof(bf), "%*d ", | ||
167 | notes->widths.jumps, | ||
168 | al->jump_sources); | ||
169 | prev = ui_browser__set_jumps_percent_color(browser, al->jump_sources, | ||
170 | current_entry); | ||
171 | ui_browser__write_nstring(browser, bf, printed); | ||
172 | ui_browser__set_color(browser, prev); | ||
173 | } | ||
174 | |||
175 | printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ", | ||
176 | notes->widths.target, addr); | ||
177 | } else { | ||
178 | printed = scnprintf(bf, sizeof(bf), "%*s ", | ||
179 | notes->widths.addr, " "); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | if (change_color) | ||
184 | color = ui_browser__set_color(browser, HE_COLORSET_ADDR); | ||
185 | ui_browser__write_nstring(browser, bf, printed); | ||
186 | if (change_color) | ||
187 | ui_browser__set_color(browser, color); | ||
188 | |||
189 | disasm_line__write(disasm_line(al), browser, bf, sizeof(bf)); | ||
190 | |||
191 | ui_browser__write_nstring(browser, bf, width - pcnt_width - cycles_width - 3 - printed); | ||
192 | } | ||
193 | 126 | ||
194 | if (current_entry) | 127 | if (current_entry) |
195 | ab->selection = al; | 128 | ab->selection = al; |
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 046feda11052..45a52e2658c8 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -27,6 +27,18 @@ | |||
27 | #include <linux/bitops.h> | 27 | #include <linux/bitops.h> |
28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
29 | 29 | ||
30 | /* FIXME: For the HE_COLORSET */ | ||
31 | #include "ui/browser.h" | ||
32 | |||
33 | /* | ||
34 | * FIXME: Using the same values as slang.h, | ||
35 | * but that header may not be available everywhere | ||
36 | */ | ||
37 | #define LARROW_CHAR 0x1B | ||
38 | #define RARROW_CHAR 0x1A | ||
39 | #define DARROW_CHAR 0x19 | ||
40 | #define UARROW_CHAR 0x18 | ||
41 | |||
30 | #include "sane_ctype.h" | 42 | #include "sane_ctype.h" |
31 | 43 | ||
32 | const char *disassembler_style; | 44 | const char *disassembler_style; |
@@ -2204,14 +2216,48 @@ static void set_percent_color_stub(void *obj __maybe_unused, | |||
2204 | { | 2216 | { |
2205 | } | 2217 | } |
2206 | 2218 | ||
2207 | void annotation_line__print_start(struct annotation_line *al, struct annotation *notes, | 2219 | static void disasm_line__write(struct disasm_line *dl, struct annotation *notes, |
2208 | bool first_line, bool current_entry, | 2220 | void *obj, char *bf, size_t size, |
2209 | void *obj, | 2221 | void (*obj__printf)(void *obj, const char *fmt, ...), |
2210 | void (*obj__set_percent_color)(void *obj, double percent, bool current), | 2222 | void (*obj__write_graph)(void *obj, int graph)) |
2211 | void (*obj__printf)(void *obj, const char *fmt, ...)) | 2223 | { |
2224 | if (dl->ins.ops && dl->ins.ops->scnprintf) { | ||
2225 | if (ins__is_jump(&dl->ins)) { | ||
2226 | bool fwd = dl->ops.target.offset > dl->al.offset; | ||
2227 | |||
2228 | obj__write_graph(obj, fwd ? DARROW_CHAR : UARROW_CHAR); | ||
2229 | obj__printf(obj, " "); | ||
2230 | } else if (ins__is_call(&dl->ins)) { | ||
2231 | obj__write_graph(obj, RARROW_CHAR); | ||
2232 | obj__printf(obj, " "); | ||
2233 | } else if (ins__is_ret(&dl->ins)) { | ||
2234 | obj__write_graph(obj, LARROW_CHAR); | ||
2235 | obj__printf(obj, " "); | ||
2236 | } else { | ||
2237 | obj__printf(obj, " "); | ||
2238 | } | ||
2239 | } else { | ||
2240 | obj__printf(obj, " "); | ||
2241 | } | ||
2242 | |||
2243 | disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset); | ||
2244 | } | ||
2245 | |||
2246 | void annotation_line__write(struct annotation_line *al, struct annotation *notes, | ||
2247 | bool first_line, bool current_entry, bool change_color, int width, | ||
2248 | void *obj, | ||
2249 | int (*obj__set_color)(void *obj, int color), | ||
2250 | void (*obj__set_percent_color)(void *obj, double percent, bool current), | ||
2251 | int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current), | ||
2252 | void (*obj__printf)(void *obj, const char *fmt, ...), | ||
2253 | void (*obj__write_graph)(void *obj, int graph)) | ||
2212 | { | 2254 | { |
2213 | double percent_max = annotation_line__max_percent(al, notes); | 2255 | double percent_max = annotation_line__max_percent(al, notes); |
2256 | int pcnt_width = annotation__pcnt_width(notes), | ||
2257 | cycles_width = annotation__cycles_width(notes); | ||
2214 | bool show_title = false; | 2258 | bool show_title = false; |
2259 | char bf[256]; | ||
2260 | int printed; | ||
2215 | 2261 | ||
2216 | if (first_line && (al->offset == -1 || percent_max == 0.0)) { | 2262 | if (first_line && (al->offset == -1 || percent_max == 0.0)) { |
2217 | if (notes->have_cycles) { | 2263 | if (notes->have_cycles) { |
@@ -2240,14 +2286,12 @@ void annotation_line__print_start(struct annotation_line *al, struct annotation | |||
2240 | } | 2286 | } |
2241 | } | 2287 | } |
2242 | } else { | 2288 | } else { |
2243 | int pcnt_width = annotation__pcnt_width(notes); | ||
2244 | |||
2245 | obj__set_percent_color(obj, 0, current_entry); | 2289 | obj__set_percent_color(obj, 0, current_entry); |
2246 | 2290 | ||
2247 | if (!show_title) | 2291 | if (!show_title) |
2248 | obj__printf(obj, "%*s", pcnt_width, " "); | 2292 | obj__printf(obj, "%-*s", pcnt_width, " "); |
2249 | else { | 2293 | else { |
2250 | obj__printf(obj, "%*s", pcnt_width, | 2294 | obj__printf(obj, "%-*s", pcnt_width, |
2251 | notes->options->show_total_period ? "Period" : | 2295 | notes->options->show_total_period ? "Period" : |
2252 | notes->options->show_nr_samples ? "Samples" : "Percent"); | 2296 | notes->options->show_nr_samples ? "Samples" : "Percent"); |
2253 | } | 2297 | } |
@@ -2271,6 +2315,57 @@ void annotation_line__print_start(struct annotation_line *al, struct annotation | |||
2271 | } | 2315 | } |
2272 | 2316 | ||
2273 | obj__printf(obj, " "); | 2317 | obj__printf(obj, " "); |
2318 | |||
2319 | if (!*al->line) | ||
2320 | obj__printf(obj, "%-*s", width - pcnt_width - cycles_width, " "); | ||
2321 | else if (al->offset == -1) { | ||
2322 | if (al->line_nr && notes->options->show_linenr) | ||
2323 | printed = scnprintf(bf, sizeof(bf), "%-*d ", notes->widths.addr + 1, al->line_nr); | ||
2324 | else | ||
2325 | printed = scnprintf(bf, sizeof(bf), "%-*s ", notes->widths.addr, " "); | ||
2326 | obj__printf(obj, bf); | ||
2327 | obj__printf(obj, "%-*s", width - printed - pcnt_width - cycles_width + 1, al->line); | ||
2328 | } else { | ||
2329 | u64 addr = al->offset; | ||
2330 | int color = -1; | ||
2331 | |||
2332 | if (!notes->options->use_offset) | ||
2333 | addr += notes->start; | ||
2334 | |||
2335 | if (!notes->options->use_offset) { | ||
2336 | printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr); | ||
2337 | } else { | ||
2338 | if (al->jump_sources) { | ||
2339 | if (notes->options->show_nr_jumps) { | ||
2340 | int prev; | ||
2341 | printed = scnprintf(bf, sizeof(bf), "%*d ", | ||
2342 | notes->widths.jumps, | ||
2343 | al->jump_sources); | ||
2344 | prev = obj__set_jumps_percent_color(obj, al->jump_sources, | ||
2345 | current_entry); | ||
2346 | obj__printf(obj, bf); | ||
2347 | obj__set_color(obj, prev); | ||
2348 | } | ||
2349 | |||
2350 | printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ", | ||
2351 | notes->widths.target, addr); | ||
2352 | } else { | ||
2353 | printed = scnprintf(bf, sizeof(bf), "%-*s ", | ||
2354 | notes->widths.addr, " "); | ||
2355 | } | ||
2356 | } | ||
2357 | |||
2358 | if (change_color) | ||
2359 | color = obj__set_color(obj, HE_COLORSET_ADDR); | ||
2360 | obj__printf(obj, bf); | ||
2361 | if (change_color) | ||
2362 | obj__set_color(obj, color); | ||
2363 | |||
2364 | disasm_line__write(disasm_line(al), notes, obj, bf, sizeof(bf), obj__printf, obj__write_graph); | ||
2365 | |||
2366 | obj__printf(obj, "%-*s", width - pcnt_width - cycles_width - 3 - printed, bf); | ||
2367 | } | ||
2368 | |||
2274 | } | 2369 | } |
2275 | 2370 | ||
2276 | int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel, | 2371 | int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel, |
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 84c99774bfed..27fcdacbb497 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h | |||
@@ -126,11 +126,14 @@ struct annotation_line * | |||
126 | annotation_line__next(struct annotation_line *pos, struct list_head *head); | 126 | annotation_line__next(struct annotation_line *pos, struct list_head *head); |
127 | 127 | ||
128 | double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes); | 128 | double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes); |
129 | void annotation_line__print_start(struct annotation_line *al, struct annotation *notes, | 129 | void annotation_line__write(struct annotation_line *al, struct annotation *notes, |
130 | bool first_line, bool current_entry, | 130 | bool first_line, bool current_entry, bool change_color, int width, |
131 | void *obj, | 131 | void *obj, |
132 | void (*obj__set_percent_color)(void *obj, double percent, bool current), | 132 | int (*obj__set_color)(void *obj, int color), |
133 | void (*obj__printf)(void *obj, const char *fmt, ...)); | 133 | void (*obj__set_percent_color)(void *obj, double percent, bool current), |
134 | int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current), | ||
135 | void (*obj__printf)(void *obj, const char *fmt, ...), | ||
136 | void (*obj__write_graph)(void *obj, int graph)); | ||
134 | 137 | ||
135 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); | 138 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); |
136 | size_t disasm__fprintf(struct list_head *head, FILE *fp); | 139 | size_t disasm__fprintf(struct list_head *head, FILE *fp); |