Skip to content

Commit bc3bb79

Browse files
committed
perf annotate: Calculate the max instruction name, align column to that
We were hardcoding '6' as the max instruction name, and we have lots that are longer than that, see the diff from two 'P' printed TUI annotations for a libc function that uses instructions with long names, such as 'vpmovmskb' with its 9 chars: --- __strcmp_avx2.annotation.before 2019-03-06 16:31:39.368020425 -0300 +++ __strcmp_avx2.annotation 2019-03-06 16:32:12.079450508 -0300 @@ -2,284 +2,284 @@ Event: cycles:ppp Percent endbr64 - 0.10 mov %edi,%eax + 0.10 mov %edi,%eax - xor %edx,%edx + xor %edx,%edx - 3.54 vpxor %ymm7,%ymm7,%ymm7 + 3.54 vpxor %ymm7,%ymm7,%ymm7 - or %esi,%eax + or %esi,%eax - and $0xfff,%eax + and $0xfff,%eax - cmp $0xf80,%eax + cmp $0xf80,%eax - ↓ jg 370 + ↓ jg 370 - 27.07 vmovdqu (%rdi),%ymm1 + 27.07 vmovdqu (%rdi),%ymm1 - 7.97 vpcmpeqb (%rsi),%ymm1,%ymm0 + 7.97 vpcmpeqb (%rsi),%ymm1,%ymm0 - 2.15 vpminub %ymm1,%ymm0,%ymm0 + 2.15 vpminub %ymm1,%ymm0,%ymm0 - 4.09 vpcmpeqb %ymm7,%ymm0,%ymm0 + 4.09 vpcmpeqb %ymm7,%ymm0,%ymm0 - 0.43 vpmovmskb %ymm0,%ecx + 0.43 vpmovmskb %ymm0,%ecx - 1.53 test %ecx,%ecx + 1.53 test %ecx,%ecx - ↓ je b0 + ↓ je b0 - 5.26 tzcnt %ecx,%edx + 5.26 tzcnt %ecx,%edx - 18.40 movzbl (%rdi,%rdx,1),%eax + 18.40 movzbl (%rdi,%rdx,1),%eax - 7.09 movzbl (%rsi,%rdx,1),%edx + 7.09 movzbl (%rsi,%rdx,1),%edx - 3.34 sub %edx,%eax + 3.34 sub %edx,%eax 2.37 vzeroupper ← retq nop - 50: tzcnt %ecx,%edx + 50: tzcnt %ecx,%edx - movzbl 0x20(%rdi,%rdx,1),%eax + movzbl 0x20(%rdi,%rdx,1),%eax - movzbl 0x20(%rsi,%rdx,1),%edx + movzbl 0x20(%rsi,%rdx,1),%edx - sub %edx,%eax + sub %edx,%eax vzeroupper ← retq - data16 nopw %cs:0x0(%rax,%rax,1) + data16 nopw %cs:0x0(%rax,%rax,1) Reported-by: Travis Downs <travis.downs@gmail.com> LPU-Reference: CAOBGo4z1KfmWeOm6Et0cnX5Z6DWsG2PQbAvRn1MhVPJmXHrc5g@mail.gmail.com Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lkml.kernel.org/n/tip-89wsdd9h9g6bvq52sgp6d0u4@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent a53837a commit bc3bb79

4 files changed

Lines changed: 52 additions & 33 deletions

File tree

‎tools/perf/arch/arm64/annotate/instructions.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int arm64_mov__parse(struct arch *arch __maybe_unused,
5858
}
5959

6060
static 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);
6262

6363
static struct ins_ops arm64_mov_ops = {
6464
.parse = arm64_mov__parse,

‎tools/perf/arch/s390/annotate/instructions.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
4646
}
4747

4848
static 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);
5050

5151
static struct ins_ops s390_call_ops = {
5252
.parse = s390_call__parse,

‎tools/perf/util/annotate.c‎

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,18 @@ static void ins__delete(struct ins_operands *ops)
198198
}
199199

200200
static 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)
202202
{
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);
204204
}
205205

206206
int ins__scnprintf(struct ins *ins, char *bf, size_t size,
207-
struct ins_operands *ops)
207+
struct ins_operands *ops, int max_ins_name)
208208
{
209209
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);
211211

212-
return ins__raw_scnprintf(ins, bf, size, ops);
212+
return ins__raw_scnprintf(ins, bf, size, ops, max_ins_name);
213213
}
214214

215215
bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2)
@@ -273,18 +273,18 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map_s
273273
}
274274

275275
static 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)
277277
{
278278
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);
280280

281281
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);
283283

284284
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);
286286

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);
288288
}
289289

290290
static struct ins_ops call_ops = {
@@ -388,15 +388,15 @@ static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_s
388388
}
389389

390390
static 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)
392392
{
393393
const char *c;
394394

395395
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);
397397

398398
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);
400400

401401
c = strchr(ops->raw, ',');
402402
c = validate_comma(c, ops);
@@ -415,7 +415,7 @@ static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
415415
c++;
416416
}
417417

418-
return scnprintf(bf, size, "%-6s %.*s%" PRIx64,
418+
return scnprintf(bf, size, "%-*s %.*s%" PRIx64, max_ins_name,
419419
ins->name, c ? c - ops->raw : 0, ops->raw,
420420
ops->target.offset);
421421
}
@@ -483,16 +483,16 @@ static int lock__parse(struct arch *arch, struct ins_operands *ops, struct map_s
483483
}
484484

485485
static 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)
487487
{
488488
int printed;
489489

490490
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);
492492

493-
printed = scnprintf(bf, size, "%-6s ", ins->name);
493+
printed = scnprintf(bf, size, "%-*s ", max_ins_name, ins->name);
494494
return printed + ins__scnprintf(&ops->locked.ins, bf + printed,
495-
size - printed, ops->locked.ops);
495+
size - printed, ops->locked.ops, max_ins_name);
496496
}
497497

498498
static void lock__delete(struct ins_operands *ops)
@@ -564,9 +564,9 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_sy
564564
}
565565

566566
static 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)
568568
{
569-
return scnprintf(bf, size, "%-6s %s,%s", ins->name,
569+
return scnprintf(bf, size, "%-*s %s,%s", max_ins_name, ins->name,
570570
ops->source.name ?: ops->source.raw,
571571
ops->target.name ?: ops->target.raw);
572572
}
@@ -604,9 +604,9 @@ static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands *ops
604604
}
605605

606606
static 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)
608608
{
609-
return scnprintf(bf, size, "%-6s %s", ins->name,
609+
return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name,
610610
ops->target.name ?: ops->target.raw);
611611
}
612612

@@ -616,9 +616,9 @@ static struct ins_ops dec_ops = {
616616
};
617617

618618
static 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)
620620
{
621-
return scnprintf(bf, size, "%-6s", "nop");
621+
return scnprintf(bf, size, "%-*s", max_ins_name, "nop");
622622
}
623623

624624
static struct ins_ops nop_ops = {
@@ -1232,12 +1232,12 @@ void disasm_line__free(struct disasm_line *dl)
12321232
annotation_line__delete(&dl->al);
12331233
}
12341234

1235-
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw)
1235+
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name)
12361236
{
12371237
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);
12391239

1240-
return ins__scnprintf(&dl->ins, bf, size, &dl->ops);
1240+
return ins__scnprintf(&dl->ins, bf, size, &dl->ops, max_ins_name);
12411241
}
12421242

12431243
static void annotation_line__add(struct annotation_line *al, struct list_head *head)
@@ -2414,12 +2414,30 @@ static inline int width_jumps(int n)
24142414
return 1;
24152415
}
24162416

2417+
static 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+
24172434
void annotation__init_column_widths(struct annotation *notes, struct symbol *sym)
24182435
{
24192436
notes->widths.addr = notes->widths.target =
24202437
notes->widths.min_addr = hex_width(symbol__size(sym));
24212438
notes->widths.max_addr = hex_width(sym->end);
24222439
notes->widths.jumps = width_jumps(notes->max_jump_sources);
2440+
notes->widths.max_ins_name = annotation__max_ins_name(notes);
24232441
}
24242442

24252443
void annotation__update_column_widths(struct annotation *notes)
@@ -2583,7 +2601,7 @@ static void disasm_line__write(struct disasm_line *dl, struct annotation *notes,
25832601
obj__printf(obj, " ");
25842602
}
25852603

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);
25872605
}
25882606

25892607
static void ipc_coverage_string(char *bf, int size, struct annotation *notes)

‎tools/perf/util/annotate.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ struct ins_ops {
5959
void (*free)(struct ins_operands *ops);
6060
int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms);
6161
int (*scnprintf)(struct ins *ins, char *bf, size_t size,
62-
struct ins_operands *ops);
62+
struct ins_operands *ops, int max_ins_name);
6363
};
6464

6565
bool ins__is_jump(const struct ins *ins);
6666
bool ins__is_call(const struct ins *ins);
6767
bool ins__is_ret(const struct ins *ins);
6868
bool ins__is_lock(const struct ins *ins);
69-
int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops);
69+
int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name);
7070
bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
7171

7272
#define ANNOTATION__IPC_WIDTH 6
@@ -219,7 +219,7 @@ int __annotation__scnprintf_samples_period(struct annotation *notes,
219219
struct perf_evsel *evsel,
220220
bool show_freq);
221221

222-
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
222+
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name);
223223
size_t disasm__fprintf(struct list_head *head, FILE *fp);
224224
void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel);
225225

@@ -289,6 +289,7 @@ struct annotation {
289289
u8 target;
290290
u8 min_addr;
291291
u8 max_addr;
292+
u8 max_ins_name;
292293
} widths;
293294
bool have_cycles;
294295
struct annotated_source *src;

0 commit comments

Comments
 (0)