Skip to content

Commit

Permalink
perf annotate browser: Do raw printing in 'o'ffset in a single place
Browse files Browse the repository at this point in the history
Instead of doing the same in all ins scnprintf methods.

Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed May 7, 2012
1 parent 64aa17c commit 5417072
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
6 changes: 1 addition & 5 deletions tools/perf/ui/browsers/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,16 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
} else {
slsmg_write_nstring(" ", 2);
}

dl->ins->ops->scnprintf(dl->ins, bf, sizeof(bf), &dl->ops,
!ab->use_offset);
} else {
if (strcmp(dl->name, "retq")) {
slsmg_write_nstring(" ", 2);
} else {
ui_browser__write_graph(self, SLSMG_LARROW_CHAR);
SLsmg_write_char(' ');
}

scnprintf(bf, sizeof(bf), "%-6.6s %s", dl->name, dl->ops.raw);
}

disasm_line__scnprintf(dl, bf, sizeof(bf), !ab->use_offset);
slsmg_write_nstring(bf, width - 10 - printed);
}

Expand Down
33 changes: 25 additions & 8 deletions tools/perf/util/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@

const char *disassembler_style;

static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops)
{
return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->raw);
}

int ins__scnprintf(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops)
{
if (ins->ops->scnprintf)
return ins->ops->scnprintf(ins, bf, size, ops);

return ins__raw_scnprintf(ins, bf, size, ops);
}

static int call__parse(struct ins_operands *ops)
{
char *endptr, *tok, *name;
Expand Down Expand Up @@ -50,11 +65,8 @@ static int call__parse(struct ins_operands *ops)
}

static int call__scnprintf(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops, bool addrs)
struct ins_operands *ops)
{
if (addrs)
return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->raw);

if (ops->target.name)
return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->target.name);

Expand Down Expand Up @@ -86,11 +98,8 @@ static int jump__parse(struct ins_operands *ops)
}

static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops, bool addrs)
struct ins_operands *ops)
{
if (addrs)
return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->raw);

return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, ops->target.offset);
}

Expand Down Expand Up @@ -296,6 +305,14 @@ void disasm_line__free(struct disasm_line *dl)
free(dl);
}

int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw)
{
if (raw || !dl->ins)
return scnprintf(bf, size, "%-6.6s %s", dl->name, dl->ops.raw);

return ins__scnprintf(dl->ins, bf, size, &dl->ops);
}

static void disasm__add(struct list_head *head, struct disasm_line *line)
{
list_add_tail(&line->node, head);
Expand Down
4 changes: 3 additions & 1 deletion tools/perf/util/annotate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct ins_operands {
struct ins_ops {
int (*parse)(struct ins_operands *ops);
int (*scnprintf)(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops, bool addrs);
struct ins_operands *ops);
};

struct ins {
Expand All @@ -32,6 +32,7 @@ struct ins {

bool ins__is_jump(const struct ins *ins);
bool ins__is_call(const struct ins *ins);
int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops);

struct disasm_line {
struct list_head node;
Expand All @@ -49,6 +50,7 @@ static inline bool disasm_line__has_offset(const struct disasm_line *dl)

void disasm_line__free(struct disasm_line *dl);
struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
size_t disasm__fprintf(struct list_head *head, FILE *fp);

struct sym_hist {
Expand Down

0 comments on commit 5417072

Please sign in to comment.