aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2014-10-09 15:16:00 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-10-14 16:32:52 -0400
commita635fc511e05774298153e3ddfef7c4cd51a1bb4 (patch)
tree1e6fc65518fb3dc6ebab1ab60663812b14caae5d /tools
parent8f651eae186f4dfb1740988623c83ba03dcf3a76 (diff)
perf tools: Remove hists from evsel
Now tools that deals want to have an hists per evsel need to call hists__init() before creating any evsels, which can be as early as when parsing the command line, so do it before calling parse_options(). The current tools using hists/hist_entries are report, top and annotate, change them to request per evsel hists. This is in preparation for making evsels usable by 3rd party tools, that not necessarily live in perf's source code repository. Acked-by: Borislav Petkov <bp@suse.de> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Ahern <dsahern@gmail.com> Cc: Don Zickus <dzickus@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jean Pihet <jean.pihet@linaro.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-usjx2la743f10ippj7p1b20x@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-annotate.c5
-rw-r--r--tools/perf/builtin-report.c5
-rw-r--r--tools/perf/builtin-top.c5
-rw-r--r--tools/perf/tests/builtin-test.c5
-rw-r--r--tools/perf/util/evsel.c11
-rw-r--r--tools/perf/util/evsel.h11
-rw-r--r--tools/perf/util/hist.c28
-rw-r--r--tools/perf/util/hist.h20
8 files changed, 65 insertions, 25 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index a5969fa64503..e7417fe97a97 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -326,7 +326,10 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
326 "Show event group information together"), 326 "Show event group information together"),
327 OPT_END() 327 OPT_END()
328 }; 328 };
329 int ret; 329 int ret = hists__init();
330
331 if (ret < 0)
332 return ret;
330 333
331 argc = parse_options(argc, argv, options, annotate_usage, 0); 334 argc = parse_options(argc, argv, options, annotate_usage, 0);
332 335
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 8043b5a7240a..2cfc4b93991f 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -568,7 +568,6 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
568 struct stat st; 568 struct stat st;
569 bool has_br_stack = false; 569 bool has_br_stack = false;
570 int branch_mode = -1; 570 int branch_mode = -1;
571 int ret = -1;
572 char callchain_default_opt[] = "fractal,0.5,callee"; 571 char callchain_default_opt[] = "fractal,0.5,callee";
573 const char * const report_usage[] = { 572 const char * const report_usage[] = {
574 "perf report [<options>]", 573 "perf report [<options>]",
@@ -695,6 +694,10 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
695 struct perf_data_file file = { 694 struct perf_data_file file = {
696 .mode = PERF_DATA_MODE_READ, 695 .mode = PERF_DATA_MODE_READ,
697 }; 696 };
697 int ret = hists__init();
698
699 if (ret < 0)
700 return ret;
698 701
699 perf_config(report__config, &report); 702 perf_config(report__config, &report);
700 703
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 8ab9716db593..0aa7747ff139 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1047,7 +1047,6 @@ parse_percent_limit(const struct option *opt, const char *arg,
1047 1047
1048int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) 1048int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1049{ 1049{
1050 int status = -1;
1051 char errbuf[BUFSIZ]; 1050 char errbuf[BUFSIZ];
1052 struct perf_top top = { 1051 struct perf_top top = {
1053 .count_filter = 5, 1052 .count_filter = 5,
@@ -1165,6 +1164,10 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1165 "perf top [<options>]", 1164 "perf top [<options>]",
1166 NULL 1165 NULL
1167 }; 1166 };
1167 int status = hists__init();
1168
1169 if (status < 0)
1170 return status;
1168 1171
1169 top.evlist = perf_evlist__new(); 1172 top.evlist = perf_evlist__new();
1170 if (top.evlist == NULL) 1173 if (top.evlist == NULL)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index ac655b0700e7..162c978f1491 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -6,6 +6,7 @@
6#include <unistd.h> 6#include <unistd.h>
7#include <string.h> 7#include <string.h>
8#include "builtin.h" 8#include "builtin.h"
9#include "hist.h"
9#include "intlist.h" 10#include "intlist.h"
10#include "tests.h" 11#include "tests.h"
11#include "debug.h" 12#include "debug.h"
@@ -302,6 +303,10 @@ int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
302 OPT_END() 303 OPT_END()
303 }; 304 };
304 struct intlist *skiplist = NULL; 305 struct intlist *skiplist = NULL;
306 int ret = hists__init();
307
308 if (ret < 0)
309 return ret;
305 310
306 argc = parse_options(argc, argv, test_options, test_usage, 0); 311 argc = parse_options(argc, argv, test_options, test_usage, 0);
307 if (argc >= 1 && !strcmp(argv[0], "list")) 312 if (argc >= 1 && !strcmp(argv[0], "list"))
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index a08376427448..7a3c4c47ceda 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -159,16 +159,6 @@ void perf_evsel__calc_id_pos(struct perf_evsel *evsel)
159 evsel->is_pos = __perf_evsel__calc_is_pos(evsel->attr.sample_type); 159 evsel->is_pos = __perf_evsel__calc_is_pos(evsel->attr.sample_type);
160} 160}
161 161
162void hists__init(struct hists *hists)
163{
164 memset(hists, 0, sizeof(*hists));
165 hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT;
166 hists->entries_in = &hists->entries_in_array[0];
167 hists->entries_collapsed = RB_ROOT;
168 hists->entries = RB_ROOT;
169 pthread_mutex_init(&hists->lock, NULL);
170}
171
172void __perf_evsel__set_sample_bit(struct perf_evsel *evsel, 162void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
173 enum perf_event_sample_format bit) 163 enum perf_event_sample_format bit)
174{ 164{
@@ -211,7 +201,6 @@ void perf_evsel__init(struct perf_evsel *evsel,
211 evsel->unit = ""; 201 evsel->unit = "";
212 evsel->scale = 1.0; 202 evsel->scale = 1.0;
213 INIT_LIST_HEAD(&evsel->node); 203 INIT_LIST_HEAD(&evsel->node);
214 hists__init(&evsel->hists);
215 perf_evsel__object.init(evsel); 204 perf_evsel__object.init(evsel);
216 evsel->sample_size = __perf_evsel__sample_size(attr->sample_type); 205 evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
217 perf_evsel__calc_id_pos(evsel); 206 perf_evsel__calc_id_pos(evsel);
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index d6325106c8fd..fee927404720 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -8,7 +8,6 @@
8#include <linux/types.h> 8#include <linux/types.h>
9#include "xyarray.h" 9#include "xyarray.h"
10#include "cgroup.h" 10#include "cgroup.h"
11#include "hist.h"
12#include "symbol.h" 11#include "symbol.h"
13 12
14struct perf_counts_values { 13struct perf_counts_values {
@@ -66,7 +65,6 @@ struct perf_evsel {
66 struct perf_counts *prev_raw_counts; 65 struct perf_counts *prev_raw_counts;
67 int idx; 66 int idx;
68 u32 ids; 67 u32 ids;
69 struct hists hists;
70 char *name; 68 char *name;
71 double scale; 69 double scale;
72 const char *unit; 70 const char *unit;
@@ -100,13 +98,6 @@ union u64_swap {
100 u32 val32[2]; 98 u32 val32[2];
101}; 99};
102 100
103#define hists_to_evsel(h) container_of(h, struct perf_evsel, hists)
104
105static inline struct hists *evsel__hists(struct perf_evsel *evsel)
106{
107 return &evsel->hists;
108}
109
110struct cpu_map; 101struct cpu_map;
111struct thread_map; 102struct thread_map;
112struct perf_evlist; 103struct perf_evlist;
@@ -290,8 +281,6 @@ static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
290 return __perf_evsel__read(evsel, ncpus, nthreads, true); 281 return __perf_evsel__read(evsel, ncpus, nthreads, true);
291} 282}
292 283
293void hists__init(struct hists *hists);
294
295int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, 284int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
296 struct perf_sample *sample); 285 struct perf_sample *sample);
297 286
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index b143e404e5b1..6e88b9e395df 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1447,3 +1447,31 @@ int perf_hist_config(const char *var, const char *value)
1447 1447
1448 return 0; 1448 return 0;
1449} 1449}
1450
1451static int hists_evsel__init(struct perf_evsel *evsel)
1452{
1453 struct hists *hists = evsel__hists(evsel);
1454
1455 memset(hists, 0, sizeof(*hists));
1456 hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT;
1457 hists->entries_in = &hists->entries_in_array[0];
1458 hists->entries_collapsed = RB_ROOT;
1459 hists->entries = RB_ROOT;
1460 pthread_mutex_init(&hists->lock, NULL);
1461 return 0;
1462}
1463
1464/*
1465 * XXX We probably need a hists_evsel__exit() to free the hist_entries
1466 * stored in the rbtree...
1467 */
1468
1469int hists__init(void)
1470{
1471 int err = perf_evsel__object_config(sizeof(struct hists_evsel),
1472 hists_evsel__init, NULL);
1473 if (err)
1474 fputs("FATAL ERROR: Couldn't setup hists class\n", stderr);
1475
1476 return err;
1477}
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index ebfc25886cac..d0ef9a19a744 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -4,6 +4,7 @@
4#include <linux/types.h> 4#include <linux/types.h>
5#include <pthread.h> 5#include <pthread.h>
6#include "callchain.h" 6#include "callchain.h"
7#include "evsel.h"
7#include "header.h" 8#include "header.h"
8#include "color.h" 9#include "color.h"
9#include "ui/progress.h" 10#include "ui/progress.h"
@@ -158,6 +159,25 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *he);
158void hists__match(struct hists *leader, struct hists *other); 159void hists__match(struct hists *leader, struct hists *other);
159int hists__link(struct hists *leader, struct hists *other); 160int hists__link(struct hists *leader, struct hists *other);
160 161
162struct hists_evsel {
163 struct perf_evsel evsel;
164 struct hists hists;
165};
166
167static inline struct perf_evsel *hists_to_evsel(struct hists *hists)
168{
169 struct hists_evsel *hevsel = container_of(hists, struct hists_evsel, hists);
170 return &hevsel->evsel;
171}
172
173static inline struct hists *evsel__hists(struct perf_evsel *evsel)
174{
175 struct hists_evsel *hevsel = (struct hists_evsel *)evsel;
176 return &hevsel->hists;
177}
178
179int hists__init(void);
180
161struct perf_hpp { 181struct perf_hpp {
162 char *buf; 182 char *buf;
163 size_t size; 183 size_t size;