tools lib traceevent: Add pevent_unregister_print_function()
[platform/adaptation/renesas_rcar/renesas_kernel.git] / tools / perf / builtin-report.c
index f2ff860..3c53ec2 100644 (file)
@@ -75,24 +75,6 @@ static int report__config(const char *var, const char *value, void *cb)
        return perf_default_config(var, value, cb);
 }
 
-static int report__resolve_callchain(struct report *rep, struct symbol **parent,
-                                    struct perf_evsel *evsel, struct addr_location *al,
-                                    struct perf_sample *sample)
-{
-       if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) {
-               return machine__resolve_callchain(al->machine, evsel, al->thread, sample,
-                                                 parent, al, rep->max_stack);
-       }
-       return 0;
-}
-
-static int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample)
-{
-       if (!symbol_conf.use_callchain)
-               return 0;
-       return callchain_append(he->callchain, &callchain_cursor, sample->period);
-}
-
 static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_location *al,
                                      struct perf_sample *sample, struct perf_evsel *evsel,
                                      union perf_event *event)
@@ -103,7 +85,7 @@ static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_locati
        struct hist_entry *he;
        struct mem_info *mi, *mx;
        uint64_t cost;
-       int err = report__resolve_callchain(rep, &parent, evsel, al, sample);
+       int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack);
 
        if (err)
                return err;
@@ -155,7 +137,7 @@ static int report__add_branch_hist_entry(struct perf_tool *tool, struct addr_loc
        unsigned i;
        struct hist_entry *he;
        struct branch_info *bi, *bx;
-       int err = report__resolve_callchain(rep, &parent, evsel, al, sample);
+       int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack);
 
        if (err)
                return err;
@@ -208,7 +190,7 @@ static int report__add_hist_entry(struct perf_tool *tool, struct perf_evsel *evs
        struct report *rep = container_of(tool, struct report, tool);
        struct symbol *parent = NULL;
        struct hist_entry *he;
-       int err = report__resolve_callchain(rep, &parent, evsel, al, sample);
+       int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack);
 
        if (err)
                return err;
@@ -384,7 +366,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
 {
        struct perf_evsel *pos;
 
-       list_for_each_entry(pos, &evlist->entries, node) {
+       evlist__for_each(evlist, pos) {
                struct hists *hists = &pos->hists;
                const char *evname = perf_evsel__name(pos);
 
@@ -441,14 +423,100 @@ static void report__warn_kptr_restrict(const struct report *rep)
        }
 }
 
+static int report__gtk_browse_hists(struct report *rep, const char *help)
+{
+       int (*hist_browser)(struct perf_evlist *evlist, const char *help,
+                           struct hist_browser_timer *timer, float min_pcnt);
+
+       hist_browser = dlsym(perf_gtk_handle, "perf_evlist__gtk_browse_hists");
+
+       if (hist_browser == NULL) {
+               ui__error("GTK browser not found!\n");
+               return -1;
+       }
+
+       return hist_browser(rep->session->evlist, help, NULL, rep->min_percent);
+}
+
+static int report__browse_hists(struct report *rep)
+{
+       int ret;
+       struct perf_session *session = rep->session;
+       struct perf_evlist *evlist = session->evlist;
+       const char *help = "For a higher level overview, try: perf report --sort comm,dso";
+
+       switch (use_browser) {
+       case 1:
+               ret = perf_evlist__tui_browse_hists(evlist, help, NULL,
+                                                   rep->min_percent,
+                                                   &session->header.env);
+               /*
+                * Usually "ret" is the last pressed key, and we only
+                * care if the key notifies us to switch data file.
+                */
+               if (ret != K_SWITCH_INPUT_DATA)
+                       ret = 0;
+               break;
+       case 2:
+               ret = report__gtk_browse_hists(rep, help);
+               break;
+       default:
+               ret = perf_evlist__tty_browse_hists(evlist, rep, help);
+               break;
+       }
+
+       return ret;
+}
+
+static u64 report__collapse_hists(struct report *rep)
+{
+       struct ui_progress prog;
+       struct perf_evsel *pos;
+       u64 nr_samples = 0;
+       /*
+        * Count number of histogram entries to use when showing progress,
+        * reusing nr_samples variable.
+        */
+       evlist__for_each(rep->session->evlist, pos)
+               nr_samples += pos->hists.nr_entries;
+
+       ui_progress__init(&prog, nr_samples, "Merging related events...");
+       /*
+        * Count total number of samples, will be used to check if this
+        * session had any.
+        */
+       nr_samples = 0;
+
+       evlist__for_each(rep->session->evlist, pos) {
+               struct hists *hists = &pos->hists;
+
+               if (pos->idx == 0)
+                       hists->symbol_filter_str = rep->symbol_filter_str;
+
+               hists__collapse_resort(hists, &prog);
+               nr_samples += hists->stats.nr_events[PERF_RECORD_SAMPLE];
+
+               /* Non-group events are considered as leader */
+               if (symbol_conf.event_group &&
+                   !perf_evsel__is_group_leader(pos)) {
+                       struct hists *leader_hists = &pos->leader->hists;
+
+                       hists__match(leader_hists, hists);
+                       hists__link(leader_hists, hists);
+               }
+       }
+
+       ui_progress__finish();
+
+       return nr_samples;
+}
+
 static int __cmd_report(struct report *rep)
 {
-       int ret = -EINVAL;
+       int ret;
        u64 nr_samples;
        struct perf_session *session = rep->session;
        struct perf_evsel *pos;
-       const char *help = "For a higher level overview, try: perf report --sort comm,dso";
-       struct ui_progress prog;
        struct perf_data_file *file = session->file;
 
        signal(SIGINT, sig_handler);
@@ -486,32 +554,7 @@ static int __cmd_report(struct report *rep)
                }
        }
 
-       nr_samples = 0;
-       list_for_each_entry(pos, &session->evlist->entries, node)
-               nr_samples += pos->hists.nr_entries;
-
-       ui_progress__init(&prog, nr_samples, "Merging related events...");
-
-       nr_samples = 0;
-       list_for_each_entry(pos, &session->evlist->entries, node) {
-               struct hists *hists = &pos->hists;
-
-               if (pos->idx == 0)
-                       hists->symbol_filter_str = rep->symbol_filter_str;
-
-               hists__collapse_resort(hists, &prog);
-               nr_samples += hists->stats.nr_events[PERF_RECORD_SAMPLE];
-
-               /* Non-group events are considered as leader */
-               if (symbol_conf.event_group &&
-                   !perf_evsel__is_group_leader(pos)) {
-                       struct hists *leader_hists = &pos->leader->hists;
-
-                       hists__match(leader_hists, hists);
-                       hists__link(leader_hists, hists);
-               }
-       }
-       ui_progress__finish();
+       nr_samples = report__collapse_hists(rep);
 
        if (session_done())
                return 0;
@@ -521,41 +564,10 @@ static int __cmd_report(struct report *rep)
                return 0;
        }
 
-       list_for_each_entry(pos, &session->evlist->entries, node)
+       evlist__for_each(session->evlist, pos)
                hists__output_resort(&pos->hists);
 
-       if (use_browser > 0) {
-               if (use_browser == 1) {
-                       ret = perf_evlist__tui_browse_hists(session->evlist,
-                                                       help, NULL,
-                                                       rep->min_percent,
-                                                       &session->header.env);
-                       /*
-                        * Usually "ret" is the last pressed key, and we only
-                        * care if the key notifies us to switch data file.
-                        */
-                       if (ret != K_SWITCH_INPUT_DATA)
-                               ret = 0;
-
-               } else if (use_browser == 2) {
-                       int (*hist_browser)(struct perf_evlist *,
-                                           const char *,
-                                           struct hist_browser_timer *,
-                                           float min_pcnt);
-
-                       hist_browser = dlsym(perf_gtk_handle,
-                                            "perf_evlist__gtk_browse_hists");
-                       if (hist_browser == NULL) {
-                               ui__error("GTK browser not found!\n");
-                               return ret;
-                       }
-                       hist_browser(session->evlist, help, NULL,
-                                    rep->min_percent);
-               }
-       } else
-               perf_evlist__tty_browse_hists(session->evlist, rep, help);
-
-       return ret;
+       return report__browse_hists(rep);
 }
 
 static int