aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-04-20 13:38:46 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-04-20 13:38:46 -0400
commitc7e6ead7347813b5833efb9b32908c08ff131259 (patch)
tree4cd53ffe880c0cf15ee9539682623f5aed8f4378
parent3f862fd076275c442dfe295eddb5650a6e0aecd4 (diff)
perf annotate: Group operands members
So that the ins_ops can handle them in a single place, instead of adding more and more functions or ins_ops parameters. 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-pk4dqaum6ftiz104dvimwgtb@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/ui/browsers/annotate.c17
-rw-r--r--tools/perf/util/annotate.c56
-rw-r--r--tools/perf/util/annotate.h22
3 files changed, 49 insertions, 46 deletions
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index e760326efca0..9c7b6d87822e 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -113,13 +113,12 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
113 if (change_color) 113 if (change_color)
114 ui_browser__set_color(self, color); 114 ui_browser__set_color(self, color);
115 if (dl->ins && dl->ins->ops->scnprintf) { 115 if (dl->ins && dl->ins->ops->scnprintf) {
116 dl->ins->ops->scnprintf(dl->ins, bf, sizeof(bf), 116 dl->ins->ops->scnprintf(dl->ins, bf, sizeof(bf), &dl->ops,
117 !ab->use_offset ? dl->operands : NULL, 117 !ab->use_offset);
118 dl->target);
119 slsmg_write_nstring(" ", 2); 118 slsmg_write_nstring(" ", 2);
120 printed += 2; 119 printed += 2;
121 } else 120 } else
122 scnprintf(bf, sizeof(bf), " %-6.6s %s", dl->name, dl->operands); 121 scnprintf(bf, sizeof(bf), " %-6.6s %s", dl->name, dl->ops.raw);
123 122
124 slsmg_write_nstring(bf, width - 10 - printed); 123 slsmg_write_nstring(bf, width - 10 - printed);
125 } 124 }
@@ -294,7 +293,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
294 if (!ins__is_call(dl->ins)) 293 if (!ins__is_call(dl->ins))
295 return false; 294 return false;
296 295
297 ip = ms->map->map_ip(ms->map, dl->target); 296 ip = ms->map->map_ip(ms->map, dl->ops.target);
298 target = map__find_symbol(ms->map, ip, NULL); 297 target = map__find_symbol(ms->map, ip, NULL);
299 if (target == NULL) { 298 if (target == NULL) {
300 ui_helpline__puts("The called function was not found."); 299 ui_helpline__puts("The called function was not found.");
@@ -345,7 +344,7 @@ static bool annotate_browser__jump(struct annotate_browser *browser)
345 if (!ins__is_jump(dl->ins)) 344 if (!ins__is_jump(dl->ins))
346 return false; 345 return false;
347 346
348 dl = annotate_browser__find_offset(browser, dl->target, &idx); 347 dl = annotate_browser__find_offset(browser, dl->ops.target, &idx);
349 if (dl == NULL) { 348 if (dl == NULL) {
350 ui_helpline__puts("Invallid jump offset"); 349 ui_helpline__puts("Invallid jump offset");
351 return true; 350 return true;
@@ -621,14 +620,14 @@ static void annotate_browser__mark_jump_targets(struct annotate_browser *browser
621 if (!dl || !dl->ins || !ins__is_jump(dl->ins)) 620 if (!dl || !dl->ins || !ins__is_jump(dl->ins))
622 continue; 621 continue;
623 622
624 if (dl->target >= size) { 623 if (dl->ops.target >= size) {
625 ui__error("jump to after symbol!\n" 624 ui__error("jump to after symbol!\n"
626 "size: %zx, jump target: %" PRIx64, 625 "size: %zx, jump target: %" PRIx64,
627 size, dl->target); 626 size, dl->ops.target);
628 continue; 627 continue;
629 } 628 }
630 629
631 dlt = browser->offsets[dl->target]; 630 dlt = browser->offsets[dl->ops.target];
632 bdlt = disasm_line__browser(dlt); 631 bdlt = disasm_line__browser(dlt);
633 bdlt->jump_target = true; 632 bdlt->jump_target = true;
634 } 633 }
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index e70cbb4f3bed..7f6c14b3fd7f 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -18,14 +18,14 @@
18 18
19const char *disassembler_style; 19const char *disassembler_style;
20 20
21static int call_ops__parse_target(const char *operands, u64 *target) 21static int call__parse(struct ins_operands *ops)
22{ 22{
23 *target = strtoull(operands, NULL, 16); 23 ops->target = strtoull(ops->raw, NULL, 16);
24 return 0; 24 return 0;
25} 25}
26 26
27static struct ins_ops call_ops = { 27static struct ins_ops call_ops = {
28 .parse_target = call_ops__parse_target, 28 .parse = call__parse,
29}; 29};
30 30
31bool ins__is_call(const struct ins *ins) 31bool ins__is_call(const struct ins *ins)
@@ -33,29 +33,29 @@ bool ins__is_call(const struct ins *ins)
33 return ins->ops == &call_ops; 33 return ins->ops == &call_ops;
34} 34}
35 35
36static int jump_ops__parse_target(const char *operands, u64 *target) 36static int jump__parse(struct ins_operands *ops)
37{ 37{
38 const char *s = strchr(operands, '+'); 38 const char *s = strchr(ops->raw, '+');
39 39
40 if (s++ == NULL) 40 if (s++ == NULL)
41 return -1; 41 return -1;
42 42
43 *target = strtoll(s, NULL, 16); 43 ops->target = strtoll(s, NULL, 16);
44 return 0; 44 return 0;
45} 45}
46 46
47static int jump_ops__scnprintf(struct ins *ins, char *bf, size_t size, 47static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
48 const char *operands, u64 target) 48 struct ins_operands *ops, bool addrs)
49{ 49{
50 if (operands) 50 if (addrs)
51 return scnprintf(bf, size, "%-6.6s %s", ins->name, operands); 51 return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->raw);
52 52
53 return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, target); 53 return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, ops->target);
54} 54}
55 55
56static struct ins_ops jump_ops = { 56static struct ins_ops jump_ops = {
57 .parse_target = jump_ops__parse_target, 57 .parse = jump__parse,
58 .scnprintf = jump_ops__scnprintf, 58 .scnprintf = jump__scnprintf,
59}; 59};
60 60
61bool ins__is_jump(const struct ins *ins) 61bool ins__is_jump(const struct ins *ins)
@@ -190,8 +190,8 @@ static void disasm_line__init_ins(struct disasm_line *dl)
190 if (!dl->ins->ops) 190 if (!dl->ins->ops)
191 return; 191 return;
192 192
193 if (dl->ins->ops->parse_target) 193 if (dl->ins->ops->parse)
194 dl->ins->ops->parse_target(dl->operands, &dl->target); 194 dl->ins->ops->parse(&dl->ops);
195} 195}
196 196
197static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privsize) 197static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privsize)
@@ -213,25 +213,25 @@ static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privs
213 if (name[0] == '\0') 213 if (name[0] == '\0')
214 goto out_delete; 214 goto out_delete;
215 215
216 dl->operands = name + 1; 216 dl->ops.raw = name + 1;
217 217
218 while (dl->operands[0] != '\0' && 218 while (dl->ops.raw[0] != '\0' &&
219 !isspace(dl->operands[0])) 219 !isspace(dl->ops.raw[0]))
220 ++dl->operands; 220 ++dl->ops.raw;
221 221
222 tmp = dl->operands[0]; 222 tmp = dl->ops.raw[0];
223 dl->operands[0] = '\0'; 223 dl->ops.raw[0] = '\0';
224 dl->name = strdup(name); 224 dl->name = strdup(name);
225 225
226 if (dl->name == NULL) 226 if (dl->name == NULL)
227 goto out_free_line; 227 goto out_free_line;
228 228
229 dl->operands[0] = tmp; 229 dl->ops.raw[0] = tmp;
230 230
231 if (dl->operands[0] != '\0') { 231 if (dl->ops.raw[0] != '\0') {
232 dl->operands++; 232 dl->ops.raw++;
233 while (isspace(dl->operands[0])) 233 while (isspace(dl->ops.raw[0]))
234 ++dl->operands; 234 ++dl->ops.raw;
235 } 235 }
236 236
237 disasm_line__init_ins(dl); 237 disasm_line__init_ins(dl);
@@ -753,9 +753,9 @@ static size_t disasm_line__fprintf(struct disasm_line *dl, FILE *fp)
753 753
754 printed = fprintf(fp, "%#" PRIx64 " %s", dl->offset, dl->name); 754 printed = fprintf(fp, "%#" PRIx64 " %s", dl->offset, dl->name);
755 755
756 if (dl->operands[0] != '\0') { 756 if (dl->ops.raw[0] != '\0') {
757 printed += fprintf(fp, "%.*s %s\n", 6 - (int)printed, " ", 757 printed += fprintf(fp, "%.*s %s\n", 6 - (int)printed, " ",
758 dl->operands); 758 dl->ops.raw);
759 } 759 }
760 760
761 return printed + fprintf(fp, "\n"); 761 return printed + fprintf(fp, "\n");
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 6314335007f0..a6f60d5c5138 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -9,10 +9,15 @@
9 9
10struct ins; 10struct ins;
11 11
12struct ins_operands {
13 char *raw;
14 u64 target;
15};
16
12struct ins_ops { 17struct ins_ops {
13 int (*parse_target)(const char *operands, u64 *target); 18 int (*parse)(struct ins_operands *ops);
14 int (*scnprintf)(struct ins *ins, char *bf, size_t size, 19 int (*scnprintf)(struct ins *ins, char *bf, size_t size,
15 const char *operands, u64 target); 20 struct ins_operands *ops, bool addrs);
16}; 21};
17 22
18struct ins { 23struct ins {
@@ -24,13 +29,12 @@ bool ins__is_jump(const struct ins *ins);
24bool ins__is_call(const struct ins *ins); 29bool ins__is_call(const struct ins *ins);
25 30
26struct disasm_line { 31struct disasm_line {
27 struct list_head node; 32 struct list_head node;
28 s64 offset; 33 s64 offset;
29 u64 target; 34 char *line;
30 char *line; 35 char *name;
31 char *name; 36 struct ins *ins;
32 struct ins *ins; 37 struct ins_operands ops;
33 char *operands;
34}; 38};
35 39
36void disasm_line__free(struct disasm_line *dl); 40void disasm_line__free(struct disasm_line *dl);