hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/tools/perf/ui/browsers/annotate.c
....@@ -1,12 +1,13 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-#include "../../util/util.h"
32 #include "../browser.h"
43 #include "../helpline.h"
54 #include "../ui.h"
6
-#include "../util.h"
75 #include "../../util/annotate.h"
6
+#include "../../util/debug.h"
7
+#include "../../util/dso.h"
88 #include "../../util/hist.h"
99 #include "../../util/sort.h"
10
+#include "../../util/map.h"
1011 #include "../../util/symbol.h"
1112 #include "../../util/evsel.h"
1213 #include "../../util/evlist.h"
....@@ -14,6 +15,7 @@
1415 #include <pthread.h>
1516 #include <linux/kernel.h>
1617 #include <linux/string.h>
18
+#include <linux/zalloc.h>
1719 #include <sys/ttydefaults.h>
1820 #include <asm/bug.h>
1921
....@@ -207,7 +209,7 @@
207209 ui_browser__mark_fused(browser,
208210 pcnt_width + 3 + notes->widths.addr + width,
209211 from - 1,
210
- to > from ? true : false);
212
+ to > from);
211213 }
212214 }
213215
....@@ -225,20 +227,24 @@
225227 return ret;
226228 }
227229
228
-static int disasm__cmp(struct annotation_line *a, struct annotation_line *b)
230
+static double disasm__cmp(struct annotation_line *a, struct annotation_line *b,
231
+ int percent_type)
229232 {
230233 int i;
231234
232235 for (i = 0; i < a->data_nr; i++) {
233
- if (a->data[i].percent == b->data[i].percent)
236
+ if (a->data[i].percent[percent_type] == b->data[i].percent[percent_type])
234237 continue;
235
- return a->data[i].percent < b->data[i].percent;
238
+ return a->data[i].percent[percent_type] -
239
+ b->data[i].percent[percent_type];
236240 }
237241 return 0;
238242 }
239243
240
-static void disasm_rb_tree__insert(struct rb_root *root, struct annotation_line *al)
244
+static void disasm_rb_tree__insert(struct annotate_browser *browser,
245
+ struct annotation_line *al)
241246 {
247
+ struct rb_root *root = &browser->entries;
242248 struct rb_node **p = &root->rb_node;
243249 struct rb_node *parent = NULL;
244250 struct annotation_line *l;
....@@ -247,7 +253,7 @@
247253 parent = *p;
248254 l = rb_entry(parent, struct annotation_line, rb_node);
249255
250
- if (disasm__cmp(al, l))
256
+ if (disasm__cmp(al, l, browser->opts->percent_type) < 0)
251257 p = &(*p)->rb_left;
252258 else
253259 p = &(*p)->rb_right;
....@@ -294,7 +300,7 @@
294300 }
295301
296302 static void annotate_browser__calc_percent(struct annotate_browser *browser,
297
- struct perf_evsel *evsel)
303
+ struct evsel *evsel)
298304 {
299305 struct map_symbol *ms = browser->b.priv;
300306 struct symbol *sym = ms->sym;
....@@ -330,7 +336,7 @@
330336 RB_CLEAR_NODE(&pos->al.rb_node);
331337 continue;
332338 }
333
- disasm_rb_tree__insert(&browser->entries, &pos->al);
339
+ disasm_rb_tree__insert(browser, &pos->al);
334340 }
335341 pthread_mutex_unlock(&notes->lock);
336342
....@@ -401,10 +407,10 @@
401407 * to the calling function.
402408 */
403409 static bool annotate_browser__callq(struct annotate_browser *browser,
404
- struct perf_evsel *evsel,
410
+ struct evsel *evsel,
405411 struct hist_browser_timer *hbt)
406412 {
407
- struct map_symbol *ms = browser->b.priv;
413
+ struct map_symbol *ms = browser->b.priv, target_ms;
408414 struct disasm_line *dl = disasm_line(browser->selection);
409415 struct annotation *notes;
410416 char title[SYM_TITLE_MAX_SIZE];
....@@ -417,15 +423,18 @@
417423 notes = symbol__annotation(dl->ops.target.sym);
418424 pthread_mutex_lock(&notes->lock);
419425
420
- if (!symbol__hists(dl->ops.target.sym, evsel->evlist->nr_entries)) {
426
+ if (!symbol__hists(dl->ops.target.sym, evsel->evlist->core.nr_entries)) {
421427 pthread_mutex_unlock(&notes->lock);
422428 ui__warning("Not enough memory for annotating '%s' symbol!\n",
423429 dl->ops.target.sym->name);
424430 return true;
425431 }
426432
433
+ target_ms.maps = ms->maps;
434
+ target_ms.map = ms->map;
435
+ target_ms.sym = dl->ops.target.sym;
427436 pthread_mutex_unlock(&notes->lock);
428
- symbol__tui_annotate(dl->ops.target.sym, ms->map, evsel, hbt, browser->opts);
437
+ symbol__tui_annotate(&target_ms, evsel, hbt, browser->opts);
429438 sym_title(ms->sym, ms->map, title, sizeof(title), browser->opts->percent_type);
430439 ui_browser__show_title(&browser->b, title);
431440 return true;
....@@ -450,7 +459,7 @@
450459 }
451460
452461 static bool annotate_browser__jump(struct annotate_browser *browser,
453
- struct perf_evsel *evsel,
462
+ struct evsel *evsel,
454463 struct hist_browser_timer *hbt)
455464 {
456465 struct disasm_line *dl = disasm_line(browser->selection);
....@@ -651,7 +660,7 @@
651660 }
652661
653662 static int annotate_browser__run(struct annotate_browser *browser,
654
- struct perf_evsel *evsel,
663
+ struct evsel *evsel,
655664 struct hist_browser_timer *hbt)
656665 {
657666 struct rb_node *nd = NULL;
....@@ -745,10 +754,9 @@
745754 "? Search string backwards\n");
746755 continue;
747756 case 'r':
748
- {
749
- script_browse(NULL);
750
- continue;
751
- }
757
+ script_browse(NULL, NULL);
758
+ annotate_browser__show(&browser->b, title, help);
759
+ continue;
752760 case 'k':
753761 notes->options->show_linenr = !notes->options->show_linenr;
754762 break;
....@@ -825,13 +833,13 @@
825833 map_symbol__annotation_dump(ms, evsel, browser->opts);
826834 continue;
827835 case 't':
828
- if (notes->options->show_total_period) {
829
- notes->options->show_total_period = false;
830
- notes->options->show_nr_samples = true;
831
- } else if (notes->options->show_nr_samples)
832
- notes->options->show_nr_samples = false;
836
+ if (symbol_conf.show_total_period) {
837
+ symbol_conf.show_total_period = false;
838
+ symbol_conf.show_nr_samples = true;
839
+ } else if (symbol_conf.show_nr_samples)
840
+ symbol_conf.show_nr_samples = false;
833841 else
834
- notes->options->show_total_period = true;
842
+ symbol_conf.show_total_period = true;
835843 annotation__update_column_widths(notes);
836844 continue;
837845 case 'c':
....@@ -864,14 +872,14 @@
864872 return key;
865873 }
866874
867
-int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel,
875
+int map_symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
868876 struct hist_browser_timer *hbt,
869877 struct annotation_options *opts)
870878 {
871
- return symbol__tui_annotate(ms->sym, ms->map, evsel, hbt, opts);
879
+ return symbol__tui_annotate(ms, evsel, hbt, opts);
872880 }
873881
874
-int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel,
882
+int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel,
875883 struct hist_browser_timer *hbt,
876884 struct annotation_options *opts)
877885 {
....@@ -882,16 +890,12 @@
882890 return map_symbol__tui_annotate(&he->ms, evsel, hbt, opts);
883891 }
884892
885
-int symbol__tui_annotate(struct symbol *sym, struct map *map,
886
- struct perf_evsel *evsel,
893
+int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
887894 struct hist_browser_timer *hbt,
888895 struct annotation_options *opts)
889896 {
897
+ struct symbol *sym = ms->sym;
890898 struct annotation *notes = symbol__annotation(sym);
891
- struct map_symbol ms = {
892
- .map = map,
893
- .sym = sym,
894
- };
895899 struct annotate_browser browser = {
896900 .b = {
897901 .refresh = annotate_browser__refresh,
....@@ -899,7 +903,7 @@
899903 .write = annotate_browser__write,
900904 .filter = disasm_line__filter,
901905 .extra_title_lines = 1, /* for hists__scnprintf_title() */
902
- .priv = &ms,
906
+ .priv = ms,
903907 .use_navkeypressed = true,
904908 },
905909 .opts = opts,
....@@ -909,13 +913,13 @@
909913 if (sym == NULL)
910914 return -1;
911915
912
- if (map->dso->annotate_warned)
916
+ if (ms->map->dso->annotate_warned)
913917 return -1;
914918
915
- err = symbol__annotate2(sym, map, evsel, opts, &browser.arch);
919
+ err = symbol__annotate2(ms, evsel, opts, &browser.arch);
916920 if (err) {
917921 char msg[BUFSIZ];
918
- symbol__strerror_disassemble(sym, map, err, msg, sizeof(msg));
922
+ symbol__strerror_disassemble(ms, err, msg, sizeof(msg));
919923 ui__error("Couldn't annotate %s:\n%s", sym->name, msg);
920924 goto out_free_offsets;
921925 }