aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui/browsers/annotate.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2017-10-11 11:01:57 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-11-16 12:49:49 -0500
commita5433b3ec937765a1d7521bc6bb87f6e76497640 (patch)
tree77353a8fca5dec7a1049dc329a44010dfff853a6 /tools/perf/ui/browsers/annotate.c
parentec03a77d7d28a2c2de246f67322c5d916852dd9d (diff)
perf annotate browser: Add disasm_line__write function
Factor disasm_line__write function from annotate_browser__write, which now keeps only generic display code. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Andi Kleen <andi@firstfloor.org> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20171011150158.11895-35-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui/browsers/annotate.c')
-rw-r--r--tools/perf/ui/browsers/annotate.c98
1 files changed, 53 insertions, 45 deletions
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index f0f27cf9db85..5a2f37a91feb 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -118,11 +118,37 @@ static int annotate_browser__cycles_width(struct annotate_browser *ab)
118 return ab->have_cycles ? IPC_WIDTH + CYCLES_WIDTH : 0; 118 return ab->have_cycles ? IPC_WIDTH + CYCLES_WIDTH : 0;
119} 119}
120 120
121static void disasm_line__write(struct disasm_line *dl, struct ui_browser *browser,
122 char *bf, size_t size)
123{
124 if (dl->ins.ops && dl->ins.ops->scnprintf) {
125 if (ins__is_jump(&dl->ins)) {
126 bool fwd = dl->ops.target.offset > dl->al.offset;
127
128 ui_browser__write_graph(browser, fwd ? SLSMG_DARROW_CHAR :
129 SLSMG_UARROW_CHAR);
130 SLsmg_write_char(' ');
131 } else if (ins__is_call(&dl->ins)) {
132 ui_browser__write_graph(browser, SLSMG_RARROW_CHAR);
133 SLsmg_write_char(' ');
134 } else if (ins__is_ret(&dl->ins)) {
135 ui_browser__write_graph(browser, SLSMG_LARROW_CHAR);
136 SLsmg_write_char(' ');
137 } else {
138 ui_browser__write_nstring(browser, " ", 2);
139 }
140 } else {
141 ui_browser__write_nstring(browser, " ", 2);
142 }
143
144 disasm_line__scnprintf(dl, bf, size, !annotate_browser__opts.use_offset);
145}
146
121static void annotate_browser__write(struct ui_browser *browser, void *entry, int row) 147static void annotate_browser__write(struct ui_browser *browser, void *entry, int row)
122{ 148{
123 struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); 149 struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
124 struct disasm_line *dl = list_entry(entry, struct disasm_line, al.node); 150 struct annotation_line *al = list_entry(entry, struct annotation_line, node);
125 struct browser_line *bdl = browser_line(&dl->al); 151 struct browser_line *bl = browser_line(al);
126 bool current_entry = ui_browser__is_current_entry(browser, row); 152 bool current_entry = ui_browser__is_current_entry(browser, row);
127 bool change_color = (!annotate_browser__opts.hide_src_code && 153 bool change_color = (!annotate_browser__opts.hide_src_code &&
128 (!current_entry || (browser->use_navkeypressed && 154 (!current_entry || (browser->use_navkeypressed &&
@@ -135,32 +161,32 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
135 bool show_title = false; 161 bool show_title = false;
136 162
137 for (i = 0; i < ab->nr_events; i++) { 163 for (i = 0; i < ab->nr_events; i++) {
138 if (dl->al.samples[i].percent > percent_max) 164 if (al->samples[i].percent > percent_max)
139 percent_max = dl->al.samples[i].percent; 165 percent_max = al->samples[i].percent;
140 } 166 }
141 167
142 if ((row == 0) && (dl->al.offset == -1 || percent_max == 0.0)) { 168 if ((row == 0) && (al->offset == -1 || percent_max == 0.0)) {
143 if (ab->have_cycles) { 169 if (ab->have_cycles) {
144 if (dl->al.ipc == 0.0 && dl->al.cycles == 0) 170 if (al->ipc == 0.0 && al->cycles == 0)
145 show_title = true; 171 show_title = true;
146 } else 172 } else
147 show_title = true; 173 show_title = true;
148 } 174 }
149 175
150 if (dl->al.offset != -1 && percent_max != 0.0) { 176 if (al->offset != -1 && percent_max != 0.0) {
151 for (i = 0; i < ab->nr_events; i++) { 177 for (i = 0; i < ab->nr_events; i++) {
152 ui_browser__set_percent_color(browser, 178 ui_browser__set_percent_color(browser,
153 dl->al.samples[i].percent, 179 al->samples[i].percent,
154 current_entry); 180 current_entry);
155 if (annotate_browser__opts.show_total_period) { 181 if (annotate_browser__opts.show_total_period) {
156 ui_browser__printf(browser, "%11" PRIu64 " ", 182 ui_browser__printf(browser, "%11" PRIu64 " ",
157 dl->al.samples[i].he.period); 183 al->samples[i].he.period);
158 } else if (annotate_browser__opts.show_nr_samples) { 184 } else if (annotate_browser__opts.show_nr_samples) {
159 ui_browser__printf(browser, "%6" PRIu64 " ", 185 ui_browser__printf(browser, "%6" PRIu64 " ",
160 dl->al.samples[i].he.nr_samples); 186 al->samples[i].he.nr_samples);
161 } else { 187 } else {
162 ui_browser__printf(browser, "%6.2f ", 188 ui_browser__printf(browser, "%6.2f ",
163 dl->al.samples[i].percent); 189 al->samples[i].percent);
164 } 190 }
165 } 191 }
166 } else { 192 } else {
@@ -175,16 +201,16 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
175 } 201 }
176 } 202 }
177 if (ab->have_cycles) { 203 if (ab->have_cycles) {
178 if (dl->al.ipc) 204 if (al->ipc)
179 ui_browser__printf(browser, "%*.2f ", IPC_WIDTH - 1, dl->al.ipc); 205 ui_browser__printf(browser, "%*.2f ", IPC_WIDTH - 1, al->ipc);
180 else if (!show_title) 206 else if (!show_title)
181 ui_browser__write_nstring(browser, " ", IPC_WIDTH); 207 ui_browser__write_nstring(browser, " ", IPC_WIDTH);
182 else 208 else
183 ui_browser__printf(browser, "%*s ", IPC_WIDTH - 1, "IPC"); 209 ui_browser__printf(browser, "%*s ", IPC_WIDTH - 1, "IPC");
184 210
185 if (dl->al.cycles) 211 if (al->cycles)
186 ui_browser__printf(browser, "%*" PRIu64 " ", 212 ui_browser__printf(browser, "%*" PRIu64 " ",
187 CYCLES_WIDTH - 1, dl->al.cycles); 213 CYCLES_WIDTH - 1, al->cycles);
188 else if (!show_title) 214 else if (!show_title)
189 ui_browser__write_nstring(browser, " ", CYCLES_WIDTH); 215 ui_browser__write_nstring(browser, " ", CYCLES_WIDTH);
190 else 216 else
@@ -197,19 +223,19 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
197 if (!browser->navkeypressed) 223 if (!browser->navkeypressed)
198 width += 1; 224 width += 1;
199 225
200 if (!*dl->al.line) 226 if (!*al->line)
201 ui_browser__write_nstring(browser, " ", width - pcnt_width - cycles_width); 227 ui_browser__write_nstring(browser, " ", width - pcnt_width - cycles_width);
202 else if (dl->al.offset == -1) { 228 else if (al->offset == -1) {
203 if (dl->al.line_nr && annotate_browser__opts.show_linenr) 229 if (al->line_nr && annotate_browser__opts.show_linenr)
204 printed = scnprintf(bf, sizeof(bf), "%-*d ", 230 printed = scnprintf(bf, sizeof(bf), "%-*d ",
205 ab->addr_width + 1, dl->al.line_nr); 231 ab->addr_width + 1, al->line_nr);
206 else 232 else
207 printed = scnprintf(bf, sizeof(bf), "%*s ", 233 printed = scnprintf(bf, sizeof(bf), "%*s ",
208 ab->addr_width, " "); 234 ab->addr_width, " ");
209 ui_browser__write_nstring(browser, bf, printed); 235 ui_browser__write_nstring(browser, bf, printed);
210 ui_browser__write_nstring(browser, dl->al.line, width - printed - pcnt_width - cycles_width + 1); 236 ui_browser__write_nstring(browser, al->line, width - printed - pcnt_width - cycles_width + 1);
211 } else { 237 } else {
212 u64 addr = dl->al.offset; 238 u64 addr = al->offset;
213 int color = -1; 239 int color = -1;
214 240
215 if (!annotate_browser__opts.use_offset) 241 if (!annotate_browser__opts.use_offset)
@@ -218,13 +244,13 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
218 if (!annotate_browser__opts.use_offset) { 244 if (!annotate_browser__opts.use_offset) {
219 printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr); 245 printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", addr);
220 } else { 246 } else {
221 if (bdl->jump_sources) { 247 if (bl->jump_sources) {
222 if (annotate_browser__opts.show_nr_jumps) { 248 if (annotate_browser__opts.show_nr_jumps) {
223 int prev; 249 int prev;
224 printed = scnprintf(bf, sizeof(bf), "%*d ", 250 printed = scnprintf(bf, sizeof(bf), "%*d ",
225 ab->jumps_width, 251 ab->jumps_width,
226 bdl->jump_sources); 252 bl->jump_sources);
227 prev = annotate_browser__set_jumps_percent_color(ab, bdl->jump_sources, 253 prev = annotate_browser__set_jumps_percent_color(ab, bl->jump_sources,
228 current_entry); 254 current_entry);
229 ui_browser__write_nstring(browser, bf, printed); 255 ui_browser__write_nstring(browser, bf, printed);
230 ui_browser__set_color(browser, prev); 256 ui_browser__set_color(browser, prev);
@@ -243,32 +269,14 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
243 ui_browser__write_nstring(browser, bf, printed); 269 ui_browser__write_nstring(browser, bf, printed);
244 if (change_color) 270 if (change_color)
245 ui_browser__set_color(browser, color); 271 ui_browser__set_color(browser, color);
246 if (dl->ins.ops && dl->ins.ops->scnprintf) {
247 if (ins__is_jump(&dl->ins)) {
248 bool fwd = dl->ops.target.offset > dl->al.offset;
249
250 ui_browser__write_graph(browser, fwd ? SLSMG_DARROW_CHAR :
251 SLSMG_UARROW_CHAR);
252 SLsmg_write_char(' ');
253 } else if (ins__is_call(&dl->ins)) {
254 ui_browser__write_graph(browser, SLSMG_RARROW_CHAR);
255 SLsmg_write_char(' ');
256 } else if (ins__is_ret(&dl->ins)) {
257 ui_browser__write_graph(browser, SLSMG_LARROW_CHAR);
258 SLsmg_write_char(' ');
259 } else {
260 ui_browser__write_nstring(browser, " ", 2);
261 }
262 } else {
263 ui_browser__write_nstring(browser, " ", 2);
264 }
265 272
266 disasm_line__scnprintf(dl, bf, sizeof(bf), !annotate_browser__opts.use_offset); 273 disasm_line__write(disasm_line(al), browser, bf, sizeof(bf));
274
267 ui_browser__write_nstring(browser, bf, width - pcnt_width - cycles_width - 3 - printed); 275 ui_browser__write_nstring(browser, bf, width - pcnt_width - cycles_width - 3 - printed);
268 } 276 }
269 277
270 if (current_entry) 278 if (current_entry)
271 ab->selection = &dl->al; 279 ab->selection = al;
272} 280}
273 281
274static bool disasm_line__is_valid_jump(struct disasm_line *dl, struct symbol *sym) 282static bool disasm_line__is_valid_jump(struct disasm_line *dl, struct symbol *sym)