diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-03-15 18:12:39 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-03-20 12:19:30 -0400 |
commit | a1e9b74cc2ef80131b9f955c0e1acc25285dc88c (patch) | |
tree | bc27c0b0dea8212516638b0638d636176158243b /tools/perf/util/annotate.c | |
parent | 2ba5eca10486eeb37030f8bce27cecda3763502f (diff) |
perf annotate: Finish the generalization of annotate_browser__write()
We pass some more callbacks and all of annotate_browser__write() seems
to be free of TUI code (except for some arrow constants, will fix).
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-5uo6yvwnxtsbe8y6v0ysaakf@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/annotate.c')
-rw-r--r-- | tools/perf/util/annotate.c | 113 |
1 files changed, 104 insertions, 9 deletions
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, |