perf annotate: Introduce scnprintf ins_ops method

And implement the jump one, where if the operands string is not passed,
a compact form that uses just the target address is used.

Right now this is toggled via the 'o' option in the annotate browser,
switching from:

    0.00 :         ffffffff811661e8:       je     ffffffff81166204 <mem_cgroup_count_vm_event+0x44>
    0.00 :         ffffffff811661ea:       cmp    $0xb,%esi
    0.00 :         ffffffff811661ed:       je     ffffffff811661f8 <mem_cgroup_count_vm_event+0x38>

To:

    0.00 :         28:       je     44
    0.00 :         2a:       cmp    $0xb,%esi
    0.00 :         2d:       je     38
Suggested-by: NLinus Torvalds <torvalds@linux-foundation.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-o88q46yh4kxgpd1chk5gvjl5@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 d86b0597
...@@ -83,7 +83,7 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro ...@@ -83,7 +83,7 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
else if (dl->offset == -1) else if (dl->offset == -1)
slsmg_write_nstring(dl->line, width - 18); slsmg_write_nstring(dl->line, width - 18);
else { else {
char bf[64]; char bf[256], *line = dl->line;
u64 addr = dl->offset; u64 addr = dl->offset;
int printed, color = -1; int printed, color = -1;
...@@ -96,7 +96,16 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro ...@@ -96,7 +96,16 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
slsmg_write_nstring(bf, printed); slsmg_write_nstring(bf, printed);
if (change_color) if (change_color)
ui_browser__set_color(self, color); ui_browser__set_color(self, color);
slsmg_write_nstring(dl->line, width - 18 - printed); if (dl->ins && dl->ins->ops->scnprintf) {
dl->ins->ops->scnprintf(dl->ins, bf, sizeof(bf),
!ab->use_offset ? dl->operands : NULL,
dl->target);
line = bf;
slsmg_write_nstring(" ", 7);
printed += 7;
}
slsmg_write_nstring(line, width - 18 - printed);
} }
if (current_entry) if (current_entry)
......
...@@ -44,8 +44,18 @@ static int jump_ops__parse_target(const char *operands, u64 *target) ...@@ -44,8 +44,18 @@ static int jump_ops__parse_target(const char *operands, u64 *target)
return 0; return 0;
} }
static int jump_ops__scnprintf(struct ins *ins, char *bf, size_t size,
const char *operands, u64 target)
{
if (operands)
return scnprintf(bf, size, "%-6.6s %s", ins->name, operands);
return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, target);
}
static struct ins_ops jump_ops = { static struct ins_ops jump_ops = {
.parse_target = jump_ops__parse_target, .parse_target = jump_ops__parse_target,
.scnprintf = jump_ops__scnprintf,
}; };
bool ins__is_jump(const struct ins *ins) bool ins__is_jump(const struct ins *ins)
......
...@@ -7,8 +7,12 @@ ...@@ -7,8 +7,12 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/rbtree.h> #include <linux/rbtree.h>
struct ins;
struct ins_ops { struct ins_ops {
int (*parse_target)(const char *operands, u64 *target); int (*parse_target)(const char *operands, u64 *target);
int (*scnprintf)(struct ins *ins, char *bf, size_t size,
const char *operands, u64 target);
}; };
struct ins { struct ins {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册