[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1453715801-7732-43-git-send-email-wangnan0@huawei.com>
Date: Mon, 25 Jan 2016 09:56:29 +0000
From: Wang Nan <wangnan0@...wei.com>
To: Alexei Starovoitov <ast@...nel.org>,
Arnaldo Carvalho de Melo <acme@...hat.com>
CC: Brendan Gregg <brendan.d.gregg@...il.com>,
Daniel Borkmann <daniel@...earbox.net>,
"David S. Miller" <davem@...emloft.net>,
He Kuang <hekuang@...wei.com>, Jiri Olsa <jolsa@...nel.org>,
Li Zefan <lizefan@...wei.com>,
Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>,
Namhyung Kim <namhyung@...nel.org>,
Peter Zijlstra <peterz@...radead.org>, <pi3orama@....com>,
Will Deacon <will.deacon@....com>,
<linux-kernel@...r.kernel.org>, Wang Nan <wangnan0@...wei.com>
Subject: [PATCH 42/54] perf tools: Automatically add new channel according to evlist
perf_evlist__channel_find() can be used to find a proper channel based
on propreties of a evsel. If the channel doesn't exist, it can create
new one for it. After this patch there's no need to create default
channel explicitly.
Signed-off-by: Wang Nan <wangnan0@...wei.com>
Signed-off-by: He Kuang <hekuang@...wei.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Zefan Li <lizefan@...wei.com>
Cc: pi3orama@....com
---
tools/perf/builtin-record.c | 5 -----
tools/perf/util/evlist.c | 47 ++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 2d9e6c6..30a3c5c 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -357,11 +357,6 @@ try_again:
}
perf_evlist__channel_reset(evlist);
- rc = perf_evlist__channel_add(evlist, 0, true);
- if (rc < 0)
- goto out;
- rc = 0;
-
if (perf_evlist__mmap_ex(evlist, opts->mmap_pages, false,
opts->auxtrace_mmap_pages,
opts->auxtrace_snapshot_mode) < 0) {
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c565563..10eeacf 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -943,6 +943,43 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist, int idx,
return 0;
}
+static unsigned long
+perf_evlist__channel_for_evsel(struct perf_evsel *evsel __maybe_unused)
+{
+ return 0;
+}
+
+static int
+perf_evlist__channel_find(struct perf_evlist *evlist,
+ struct perf_evsel *evsel,
+ bool add_new)
+{
+ unsigned long flag = perf_evlist__channel_for_evsel(evsel);
+ int i;
+
+ flag |= PERF_EVLIST__CHANNEL_ENABLED;
+ for (i = 0; i < perf_evlist__channel_nr(evlist); i++)
+ if (evlist->channel_flags[i] == flag)
+ return i;
+ if (add_new)
+ return perf_evlist__channel_add(evlist, flag, false);
+ return -ENOENT;
+}
+
+static int
+perf_evlist__channel_complete(struct perf_evlist *evlist)
+{
+ struct perf_evsel *evsel;
+ int err;
+
+ evlist__for_each(evlist, evsel) {
+ err = perf_evlist__channel_find(evlist, evsel, true);
+ if (err < 0)
+ return err;
+ }
+ return 0;
+}
+
static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
struct mmap_params *mp, int cpu,
int thread, int *output)
@@ -1162,6 +1199,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
bool overwrite, unsigned int auxtrace_pages,
bool auxtrace_overwrite)
{
+ int err;
struct perf_evsel *evsel;
const struct cpu_map *cpus = evlist->cpus;
const struct thread_map *threads = evlist->threads;
@@ -1169,6 +1207,10 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
.prot = PROT_READ | (overwrite ? 0 : PROT_WRITE),
};
+ err = perf_evlist__channel_complete(evlist);
+ if (err)
+ return err;
+
if (evlist->mmap == NULL && perf_evlist__alloc_mmap(evlist) < 0)
return -ENOMEM;
@@ -1199,12 +1241,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
bool overwrite)
{
- int err;
-
perf_evlist__channel_reset(evlist);
- err = perf_evlist__channel_add(evlist, 0, true);
- if (err < 0)
- return err;
return perf_evlist__mmap_ex(evlist, pages, overwrite, 0, false);
}
--
1.8.3.4
Powered by blists - more mailing lists