From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
David Ahern <dsahern@gmail.com>,
Stephane Eranian <eranian@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Andi Kleen <andi@firstfloor.org>,
Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH 16/37] perf tools: Add a test case for timed thread handling
Date: Wed, 24 Dec 2014 16:15:12 +0900 [thread overview]
Message-ID: <1419405333-27952-17-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1419405333-27952-1-git-send-email-namhyung@kernel.org>
A test case for verifying live and dead thread tree management during
time change and new machine__find{,new}_thread_time().
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/Makefile.perf | 1 +
tools/perf/tests/builtin-test.c | 4 +
tools/perf/tests/tests.h | 1 +
tools/perf/tests/thread-lookup-time.c | 174 ++++++++++++++++++++++++++++++++++
4 files changed, 180 insertions(+)
create mode 100644 tools/perf/tests/thread-lookup-time.c
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index e4528a4a3a8c..6094f0a10d8b 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -448,6 +448,7 @@ LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o
LIB_OBJS += $(OUTPUT)tests/thread-mg-share.o
LIB_OBJS += $(OUTPUT)tests/switch-tracking.o
LIB_OBJS += $(OUTPUT)tests/thread-comm.o
+LIB_OBJS += $(OUTPUT)tests/thread-lookup-time.o
BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 1b463d82a71a..e4d335de19ea 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -171,6 +171,10 @@ static struct test {
.func = test__thread_comm,
},
{
+ .desc = "Test thread lookup with time",
+ .func = test__thread_lookup_time,
+ },
+ {
.func = NULL,
},
};
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 43ac17780629..1090337f63e5 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -52,6 +52,7 @@ int test__switch_tracking(void);
int test__fdarray__filter(void);
int test__fdarray__add(void);
int test__thread_comm(void);
+int test__thread_lookup_time(void);
#if defined(__x86_64__) || defined(__i386__) || defined(__arm__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/tests/thread-lookup-time.c b/tools/perf/tests/thread-lookup-time.c
new file mode 100644
index 000000000000..6237ecf8caae
--- /dev/null
+++ b/tools/perf/tests/thread-lookup-time.c
@@ -0,0 +1,174 @@
+#include "tests.h"
+#include "machine.h"
+#include "thread.h"
+#include "map.h"
+#include "debug.h"
+
+static int thread__print_cb(struct thread *th, void *arg __maybe_unused)
+{
+ printf("thread: %d, start time: %"PRIu64" %s\n",
+ th->tid, th->start_time, th->dead ? "(dead)" : "");
+ return 0;
+}
+
+static int lookup_with_timestamp(struct machine *machine)
+{
+ struct thread *t1, *t2, *t3;
+ union perf_event fork = {
+ .fork = {
+ .pid = 0,
+ .tid = 0,
+ .ppid = 1,
+ .ptid = 1,
+ },
+ };
+ struct perf_sample sample = {
+ .time = 50000,
+ };
+
+ /* start_time is set to 0 */
+ t1 = machine__findnew_thread(machine, 0, 0);
+
+ if (verbose > 1) {
+ printf("========= after t1 created ==========\n");
+ machine__for_each_thread(machine, thread__print_cb, NULL);
+ }
+
+ TEST_ASSERT_VAL("wrong start time of old thread", t1->start_time == 0);
+
+ TEST_ASSERT_VAL("cannot find current thread",
+ machine__find_thread(machine, 0, 0) == t1);
+
+ TEST_ASSERT_VAL("cannot find current thread with time",
+ machine__findnew_thread_time(machine, 0, 0, 10000) == t1);
+
+ /* start_time is overwritten to new value */
+ thread__set_comm(t1, "/usr/bin/perf", 20000);
+
+ if (verbose > 1) {
+ printf("========= after t1 set comm ==========\n");
+ machine__for_each_thread(machine, thread__print_cb, NULL);
+ }
+
+ TEST_ASSERT_VAL("failed to update start time", t1->start_time == 20000);
+
+ TEST_ASSERT_VAL("should not find passed thread",
+ /* this will create yet another dead thread */
+ machine__findnew_thread_time(machine, 0, 0, 10000) != t1);
+
+ TEST_ASSERT_VAL("cannot find overwritten thread with time",
+ machine__find_thread_time(machine, 0, 0, 20000) == t1);
+
+ /* now t1 goes to dead thread tree, and create t2 */
+ machine__process_fork_event(machine, &fork, &sample);
+
+ if (verbose > 1) {
+ printf("========= after t2 forked ==========\n");
+ machine__for_each_thread(machine, thread__print_cb, NULL);
+ }
+
+ t2 = machine__find_thread(machine, 0, 0);
+ TEST_ASSERT_VAL("cannot find current thread", t2 != NULL);
+
+ TEST_ASSERT_VAL("wrong start time of new thread", t2->start_time == 50000);
+
+ TEST_ASSERT_VAL("dead thread cannot be found",
+ machine__find_thread_time(machine, 0, 0, 10000) != t1);
+
+ TEST_ASSERT_VAL("cannot find dead thread after new thread",
+ machine__find_thread_time(machine, 0, 0, 30000) == t1);
+
+ TEST_ASSERT_VAL("cannot find current thread after new thread",
+ machine__find_thread_time(machine, 0, 0, 50000) == t2);
+
+ /* now t2 goes to dead thread tree, and create t3 */
+ sample.time = 60000;
+ machine__process_fork_event(machine, &fork, &sample);
+
+ if (verbose > 1) {
+ printf("========= after t3 forked ==========\n");
+ machine__for_each_thread(machine, thread__print_cb, NULL);
+ }
+
+ t3 = machine__find_thread(machine, 0, 0);
+ TEST_ASSERT_VAL("cannot find current thread", t3 != NULL);
+
+ TEST_ASSERT_VAL("wrong start time of new thread", t3->start_time == 60000);
+
+ TEST_ASSERT_VAL("cannot find dead thread after new thread",
+ machine__findnew_thread_time(machine, 0, 0, 30000) == t1);
+
+ TEST_ASSERT_VAL("cannot find dead thread after new thread",
+ machine__findnew_thread_time(machine, 0, 0, 50000) == t2);
+
+ TEST_ASSERT_VAL("cannot find current thread after new thread",
+ machine__findnew_thread_time(machine, 0, 0, 70000) == t3);
+
+ machine__delete_threads(machine);
+ return 0;
+}
+
+static int lookup_without_timestamp(struct machine *machine)
+{
+ struct thread *t1, *t2, *t3;
+ union perf_event fork = {
+ .fork = {
+ .pid = 0,
+ .tid = 0,
+ .ppid = 1,
+ .ptid = 1,
+ },
+ };
+ struct perf_sample sample = {
+ .time = -1ULL,
+ };
+
+ t1 = machine__findnew_thread(machine, 0, 0);
+ TEST_ASSERT_VAL("cannot find current thread", t1 != NULL);
+
+ TEST_ASSERT_VAL("cannot find new thread with time",
+ machine__findnew_thread_time(machine, 0, 0, -1ULL) == t1);
+
+ machine__process_fork_event(machine, &fork, &sample);
+
+ t2 = machine__find_thread(machine, 0, 0);
+ TEST_ASSERT_VAL("cannot find current thread", t2 != NULL);
+
+ TEST_ASSERT_VAL("cannot find new thread with time",
+ machine__find_thread_time(machine, 0, 0, -1ULL) == t2);
+
+ machine__process_fork_event(machine, &fork, &sample);
+
+ t3 = machine__find_thread(machine, 0, 0);
+ TEST_ASSERT_VAL("cannot find current thread", t3 != NULL);
+
+ TEST_ASSERT_VAL("cannot find new thread with time",
+ machine__findnew_thread_time(machine, 0, 0, -1ULL) == t3);
+
+ machine__delete_threads(machine);
+ return 0;
+}
+
+int test__thread_lookup_time(void)
+{
+ struct machines machines;
+ struct machine *machine;
+
+ /*
+ * This test is to check whether it can retrieve a correct
+ * thread for a given time. When multi-file data storage is
+ * enabled, those task/comm/mmap events are processed first so
+ * the later sample should find a matching thread properly.
+ */
+ machines__init(&machines);
+ machine = &machines.host;
+
+ if (lookup_with_timestamp(machine) < 0)
+ return -1;
+
+ if (lookup_without_timestamp(machine) < 0)
+ return -1;
+
+ machines__exit(&machines);
+ return 0;
+}
--
2.1.3
next prev parent reply other threads:[~2014-12-24 7:15 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-24 7:14 [RFC/PATCHSET 00/37] perf tools: Speed-up perf report by using multi thread (v1) Namhyung Kim
2014-12-24 7:14 ` [PATCH 01/37] perf tools: Set attr.task bit for a tracking event Namhyung Kim
2014-12-31 11:25 ` Jiri Olsa
2014-12-24 7:14 ` [PATCH 02/37] perf record: Use a software dummy event to track task/mmap events Namhyung Kim
2014-12-26 16:27 ` David Ahern
2014-12-27 5:28 ` Namhyung Kim
2014-12-29 12:58 ` Adrian Hunter
2014-12-30 5:51 ` Namhyung Kim
2014-12-30 9:04 ` Adrian Hunter
2014-12-24 7:14 ` [PATCH 03/37] perf tools: Use perf_data_file__fd() consistently Namhyung Kim
2014-12-26 16:30 ` David Ahern
2014-12-27 5:30 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 04/37] perf tools: Add multi file interface to perf_data_file Namhyung Kim
2014-12-25 22:08 ` Jiri Olsa
2014-12-26 1:19 ` Namhyung Kim
2014-12-31 11:26 ` Jiri Olsa
2014-12-31 14:55 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 05/37] perf tools: Create separate mmap for dummy tracking event Namhyung Kim
2014-12-25 22:08 ` Jiri Olsa
2014-12-26 1:45 ` Namhyung Kim
2014-12-25 22:09 ` Jiri Olsa
2014-12-26 1:55 ` Namhyung Kim
2014-12-26 16:51 ` David Ahern
2014-12-27 5:32 ` Namhyung Kim
2014-12-29 13:44 ` Adrian Hunter
2014-12-30 5:57 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 06/37] perf tools: Introduce perf_evlist__mmap_multi() Namhyung Kim
2014-12-24 7:15 ` [PATCH 07/37] perf tools: Do not use __perf_session__process_events() directly Namhyung Kim
2014-12-31 11:33 ` Jiri Olsa
2014-12-24 7:15 ` [PATCH 08/37] perf tools: Handle multi-file session properly Namhyung Kim
2014-12-31 12:01 ` Jiri Olsa
2014-12-31 14:53 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 09/37] perf record: Add -M/--multi option for multi file recording Namhyung Kim
2014-12-24 7:15 ` [PATCH 10/37] perf report: Skip dummy tracking event Namhyung Kim
2014-12-24 7:15 ` [PATCH 11/37] perf tools: Introduce thread__comm_time() helpers Namhyung Kim
2014-12-26 17:00 ` David Ahern
2014-12-27 5:36 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 12/37] perf tools: Add a test case for thread comm handling Namhyung Kim
2014-12-24 7:15 ` [PATCH 13/37] perf tools: Use thread__comm_time() when adding hist entries Namhyung Kim
2014-12-25 22:53 ` Jiri Olsa
2014-12-26 2:10 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 14/37] perf tools: Convert dead thread list into rbtree Namhyung Kim
2014-12-25 23:05 ` Jiri Olsa
2014-12-26 2:26 ` Namhyung Kim
2014-12-26 17:14 ` David Ahern
2014-12-27 5:42 ` Namhyung Kim
2014-12-27 15:31 ` David Ahern
2014-12-28 13:24 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 15/37] perf tools: Introduce machine__find*_thread_time() Namhyung Kim
2014-12-27 16:33 ` David Ahern
2014-12-28 14:50 ` Namhyung Kim
2014-12-24 7:15 ` Namhyung Kim [this message]
2014-12-31 14:17 ` [PATCH 16/37] perf tools: Add a test case for timed thread handling Jiri Olsa
2014-12-31 15:32 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 17/37] perf tools: Maintain map groups list in a leader thread Namhyung Kim
2014-12-24 7:15 ` [PATCH 18/37] perf tools: Remove thread when map groups initialization failed Namhyung Kim
2014-12-28 0:45 ` David Ahern
2014-12-29 7:08 ` Namhyung Kim
2014-12-24 7:15 ` [PATCH 19/37] perf tools: Introduce thread__find_addr_location_time() and friends Namhyung Kim
2014-12-24 7:15 ` [PATCH 20/37] perf tools: Add a test case for timed map groups handling Namhyung Kim
2014-12-24 7:15 ` [PATCH 21/37] perf tools: Protect dso symbol loading using a mutex Namhyung Kim
2014-12-24 7:15 ` [PATCH 22/37] perf tools: Protect dso cache tree using dso->lock Namhyung Kim
2014-12-24 7:15 ` [PATCH 23/37] perf tools: Protect dso cache fd with a mutex Namhyung Kim
2014-12-24 7:15 ` [PATCH 24/37] perf session: Pass struct events stats to event processing functions Namhyung Kim
2014-12-24 7:15 ` [PATCH 25/37] perf hists: Pass hists struct to hist_entry_iter functions Namhyung Kim
2014-12-24 7:15 ` [PATCH 26/37] perf tools: Move BUILD_ID_SIZE definition to perf.h Namhyung Kim
2014-12-24 7:15 ` [PATCH 27/37] perf report: Parallelize perf report using multi-thread Namhyung Kim
2014-12-24 7:15 ` [PATCH 28/37] perf tools: Add missing_threads rb tree Namhyung Kim
2014-12-24 7:15 ` [PATCH 29/37] perf top: Always creates thread in the current task tree Namhyung Kim
2014-12-24 7:15 ` [PATCH 30/37] perf tools: Fix progress ui to support multi thread Namhyung Kim
2014-12-24 7:15 ` [PATCH 31/37] perf record: Show total size of multi file data Namhyung Kim
2014-12-24 7:15 ` [PATCH 32/37] perf report: Add --multi-thread option and config item Namhyung Kim
2014-12-24 7:15 ` [PATCH 33/37] perf tools: Add front cache for dso data access Namhyung Kim
2014-12-24 7:15 ` [PATCH 34/37] perf tools: Convert lseek + read to pread Namhyung Kim
2014-12-24 7:15 ` [PATCH 35/37] perf callchain: Save eh/debug frame offset for dwarf unwind Namhyung Kim
2014-12-24 7:15 ` [PATCH 36/37] perf tools: Add new perf data command Namhyung Kim
2014-12-24 7:15 ` [PATCH 37/37] perf data: Implement 'split' subcommand Namhyung Kim
2014-12-24 13:51 ` Arnaldo Carvalho de Melo
2014-12-24 14:14 ` Namhyung Kim
2014-12-24 14:45 ` Arnaldo Carvalho de Melo
2014-12-26 13:59 ` Jiri Olsa
2014-12-27 5:21 ` Namhyung Kim
2014-12-26 14:02 ` [RFC/PATCHSET 00/37] perf tools: Speed-up perf report by using multi thread (v1) Jiri Olsa
2014-12-27 5:23 ` Namhyung Kim
2015-01-05 18:48 ` Andi Kleen
2015-01-06 15:50 ` Stephane Eranian
2015-01-07 7:13 ` Namhyung Kim
2015-01-07 15:14 ` Stephane Eranian
2015-01-08 5:19 ` Namhyung Kim
2015-01-07 6:58 ` Namhyung Kim
2015-01-08 14:52 ` Andi Kleen
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=1419405333-27952-17-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=andi@firstfloor.org \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@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
all inboxes | Powered by JetHome®