aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2018-03-15 16:54:36 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-03-20 12:19:30 -0400
commit2ba5eca10486eeb37030f8bce27cecda3763502f (patch)
tree9716939204c684cbf04f53d6984b6cd691cb4a84
parentc52202434de2bd3e0c447c6dce992266fd7fc589 (diff)
perf annotate: Introduce annotation_line__print_start() out of TUI code
For the --tui and --stdio2 cases using callbacks for print() and set_percent_color() end up being the easiest path, real GUI remains as an exercise. 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-1o7az1ng55g2g6ppr2jpeuct@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/ui/browsers/annotate.c82
-rw-r--r--tools/perf/util/annotate.c75
-rw-r--r--tools/perf/util/annotate.h5
3 files changed, 101 insertions, 61 deletions
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 05f79f36e906..9b77a016e299 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -105,6 +105,20 @@ static void disasm_line__write(struct disasm_line *dl, struct ui_browser *browse
105 disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset); 105 disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset);
106} 106}
107 107
108static void annotate_browser__set_percent_color(void *browser, double percent, bool current)
109{
110 ui_browser__set_percent_color(browser, percent, current);
111}
112
113static void annotate_browser__printf(void *browser, const char *fmt, ...)
114{
115 va_list args;
116
117 va_start(args, fmt);
118 ui_browser__vprintf(browser, fmt, args);
119 va_end(args);
120}
121
108static void annotate_browser__write(struct ui_browser *browser, void *entry, int row) 122static void annotate_browser__write(struct ui_browser *browser, void *entry, int row)
109{ 123{
110 struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); 124 struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
@@ -115,65 +129,13 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
115 (!current_entry || (browser->use_navkeypressed && 129 (!current_entry || (browser->use_navkeypressed &&
116 !browser->navkeypressed))); 130 !browser->navkeypressed)));
117 int width = browser->width, printed; 131 int width = browser->width, printed;
118 int i, pcnt_width = annotation__pcnt_width(notes), 132 int pcnt_width = annotation__pcnt_width(notes),
119 cycles_width = annotation__cycles_width(notes); 133 cycles_width = annotation__cycles_width(notes);
120 double percent_max = annotation_line__max_percent(al, notes);
121 char bf[256]; 134 char bf[256];
122 bool show_title = false;
123
124 if ((row == 0) && (al->offset == -1 || percent_max == 0.0)) {
125 if (notes->have_cycles) {
126 if (al->ipc == 0.0 && al->cycles == 0)
127 show_title = true;
128 } else
129 show_title = true;
130 }
131
132 if (al->offset != -1 && percent_max != 0.0) {
133 for (i = 0; i < notes->nr_events; i++) {
134 ui_browser__set_percent_color(browser,
135 al->samples[i].percent,
136 current_entry);
137 if (notes->options->show_total_period) {
138 ui_browser__printf(browser, "%11" PRIu64 " ",
139 al->samples[i].he.period);
140 } else if (notes->options->show_nr_samples) {
141 ui_browser__printf(browser, "%6" PRIu64 " ",
142 al->samples[i].he.nr_samples);
143 } else {
144 ui_browser__printf(browser, "%6.2f ",
145 al->samples[i].percent);
146 }
147 }
148 } else {
149 ui_browser__set_percent_color(browser, 0, current_entry);
150
151 if (!show_title)
152 ui_browser__write_nstring(browser, " ", pcnt_width);
153 else {
154 ui_browser__printf(browser, "%*s", pcnt_width,
155 notes->options->show_total_period ? "Period" :
156 notes->options->show_nr_samples ? "Samples" : "Percent");
157 }
158 }
159 if (notes->have_cycles) {
160 if (al->ipc)
161 ui_browser__printf(browser, "%*.2f ", ANNOTATION__IPC_WIDTH - 1, al->ipc);
162 else if (!show_title)
163 ui_browser__write_nstring(browser, " ", ANNOTATION__IPC_WIDTH);
164 else
165 ui_browser__printf(browser, "%*s ", ANNOTATION__IPC_WIDTH - 1, "IPC");
166
167 if (al->cycles)
168 ui_browser__printf(browser, "%*" PRIu64 " ",
169 ANNOTATION__CYCLES_WIDTH - 1, al->cycles);
170 else if (!show_title)
171 ui_browser__write_nstring(browser, " ", ANNOTATION__CYCLES_WIDTH);
172 else
173 ui_browser__printf(browser, "%*s ", ANNOTATION__CYCLES_WIDTH - 1, "Cycle");
174 }
175 135
176 SLsmg_write_char(' '); 136 annotation_line__print_start(al, notes, row == 0, current_entry, browser,
137 annotate_browser__set_percent_color,
138 annotate_browser__printf);
177 139
178 /* The scroll bar isn't being used */ 140 /* The scroll bar isn't being used */
179 if (!browser->navkeypressed) 141 if (!browser->navkeypressed)
@@ -183,11 +145,9 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
183 ui_browser__write_nstring(browser, " ", width - pcnt_width - cycles_width); 145 ui_browser__write_nstring(browser, " ", width - pcnt_width - cycles_width);
184 else if (al->offset == -1) { 146 else if (al->offset == -1) {
185 if (al->line_nr && notes->options->show_linenr) 147 if (al->line_nr && notes->options->show_linenr)
186 printed = scnprintf(bf, sizeof(bf), "%-*d ", 148 printed = scnprintf(bf, sizeof(bf), "%-*d ", notes->widths.addr + 1, al->line_nr);
187 notes->widths.addr + 1, al->line_nr);
188 else 149 else
189 printed = scnprintf(bf, sizeof(bf), "%*s ", 150 printed = scnprintf(bf, sizeof(bf), "%*s ", notes->widths.addr, " ");
190 notes->widths.addr, " ");
191 ui_browser__write_nstring(browser, bf, printed); 151 ui_browser__write_nstring(browser, bf, printed);
192 ui_browser__write_nstring(browser, al->line, width - printed - pcnt_width - cycles_width + 1); 152 ui_browser__write_nstring(browser, al->line, width - printed - pcnt_width - cycles_width + 1);
193 } else { 153 } else {
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 3bd6f9b0147f..046feda11052 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2198,6 +2198,81 @@ double annotation_line__max_percent(struct annotation_line *al, struct annotatio
2198 return percent_max; 2198 return percent_max;
2199} 2199}
2200 2200
2201static void set_percent_color_stub(void *obj __maybe_unused,
2202 double percent __maybe_unused,
2203 bool current __maybe_unused)
2204{
2205}
2206
2207void annotation_line__print_start(struct annotation_line *al, struct annotation *notes,
2208 bool first_line, bool current_entry,
2209 void *obj,
2210 void (*obj__set_percent_color)(void *obj, double percent, bool current),
2211 void (*obj__printf)(void *obj, const char *fmt, ...))
2212{
2213 double percent_max = annotation_line__max_percent(al, notes);
2214 bool show_title = false;
2215
2216 if (first_line && (al->offset == -1 || percent_max == 0.0)) {
2217 if (notes->have_cycles) {
2218 if (al->ipc == 0.0 && al->cycles == 0)
2219 show_title = true;
2220 } else
2221 show_title = true;
2222 }
2223
2224 if (!obj__set_percent_color)
2225 obj__set_percent_color = set_percent_color_stub;
2226
2227 if (al->offset != -1 && percent_max != 0.0) {
2228 int i;
2229
2230 for (i = 0; i < notes->nr_events; i++) {
2231 obj__set_percent_color(obj, al->samples[i].percent, current_entry);
2232 if (notes->options->show_total_period) {
2233 obj__printf(obj, "%11" PRIu64 " ", al->samples[i].he.period);
2234 } else if (notes->options->show_nr_samples) {
2235 obj__printf(obj, "%6" PRIu64 " ",
2236 al->samples[i].he.nr_samples);
2237 } else {
2238 obj__printf(obj, "%6.2f ",
2239 al->samples[i].percent);
2240 }
2241 }
2242 } else {
2243 int pcnt_width = annotation__pcnt_width(notes);
2244
2245 obj__set_percent_color(obj, 0, current_entry);
2246
2247 if (!show_title)
2248 obj__printf(obj, "%*s", pcnt_width, " ");
2249 else {
2250 obj__printf(obj, "%*s", pcnt_width,
2251 notes->options->show_total_period ? "Period" :
2252 notes->options->show_nr_samples ? "Samples" : "Percent");
2253 }
2254 }
2255
2256 if (notes->have_cycles) {
2257 if (al->ipc)
2258 obj__printf(obj, "%*.2f ", ANNOTATION__IPC_WIDTH - 1, al->ipc);
2259 else if (!show_title)
2260 obj__printf(obj, "%*s", ANNOTATION__IPC_WIDTH, " ");
2261 else
2262 obj__printf(obj, "%*s ", ANNOTATION__IPC_WIDTH - 1, "IPC");
2263
2264 if (al->cycles)
2265 obj__printf(obj, "%*" PRIu64 " ",
2266 ANNOTATION__CYCLES_WIDTH - 1, al->cycles);
2267 else if (!show_title)
2268 obj__printf(obj, "%*s", ANNOTATION__CYCLES_WIDTH, " ");
2269 else
2270 obj__printf(obj, "%*s ", ANNOTATION__CYCLES_WIDTH - 1, "Cycle");
2271 }
2272
2273 obj__printf(obj, " ");
2274}
2275
2201int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel, 2276int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel,
2202 struct annotation_options *options, struct arch **parch) 2277 struct annotation_options *options, struct arch **parch)
2203{ 2278{
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 83484e236f33..84c99774bfed 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -126,6 +126,11 @@ struct annotation_line *
126annotation_line__next(struct annotation_line *pos, struct list_head *head); 126annotation_line__next(struct annotation_line *pos, struct list_head *head);
127 127
128double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes); 128double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes);
129void annotation_line__print_start(struct annotation_line *al, struct annotation *notes,
130 bool first_line, bool current_entry,
131 void *obj,
132 void (*obj__set_percent_color)(void *obj, double percent, bool current),
133 void (*obj__printf)(void *obj, const char *fmt, ...));
129 134
130int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); 135int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
131size_t disasm__fprintf(struct list_head *head, FILE *fp); 136size_t disasm__fprintf(struct list_head *head, FILE *fp);