diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-03-15 22:14:51 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-03-20 14:36:18 -0400 |
commit | c298304bd747d6a0b733f0becb470ff07ead0317 (patch) | |
tree | 41bd9879719d1305d2d201e64109d6f883c5f2eb | |
parent | a1e9b74cc2ef80131b9f955c0e1acc25285dc88c (diff) |
perf annotate: Use a ops table for annotation_line__write()
To simplify the passing of arguments, the --stdio2 code will have to set
all the fields with operations printing to stdout.
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-pcs3c7vdy9ucygxflo4nl1o7@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/ui/browsers/annotate.c | 32 | ||||
-rw-r--r-- | tools/perf/util/annotate.c | 44 | ||||
-rw-r--r-- | tools/perf/util/annotate.h | 19 |
3 files changed, 53 insertions, 42 deletions
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 2b18c462b882..bed647807d37 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c | |||
@@ -106,25 +106,29 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int | |||
106 | struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); | 106 | struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); |
107 | struct annotation *notes = browser__annotation(browser); | 107 | struct annotation *notes = browser__annotation(browser); |
108 | struct annotation_line *al = list_entry(entry, struct annotation_line, node); | 108 | struct annotation_line *al = list_entry(entry, struct annotation_line, node); |
109 | bool current_entry = ui_browser__is_current_entry(browser, row); | 109 | struct annotation_write_ops ops = { |
110 | bool change_color = (!notes->options->hide_src_code && | 110 | .first_line = row == 0, |
111 | (!current_entry || (browser->use_navkeypressed && | 111 | .current_entry = ui_browser__is_current_entry(browser, row), |
112 | !browser->navkeypressed))); | 112 | .change_color = (!notes->options->hide_src_code && |
113 | int width = browser->width; | 113 | (!ops.current_entry || |
114 | (browser->use_navkeypressed && | ||
115 | !browser->navkeypressed))), | ||
116 | .width = browser->width, | ||
117 | .obj = browser, | ||
118 | .set_color = annotate_browser__set_color, | ||
119 | .set_percent_color = annotate_browser__set_percent_color, | ||
120 | .set_jumps_percent_color = ui_browser__set_jumps_percent_color, | ||
121 | .printf = annotate_browser__printf, | ||
122 | .write_graph = annotate_browser__write_graph, | ||
123 | }; | ||
114 | 124 | ||
115 | /* The scroll bar isn't being used */ | 125 | /* The scroll bar isn't being used */ |
116 | if (!browser->navkeypressed) | 126 | if (!browser->navkeypressed) |
117 | width += 1; | 127 | ops.width += 1; |
118 | 128 | ||
119 | annotation_line__write(al, notes, row == 0, current_entry, change_color, | 129 | annotation_line__write(al, notes, &ops); |
120 | width, browser, | ||
121 | annotate_browser__set_color, | ||
122 | annotate_browser__set_percent_color, | ||
123 | ui_browser__set_jumps_percent_color, | ||
124 | annotate_browser__printf, | ||
125 | annotate_browser__write_graph); | ||
126 | 130 | ||
127 | if (current_entry) | 131 | if (ops.current_entry) |
128 | ab->selection = al; | 132 | ab->selection = al; |
129 | } | 133 | } |
130 | 134 | ||
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 45a52e2658c8..11ad73211538 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -34,10 +34,10 @@ | |||
34 | * FIXME: Using the same values as slang.h, | 34 | * FIXME: Using the same values as slang.h, |
35 | * but that header may not be available everywhere | 35 | * but that header may not be available everywhere |
36 | */ | 36 | */ |
37 | #define LARROW_CHAR 0x1B | 37 | #define LARROW_CHAR ((unsigned char)',') |
38 | #define RARROW_CHAR 0x1A | 38 | #define RARROW_CHAR ((unsigned char)'+') |
39 | #define DARROW_CHAR 0x19 | 39 | #define DARROW_CHAR ((unsigned char)'.') |
40 | #define UARROW_CHAR 0x18 | 40 | #define UARROW_CHAR ((unsigned char)'-') |
41 | 41 | ||
42 | #include "sane_ctype.h" | 42 | #include "sane_ctype.h" |
43 | 43 | ||
@@ -2210,12 +2210,6 @@ double annotation_line__max_percent(struct annotation_line *al, struct annotatio | |||
2210 | return percent_max; | 2210 | return percent_max; |
2211 | } | 2211 | } |
2212 | 2212 | ||
2213 | static void set_percent_color_stub(void *obj __maybe_unused, | ||
2214 | double percent __maybe_unused, | ||
2215 | bool current __maybe_unused) | ||
2216 | { | ||
2217 | } | ||
2218 | |||
2219 | static void disasm_line__write(struct disasm_line *dl, struct annotation *notes, | 2213 | static void disasm_line__write(struct disasm_line *dl, struct annotation *notes, |
2220 | void *obj, char *bf, size_t size, | 2214 | void *obj, char *bf, size_t size, |
2221 | void (*obj__printf)(void *obj, const char *fmt, ...), | 2215 | void (*obj__printf)(void *obj, const char *fmt, ...), |
@@ -2243,14 +2237,15 @@ static void disasm_line__write(struct disasm_line *dl, struct annotation *notes, | |||
2243 | disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset); | 2237 | disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset); |
2244 | } | 2238 | } |
2245 | 2239 | ||
2246 | void annotation_line__write(struct annotation_line *al, struct annotation *notes, | 2240 | static void __annotation_line__write(struct annotation_line *al, struct annotation *notes, |
2247 | bool first_line, bool current_entry, bool change_color, int width, | 2241 | bool first_line, bool current_entry, bool change_color, int width, |
2248 | void *obj, | 2242 | void *obj, |
2249 | int (*obj__set_color)(void *obj, int color), | 2243 | int (*obj__set_color)(void *obj, int color), |
2250 | void (*obj__set_percent_color)(void *obj, double percent, bool current), | 2244 | void (*obj__set_percent_color)(void *obj, double percent, bool current), |
2251 | int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current), | 2245 | int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current), |
2252 | void (*obj__printf)(void *obj, const char *fmt, ...), | 2246 | void (*obj__printf)(void *obj, const char *fmt, ...), |
2253 | void (*obj__write_graph)(void *obj, int graph)) | 2247 | void (*obj__write_graph)(void *obj, int graph)) |
2248 | |||
2254 | { | 2249 | { |
2255 | double percent_max = annotation_line__max_percent(al, notes); | 2250 | double percent_max = annotation_line__max_percent(al, notes); |
2256 | int pcnt_width = annotation__pcnt_width(notes), | 2251 | int pcnt_width = annotation__pcnt_width(notes), |
@@ -2267,9 +2262,6 @@ void annotation_line__write(struct annotation_line *al, struct annotation *notes | |||
2267 | show_title = true; | 2262 | show_title = true; |
2268 | } | 2263 | } |
2269 | 2264 | ||
2270 | if (!obj__set_percent_color) | ||
2271 | obj__set_percent_color = set_percent_color_stub; | ||
2272 | |||
2273 | if (al->offset != -1 && percent_max != 0.0) { | 2265 | if (al->offset != -1 && percent_max != 0.0) { |
2274 | int i; | 2266 | int i; |
2275 | 2267 | ||
@@ -2368,6 +2360,16 @@ void annotation_line__write(struct annotation_line *al, struct annotation *notes | |||
2368 | 2360 | ||
2369 | } | 2361 | } |
2370 | 2362 | ||
2363 | void annotation_line__write(struct annotation_line *al, struct annotation *notes, | ||
2364 | struct annotation_write_ops *ops) | ||
2365 | { | ||
2366 | __annotation_line__write(al, notes, ops->first_line, ops->current_entry, | ||
2367 | ops->change_color, ops->width, ops->obj, | ||
2368 | ops->set_color, ops->set_percent_color, | ||
2369 | ops->set_jumps_percent_color, ops->printf, | ||
2370 | ops->write_graph); | ||
2371 | } | ||
2372 | |||
2371 | int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel, | 2373 | int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel, |
2372 | struct annotation_options *options, struct arch **parch) | 2374 | struct annotation_options *options, struct arch **parch) |
2373 | { | 2375 | { |
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 27fcdacbb497..6fbb34b9bd77 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h | |||
@@ -125,15 +125,20 @@ void disasm_line__free(struct disasm_line *dl); | |||
125 | struct annotation_line * | 125 | 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 | struct annotation_write_ops { | ||
129 | bool first_line, current_entry, change_color; | ||
130 | int width; | ||
131 | void *obj; | ||
132 | int (*set_color)(void *obj, int color); | ||
133 | void (*set_percent_color)(void *obj, double percent, bool current); | ||
134 | int (*set_jumps_percent_color)(void *obj, int nr, bool current); | ||
135 | void (*printf)(void *obj, const char *fmt, ...); | ||
136 | void (*write_graph)(void *obj, int graph); | ||
137 | }; | ||
138 | |||
128 | double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes); | 139 | double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes); |
129 | void annotation_line__write(struct annotation_line *al, struct annotation *notes, | 140 | void annotation_line__write(struct annotation_line *al, struct annotation *notes, |
130 | bool first_line, bool current_entry, bool change_color, int width, | 141 | struct annotation_write_ops *ops); |
131 | void *obj, | ||
132 | int (*obj__set_color)(void *obj, int color), | ||
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)); | ||
137 | 142 | ||
138 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); | 143 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); |
139 | size_t disasm__fprintf(struct list_head *head, FILE *fp); | 144 | size_t disasm__fprintf(struct list_head *head, FILE *fp); |