Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1400603

[PATCH 03/17] perf tools: Automatically add new channel according to evlist

From Wang Nan <wangnan0@huawei.com>
Newsgroups linux.kernel
Subject [PATCH 03/17] perf tools: Automatically add new channel according to evlist
Date 2016-05-13 10:20 +0200
Message-ID <ryguf-822-19@gated-at.bofh.it> (permalink)
References <rygaR-7tc-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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@huawei.com>
Signed-off-by: He Kuang <hekuang@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.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 6e44834..3140378 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -317,11 +317,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 6c11b9e..47a8f1f 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1017,6 +1017,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)
@@ -1244,6 +1281,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;
@@ -1251,6 +1289,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;
 
@@ -1281,12 +1323,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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/17] perf tools: Support overwritable ring buffer Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
  [PATCH 15/17] perf record: Read from backward ring buffer Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
  [PATCH 01/17] perf tools: Extract __perf_evlist__mmap_read() Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
    Re: [PATCH 01/17] perf tools: Extract __perf_evlist__mmap_read() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-13 15:10 +0200
  [PATCH 09/17] perf tools: Detect avalibility of write_backward Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
    Re: [PATCH 09/17] perf tools: Detect avalibility of write_backward Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-13 15:10 +0200
      Re: [PATCH 09/17] perf tools: Detect avalibility of write_backward "Wangnan (F)" <wangnan0@huawei.com> - 2016-05-20 17:40 +0200
        Re: [PATCH 09/17] perf tools: Detect avalibility of write_backward Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 17:40 +0200
  [PATCH 05/17] perf record: Prevent reading invalid data in record__mmap_read Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
  [PATCH 17/17] perf tools: Don't warn about out of order event if write_backward is used Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
  [PATCH 11/17] perf tools: Set write_backward attribut bit for overwrite events Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
  [PATCH 04/17] perf tools: Operate multiple channels Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
  [PATCH 08/17] perf record: Don't poll on overwrite channel Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
    Re: [PATCH 08/17] perf record: Don't poll on overwrite channel Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-13 15:20 +0200
      Re: [PATCH 08/17] perf record: Don't poll on overwrite channel "Wangnan (F)" <wangnan0@huawei.com> - 2016-05-16 05:20 +0200
  [PATCH 16/17] perf record: Toggle overwrite ring buffer for reading Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
  [PATCH 10/17] perf tools: Enable overwrite settings Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
    Re: [PATCH 10/17] perf tools: Enable overwrite settings Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-16 15:40 +0200
  [PATCH 07/17] perf record: Don't read from and poll overwrite channel Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
  [PATCH 12/17] perf tools: Record fd into perf_mmap Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
  [PATCH 13/17] perf tools: Add API to pause a channel Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:00 +0200
  [PATCH 14/17] perf record: Rename variable to make code clear Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:10 +0200
  [PATCH 02/17] perf tools: Add evlist channel helpers Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:10 +0200
    Re: [PATCH 02/17] perf tools: Add evlist channel helpers Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-13 15:10 +0200
      Re: [PATCH 02/17] perf tools: Add evlist channel helpers "Wangnan (F)" <wangnan0@huawei.com> - 2016-05-18 05:40 +0200
        Re: [PATCH 02/17] perf tools: Add evlist channel helpers Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com> - 2016-05-18 15:30 +0200
  [PATCH 03/17] perf tools: Automatically add new channel according to evlist Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:20 +0200
  [PATCH 06/17] perf tools: Squash overwrite setting into channel Wang Nan <wangnan0@huawei.com> - 2016-05-13 10:20 +0200

csiph-web