diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-05-18 11:19:03 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-05-18 11:19:03 -0400 |
| commit | 4d7b4ac22fbec1a03206c6cde353f2fd6942f828 (patch) | |
| tree | 2d96a9e9c28cf6fa628a278decc00ad55a8b043b /tools/perf/builtin-annotate.c | |
| parent | 3aaf51ace5975050ab43c7d4d7e439e0ae7d13d7 (diff) | |
| parent | 94f3ca95787ada3d64339a4ecb2754236ab563f6 (diff) | |
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (311 commits)
perf tools: Add mode to build without newt support
perf symbols: symbol inconsistency message should be done only at verbose=1
perf tui: Add explicit -lslang option
perf options: Type check all the remaining OPT_ variants
perf options: Type check OPT_BOOLEAN and fix the offenders
perf options: Check v type in OPT_U?INTEGER
perf options: Introduce OPT_UINTEGER
perf tui: Add workaround for slang < 2.1.4
perf record: Fix bug mismatch with -c option definition
perf options: Introduce OPT_U64
perf tui: Add help window to show key associations
perf tui: Make <- exit menus too
perf newt: Add single key shortcuts for zoom into DSO and threads
perf newt: Exit browser unconditionally when CTRL+C, q or Q is pressed
perf newt: Fix the 'A'/'a' shortcut for annotate
perf newt: Make <- exit the ui_browser
x86, perf: P4 PMU - fix counters management logic
perf newt: Make <- zoom out filters
perf report: Report number of events, not samples
perf hist: Clarify events_stats fields usage
...
Fix up trivial conflicts in kernel/fork.c and tools/perf/builtin-record.c
Diffstat (limited to 'tools/perf/builtin-annotate.c')
| -rw-r--r-- | tools/perf/builtin-annotate.c | 245 |
1 files changed, 29 insertions, 216 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 6ad7148451c5..77bcc9b130f5 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
| @@ -14,7 +14,6 @@ | |||
| 14 | #include "util/cache.h" | 14 | #include "util/cache.h" |
| 15 | #include <linux/rbtree.h> | 15 | #include <linux/rbtree.h> |
| 16 | #include "util/symbol.h" | 16 | #include "util/symbol.h" |
| 17 | #include "util/string.h" | ||
| 18 | 17 | ||
| 19 | #include "perf.h" | 18 | #include "perf.h" |
| 20 | #include "util/debug.h" | 19 | #include "util/debug.h" |
| @@ -29,80 +28,16 @@ | |||
| 29 | 28 | ||
| 30 | static char const *input_name = "perf.data"; | 29 | static char const *input_name = "perf.data"; |
| 31 | 30 | ||
| 32 | static int force; | 31 | static bool force; |
| 33 | 32 | ||
| 34 | static int full_paths; | 33 | static bool full_paths; |
| 35 | 34 | ||
| 36 | static int print_line; | 35 | static bool print_line; |
| 37 | |||
| 38 | struct sym_hist { | ||
| 39 | u64 sum; | ||
| 40 | u64 ip[0]; | ||
| 41 | }; | ||
| 42 | |||
| 43 | struct sym_ext { | ||
| 44 | struct rb_node node; | ||
| 45 | double percent; | ||
| 46 | char *path; | ||
| 47 | }; | ||
| 48 | |||
| 49 | struct sym_priv { | ||
| 50 | struct sym_hist *hist; | ||
| 51 | struct sym_ext *ext; | ||
| 52 | }; | ||
| 53 | 36 | ||
| 54 | static const char *sym_hist_filter; | 37 | static const char *sym_hist_filter; |
| 55 | 38 | ||
| 56 | static int sym__alloc_hist(struct symbol *self) | 39 | static int hists__add_entry(struct hists *self, struct addr_location *al) |
| 57 | { | ||
| 58 | struct sym_priv *priv = symbol__priv(self); | ||
| 59 | const int size = (sizeof(*priv->hist) + | ||
| 60 | (self->end - self->start) * sizeof(u64)); | ||
| 61 | |||
| 62 | priv->hist = zalloc(size); | ||
| 63 | return priv->hist == NULL ? -1 : 0; | ||
| 64 | } | ||
| 65 | |||
| 66 | /* | ||
| 67 | * collect histogram counts | ||
| 68 | */ | ||
| 69 | static int annotate__hist_hit(struct hist_entry *he, u64 ip) | ||
| 70 | { | ||
| 71 | unsigned int sym_size, offset; | ||
| 72 | struct symbol *sym = he->sym; | ||
| 73 | struct sym_priv *priv; | ||
| 74 | struct sym_hist *h; | ||
| 75 | |||
| 76 | he->count++; | ||
| 77 | |||
| 78 | if (!sym || !he->map) | ||
| 79 | return 0; | ||
| 80 | |||
| 81 | priv = symbol__priv(sym); | ||
| 82 | if (priv->hist == NULL && sym__alloc_hist(sym) < 0) | ||
| 83 | return -ENOMEM; | ||
| 84 | |||
| 85 | sym_size = sym->end - sym->start; | ||
| 86 | offset = ip - sym->start; | ||
| 87 | |||
| 88 | pr_debug3("%s: ip=%#Lx\n", __func__, he->map->unmap_ip(he->map, ip)); | ||
| 89 | |||
| 90 | if (offset >= sym_size) | ||
| 91 | return 0; | ||
| 92 | |||
| 93 | h = priv->hist; | ||
| 94 | h->sum++; | ||
| 95 | h->ip[offset]++; | ||
| 96 | |||
| 97 | pr_debug3("%#Lx %s: count++ [ip: %#Lx, %#Lx] => %Ld\n", he->sym->start, | ||
| 98 | he->sym->name, ip, ip - he->sym->start, h->ip[offset]); | ||
| 99 | return 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | static int perf_session__add_hist_entry(struct perf_session *self, | ||
| 103 | struct addr_location *al, u64 count) | ||
| 104 | { | 40 | { |
| 105 | bool hit; | ||
| 106 | struct hist_entry *he; | 41 | struct hist_entry *he; |
| 107 | 42 | ||
| 108 | if (sym_hist_filter != NULL && | 43 | if (sym_hist_filter != NULL && |
| @@ -116,11 +51,11 @@ static int perf_session__add_hist_entry(struct perf_session *self, | |||
| 116 | return 0; | 51 | return 0; |
| 117 | } | 52 | } |
| 118 | 53 | ||
| 119 | he = __perf_session__add_hist_entry(&self->hists, al, NULL, count, &hit); | 54 | he = __hists__add_entry(self, al, NULL, 1); |
| 120 | if (he == NULL) | 55 | if (he == NULL) |
| 121 | return -ENOMEM; | 56 | return -ENOMEM; |
| 122 | 57 | ||
| 123 | return annotate__hist_hit(he, al->addr); | 58 | return hist_entry__inc_addr_samples(he, al->addr); |
| 124 | } | 59 | } |
| 125 | 60 | ||
| 126 | static int process_sample_event(event_t *event, struct perf_session *session) | 61 | static int process_sample_event(event_t *event, struct perf_session *session) |
| @@ -136,7 +71,7 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
| 136 | return -1; | 71 | return -1; |
| 137 | } | 72 | } |
| 138 | 73 | ||
| 139 | if (!al.filtered && perf_session__add_hist_entry(session, &al, 1)) { | 74 | if (!al.filtered && hists__add_entry(&session->hists, &al)) { |
| 140 | pr_warning("problem incrementing symbol count, " | 75 | pr_warning("problem incrementing symbol count, " |
| 141 | "skipping event\n"); | 76 | "skipping event\n"); |
| 142 | return -1; | 77 | return -1; |
| @@ -145,106 +80,11 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
| 145 | return 0; | 80 | return 0; |
| 146 | } | 81 | } |
| 147 | 82 | ||
| 148 | struct objdump_line { | ||
| 149 | struct list_head node; | ||
| 150 | s64 offset; | ||
| 151 | char *line; | ||
| 152 | }; | ||
| 153 | |||
| 154 | static struct objdump_line *objdump_line__new(s64 offset, char *line) | ||
| 155 | { | ||
| 156 | struct objdump_line *self = malloc(sizeof(*self)); | ||
| 157 | |||
| 158 | if (self != NULL) { | ||
| 159 | self->offset = offset; | ||
| 160 | self->line = line; | ||
| 161 | } | ||
| 162 | |||
| 163 | return self; | ||
| 164 | } | ||
| 165 | |||
| 166 | static void objdump_line__free(struct objdump_line *self) | ||
| 167 | { | ||
| 168 | free(self->line); | ||
| 169 | free(self); | ||
| 170 | } | ||
| 171 | |||
| 172 | static void objdump__add_line(struct list_head *head, struct objdump_line *line) | ||
| 173 | { | ||
| 174 | list_add_tail(&line->node, head); | ||
| 175 | } | ||
| 176 | |||
| 177 | static struct objdump_line *objdump__get_next_ip_line(struct list_head *head, | ||
| 178 | struct objdump_line *pos) | ||
| 179 | { | ||
| 180 | list_for_each_entry_continue(pos, head, node) | ||
| 181 | if (pos->offset >= 0) | ||
| 182 | return pos; | ||
| 183 | |||
| 184 | return NULL; | ||
| 185 | } | ||
| 186 | |||
| 187 | static int parse_line(FILE *file, struct hist_entry *he, | ||
| 188 | struct list_head *head) | ||
| 189 | { | ||
| 190 | struct symbol *sym = he->sym; | ||
| 191 | struct objdump_line *objdump_line; | ||
| 192 | char *line = NULL, *tmp, *tmp2; | ||
| 193 | size_t line_len; | ||
| 194 | s64 line_ip, offset = -1; | ||
| 195 | char *c; | ||
| 196 | |||
| 197 | if (getline(&line, &line_len, file) < 0) | ||
| 198 | return -1; | ||
| 199 | |||
| 200 | if (!line) | ||
| 201 | return -1; | ||
| 202 | |||
| 203 | c = strchr(line, '\n'); | ||
| 204 | if (c) | ||
| 205 | *c = 0; | ||
| 206 | |||
| 207 | line_ip = -1; | ||
| 208 | |||
| 209 | /* | ||
| 210 | * Strip leading spaces: | ||
| 211 | */ | ||
| 212 | tmp = line; | ||
| 213 | while (*tmp) { | ||
| 214 | if (*tmp != ' ') | ||
| 215 | break; | ||
| 216 | tmp++; | ||
| 217 | } | ||
| 218 | |||
| 219 | if (*tmp) { | ||
| 220 | /* | ||
| 221 | * Parse hexa addresses followed by ':' | ||
| 222 | */ | ||
| 223 | line_ip = strtoull(tmp, &tmp2, 16); | ||
| 224 | if (*tmp2 != ':') | ||
| 225 | line_ip = -1; | ||
| 226 | } | ||
| 227 | |||
| 228 | if (line_ip != -1) { | ||
| 229 | u64 start = map__rip_2objdump(he->map, sym->start); | ||
| 230 | offset = line_ip - start; | ||
| 231 | } | ||
| 232 | |||
| 233 | objdump_line = objdump_line__new(offset, line); | ||
| 234 | if (objdump_line == NULL) { | ||
| 235 | free(line); | ||
| 236 | return -1; | ||
| 237 | } | ||
| 238 | objdump__add_line(head, objdump_line); | ||
| 239 | |||
| 240 | return 0; | ||
| 241 | } | ||
| 242 | |||
| 243 | static int objdump_line__print(struct objdump_line *self, | 83 | static int objdump_line__print(struct objdump_line *self, |
| 244 | struct list_head *head, | 84 | struct list_head *head, |
| 245 | struct hist_entry *he, u64 len) | 85 | struct hist_entry *he, u64 len) |
| 246 | { | 86 | { |
| 247 | struct symbol *sym = he->sym; | 87 | struct symbol *sym = he->ms.sym; |
| 248 | static const char *prev_line; | 88 | static const char *prev_line; |
| 249 | static const char *prev_color; | 89 | static const char *prev_color; |
| 250 | 90 | ||
| @@ -327,7 +167,7 @@ static void insert_source_line(struct sym_ext *sym_ext) | |||
| 327 | 167 | ||
| 328 | static void free_source_line(struct hist_entry *he, int len) | 168 | static void free_source_line(struct hist_entry *he, int len) |
| 329 | { | 169 | { |
| 330 | struct sym_priv *priv = symbol__priv(he->sym); | 170 | struct sym_priv *priv = symbol__priv(he->ms.sym); |
| 331 | struct sym_ext *sym_ext = priv->ext; | 171 | struct sym_ext *sym_ext = priv->ext; |
| 332 | int i; | 172 | int i; |
| 333 | 173 | ||
| @@ -346,7 +186,7 @@ static void free_source_line(struct hist_entry *he, int len) | |||
| 346 | static void | 186 | static void |
| 347 | get_source_line(struct hist_entry *he, int len, const char *filename) | 187 | get_source_line(struct hist_entry *he, int len, const char *filename) |
| 348 | { | 188 | { |
| 349 | struct symbol *sym = he->sym; | 189 | struct symbol *sym = he->ms.sym; |
| 350 | u64 start; | 190 | u64 start; |
| 351 | int i; | 191 | int i; |
| 352 | char cmd[PATH_MAX * 2]; | 192 | char cmd[PATH_MAX * 2]; |
| @@ -361,7 +201,7 @@ get_source_line(struct hist_entry *he, int len, const char *filename) | |||
| 361 | if (!priv->ext) | 201 | if (!priv->ext) |
| 362 | return; | 202 | return; |
| 363 | 203 | ||
| 364 | start = he->map->unmap_ip(he->map, sym->start); | 204 | start = he->ms.map->unmap_ip(he->ms.map, sym->start); |
| 365 | 205 | ||
| 366 | for (i = 0; i < len; i++) { | 206 | for (i = 0; i < len; i++) { |
| 367 | char *path = NULL; | 207 | char *path = NULL; |
| @@ -425,7 +265,7 @@ static void print_summary(const char *filename) | |||
| 425 | 265 | ||
| 426 | static void hist_entry__print_hits(struct hist_entry *self) | 266 | static void hist_entry__print_hits(struct hist_entry *self) |
| 427 | { | 267 | { |
| 428 | struct symbol *sym = self->sym; | 268 | struct symbol *sym = self->ms.sym; |
| 429 | struct sym_priv *priv = symbol__priv(sym); | 269 | struct sym_priv *priv = symbol__priv(sym); |
| 430 | struct sym_hist *h = priv->hist; | 270 | struct sym_hist *h = priv->hist; |
| 431 | u64 len = sym->end - sym->start, offset; | 271 | u64 len = sym->end - sym->start, offset; |
| @@ -439,23 +279,17 @@ static void hist_entry__print_hits(struct hist_entry *self) | |||
| 439 | 279 | ||
| 440 | static void annotate_sym(struct hist_entry *he) | 280 | static void annotate_sym(struct hist_entry *he) |
| 441 | { | 281 | { |
| 442 | struct map *map = he->map; | 282 | struct map *map = he->ms.map; |
| 443 | struct dso *dso = map->dso; | 283 | struct dso *dso = map->dso; |
| 444 | struct symbol *sym = he->sym; | 284 | struct symbol *sym = he->ms.sym; |
| 445 | const char *filename = dso->long_name, *d_filename; | 285 | const char *filename = dso->long_name, *d_filename; |
| 446 | u64 len; | 286 | u64 len; |
| 447 | char command[PATH_MAX*2]; | ||
| 448 | FILE *file; | ||
| 449 | LIST_HEAD(head); | 287 | LIST_HEAD(head); |
| 450 | struct objdump_line *pos, *n; | 288 | struct objdump_line *pos, *n; |
| 451 | 289 | ||
| 452 | if (!filename) | 290 | if (hist_entry__annotate(he, &head) < 0) |
| 453 | return; | 291 | return; |
| 454 | 292 | ||
| 455 | pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__, | ||
| 456 | filename, sym->name, map->unmap_ip(map, sym->start), | ||
| 457 | map->unmap_ip(map, sym->end)); | ||
| 458 | |||
| 459 | if (full_paths) | 293 | if (full_paths) |
| 460 | d_filename = filename; | 294 | d_filename = filename; |
| 461 | else | 295 | else |
| @@ -472,29 +306,6 @@ static void annotate_sym(struct hist_entry *he) | |||
| 472 | printf(" Percent | Source code & Disassembly of %s\n", d_filename); | 306 | printf(" Percent | Source code & Disassembly of %s\n", d_filename); |
| 473 | printf("------------------------------------------------\n"); | 307 | printf("------------------------------------------------\n"); |
| 474 | 308 | ||
| 475 | if (verbose >= 2) | ||
| 476 | printf("annotating [%p] %30s : [%p] %30s\n", | ||
| 477 | dso, dso->long_name, sym, sym->name); | ||
| 478 | |||
| 479 | sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s", | ||
| 480 | map__rip_2objdump(map, sym->start), | ||
| 481 | map__rip_2objdump(map, sym->end), | ||
| 482 | filename, filename); | ||
| 483 | |||
| 484 | if (verbose >= 3) | ||
| 485 | printf("doing: %s\n", command); | ||
| 486 | |||
| 487 | file = popen(command, "r"); | ||
| 488 | if (!file) | ||
| 489 | return; | ||
| 490 | |||
| 491 | while (!feof(file)) { | ||
| 492 | if (parse_line(file, he, &head) < 0) | ||
| 493 | break; | ||
| 494 | } | ||
| 495 | |||
| 496 | pclose(file); | ||
| 497 | |||
| 498 | if (verbose) | 309 | if (verbose) |
| 499 | hist_entry__print_hits(he); | 310 | hist_entry__print_hits(he); |
| 500 | 311 | ||
| @@ -508,25 +319,25 @@ static void annotate_sym(struct hist_entry *he) | |||
| 508 | free_source_line(he, len); | 319 | free_source_line(he, len); |
| 509 | } | 320 | } |
| 510 | 321 | ||
| 511 | static void perf_session__find_annotations(struct perf_session *self) | 322 | static void hists__find_annotations(struct hists *self) |
| 512 | { | 323 | { |
| 513 | struct rb_node *nd; | 324 | struct rb_node *nd; |
| 514 | 325 | ||
| 515 | for (nd = rb_first(&self->hists); nd; nd = rb_next(nd)) { | 326 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { |
| 516 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); | 327 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
| 517 | struct sym_priv *priv; | 328 | struct sym_priv *priv; |
| 518 | 329 | ||
| 519 | if (he->sym == NULL) | 330 | if (he->ms.sym == NULL) |
| 520 | continue; | 331 | continue; |
| 521 | 332 | ||
| 522 | priv = symbol__priv(he->sym); | 333 | priv = symbol__priv(he->ms.sym); |
| 523 | if (priv->hist == NULL) | 334 | if (priv->hist == NULL) |
| 524 | continue; | 335 | continue; |
| 525 | 336 | ||
| 526 | annotate_sym(he); | 337 | annotate_sym(he); |
| 527 | /* | 338 | /* |
| 528 | * Since we have a hist_entry per IP for the same symbol, free | 339 | * Since we have a hist_entry per IP for the same symbol, free |
| 529 | * he->sym->hist to signal we already processed this symbol. | 340 | * he->ms.sym->hist to signal we already processed this symbol. |
| 530 | */ | 341 | */ |
| 531 | free(priv->hist); | 342 | free(priv->hist); |
| 532 | priv->hist = NULL; | 343 | priv->hist = NULL; |
| @@ -545,7 +356,7 @@ static int __cmd_annotate(void) | |||
| 545 | int ret; | 356 | int ret; |
| 546 | struct perf_session *session; | 357 | struct perf_session *session; |
| 547 | 358 | ||
| 548 | session = perf_session__new(input_name, O_RDONLY, force); | 359 | session = perf_session__new(input_name, O_RDONLY, force, false); |
| 549 | if (session == NULL) | 360 | if (session == NULL) |
| 550 | return -ENOMEM; | 361 | return -ENOMEM; |
| 551 | 362 | ||
| @@ -554,7 +365,7 @@ static int __cmd_annotate(void) | |||
| 554 | goto out_delete; | 365 | goto out_delete; |
| 555 | 366 | ||
| 556 | if (dump_trace) { | 367 | if (dump_trace) { |
| 557 | event__print_totals(); | 368 | perf_session__fprintf_nr_events(session, stdout); |
| 558 | goto out_delete; | 369 | goto out_delete; |
| 559 | } | 370 | } |
| 560 | 371 | ||
| @@ -562,11 +373,11 @@ static int __cmd_annotate(void) | |||
| 562 | perf_session__fprintf(session, stdout); | 373 | perf_session__fprintf(session, stdout); |
| 563 | 374 | ||
| 564 | if (verbose > 2) | 375 | if (verbose > 2) |
| 565 | dsos__fprintf(stdout); | 376 | perf_session__fprintf_dsos(session, stdout); |
| 566 | 377 | ||
| 567 | perf_session__collapse_resort(&session->hists); | 378 | hists__collapse_resort(&session->hists); |
| 568 | perf_session__output_resort(&session->hists, session->event_total[0]); | 379 | hists__output_resort(&session->hists); |
| 569 | perf_session__find_annotations(session); | 380 | hists__find_annotations(&session->hists); |
| 570 | out_delete: | 381 | out_delete: |
| 571 | perf_session__delete(session); | 382 | perf_session__delete(session); |
| 572 | 383 | ||
| @@ -581,10 +392,12 @@ static const char * const annotate_usage[] = { | |||
| 581 | static const struct option options[] = { | 392 | static const struct option options[] = { |
| 582 | OPT_STRING('i', "input", &input_name, "file", | 393 | OPT_STRING('i', "input", &input_name, "file", |
| 583 | "input file name"), | 394 | "input file name"), |
| 395 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", | ||
| 396 | "only consider symbols in these dsos"), | ||
| 584 | OPT_STRING('s', "symbol", &sym_hist_filter, "symbol", | 397 | OPT_STRING('s', "symbol", &sym_hist_filter, "symbol", |
| 585 | "symbol to annotate"), | 398 | "symbol to annotate"), |
| 586 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), | 399 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
| 587 | OPT_BOOLEAN('v', "verbose", &verbose, | 400 | OPT_INCR('v', "verbose", &verbose, |
| 588 | "be more verbose (show symbol address, etc)"), | 401 | "be more verbose (show symbol address, etc)"), |
| 589 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 402 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 590 | "dump raw trace in ASCII"), | 403 | "dump raw trace in ASCII"), |
