aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/arch/arm64/annotate/instructions.c2
-rw-r--r--tools/perf/arch/s390/annotate/instructions.c2
-rw-r--r--tools/perf/util/annotate.c74
-rw-r--r--tools/perf/util/annotate.h7
4 files changed, 52 insertions, 33 deletions
diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/arch/arm64/annotate/instructions.c
index 76c6345a57d5..8f70a1b282df 100644
--- a/tools/perf/arch/arm64/annotate/instructions.c
+++ b/tools/perf/arch/arm64/annotate/instructions.c
@@ -58,7 +58,7 @@ out_free_source:
58} 58}
59 59
60static int mov__scnprintf(struct ins *ins, char *bf, size_t size, 60static int mov__scnprintf(struct ins *ins, char *bf, size_t size,
61 struct ins_operands *ops); 61 struct ins_operands *ops, int max_ins_name);
62 62
63static struct ins_ops arm64_mov_ops = { 63static struct ins_ops arm64_mov_ops = {
64 .parse = arm64_mov__parse, 64 .parse = arm64_mov__parse,
diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch/s390/annotate/instructions.c
index de0dd66dbb48..89bb8f2c54ce 100644
--- a/tools/perf/arch/s390/annotate/instructions.c
+++ b/tools/perf/arch/s390/annotate/instructions.c
@@ -46,7 +46,7 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
46} 46}
47 47
48static int call__scnprintf(struct ins *ins, char *bf, size_t size, 48static int call__scnprintf(struct ins *ins, char *bf, size_t size,
49 struct ins_operands *ops); 49 struct ins_operands *ops, int max_ins_name);
50 50
51static struct ins_ops s390_call_ops = { 51static struct ins_ops s390_call_ops = {
52 .parse = s390_call__parse, 52 .parse = s390_call__parse,
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 11a8a447a3af..5f6dbbf5d749 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -198,18 +198,18 @@ static void ins__delete(struct ins_operands *ops)
198} 198}
199 199
200static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size, 200static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size,
201 struct ins_operands *ops) 201 struct ins_operands *ops, int max_ins_name)
202{ 202{
203 return scnprintf(bf, size, "%-6s %s", ins->name, ops->raw); 203 return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->raw);
204} 204}
205 205
206int ins__scnprintf(struct ins *ins, char *bf, size_t size, 206int ins__scnprintf(struct ins *ins, char *bf, size_t size,
207 struct ins_operands *ops) 207 struct ins_operands *ops, int max_ins_name)
208{ 208{
209 if (ins->ops->scnprintf) 209 if (ins->ops->scnprintf)
210 return ins->ops->scnprintf(ins, bf, size, ops); 210 return ins->ops->scnprintf(ins, bf, size, ops, max_ins_name);
211 211
212 return ins__raw_scnprintf(ins, bf, size, ops); 212 return ins__raw_scnprintf(ins, bf, size, ops, max_ins_name);
213} 213}
214 214
215bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2) 215bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2)
@@ -273,18 +273,18 @@ indirect_call:
273} 273}
274 274
275static int call__scnprintf(struct ins *ins, char *bf, size_t size, 275static int call__scnprintf(struct ins *ins, char *bf, size_t size,
276 struct ins_operands *ops) 276 struct ins_operands *ops, int max_ins_name)
277{ 277{
278 if (ops->target.sym) 278 if (ops->target.sym)
279 return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.sym->name); 279 return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->target.sym->name);
280 280
281 if (ops->target.addr == 0) 281 if (ops->target.addr == 0)
282 return ins__raw_scnprintf(ins, bf, size, ops); 282 return ins__raw_scnprintf(ins, bf, size, ops, max_ins_name);
283 283
284 if (ops->target.name) 284 if (ops->target.name)
285 return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.name); 285 return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->target.name);
286 286
287 return scnprintf(bf, size, "%-6s *%" PRIx64, ins->name, ops->target.addr); 287 return scnprintf(bf, size, "%-*s *%" PRIx64, max_ins_name, ins->name, ops->target.addr);
288} 288}
289 289
290static struct ins_ops call_ops = { 290static struct ins_ops call_ops = {
@@ -388,15 +388,15 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
388} 388}
389 389
390static int jump__scnprintf(struct ins *ins, char *bf, size_t size, 390static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
391 struct ins_operands *ops) 391 struct ins_operands *ops, int max_ins_name)
392{ 392{
393 const char *c; 393 const char *c;
394 394
395 if (!ops->target.addr || ops->target.offset < 0) 395 if (!ops->target.addr || ops->target.offset < 0)
396 return ins__raw_scnprintf(ins, bf, size, ops); 396 return ins__raw_scnprintf(ins, bf, size, ops, max_ins_name);
397 397
398 if (ops->target.outside && ops->target.sym != NULL) 398 if (ops->target.outside && ops->target.sym != NULL)
399 return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.sym->name); 399 return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->target.sym->name);
400 400
401 c = strchr(ops->raw, ','); 401 c = strchr(ops->raw, ',');
402 c = validate_comma(c, ops); 402 c = validate_comma(c, ops);
@@ -415,7 +415,7 @@ static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
415 c++; 415 c++;
416 } 416 }
417 417
418 return scnprintf(bf, size, "%-6s %.*s%" PRIx64, 418 return scnprintf(bf, size, "%-*s %.*s%" PRIx64, max_ins_name,
419 ins->name, c ? c - ops->raw : 0, ops->raw, 419 ins->name, c ? c - ops->raw : 0, ops->raw,
420 ops->target.offset); 420 ops->target.offset);
421} 421}
@@ -483,16 +483,16 @@ out_free_ops:
483} 483}
484 484
485static int lock__scnprintf(struct ins *ins, char *bf, size_t size, 485static int lock__scnprintf(struct ins *ins, char *bf, size_t size,
486 struct ins_operands *ops) 486 struct ins_operands *ops, int max_ins_name)
487{ 487{
488 int printed; 488 int printed;
489 489
490 if (ops->locked.ins.ops == NULL) 490 if (ops->locked.ins.ops == NULL)
491 return ins__raw_scnprintf(ins, bf, size, ops); 491 return ins__raw_scnprintf(ins, bf, size, ops, max_ins_name);
492 492
493 printed = scnprintf(bf, size, "%-6s ", ins->name); 493 printed = scnprintf(bf, size, "%-*s ", max_ins_name, ins->name);
494 return printed + ins__scnprintf(&ops->locked.ins, bf + printed, 494 return printed + ins__scnprintf(&ops->locked.ins, bf + printed,
495 size - printed, ops->locked.ops); 495 size - printed, ops->locked.ops, max_ins_name);
496} 496}
497 497
498static void lock__delete(struct ins_operands *ops) 498static void lock__delete(struct ins_operands *ops)
@@ -564,9 +564,9 @@ out_free_source:
564} 564}
565 565
566static int mov__scnprintf(struct ins *ins, char *bf, size_t size, 566static int mov__scnprintf(struct ins *ins, char *bf, size_t size,
567 struct ins_operands *ops) 567 struct ins_operands *ops, int max_ins_name)
568{ 568{
569 return scnprintf(bf, size, "%-6s %s,%s", ins->name, 569 return scnprintf(bf, size, "%-*s %s,%s", max_ins_name, ins->name,
570 ops->source.name ?: ops->source.raw, 570 ops->source.name ?: ops->source.raw,
571 ops->target.name ?: ops->target.raw); 571 ops->target.name ?: ops->target.raw);
572} 572}
@@ -604,9 +604,9 @@ static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands *ops
604} 604}
605 605
606static int dec__scnprintf(struct ins *ins, char *bf, size_t size, 606static int dec__scnprintf(struct ins *ins, char *bf, size_t size,
607 struct ins_operands *ops) 607 struct ins_operands *ops, int max_ins_name)
608{ 608{
609 return scnprintf(bf, size, "%-6s %s", ins->name, 609 return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name,
610 ops->target.name ?: ops->target.raw); 610 ops->target.name ?: ops->target.raw);
611} 611}
612 612
@@ -616,9 +616,9 @@ static struct ins_ops dec_ops = {
616}; 616};
617 617
618static int nop__scnprintf(struct ins *ins __maybe_unused, char *bf, size_t size, 618static int nop__scnprintf(struct ins *ins __maybe_unused, char *bf, size_t size,
619 struct ins_operands *ops __maybe_unused) 619 struct ins_operands *ops __maybe_unused, int max_ins_name)
620{ 620{
621 return scnprintf(bf, size, "%-6s", "nop"); 621 return scnprintf(bf, size, "%-*s", max_ins_name, "nop");
622} 622}
623 623
624static struct ins_ops nop_ops = { 624static struct ins_ops nop_ops = {
@@ -1232,12 +1232,12 @@ void disasm_line__free(struct disasm_line *dl)
1232 annotation_line__delete(&dl->al); 1232 annotation_line__delete(&dl->al);
1233} 1233}
1234 1234
1235int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw) 1235int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name)
1236{ 1236{
1237 if (raw || !dl->ins.ops) 1237 if (raw || !dl->ins.ops)
1238 return scnprintf(bf, size, "%-6s %s", dl->ins.name, dl->ops.raw); 1238 return scnprintf(bf, size, "%-*s %s", max_ins_name, dl->ins.name, dl->ops.raw);
1239 1239
1240 return ins__scnprintf(&dl->ins, bf, size, &dl->ops); 1240 return ins__scnprintf(&dl->ins, bf, size, &dl->ops, max_ins_name);
1241} 1241}
1242 1242
1243static void annotation_line__add(struct annotation_line *al, struct list_head *head) 1243static void annotation_line__add(struct annotation_line *al, struct list_head *head)
@@ -2414,12 +2414,30 @@ static inline int width_jumps(int n)
2414 return 1; 2414 return 1;
2415} 2415}
2416 2416
2417static int annotation__max_ins_name(struct annotation *notes)
2418{
2419 int max_name = 0, len;
2420 struct annotation_line *al;
2421
2422 list_for_each_entry(al, &notes->src->source, node) {
2423 if (al->offset == -1)
2424 continue;
2425
2426 len = strlen(disasm_line(al)->ins.name);
2427 if (max_name < len)
2428 max_name = len;
2429 }
2430
2431 return max_name;
2432}
2433
2417void annotation__init_column_widths(struct annotation *notes, struct symbol *sym) 2434void annotation__init_column_widths(struct annotation *notes, struct symbol *sym)
2418{ 2435{
2419 notes->widths.addr = notes->widths.target = 2436 notes->widths.addr = notes->widths.target =
2420 notes->widths.min_addr = hex_width(symbol__size(sym)); 2437 notes->widths.min_addr = hex_width(symbol__size(sym));
2421 notes->widths.max_addr = hex_width(sym->end); 2438 notes->widths.max_addr = hex_width(sym->end);
2422 notes->widths.jumps = width_jumps(notes->max_jump_sources); 2439 notes->widths.jumps = width_jumps(notes->max_jump_sources);
2440 notes->widths.max_ins_name = annotation__max_ins_name(notes);
2423} 2441}
2424 2442
2425void annotation__update_column_widths(struct annotation *notes) 2443void annotation__update_column_widths(struct annotation *notes)
@@ -2583,7 +2601,7 @@ call_like:
2583 obj__printf(obj, " "); 2601 obj__printf(obj, " ");
2584 } 2602 }
2585 2603
2586 disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset); 2604 disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset, notes->widths.max_ins_name);
2587} 2605}
2588 2606
2589static void ipc_coverage_string(char *bf, int size, struct annotation *notes) 2607static void ipc_coverage_string(char *bf, int size, struct annotation *notes)
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 95053cab41fe..df34fe483164 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -59,14 +59,14 @@ struct ins_ops {
59 void (*free)(struct ins_operands *ops); 59 void (*free)(struct ins_operands *ops);
60 int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms); 60 int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms);
61 int (*scnprintf)(struct ins *ins, char *bf, size_t size, 61 int (*scnprintf)(struct ins *ins, char *bf, size_t size,
62 struct ins_operands *ops); 62 struct ins_operands *ops, int max_ins_name);
63}; 63};
64 64
65bool ins__is_jump(const struct ins *ins); 65bool ins__is_jump(const struct ins *ins);
66bool ins__is_call(const struct ins *ins); 66bool ins__is_call(const struct ins *ins);
67bool ins__is_ret(const struct ins *ins); 67bool ins__is_ret(const struct ins *ins);
68bool ins__is_lock(const struct ins *ins); 68bool ins__is_lock(const struct ins *ins);
69int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops); 69int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name);
70bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2); 70bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
71 71
72#define ANNOTATION__IPC_WIDTH 6 72#define ANNOTATION__IPC_WIDTH 6
@@ -219,7 +219,7 @@ int __annotation__scnprintf_samples_period(struct annotation *notes,
219 struct perf_evsel *evsel, 219 struct perf_evsel *evsel,
220 bool show_freq); 220 bool show_freq);
221 221
222int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); 222int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name);
223size_t disasm__fprintf(struct list_head *head, FILE *fp); 223size_t disasm__fprintf(struct list_head *head, FILE *fp);
224void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel); 224void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel);
225 225
@@ -289,6 +289,7 @@ struct annotation {
289 u8 target; 289 u8 target;
290 u8 min_addr; 290 u8 min_addr;
291 u8 max_addr; 291 u8 max_addr;
292 u8 max_ins_name;
292 } widths; 293 } widths;
293 bool have_cycles; 294 bool have_cycles;
294 struct annotated_source *src; 295 struct annotated_source *src;