aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-01-14 00:25:35 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-01-15 13:32:43 -0500
commit2dc9fb1a7bf013ce24dd34bc25283b60b966f015 (patch)
tree5350a5b6d4fc4c469a68335c679c7d7cb35b33bf /tools/perf
parent540476de74c9b11403656791838ede91405d3859 (diff)
perf tools: Factor out sample__resolve_callchain()
The report__resolve_callchain() can be shared with perf top code as it doesn't really depend on the perf report code. Factor it out as sample__resolve_callchain(). The same goes to the hist_entry__append_ callchain() too. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Arun Sharma <asharma@fb.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Rodrigo Campos <rodrigo@sdfg.com.ar> Link: http://lkml.kernel.org/r/1389677157-30513-3-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-report.c24
-rw-r--r--tools/perf/builtin-top.c22
-rw-r--r--tools/perf/util/callchain.c23
-rw-r--r--tools/perf/util/callchain.h6
4 files changed, 39 insertions, 36 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 46864dd7eb83..3c53ec268fbc 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -75,24 +75,6 @@ static int report__config(const char *var, const char *value, void *cb)
75 return perf_default_config(var, value, cb); 75 return perf_default_config(var, value, cb);
76} 76}
77 77
78static int report__resolve_callchain(struct report *rep, struct symbol **parent,
79 struct perf_evsel *evsel, struct addr_location *al,
80 struct perf_sample *sample)
81{
82 if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) {
83 return machine__resolve_callchain(al->machine, evsel, al->thread, sample,
84 parent, al, rep->max_stack);
85 }
86 return 0;
87}
88
89static int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample)
90{
91 if (!symbol_conf.use_callchain)
92 return 0;
93 return callchain_append(he->callchain, &callchain_cursor, sample->period);
94}
95
96static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_location *al, 78static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_location *al,
97 struct perf_sample *sample, struct perf_evsel *evsel, 79 struct perf_sample *sample, struct perf_evsel *evsel,
98 union perf_event *event) 80 union perf_event *event)
@@ -103,7 +85,7 @@ static int report__add_mem_hist_entry(struct perf_tool *tool, struct addr_locati
103 struct hist_entry *he; 85 struct hist_entry *he;
104 struct mem_info *mi, *mx; 86 struct mem_info *mi, *mx;
105 uint64_t cost; 87 uint64_t cost;
106 int err = report__resolve_callchain(rep, &parent, evsel, al, sample); 88 int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack);
107 89
108 if (err) 90 if (err)
109 return err; 91 return err;
@@ -155,7 +137,7 @@ static int report__add_branch_hist_entry(struct perf_tool *tool, struct addr_loc
155 unsigned i; 137 unsigned i;
156 struct hist_entry *he; 138 struct hist_entry *he;
157 struct branch_info *bi, *bx; 139 struct branch_info *bi, *bx;
158 int err = report__resolve_callchain(rep, &parent, evsel, al, sample); 140 int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack);
159 141
160 if (err) 142 if (err)
161 return err; 143 return err;
@@ -208,7 +190,7 @@ static int report__add_hist_entry(struct perf_tool *tool, struct perf_evsel *evs
208 struct report *rep = container_of(tool, struct report, tool); 190 struct report *rep = container_of(tool, struct report, tool);
209 struct symbol *parent = NULL; 191 struct symbol *parent = NULL;
210 struct hist_entry *he; 192 struct hist_entry *he;
211 int err = report__resolve_callchain(rep, &parent, evsel, al, sample); 193 int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack);
212 194
213 if (err) 195 if (err)
214 return err; 196 return err;
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 569dd87690ef..76cd510d34d0 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -743,15 +743,10 @@ static void perf_event__process_sample(struct perf_tool *tool,
743 if (al.sym == NULL || !al.sym->ignore) { 743 if (al.sym == NULL || !al.sym->ignore) {
744 struct hist_entry *he; 744 struct hist_entry *he;
745 745
746 if ((sort__has_parent || symbol_conf.use_callchain) && 746 err = sample__resolve_callchain(sample, &parent, evsel, &al,
747 sample->callchain) { 747 top->max_stack);
748 err = machine__resolve_callchain(machine, evsel, 748 if (err)
749 al.thread, sample, 749 return;
750 &parent, &al,
751 top->max_stack);
752 if (err)
753 return;
754 }
755 750
756 he = perf_evsel__add_hist_entry(evsel, &al, sample); 751 he = perf_evsel__add_hist_entry(evsel, &al, sample);
757 if (he == NULL) { 752 if (he == NULL) {
@@ -759,12 +754,9 @@ static void perf_event__process_sample(struct perf_tool *tool,
759 return; 754 return;
760 } 755 }
761 756
762 if (symbol_conf.use_callchain) { 757 err = hist_entry__append_callchain(he, sample);
763 err = callchain_append(he->callchain, &callchain_cursor, 758 if (err)
764 sample->period); 759 return;
765 if (err)
766 return;
767 }
768 760
769 if (sort__has_sym) 761 if (sort__has_sym)
770 perf_top__record_precise_ip(top, he, evsel->idx, ip); 762 perf_top__record_precise_ip(top, he, evsel->idx, ip);
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index e3970e3eaacf..9eb4f57f8663 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -17,6 +17,8 @@
17 17
18#include "hist.h" 18#include "hist.h"
19#include "util.h" 19#include "util.h"
20#include "sort.h"
21#include "machine.h"
20#include "callchain.h" 22#include "callchain.h"
21 23
22__thread struct callchain_cursor callchain_cursor; 24__thread struct callchain_cursor callchain_cursor;
@@ -531,3 +533,24 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
531 533
532 return 0; 534 return 0;
533} 535}
536
537int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
538 struct perf_evsel *evsel, struct addr_location *al,
539 int max_stack)
540{
541 if (sample->callchain == NULL)
542 return 0;
543
544 if (symbol_conf.use_callchain || sort__has_parent) {
545 return machine__resolve_callchain(al->machine, evsel, al->thread,
546 sample, parent, al, max_stack);
547 }
548 return 0;
549}
550
551int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample)
552{
553 if (!symbol_conf.use_callchain)
554 return 0;
555 return callchain_append(he->callchain, &callchain_cursor, sample->period);
556}
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 08b25af9eea1..8ad97e9b119f 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -145,10 +145,16 @@ static inline void callchain_cursor_advance(struct callchain_cursor *cursor)
145} 145}
146 146
147struct option; 147struct option;
148struct hist_entry;
148 149
149int record_parse_callchain(const char *arg, struct record_opts *opts); 150int record_parse_callchain(const char *arg, struct record_opts *opts);
150int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset); 151int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
151int record_callchain_opt(const struct option *opt, const char *arg, int unset); 152int record_callchain_opt(const struct option *opt, const char *arg, int unset);
152 153
154int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
155 struct perf_evsel *evsel, struct addr_location *al,
156 int max_stack);
157int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample);
158
153extern const char record_callchain_help[]; 159extern const char record_callchain_help[];
154#endif /* __PERF_CALLCHAIN_H */ 160#endif /* __PERF_CALLCHAIN_H */