annotate.c (c849c12cf344e4b99dbf98df642b622b6c91bbfd) annotate.c (4c650ddc2e9e8f1d8dc46f13b30b1b9a6017fb02)
1/*
2 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
3 *
4 * Parts came from builtin-annotate.c, see those files for further
5 * copyright notes.
6 *
7 * Released under the GPL v2. (and only v2, not any later version)
8 */

--- 2142 unchanged lines hidden (view full) ---

2151 case LARROW_CHAR: s = "←"; break;
2152 case RARROW_CHAR: s = "→"; break;
2153 default: s = "?"; break;
2154 }
2155
2156 fputs(s, fp);
2157}
2158
1/*
2 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
3 *
4 * Parts came from builtin-annotate.c, see those files for further
5 * copyright notes.
6 *
7 * Released under the GPL v2. (and only v2, not any later version)
8 */

--- 2142 unchanged lines hidden (view full) ---

2151 case LARROW_CHAR: s = "←"; break;
2152 case RARROW_CHAR: s = "→"; break;
2153 default: s = "?"; break;
2154 }
2155
2156 fputs(s, fp);
2157}
2158
2159static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp)
2159static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp,
2160 struct annotation_options *opts)
2160{
2161 struct annotation *notes = symbol__annotation(sym);
2161{
2162 struct annotation *notes = symbol__annotation(sym);
2162 struct annotation_write_ops ops = {
2163 struct annotation_write_ops wops = {
2163 .first_line = true,
2164 .obj = fp,
2165 .set_color = FILE__set_color,
2166 .set_percent_color = FILE__set_percent_color,
2167 .set_jumps_percent_color = FILE__set_jumps_percent_color,
2168 .printf = FILE__printf,
2169 .write_graph = FILE__write_graph,
2170 };
2171 struct annotation_line *al;
2172
2173 list_for_each_entry(al, &notes->src->source, node) {
2174 if (annotation_line__filter(al, notes))
2175 continue;
2164 .first_line = true,
2165 .obj = fp,
2166 .set_color = FILE__set_color,
2167 .set_percent_color = FILE__set_percent_color,
2168 .set_jumps_percent_color = FILE__set_jumps_percent_color,
2169 .printf = FILE__printf,
2170 .write_graph = FILE__write_graph,
2171 };
2172 struct annotation_line *al;
2173
2174 list_for_each_entry(al, &notes->src->source, node) {
2175 if (annotation_line__filter(al, notes))
2176 continue;
2176 annotation_line__write(al, notes, &ops);
2177 annotation_line__write(al, notes, &wops, opts);
2177 fputc('\n', fp);
2178 fputc('\n', fp);
2178 ops.first_line = false;
2179 wops.first_line = false;
2179 }
2180
2181 return 0;
2182}
2183
2180 }
2181
2182 return 0;
2183}
2184
2184int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel)
2185int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel,
2186 struct annotation_options *opts)
2185{
2186 const char *ev_name = perf_evsel__name(evsel);
2187 char buf[1024];
2188 char *filename;
2189 int err = -1;
2190 FILE *fp;
2191
2192 if (asprintf(&filename, "%s.annotation", ms->sym->name) < 0)

--- 5 unchanged lines hidden (view full) ---

2198
2199 if (perf_evsel__is_group_event(evsel)) {
2200 perf_evsel__group_desc(evsel, buf, sizeof(buf));
2201 ev_name = buf;
2202 }
2203
2204 fprintf(fp, "%s() %s\nEvent: %s\n\n",
2205 ms->sym->name, ms->map->dso->long_name, ev_name);
2187{
2188 const char *ev_name = perf_evsel__name(evsel);
2189 char buf[1024];
2190 char *filename;
2191 int err = -1;
2192 FILE *fp;
2193
2194 if (asprintf(&filename, "%s.annotation", ms->sym->name) < 0)

--- 5 unchanged lines hidden (view full) ---

2200
2201 if (perf_evsel__is_group_event(evsel)) {
2202 perf_evsel__group_desc(evsel, buf, sizeof(buf));
2203 ev_name = buf;
2204 }
2205
2206 fprintf(fp, "%s() %s\nEvent: %s\n\n",
2207 ms->sym->name, ms->map->dso->long_name, ev_name);
2206 symbol__annotate_fprintf2(ms->sym, fp);
2208 symbol__annotate_fprintf2(ms->sym, fp, opts);
2207
2208 fclose(fp);
2209 err = 0;
2210out_free_filename:
2211 free(filename);
2212 return err;
2213}
2214

--- 213 unchanged lines hidden (view full) ---

2428 if (opts->print_lines) {
2429 srcline_full_filename = opts->full_path;
2430 symbol__calc_lines(sym, map, &source_line, opts);
2431 print_summary(&source_line, dso->long_name);
2432 }
2433
2434 hists__scnprintf_title(hists, buf, sizeof(buf));
2435 fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name);
2209
2210 fclose(fp);
2211 err = 0;
2212out_free_filename:
2213 free(filename);
2214 return err;
2215}
2216

--- 213 unchanged lines hidden (view full) ---

2430 if (opts->print_lines) {
2431 srcline_full_filename = opts->full_path;
2432 symbol__calc_lines(sym, map, &source_line, opts);
2433 print_summary(&source_line, dso->long_name);
2434 }
2435
2436 hists__scnprintf_title(hists, buf, sizeof(buf));
2437 fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name);
2436 symbol__annotate_fprintf2(sym, stdout);
2438 symbol__annotate_fprintf2(sym, stdout, opts);
2437
2438 annotated_source__purge(symbol__annotation(sym)->src);
2439
2440 return 0;
2441}
2442
2443int symbol__tty_annotate(struct symbol *sym, struct map *map,
2444 struct perf_evsel *evsel,

--- 22 unchanged lines hidden (view full) ---

2467
2468bool ui__has_annotation(void)
2469{
2470 return use_browser == 1 && perf_hpp_list.sym;
2471}
2472
2473
2474static double annotation_line__max_percent(struct annotation_line *al,
2439
2440 annotated_source__purge(symbol__annotation(sym)->src);
2441
2442 return 0;
2443}
2444
2445int symbol__tty_annotate(struct symbol *sym, struct map *map,
2446 struct perf_evsel *evsel,

--- 22 unchanged lines hidden (view full) ---

2469
2470bool ui__has_annotation(void)
2471{
2472 return use_browser == 1 && perf_hpp_list.sym;
2473}
2474
2475
2476static double annotation_line__max_percent(struct annotation_line *al,
2475 struct annotation *notes)
2477 struct annotation *notes,
2478 unsigned int percent_type)
2476{
2477 double percent_max = 0.0;
2478 int i;
2479
2480 for (i = 0; i < notes->nr_events; i++) {
2481 double percent;
2482
2483 percent = annotation_data__percent(&al->data[i],
2479{
2480 double percent_max = 0.0;
2481 int i;
2482
2483 for (i = 0; i < notes->nr_events; i++) {
2484 double percent;
2485
2486 percent = annotation_data__percent(&al->data[i],
2484 PERCENT_HITS_LOCAL);
2487 percent_type);
2485
2486 if (percent > percent_max)
2487 percent_max = percent;
2488 }
2489
2490 return percent_max;
2491}
2492

--- 25 unchanged lines hidden (view full) ---

2518 obj__printf(obj, " ");
2519 }
2520
2521 disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset);
2522}
2523
2524static void __annotation_line__write(struct annotation_line *al, struct annotation *notes,
2525 bool first_line, bool current_entry, bool change_color, int width,
2488
2489 if (percent > percent_max)
2490 percent_max = percent;
2491 }
2492
2493 return percent_max;
2494}
2495

--- 25 unchanged lines hidden (view full) ---

2521 obj__printf(obj, " ");
2522 }
2523
2524 disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset);
2525}
2526
2527static void __annotation_line__write(struct annotation_line *al, struct annotation *notes,
2528 bool first_line, bool current_entry, bool change_color, int width,
2526 void *obj,
2529 void *obj, unsigned int percent_type,
2527 int (*obj__set_color)(void *obj, int color),
2528 void (*obj__set_percent_color)(void *obj, double percent, bool current),
2529 int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current),
2530 void (*obj__printf)(void *obj, const char *fmt, ...),
2531 void (*obj__write_graph)(void *obj, int graph))
2532
2533{
2530 int (*obj__set_color)(void *obj, int color),
2531 void (*obj__set_percent_color)(void *obj, double percent, bool current),
2532 int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current),
2533 void (*obj__printf)(void *obj, const char *fmt, ...),
2534 void (*obj__write_graph)(void *obj, int graph))
2535
2536{
2534 double percent_max = annotation_line__max_percent(al, notes);
2537 double percent_max = annotation_line__max_percent(al, notes, percent_type);
2535 int pcnt_width = annotation__pcnt_width(notes),
2536 cycles_width = annotation__cycles_width(notes);
2537 bool show_title = false;
2538 char bf[256];
2539 int printed;
2540
2541 if (first_line && (al->offset == -1 || percent_max == 0.0)) {
2542 if (notes->have_cycles) {

--- 4 unchanged lines hidden (view full) ---

2547 }
2548
2549 if (al->offset != -1 && percent_max != 0.0) {
2550 int i;
2551
2552 for (i = 0; i < notes->nr_events; i++) {
2553 double percent;
2554
2538 int pcnt_width = annotation__pcnt_width(notes),
2539 cycles_width = annotation__cycles_width(notes);
2540 bool show_title = false;
2541 char bf[256];
2542 int printed;
2543
2544 if (first_line && (al->offset == -1 || percent_max == 0.0)) {
2545 if (notes->have_cycles) {

--- 4 unchanged lines hidden (view full) ---

2550 }
2551
2552 if (al->offset != -1 && percent_max != 0.0) {
2553 int i;
2554
2555 for (i = 0; i < notes->nr_events; i++) {
2556 double percent;
2557
2555 percent = annotation_data__percent(&al->data[i],
2556 PERCENT_HITS_LOCAL);
2558 percent = annotation_data__percent(&al->data[i], percent_type);
2557
2558 obj__set_percent_color(obj, percent, current_entry);
2559 if (notes->options->show_total_period) {
2560 obj__printf(obj, "%11" PRIu64 " ", al->data[i].he.period);
2561 } else if (notes->options->show_nr_samples) {
2562 obj__printf(obj, "%6" PRIu64 " ",
2563 al->data[i].he.nr_samples);
2564 } else {

--- 110 unchanged lines hidden (view full) ---

2675 disasm_line__write(disasm_line(al), notes, obj, bf, sizeof(bf), obj__printf, obj__write_graph);
2676
2677 obj__printf(obj, "%-*s", width - pcnt_width - cycles_width - 3 - printed, bf);
2678 }
2679
2680}
2681
2682void annotation_line__write(struct annotation_line *al, struct annotation *notes,
2559
2560 obj__set_percent_color(obj, percent, current_entry);
2561 if (notes->options->show_total_period) {
2562 obj__printf(obj, "%11" PRIu64 " ", al->data[i].he.period);
2563 } else if (notes->options->show_nr_samples) {
2564 obj__printf(obj, "%6" PRIu64 " ",
2565 al->data[i].he.nr_samples);
2566 } else {

--- 110 unchanged lines hidden (view full) ---

2677 disasm_line__write(disasm_line(al), notes, obj, bf, sizeof(bf), obj__printf, obj__write_graph);
2678
2679 obj__printf(obj, "%-*s", width - pcnt_width - cycles_width - 3 - printed, bf);
2680 }
2681
2682}
2683
2684void annotation_line__write(struct annotation_line *al, struct annotation *notes,
2683 struct annotation_write_ops *ops)
2685 struct annotation_write_ops *wops,
2686 struct annotation_options *opts)
2684{
2687{
2685 __annotation_line__write(al, notes, ops->first_line, ops->current_entry,
2686 ops->change_color, ops->width, ops->obj,
2687 ops->set_color, ops->set_percent_color,
2688 ops->set_jumps_percent_color, ops->printf,
2689 ops->write_graph);
2688 __annotation_line__write(al, notes, wops->first_line, wops->current_entry,
2689 wops->change_color, wops->width, wops->obj,
2690 opts->percent_type,
2691 wops->set_color, wops->set_percent_color,
2692 wops->set_jumps_percent_color, wops->printf,
2693 wops->write_graph);
2690}
2691
2692int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel,
2693 struct annotation_options *options, struct arch **parch)
2694{
2695 struct annotation *notes = symbol__annotation(sym);
2696 size_t size = symbol__size(sym);
2697 int nr_pcnt = 1, err;

--- 97 unchanged lines hidden ---
2694}
2695
2696int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel,
2697 struct annotation_options *options, struct arch **parch)
2698{
2699 struct annotation *notes = symbol__annotation(sym);
2700 size_t size = symbol__size(sym);
2701 int nr_pcnt = 1, err;

--- 97 unchanged lines hidden ---