mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	David Ahern <dsahern@gmail.com>, Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	"Liang, Kan" <kan.liang@intel.com>
Subject: [PATCH 03/45] perf tools: Add thread_map__new_event function
Date: Wed, 30 Sep 2015 16:10:16 +0200	[thread overview]
Message-ID: <1443622258-17158-4-git-send-email-jolsa@kernel.org> (raw)
In-Reply-To: <1443622258-17158-1-git-send-email-jolsa@kernel.org>

Introducing thread_map__new_event function to create
struct thread_map object from thread_map event.

Link: http://lkml.kernel.org/n/tip-0gu5uv3g51p4mzul93bhh2yh@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/tests/thread-map.c | 14 ++++++++++++++
 tools/perf/util/thread_map.c  | 27 +++++++++++++++++++++++++++
 tools/perf/util/thread_map.h  |  3 +++
 3 files changed, 44 insertions(+)

diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c
index 0facd9fa3458..da7b047d3ada 100644
--- a/tools/perf/tests/thread-map.c
+++ b/tools/perf/tests/thread-map.c
@@ -47,10 +47,24 @@ static int process_event(struct perf_tool *tool __maybe_unused,
 			 struct machine *machine __maybe_unused)
 {
 	struct thread_map_event *map = &event->thread_map;
+	struct thread_map *threads;
 
 	TEST_ASSERT_VAL("wrong nr",   map->nr == 1);
 	TEST_ASSERT_VAL("wrong pid",  map->data[0].pid == (u64) getpid());
 	TEST_ASSERT_VAL("wrong comm", !strcmp(map->data[0].comm, "perf"));
+
+	threads = thread_map__new_event(&event->thread_map);
+	TEST_ASSERT_VAL("failed to alloc map", threads);
+
+	TEST_ASSERT_VAL("wrong nr", threads->nr == 1);
+	TEST_ASSERT_VAL("wrong pid",
+			thread_map__pid(threads, 0) == getpid());
+	TEST_ASSERT_VAL("wrong comm",
+			thread_map__comm(threads, 0) &&
+			!strcmp(thread_map__comm(threads, 0), "perf"));
+	TEST_ASSERT_VAL("wrong refcnt",
+			atomic_read(&threads->refcnt) == 1);
+	thread_map__put(threads);
 	return 0;
 }
 
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 6ec3c5ca438f..04b8dc368cbb 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -13,6 +13,7 @@
 #include "thread_map.h"
 #include "util.h"
 #include "debug.h"
+#include "event.h"
 
 /* Skip "." and ".." directories */
 static int filter(const struct dirent *dir)
@@ -408,3 +409,29 @@ void thread_map__read_comms(struct thread_map *threads)
 	for (i = 0; i < threads->nr; ++i)
 		comm_init(threads, i);
 }
+
+static void thread_map__copy_event(struct thread_map *threads,
+				   struct thread_map_event *event)
+{
+	unsigned i;
+
+	threads->nr = (int) event->nr;
+
+	for (i = 0; i < event->nr; i++) {
+		thread_map__set_pid(threads, i, (pid_t) event->data[i].pid);
+		threads->map[i].comm = strndup(event->data[i].comm, 16);
+	}
+
+	atomic_set(&threads->refcnt, 1);
+}
+
+struct thread_map *thread_map__new_event(struct thread_map_event *event)
+{
+	struct thread_map *threads;
+
+	threads = thread_map__alloc(event->nr);
+	if (threads)
+		thread_map__copy_event(threads, event);
+
+	return threads;
+}
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index af679d8a50f8..85e4c7c4fbde 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -16,11 +16,14 @@ struct thread_map {
 	struct thread_map_data map[];
 };
 
+struct thread_map_event;
+
 struct thread_map *thread_map__new_dummy(void);
 struct thread_map *thread_map__new_by_pid(pid_t pid);
 struct thread_map *thread_map__new_by_tid(pid_t tid);
 struct thread_map *thread_map__new_by_uid(uid_t uid);
 struct thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid);
+struct thread_map *thread_map__new_event(struct thread_map_event *event);
 
 struct thread_map *thread_map__get(struct thread_map *map);
 void thread_map__put(struct thread_map *map);
-- 
2.4.3


  parent reply	other threads:[~2015-09-30 14:11 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-30 14:10 [PATCHv2 00/45] perf stat: Add scripting support Jiri Olsa
2015-09-30 14:10 ` [PATCH 01/45] perf tools: Add thread_map event Jiri Olsa
2015-09-30 14:10 ` [PATCH 02/45] perf tools: Add thread_map event synthesize function Jiri Olsa
2015-09-30 14:10 ` Jiri Olsa [this message]
2015-09-30 14:10 ` [PATCH 04/45] perf tools: Add cpu_map event Jiri Olsa
2015-09-30 14:10 ` [PATCH 05/45] perf tools: Add cpu_map event synthesize function Jiri Olsa
2015-09-30 14:10 ` [PATCH 06/45] perf tools: Add cpu_map__new_event function Jiri Olsa
2015-09-30 14:10 ` [PATCH 07/45] perf tools: Add stat config event Jiri Olsa
2015-09-30 14:10 ` [PATCH 08/45] perf tools: Add stat config event synthesize function Jiri Olsa
2015-09-30 14:10 ` [PATCH 09/45] perf tools: Add stat config event read function Jiri Olsa
2015-09-30 14:10 ` [PATCH 10/45] perf tools: Add stat event Jiri Olsa
2015-09-30 14:10 ` [PATCH 11/45] perf tools: Add stat event synthesize function Jiri Olsa
2015-09-30 14:10 ` [PATCH 12/45] perf tools: Add stat event read function Jiri Olsa
2015-09-30 14:10 ` [PATCH 13/45] perf tools: Add stat round event Jiri Olsa
2015-09-30 14:10 ` [PATCH 14/45] perf tools: Add stat round event synthesize function Jiri Olsa
2015-09-30 14:10 ` [PATCH 15/45] perf tools: Introduce stat feature Jiri Olsa
2015-09-30 14:10 ` [PATCH 16/45] perf tools: Move id_offset out of struct perf_evsel union Jiri Olsa
2015-09-30 14:10 ` [PATCH 17/45] perf stat: Rename perf_stat struct into perf_stat_evsel Jiri Olsa
2015-09-30 14:10 ` [PATCH 18/45] perf stat: Add AGGR_UNSET mode Jiri Olsa
2015-09-30 14:10 ` [PATCH 19/45] perf stat record: Add record command Jiri Olsa
2015-09-30 14:10 ` [PATCH 20/45] perf stat record: Initialize record features Jiri Olsa
2015-09-30 14:10 ` [PATCH 21/45] perf stat record: Synthesize stat record data Jiri Olsa
2015-09-30 14:10 ` [PATCH 22/45] perf stat record: Store events IDs in perf data file Jiri Olsa
2015-09-30 14:10 ` [PATCH 23/45] perf stat record: Add pipe support for record command Jiri Olsa
2015-09-30 14:10 ` [PATCH 24/45] perf stat record: Write stat events on record Jiri Olsa
2015-09-30 14:10 ` [PATCH 25/45] perf stat record: Write stat round " Jiri Olsa
2015-09-30 14:10 ` [PATCH 26/45] perf stat record: Do not allow record with multiple runs mode Jiri Olsa
2015-09-30 14:10 ` [PATCH 27/45] perf tools: Add cpu_map__empty_new interface Jiri Olsa
2015-09-30 14:10 ` [PATCH 28/45] perf tools: Make cpu_map__build_map global Jiri Olsa
2015-09-30 14:10 ` [PATCH 29/45] perf tools: Add data arg to cpu_map__build_map callback Jiri Olsa
2015-09-30 14:10 ` [PATCH 30/45] perf stat report: Cache aggregated map entries in extra cpumap Jiri Olsa
2015-09-30 14:10 ` [PATCH 31/45] perf stat report: Add report command Jiri Olsa
2015-09-30 14:10 ` [PATCH 32/45] perf stat report: Process cpu/threads maps Jiri Olsa
2015-09-30 14:10 ` [PATCH 33/45] perf stat report: Process stat config event Jiri Olsa
2015-09-30 14:10 ` [PATCH 34/45] perf stat report: Add support to initialize aggr_map from file Jiri Olsa
2015-09-30 14:10 ` [PATCH 35/45] perf stat report: Process stat and stat round events Jiri Olsa
2015-09-30 14:10 ` [PATCH 36/45] perf stat report: Move csv_sep initialization before report command Jiri Olsa
2015-09-30 14:10 ` [PATCH 37/45] perf stat report: Allow to override aggr_mode Jiri Olsa
2015-09-30 14:10 ` [PATCH 38/45] perf script: Check output fields only for samples Jiri Olsa
2015-09-30 14:10 ` [PATCH 39/45] perf script: Process cpu/threads maps Jiri Olsa
2015-09-30 14:10 ` [PATCH 40/45] perf script: Process stat config event Jiri Olsa
2015-09-30 14:10 ` [PATCH 41/45] perf script: Add process_stat/process_stat_interval scripting interface Jiri Olsa
2015-09-30 14:10 ` [PATCH 42/45] perf script: Add stat default handlers Jiri Olsa
2015-09-30 14:10 ` [PATCH 43/45] perf script: Display stat events by default Jiri Olsa
2015-09-30 14:10 ` [PATCH 44/45] perf script: Add python support for stat events Jiri Olsa
2015-09-30 14:10 ` [PATCH 45/45] perf script: Add stat-cpi.py script Jiri Olsa
2015-09-30 21:09 ` [PATCHv2 00/45] perf stat: Add scripting support Liang, Kan
2015-09-30 21:34   ` Jiri Olsa
2015-09-30 21:36   ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443622258-17158-4-git-send-email-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome