lkml.org 
[lkml]   [2012]   [Oct]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 8/9] perf stat: move to perf_evlist__open_counters
Date
Removes a lot of duplicated code moving to the common
open method.

Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
---
tools/perf/builtin-stat.c | 103 ++++++++++-----------------------------------
1 file changed, 22 insertions(+), 81 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9727d217..affbada 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -122,55 +122,6 @@ static struct stats runtime_itlb_cache_stats[MAX_NR_CPUS];
static struct stats runtime_dtlb_cache_stats[MAX_NR_CPUS];
static struct stats walltime_nsecs_stats;

-static int create_perf_stat_counter(struct perf_evsel *evsel,
- struct perf_evsel *first,
- struct perf_record_opts *opts)
-{
- struct perf_target *target = &opts->target;
- struct perf_event_attr *attr = &evsel->attr;
- bool exclude_guest_missing = false;
- int ret;
-
- if (scale)
- attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
- PERF_FORMAT_TOTAL_TIME_RUNNING;
-
- attr->inherit = !opts->no_inherit;
-
-retry:
- if (exclude_guest_missing)
- evsel->attr.exclude_guest = evsel->attr.exclude_host = 0;
-
- if (perf_target__has_cpu(target)) {
- ret = perf_evsel__open_per_cpu(evsel,
- perf_evsel__cpus(evsel, target));
- if (ret)
- goto check_ret;
- return 0;
- }
-
- if (!perf_target__has_task(target) &&
- (!opts->group || evsel == first)) {
- attr->disabled = 1;
- attr->enable_on_exec = 1;
- }
-
- ret = perf_evsel__open_per_thread(evsel, evsel_list->threads);
- if (!ret)
- return 0;
- /* fall through */
-check_ret:
- if (ret && errno == EINVAL) {
- if (!exclude_guest_missing &&
- (evsel->attr.exclude_guest || evsel->attr.exclude_host)) {
- pr_debug("Old kernel, cannot exclude "
- "guest or host samples.\n");
- exclude_guest_missing = true;
- goto retry;
- }
- }
- return ret;
-}

/*
* Does the counter have nsecs as a unit?
@@ -277,6 +228,7 @@ static int run_perf_stat(int argc __maybe_unused,
unsigned long long t0, t1;
struct perf_evsel *counter, *first;
struct cpu_map *cmap;
+ struct perf_target *target = &opts->target;
int status = 0;
int child_ready_pipe[2], go_pipe[2];
const bool forks = (argc > 0);
@@ -320,7 +272,7 @@ static int run_perf_stat(int argc __maybe_unused,
exit(-1);
}

- if (perf_target__none(&opts->target))
+ if (perf_target__none(target))
evsel_list->threads->map[0] = child_pid;

/*
@@ -339,38 +291,27 @@ static int run_perf_stat(int argc __maybe_unused,
first = perf_evlist__first(evsel_list);

list_for_each_entry(counter, &evsel_list->entries, node) {
- if (create_perf_stat_counter(counter, first, opts) < 0) {
- /*
- * PPC returns ENXIO for HW counters until 2.6.37
- * (behavior changed with commit b0a873e).
- */
- if (errno == EINVAL || errno == ENOSYS ||
- errno == ENOENT || errno == EOPNOTSUPP ||
- errno == ENXIO) {
- if (verbose)
- ui__warning("%s event is not supported by the kernel.\n",
- perf_evsel__name(counter));
- counter->supported = false;
- continue;
- }
-
- if (errno == EPERM || errno == EACCES) {
- error("You may not have permission to collect %sstats.\n"
- "\t Consider tweaking"
- " /proc/sys/kernel/perf_event_paranoid or running as root.",
- opts->target.system_wide ? "system-wide " : "");
- } else {
- error("open_counter returned with %d (%s). "
- "/bin/dmesg may provide additional information.\n",
- errno, strerror(errno));
- }
- if (child_pid != -1)
- kill(child_pid, SIGTERM);
-
- pr_err("Not all events could be opened.\n");
- return -1;
+ struct perf_event_attr *attr = &counter->attr;
+
+ if (scale)
+ attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
+ PERF_FORMAT_TOTAL_TIME_RUNNING;
+
+ attr->inherit = !opts->no_inherit;
+
+ if (perf_target__none(target) &&
+ (!opts->group || counter == first)) {
+ attr->disabled = 1;
+ attr->enable_on_exec = 1;
}
- counter->supported = true;
+ }
+
+ if (perf_evlist__open_counters(evsel_list, opts, true) != 0) {
+ if (child_pid != -1)
+ kill(child_pid, SIGTERM);
+
+ pr_err("Not all events could be opened.\n");
+ return -1;
}

if (perf_evlist__apply_filters(evsel_list)) {
--
1.7.10.1


\
 
 \ /
  Last update: 2012-10-11 07:01    [W:0.053 / U:0.440 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site