All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping
@ 2016-04-20 18:59 Wang Nan
  2016-04-20 18:59 ` [PATCH v6 1/7] perf tools: Introduce trigger class Wang Nan
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Wang Nan @ 2016-04-20 18:59 UTC (permalink / raw)
  To: acme, jolsa, namhyung
  Cc: linux-kernel, pi3orama, Wang Nan, Adrian Hunter, He Kuang,
	Jiri Olsa, Masami Hiramatsu, Zefan Li

v5 -> v6: Improve trigger class: rename (Suggested by Namhyung Kim)
          toggle -> hit; don't generate functions for each trigger,
	  use generic functions instead.

	  Patch cleanup: switch auxtrace_snapshot to trigger in a
	  isolated patch (2/7).

Cc: Wang Nan <wangnan0@huawei.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com

Wang Nan (7):
  perf tools: Introduce trigger class
  perf tools: Derive trigger class from auxtrace_snapshot
  perf record: Split output into multiple files via '--switch-output'
  perf record: Force enable --timestamp-filename when --switch-output is
    provided
  perf record: Disable buildid cache options by default in switch output
    mode
  perf record: Re-synthesize tracking events after output switching
  perf record: Generate tracking events for process forked by perf

 tools/perf/Documentation/perf-record.txt |  13 +++
 tools/perf/builtin-record.c              | 173 +++++++++++++++++++++----------
 tools/perf/util/trigger.h                |  94 +++++++++++++++++
 3 files changed, 225 insertions(+), 55 deletions(-)
 create mode 100644 tools/perf/util/trigger.h

-- 
1.8.3.4

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v6 1/7] perf tools: Introduce trigger class
  2016-04-20 18:59 [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Wang Nan
@ 2016-04-20 18:59 ` Wang Nan
  2016-05-01  7:39   ` [tip:perf/core] " tip-bot for Wang Nan
  2016-04-20 18:59 ` [PATCH v6 2/7] perf tools: Derive trigger class from auxtrace_snapshot Wang Nan
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Wang Nan @ 2016-04-20 18:59 UTC (permalink / raw)
  To: acme, jolsa, namhyung
  Cc: linux-kernel, pi3orama, Wang Nan, Adrian Hunter, He Kuang,
	Jiri Olsa, Masami Hiramatsu, Zefan Li

Use 'trigger' to model operations which need to be executed when
an event (a signal, for example) is observed.

States and transits:

 OFF--(on)--> READY --(hit)--> HIT
		^               |
		|            (ready)
		|               |
		 \_____________/

is_hit and is_ready are two key functions to query the state of
a trigger. is_hit means the event already happen; is_ready means the
trigger is waiting for the event.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
 tools/perf/util/trigger.h | 94 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 tools/perf/util/trigger.h

diff --git a/tools/perf/util/trigger.h b/tools/perf/util/trigger.h
new file mode 100644
index 0000000..e97d701
--- /dev/null
+++ b/tools/perf/util/trigger.h
@@ -0,0 +1,94 @@
+#ifndef __TRIGGER_H_
+#define __TRIGGER_H_ 1
+
+#include "util/debug.h"
+#include "asm/bug.h"
+
+/*
+ * Use trigger to model operations which need to be executed when
+ * an event (a signal, for example) is observed.
+ *
+ * States and transits:
+ *
+ *
+ *  OFF--(on)--> READY --(hit)--> HIT
+ *                 ^               |
+ *                 |            (ready)
+ *                 |               |
+ *                  \_____________/
+ *
+ * is_hit and is_ready are two key functions to query the state of
+ * a trigger. is_hit means the event already happen; is_ready means the
+ * trigger is waiting for the event.
+ */
+
+struct trigger {
+	volatile enum {
+		TRIGGER_ERROR		= -2,
+		TRIGGER_OFF		= -1,
+		TRIGGER_READY		= 0,
+		TRIGGER_HIT		= 1,
+	} state;
+	const char *name;
+};
+
+#define TRIGGER_WARN_ONCE(t, exp) \
+	WARN_ONCE(t->state != exp, "trigger '%s' state transist error: %d in %s()\n", \
+		  t->name, t->state, __func__)
+
+static inline bool trigger_is_available(struct trigger *t)
+{
+	return t->state >= 0;
+}
+
+static inline bool trigger_is_error(struct trigger *t)
+{
+	return t->state <= TRIGGER_ERROR;
+}
+
+static inline void trigger_on(struct trigger *t)
+{
+	TRIGGER_WARN_ONCE(t, TRIGGER_OFF);
+	t->state = TRIGGER_READY;
+}
+
+static inline void trigger_ready(struct trigger *t)
+{
+	if (!trigger_is_available(t))
+		return;
+	t->state = TRIGGER_READY;
+}
+
+static inline void trigger_hit(struct trigger *t)
+{
+	if (!trigger_is_available(t))
+		return;
+	TRIGGER_WARN_ONCE(t, TRIGGER_READY);
+	t->state = TRIGGER_HIT;
+}
+
+static inline void trigger_off(struct trigger *t)
+{
+	if (!trigger_is_available(t))
+		return;
+	t->state = TRIGGER_OFF;
+}
+
+static inline void trigger_error(struct trigger *t)
+{
+	t->state = TRIGGER_ERROR;
+}
+
+static inline bool trigger_is_ready(struct trigger *t)
+{
+	return t->state == TRIGGER_READY;
+}
+
+static inline bool trigger_is_hit(struct trigger *t)
+{
+	return t->state == TRIGGER_HIT;
+}
+
+#define DEFINE_TRIGGER(n) \
+struct trigger n = {.state = TRIGGER_OFF, .name = #n}
+#endif
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 2/7] perf tools: Derive trigger class from auxtrace_snapshot
  2016-04-20 18:59 [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Wang Nan
  2016-04-20 18:59 ` [PATCH v6 1/7] perf tools: Introduce trigger class Wang Nan
@ 2016-04-20 18:59 ` Wang Nan
  2016-04-26 13:54   ` Arnaldo Carvalho de Melo
  2016-05-01  7:39   ` [tip:perf/core] " tip-bot for Wang Nan
  2016-04-20 18:59 ` [PATCH v6 3/7] perf record: Split output into multiple files via '--switch-output' Wang Nan
                   ` (6 subsequent siblings)
  8 siblings, 2 replies; 20+ messages in thread
From: Wang Nan @ 2016-04-20 18:59 UTC (permalink / raw)
  To: acme, jolsa, namhyung
  Cc: linux-kernel, pi3orama, Wang Nan, Adrian Hunter, He Kuang,
	Jiri Olsa, Masami Hiramatsu, Zefan Li

auxtrace_snapshot_state matches trigger model. Use trigger to implement
it. auxtrace_snapshot_state and auxtrace_snapshot_err are absorbed.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
 tools/perf/builtin-record.c | 73 +++++++++++++--------------------------------
 1 file changed, 20 insertions(+), 53 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index bd95933..f4710c8 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -34,6 +34,7 @@
 #include "util/parse-regs-options.h"
 #include "util/llvm-utils.h"
 #include "util/bpf-loader.h"
+#include "util/trigger.h"
 #include "asm/bug.h"
 
 #include <unistd.h>
@@ -127,44 +128,8 @@ static volatile int done;
 static volatile int signr = -1;
 static volatile int child_finished;
 
-static volatile enum {
-	AUXTRACE_SNAPSHOT_OFF = -1,
-	AUXTRACE_SNAPSHOT_DISABLED = 0,
-	AUXTRACE_SNAPSHOT_ENABLED = 1,
-} auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_OFF;
-
-static inline void
-auxtrace_snapshot_on(void)
-{
-	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
-}
-
-static inline void
-auxtrace_snapshot_enable(void)
-{
-	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
-		return;
-	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_ENABLED;
-}
-
-static inline void
-auxtrace_snapshot_disable(void)
-{
-	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
-		return;
-	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
-}
-
-static inline bool
-auxtrace_snapshot_is_enabled(void)
-{
-	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
-		return false;
-	return auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_ENABLED;
-}
-
-static volatile int auxtrace_snapshot_err;
 static volatile int auxtrace_record__snapshot_started;
+static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
 
 static void sig_handler(int sig)
 {
@@ -282,11 +247,12 @@ static void record__read_auxtrace_snapshot(struct record *rec)
 {
 	pr_debug("Recording AUX area tracing snapshot\n");
 	if (record__auxtrace_read_snapshot_all(rec) < 0) {
-		auxtrace_snapshot_err = -1;
+		trigger_error(&auxtrace_snapshot_trigger);
 	} else {
-		auxtrace_snapshot_err = auxtrace_record__snapshot_finish(rec->itr);
-		if (!auxtrace_snapshot_err)
-			auxtrace_snapshot_enable();
+		if (auxtrace_record__snapshot_finish(rec->itr))
+			trigger_error(&auxtrace_snapshot_trigger);
+		else
+			trigger_ready(&auxtrace_snapshot_trigger);
 	}
 }
 
@@ -686,7 +652,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 
 	if (rec->opts.auxtrace_snapshot_mode) {
 		signal(SIGUSR2, snapshot_sig_handler);
-		auxtrace_snapshot_on();
+		trigger_on(&auxtrace_snapshot_trigger);
 	} else {
 		signal(SIGUSR2, SIG_IGN);
 	}
@@ -815,21 +781,21 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 		perf_evlist__enable(rec->evlist);
 	}
 
-	auxtrace_snapshot_enable();
+	trigger_ready(&auxtrace_snapshot_trigger);
 	for (;;) {
 		unsigned long long hits = rec->samples;
 
 		if (record__mmap_read_all(rec) < 0) {
-			auxtrace_snapshot_disable();
+			trigger_error(&auxtrace_snapshot_trigger);
 			err = -1;
 			goto out_child;
 		}
 
 		if (auxtrace_record__snapshot_started) {
 			auxtrace_record__snapshot_started = 0;
-			if (!auxtrace_snapshot_err)
+			if (!trigger_is_error(&auxtrace_snapshot_trigger))
 				record__read_auxtrace_snapshot(rec);
-			if (auxtrace_snapshot_err) {
+			if (trigger_is_error(&auxtrace_snapshot_trigger)) {
 				pr_err("AUX area tracing snapshot failed\n");
 				err = -1;
 				goto out_child;
@@ -858,12 +824,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 		 * disable events in this case.
 		 */
 		if (done && !disabled && !target__none(&opts->target)) {
-			auxtrace_snapshot_disable();
+			trigger_off(&auxtrace_snapshot_trigger);
 			perf_evlist__disable(rec->evlist);
 			disabled = true;
 		}
 	}
-	auxtrace_snapshot_disable();
+	trigger_off(&auxtrace_snapshot_trigger);
 
 	if (forks && workload_exec_errno) {
 		char msg[STRERR_BUFSIZE];
@@ -1445,9 +1411,10 @@ out_symbol_exit:
 
 static void snapshot_sig_handler(int sig __maybe_unused)
 {
-	if (!auxtrace_snapshot_is_enabled())
-		return;
-	auxtrace_snapshot_disable();
-	auxtrace_snapshot_err = auxtrace_record__snapshot_start(record.itr);
-	auxtrace_record__snapshot_started = 1;
+	if (trigger_is_ready(&auxtrace_snapshot_trigger)) {
+		trigger_hit(&auxtrace_snapshot_trigger);
+		auxtrace_record__snapshot_started = 1;
+		if (auxtrace_record__snapshot_start(record.itr))
+			trigger_error(&auxtrace_snapshot_trigger);
+	}
 }
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 3/7] perf record: Split output into multiple files via '--switch-output'
  2016-04-20 18:59 [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Wang Nan
  2016-04-20 18:59 ` [PATCH v6 1/7] perf tools: Introduce trigger class Wang Nan
  2016-04-20 18:59 ` [PATCH v6 2/7] perf tools: Derive trigger class from auxtrace_snapshot Wang Nan
@ 2016-04-20 18:59 ` Wang Nan
  2016-04-27 21:32   ` Arnaldo Carvalho de Melo
  2016-05-01  7:39   ` [tip:perf/core] " tip-bot for Wang Nan
  2016-04-20 18:59 ` [PATCH v6 4/7] perf record: Force enable --timestamp-filename when --switch-output is provided Wang Nan
                   ` (5 subsequent siblings)
  8 siblings, 2 replies; 20+ messages in thread
From: Wang Nan @ 2016-04-20 18:59 UTC (permalink / raw)
  To: acme, jolsa, namhyung
  Cc: linux-kernel, pi3orama, Wang Nan, Adrian Hunter, Jiri Olsa,
	Masami Hiramatsu, Zefan Li, He Kuang, Arnaldo Carvalho de Melo

Allow 'perf record' to split its output into multiple files.

For example:

  # ~/perf record -a --timestamp-filename --switch-output &
  [1] 10763
  # kill -s SIGUSR2 10763
  [ perf record: dump data: Woken up 1 times ]
  # [ perf record: Dump perf.data.2015122622314468 ]

  # kill -s SIGUSR2 10763
  [ perf record: dump data: Woken up 1 times ]
  # [ perf record: Dump perf.data.2015122622314762 ]

  # kill -s SIGUSR2 10763
  [ perf record: dump data: Woken up 1 times ]
  #[ perf record: Dump perf.data.2015122622315171 ]

  # fg
  perf record -a --timestamp-filename --switch-output
  ^C[ perf record: Woken up 1 times to write data ]
  [ perf record: Dump perf.data.2015122622315513 ]
  [ perf record: Captured and wrote 0.014 MB perf.data.<timestamp> (296 samples) ]

  # ls -l
  total 920
  -rw------- 1 root root 797692 Dec 26 22:31 perf.data.2015122622314468
  -rw------- 1 root root  59960 Dec 26 22:31 perf.data.2015122622314762
  -rw------- 1 root root  59912 Dec 26 22:31 perf.data.2015122622315171
  -rw------- 1 root root  19220 Dec 26 22:31 perf.data.2015122622315513

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1460643725-167413-3-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
[ Added man page entry ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-record.txt |  8 ++++++++
 tools/perf/builtin-record.c              | 33 ++++++++++++++++++++++++++++++--
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 19aa175..a77a431 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -347,6 +347,14 @@ Configure all used events to run in kernel space.
 --all-user::
 Configure all used events to run in user space.
 
+--switch-output::
+Generate multiple perf.data files, timestamp prefixed, switching to a new one
+when receiving a SIGUSR2.
+
+A possible use case is to, given an external event, slice the perf.data file
+that gets then processed, possibly via a perf script, to decide if that
+particular perf.data snapshot should be kept or not.
+
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f4710c8..72246e2 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -58,6 +58,7 @@ struct record {
 	bool			no_buildid_cache_set;
 	bool			buildid_all;
 	bool			timestamp_filename;
+	bool			switch_output;
 	unsigned long long	samples;
 };
 
@@ -130,6 +131,7 @@ static volatile int child_finished;
 
 static volatile int auxtrace_record__snapshot_started;
 static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
+static DEFINE_TRIGGER(switch_output_trigger);
 
 static void sig_handler(int sig)
 {
@@ -650,9 +652,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 	signal(SIGINT, sig_handler);
 	signal(SIGTERM, sig_handler);
 
-	if (rec->opts.auxtrace_snapshot_mode) {
+	if (rec->opts.auxtrace_snapshot_mode || rec->switch_output) {
 		signal(SIGUSR2, snapshot_sig_handler);
-		trigger_on(&auxtrace_snapshot_trigger);
+		if (rec->opts.auxtrace_snapshot_mode)
+			trigger_on(&auxtrace_snapshot_trigger);
+		if (rec->switch_output)
+			trigger_on(&switch_output_trigger);
 	} else {
 		signal(SIGUSR2, SIG_IGN);
 	}
@@ -782,11 +787,13 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 	}
 
 	trigger_ready(&auxtrace_snapshot_trigger);
+	trigger_ready(&switch_output_trigger);
 	for (;;) {
 		unsigned long long hits = rec->samples;
 
 		if (record__mmap_read_all(rec) < 0) {
 			trigger_error(&auxtrace_snapshot_trigger);
+			trigger_error(&switch_output_trigger);
 			err = -1;
 			goto out_child;
 		}
@@ -802,6 +809,22 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 			}
 		}
 
+		if (trigger_is_hit(&switch_output_trigger)) {
+			trigger_ready(&switch_output_trigger);
+
+			if (!quiet)
+				fprintf(stderr, "[ perf record: dump data: Woken up %ld times ]\n",
+					waking);
+			waking = 0;
+			fd = record__switch_output(rec, false);
+			if (fd < 0) {
+				pr_err("Failed to switch to new file\n");
+				trigger_error(&switch_output_trigger);
+				err = fd;
+				goto out_child;
+			}
+		}
+
 		if (hits == rec->samples) {
 			if (done || draining)
 				break;
@@ -830,6 +853,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 		}
 	}
 	trigger_off(&auxtrace_snapshot_trigger);
+	trigger_off(&switch_output_trigger);
 
 	if (forks && workload_exec_errno) {
 		char msg[STRERR_BUFSIZE];
@@ -1263,6 +1287,8 @@ struct option __record_options[] = {
 		    "Record build-id of all DSOs regardless of hits"),
 	OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
 		    "append timestamp to output filename"),
+	OPT_BOOLEAN(0, "switch-output", &record.switch_output,
+		    "Switch output when receive SIGUSR2"),
 	OPT_END()
 };
 
@@ -1417,4 +1443,7 @@ static void snapshot_sig_handler(int sig __maybe_unused)
 		if (auxtrace_record__snapshot_start(record.itr))
 			trigger_error(&auxtrace_snapshot_trigger);
 	}
+
+	if (trigger_is_ready(&switch_output_trigger))
+		trigger_hit(&switch_output_trigger);
 }
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 4/7] perf record: Force enable --timestamp-filename when --switch-output is provided
  2016-04-20 18:59 [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Wang Nan
                   ` (2 preceding siblings ...)
  2016-04-20 18:59 ` [PATCH v6 3/7] perf record: Split output into multiple files via '--switch-output' Wang Nan
@ 2016-04-20 18:59 ` Wang Nan
  2016-05-01  7:40   ` [tip:perf/core] " tip-bot for Wang Nan
  2016-04-20 18:59 ` [PATCH v6 5/7] perf record: Disable buildid cache options by default in switch output mode Wang Nan
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Wang Nan @ 2016-04-20 18:59 UTC (permalink / raw)
  To: acme, jolsa, namhyung
  Cc: linux-kernel, pi3orama, Wang Nan, Adrian Hunter, Jiri Olsa,
	Masami Hiramatsu, Zefan Li, He Kuang, Arnaldo Carvalho de Melo

Without this patch, the last output doesn't have timestamp appended if
--timestamp-filename is not explicitly provided. For example:

  # perf record -a --switch-output &
  [1] 11224
  # kill -s SIGUSR2 11224
  [ perf record: dump data: Woken up 1 times ]
  # [ perf record: Dump perf.data.2015122622372823 ]

  # fg
  perf record -a --switch-output
  ^C[ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.027 MB perf.data (540 samples) ]

  # ls -l
  total 836
  -rw------- 1 root root  33256 Dec 26 22:37 perf.data   <---- *Odd*
  -rw------- 1 root root 817156 Dec 26 22:37 perf.data.2015122622372823

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1460643725-167413-4-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
[ Updated man page, that also got an entry for --timestamp-filename ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-record.txt | 5 +++++
 tools/perf/builtin-record.c              | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index a77a431..79a8a14 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -347,6 +347,9 @@ Configure all used events to run in kernel space.
 --all-user::
 Configure all used events to run in user space.
 
+--timestamp-filename
+Append timestamp to output file name.
+
 --switch-output::
 Generate multiple perf.data files, timestamp prefixed, switching to a new one
 when receiving a SIGUSR2.
@@ -355,6 +358,8 @@ A possible use case is to, given an external event, slice the perf.data file
 that gets then processed, possibly via a perf script, to decide if that
 particular perf.data snapshot should be kept or not.
 
+Implies --timestamp-filename.
+
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 72246e2..3676af4 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1344,6 +1344,9 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
 		return -EINVAL;
 	}
 
+	if (rec->switch_output)
+		rec->timestamp_filename = true;
+
 	if (!rec->itr) {
 		rec->itr = auxtrace_record__init(rec->evlist, &err);
 		if (err)
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 5/7] perf record: Disable buildid cache options by default in switch output mode
  2016-04-20 18:59 [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Wang Nan
                   ` (3 preceding siblings ...)
  2016-04-20 18:59 ` [PATCH v6 4/7] perf record: Force enable --timestamp-filename when --switch-output is provided Wang Nan
@ 2016-04-20 18:59 ` Wang Nan
  2016-05-01  7:40   ` [tip:perf/core] " tip-bot for Wang Nan
  2016-04-20 18:59 ` [PATCH v6 6/7] perf record: Re-synthesize tracking events after output switching Wang Nan
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Wang Nan @ 2016-04-20 18:59 UTC (permalink / raw)
  To: acme, jolsa, namhyung
  Cc: linux-kernel, pi3orama, Wang Nan, Adrian Hunter, Jiri Olsa,
	Masami Hiramatsu, Zefan Li, He Kuang, Arnaldo Carvalho de Melo

The cost of buildid cache processing is high: reading all events in
output perf.data, opening each elf file to read buildids then copying
them into ~/.debug directory. In switch output mode, these heavy works
block perf from receiving perf events for too long.

Enable no-buildid and no-buildid-cache by default if --switch-output
is provided. Still allow user use --no-no-buildid to explicitly enable
buildid in this case.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1460643725-167413-5-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
[ Updated man page ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-record.txt |  2 +-
 tools/perf/builtin-record.c              | 30 +++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 79a8a14..8dbee83 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -358,7 +358,7 @@ A possible use case is to, given an external event, slice the perf.data file
 that gets then processed, possibly via a perf script, to decide if that
 particular perf.data snapshot should be kept or not.
 
-Implies --timestamp-filename.
+Implies --timestamp-filename, --no-buildid and --no-buildid-cache.
 
 SEE ALSO
 --------
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3676af4..3ae1afd 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1380,8 +1380,36 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
 "If some relocation was applied (e.g. kexec) symbols may be misresolved\n"
 "even with a suitable vmlinux or kallsyms file.\n\n");
 
-	if (rec->no_buildid_cache || rec->no_buildid)
+	if (rec->no_buildid_cache || rec->no_buildid) {
 		disable_buildid_cache();
+	} else if (rec->switch_output) {
+		/*
+		 * In 'perf record --switch-output', disable buildid
+		 * generation by default to reduce data file switching
+		 * overhead. Still generate buildid if they are required
+		 * explicitly using
+		 *
+		 *  perf record --signal-trigger --no-no-buildid \
+		 *              --no-no-buildid-cache
+		 *
+		 * Following code equals to:
+		 *
+		 * if ((rec->no_buildid || !rec->no_buildid_set) &&
+		 *     (rec->no_buildid_cache || !rec->no_buildid_cache_set))
+		 *         disable_buildid_cache();
+		 */
+		bool disable = true;
+
+		if (rec->no_buildid_set && !rec->no_buildid)
+			disable = false;
+		if (rec->no_buildid_cache_set && !rec->no_buildid_cache)
+			disable = false;
+		if (disable) {
+			rec->no_buildid = true;
+			rec->no_buildid_cache = true;
+			disable_buildid_cache();
+		}
+	}
 
 	if (rec->evlist->nr_entries == 0 &&
 	    perf_evlist__add_default(rec->evlist) < 0) {
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 6/7] perf record: Re-synthesize tracking events after output switching
  2016-04-20 18:59 [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Wang Nan
                   ` (4 preceding siblings ...)
  2016-04-20 18:59 ` [PATCH v6 5/7] perf record: Disable buildid cache options by default in switch output mode Wang Nan
@ 2016-04-20 18:59 ` Wang Nan
  2016-04-20 18:59 ` [PATCH v6 7/7] perf record: Generate tracking events for process forked by perf Wang Nan
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Wang Nan @ 2016-04-20 18:59 UTC (permalink / raw)
  To: acme, jolsa, namhyung
  Cc: linux-kernel, pi3orama, Wang Nan, Adrian Hunter, He Kuang,
	Jiri Olsa, Masami Hiramatsu, Zefan Li, Arnaldo Carvalho de Melo

Tracking events describe kernel and threads. They are generated by
reading /proc/kallsyms, /proc/*/maps and /proc/*/task/* during
initialization of 'perf record', serialized into event sequences and put
at the head of 'perf.data'. In case of output switching, each output
file should contain those events.

This patch calls record__synthesize() during output switching, so the
event sequences described above can be collected again.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1460643725-167413-6-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-record.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3ae1afd..178b49e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -500,6 +500,8 @@ record__finish_output(struct record *rec)
 	return;
 }
 
+static int record__synthesize(struct record *rec);
+
 static int
 record__switch_output(struct record *rec, bool at_exit)
 {
@@ -528,6 +530,11 @@ record__switch_output(struct record *rec, bool at_exit)
 	if (!quiet)
 		fprintf(stderr, "[ perf record: Dump %s.%s ]\n",
 			file->path, timestamp);
+
+	/* Output tracking events */
+	if (!at_exit)
+		record__synthesize(rec);
+
 	return fd;
 }
 
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 7/7] perf record: Generate tracking events for process forked by perf
  2016-04-20 18:59 [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Wang Nan
                   ` (5 preceding siblings ...)
  2016-04-20 18:59 ` [PATCH v6 6/7] perf record: Re-synthesize tracking events after output switching Wang Nan
@ 2016-04-20 18:59 ` Wang Nan
  2016-05-01  7:41   ` [tip:perf/core] " tip-bot for Wang Nan
  2016-04-22 10:30 ` [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Jiri Olsa
  2016-04-27 21:40 ` Arnaldo Carvalho de Melo
  8 siblings, 1 reply; 20+ messages in thread
From: Wang Nan @ 2016-04-20 18:59 UTC (permalink / raw)
  To: acme, jolsa, namhyung
  Cc: linux-kernel, pi3orama, Wang Nan, Adrian Hunter, Jiri Olsa,
	Masami Hiramatsu, Zefan Li, He Kuang, Arnaldo Carvalho de Melo

With 'perf record --switch-output' without -a, record__synthesize() in
record__switch_output() won't generate tracking events because there's
no thread_map in evlist. Which causes newly created perf.data doesn't
contain map and comm information.

This patch creates a fake thread_map and directly call
perf_event__synthesize_thread_map() for those events.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1460643725-167413-7-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-record.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 178b49e..f3679c4 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -500,6 +500,23 @@ record__finish_output(struct record *rec)
 	return;
 }
 
+static int record__synthesize_workload(struct record *rec)
+{
+	struct {
+		struct thread_map map;
+		struct thread_map_data map_data;
+	} thread_map;
+
+	thread_map.map.nr = 1;
+	thread_map.map.map[0].pid = rec->evlist->workload.pid;
+	thread_map.map.map[0].comm = NULL;
+	return perf_event__synthesize_thread_map(&rec->tool, &thread_map.map,
+						 process_synthesized_event,
+						 &rec->session->machines.host,
+						 rec->opts.sample_address,
+						 rec->opts.proc_map_timeout);
+}
+
 static int record__synthesize(struct record *rec);
 
 static int
@@ -532,9 +549,21 @@ record__switch_output(struct record *rec, bool at_exit)
 			file->path, timestamp);
 
 	/* Output tracking events */
-	if (!at_exit)
+	if (!at_exit) {
 		record__synthesize(rec);
 
+		/*
+		 * In 'perf record --switch-output' without -a,
+		 * record__synthesize() in record__switch_output() won't
+		 * generate tracking events because there's no thread_map
+		 * in evlist. Which causes newly created perf.data doesn't
+		 * contain map and comm information.
+		 * Create a fake thread_map and directly call
+		 * perf_event__synthesize_thread_map() for those events.
+		 */
+		if (target__none(&rec->opts.target))
+			record__synthesize_workload(rec);
+	}
 	return fd;
 }
 
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping
  2016-04-20 18:59 [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Wang Nan
                   ` (6 preceding siblings ...)
  2016-04-20 18:59 ` [PATCH v6 7/7] perf record: Generate tracking events for process forked by perf Wang Nan
@ 2016-04-22 10:30 ` Jiri Olsa
  2016-04-27 21:40 ` Arnaldo Carvalho de Melo
  8 siblings, 0 replies; 20+ messages in thread
From: Jiri Olsa @ 2016-04-22 10:30 UTC (permalink / raw)
  To: Wang Nan
  Cc: acme, namhyung, linux-kernel, pi3orama, Adrian Hunter, He Kuang,
	Jiri Olsa, Masami Hiramatsu, Zefan Li

On Wed, Apr 20, 2016 at 06:59:47PM +0000, Wang Nan wrote:
> v5 -> v6: Improve trigger class: rename (Suggested by Namhyung Kim)
>           toggle -> hit; don't generate functions for each trigger,
> 	  use generic functions instead.
> 
> 	  Patch cleanup: switch auxtrace_snapshot to trigger in a
> 	  isolated patch (2/7).
> 
> Cc: Wang Nan <wangnan0@huawei.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: He Kuang <hekuang@huawei.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Zefan Li <lizefan@huawei.com>
> Cc: pi3orama@163.com
> 
> Wang Nan (7):
>   perf tools: Introduce trigger class
>   perf tools: Derive trigger class from auxtrace_snapshot
>   perf record: Split output into multiple files via '--switch-output'
>   perf record: Force enable --timestamp-filename when --switch-output is
>     provided
>   perf record: Disable buildid cache options by default in switch output
>     mode
>   perf record: Re-synthesize tracking events after output switching
>   perf record: Generate tracking events for process forked by perf

for the patchset:

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 2/7] perf tools: Derive trigger class from auxtrace_snapshot
  2016-04-20 18:59 ` [PATCH v6 2/7] perf tools: Derive trigger class from auxtrace_snapshot Wang Nan
@ 2016-04-26 13:54   ` Arnaldo Carvalho de Melo
  2016-04-27  9:10     ` Adrian Hunter
  2016-05-01  7:39   ` [tip:perf/core] " tip-bot for Wang Nan
  1 sibling, 1 reply; 20+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-04-26 13:54 UTC (permalink / raw)
  To: Wang Nan
  Cc: jolsa, namhyung, linux-kernel, pi3orama, Adrian Hunter, He Kuang,
	Jiri Olsa, Masami Hiramatsu, Zefan Li

Em Wed, Apr 20, 2016 at 06:59:49PM +0000, Wang Nan escreveu:
> auxtrace_snapshot_state matches trigger model. Use trigger to implement
> it. auxtrace_snapshot_state and auxtrace_snapshot_err are absorbed.

Adrian, this is changing code you wrote, can you please take a look? An
Acked-by would be excellent,

Best Regards,

- Arnaldo
 
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: He Kuang <hekuang@huawei.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Zefan Li <lizefan@huawei.com>
> Cc: pi3orama@163.com
> ---
>  tools/perf/builtin-record.c | 73 +++++++++++++--------------------------------
>  1 file changed, 20 insertions(+), 53 deletions(-)
> 
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index bd95933..f4710c8 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -34,6 +34,7 @@
>  #include "util/parse-regs-options.h"
>  #include "util/llvm-utils.h"
>  #include "util/bpf-loader.h"
> +#include "util/trigger.h"
>  #include "asm/bug.h"
>  
>  #include <unistd.h>
> @@ -127,44 +128,8 @@ static volatile int done;
>  static volatile int signr = -1;
>  static volatile int child_finished;
>  
> -static volatile enum {
> -	AUXTRACE_SNAPSHOT_OFF = -1,
> -	AUXTRACE_SNAPSHOT_DISABLED = 0,
> -	AUXTRACE_SNAPSHOT_ENABLED = 1,
> -} auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_OFF;
> -
> -static inline void
> -auxtrace_snapshot_on(void)
> -{
> -	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
> -}
> -
> -static inline void
> -auxtrace_snapshot_enable(void)
> -{
> -	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
> -		return;
> -	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_ENABLED;
> -}
> -
> -static inline void
> -auxtrace_snapshot_disable(void)
> -{
> -	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
> -		return;
> -	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
> -}
> -
> -static inline bool
> -auxtrace_snapshot_is_enabled(void)
> -{
> -	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
> -		return false;
> -	return auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_ENABLED;
> -}
> -
> -static volatile int auxtrace_snapshot_err;
>  static volatile int auxtrace_record__snapshot_started;
> +static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
>  
>  static void sig_handler(int sig)
>  {
> @@ -282,11 +247,12 @@ static void record__read_auxtrace_snapshot(struct record *rec)
>  {
>  	pr_debug("Recording AUX area tracing snapshot\n");
>  	if (record__auxtrace_read_snapshot_all(rec) < 0) {
> -		auxtrace_snapshot_err = -1;
> +		trigger_error(&auxtrace_snapshot_trigger);
>  	} else {
> -		auxtrace_snapshot_err = auxtrace_record__snapshot_finish(rec->itr);
> -		if (!auxtrace_snapshot_err)
> -			auxtrace_snapshot_enable();
> +		if (auxtrace_record__snapshot_finish(rec->itr))
> +			trigger_error(&auxtrace_snapshot_trigger);
> +		else
> +			trigger_ready(&auxtrace_snapshot_trigger);
>  	}
>  }
>  
> @@ -686,7 +652,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>  
>  	if (rec->opts.auxtrace_snapshot_mode) {
>  		signal(SIGUSR2, snapshot_sig_handler);
> -		auxtrace_snapshot_on();
> +		trigger_on(&auxtrace_snapshot_trigger);
>  	} else {
>  		signal(SIGUSR2, SIG_IGN);
>  	}
> @@ -815,21 +781,21 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>  		perf_evlist__enable(rec->evlist);
>  	}
>  
> -	auxtrace_snapshot_enable();
> +	trigger_ready(&auxtrace_snapshot_trigger);
>  	for (;;) {
>  		unsigned long long hits = rec->samples;
>  
>  		if (record__mmap_read_all(rec) < 0) {
> -			auxtrace_snapshot_disable();
> +			trigger_error(&auxtrace_snapshot_trigger);
>  			err = -1;
>  			goto out_child;
>  		}
>  
>  		if (auxtrace_record__snapshot_started) {
>  			auxtrace_record__snapshot_started = 0;
> -			if (!auxtrace_snapshot_err)
> +			if (!trigger_is_error(&auxtrace_snapshot_trigger))
>  				record__read_auxtrace_snapshot(rec);
> -			if (auxtrace_snapshot_err) {
> +			if (trigger_is_error(&auxtrace_snapshot_trigger)) {
>  				pr_err("AUX area tracing snapshot failed\n");
>  				err = -1;
>  				goto out_child;
> @@ -858,12 +824,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>  		 * disable events in this case.
>  		 */
>  		if (done && !disabled && !target__none(&opts->target)) {
> -			auxtrace_snapshot_disable();
> +			trigger_off(&auxtrace_snapshot_trigger);
>  			perf_evlist__disable(rec->evlist);
>  			disabled = true;
>  		}
>  	}
> -	auxtrace_snapshot_disable();
> +	trigger_off(&auxtrace_snapshot_trigger);
>  
>  	if (forks && workload_exec_errno) {
>  		char msg[STRERR_BUFSIZE];
> @@ -1445,9 +1411,10 @@ out_symbol_exit:
>  
>  static void snapshot_sig_handler(int sig __maybe_unused)
>  {
> -	if (!auxtrace_snapshot_is_enabled())
> -		return;
> -	auxtrace_snapshot_disable();
> -	auxtrace_snapshot_err = auxtrace_record__snapshot_start(record.itr);
> -	auxtrace_record__snapshot_started = 1;
> +	if (trigger_is_ready(&auxtrace_snapshot_trigger)) {
> +		trigger_hit(&auxtrace_snapshot_trigger);
> +		auxtrace_record__snapshot_started = 1;
> +		if (auxtrace_record__snapshot_start(record.itr))
> +			trigger_error(&auxtrace_snapshot_trigger);
> +	}
>  }
> -- 
> 1.8.3.4

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 2/7] perf tools: Derive trigger class from auxtrace_snapshot
  2016-04-26 13:54   ` Arnaldo Carvalho de Melo
@ 2016-04-27  9:10     ` Adrian Hunter
  0 siblings, 0 replies; 20+ messages in thread
From: Adrian Hunter @ 2016-04-27  9:10 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Wang Nan
  Cc: jolsa, namhyung, linux-kernel, pi3orama, He Kuang, Jiri Olsa,
	Masami Hiramatsu, Zefan Li

On 26/04/16 16:54, Arnaldo Carvalho de Melo wrote:
> Em Wed, Apr 20, 2016 at 06:59:49PM +0000, Wang Nan escreveu:
>> auxtrace_snapshot_state matches trigger model. Use trigger to implement
>> it. auxtrace_snapshot_state and auxtrace_snapshot_err are absorbed.
> 
> Adrian, this is changing code you wrote, can you please take a look? An
> Acked-by would be excellent,

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> 
> Best Regards,
> 
> - Arnaldo
>  
>> Signed-off-by: Wang Nan <wangnan0@huawei.com>
>> Cc: Adrian Hunter <adrian.hunter@intel.com>
>> Cc: He Kuang <hekuang@huawei.com>
>> Cc: Jiri Olsa <jolsa@kernel.org>
>> Cc: Masami Hiramatsu <mhiramat@kernel.org>
>> Cc: Namhyung Kim <namhyung@kernel.org>
>> Cc: Zefan Li <lizefan@huawei.com>
>> Cc: pi3orama@163.com
>> ---
>>  tools/perf/builtin-record.c | 73 +++++++++++++--------------------------------
>>  1 file changed, 20 insertions(+), 53 deletions(-)
>>
>> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
>> index bd95933..f4710c8 100644
>> --- a/tools/perf/builtin-record.c
>> +++ b/tools/perf/builtin-record.c
>> @@ -34,6 +34,7 @@
>>  #include "util/parse-regs-options.h"
>>  #include "util/llvm-utils.h"
>>  #include "util/bpf-loader.h"
>> +#include "util/trigger.h"
>>  #include "asm/bug.h"
>>  
>>  #include <unistd.h>
>> @@ -127,44 +128,8 @@ static volatile int done;
>>  static volatile int signr = -1;
>>  static volatile int child_finished;
>>  
>> -static volatile enum {
>> -	AUXTRACE_SNAPSHOT_OFF = -1,
>> -	AUXTRACE_SNAPSHOT_DISABLED = 0,
>> -	AUXTRACE_SNAPSHOT_ENABLED = 1,
>> -} auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_OFF;
>> -
>> -static inline void
>> -auxtrace_snapshot_on(void)
>> -{
>> -	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
>> -}
>> -
>> -static inline void
>> -auxtrace_snapshot_enable(void)
>> -{
>> -	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
>> -		return;
>> -	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_ENABLED;
>> -}
>> -
>> -static inline void
>> -auxtrace_snapshot_disable(void)
>> -{
>> -	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
>> -		return;
>> -	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
>> -}
>> -
>> -static inline bool
>> -auxtrace_snapshot_is_enabled(void)
>> -{
>> -	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
>> -		return false;
>> -	return auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_ENABLED;
>> -}
>> -
>> -static volatile int auxtrace_snapshot_err;
>>  static volatile int auxtrace_record__snapshot_started;
>> +static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
>>  
>>  static void sig_handler(int sig)
>>  {
>> @@ -282,11 +247,12 @@ static void record__read_auxtrace_snapshot(struct record *rec)
>>  {
>>  	pr_debug("Recording AUX area tracing snapshot\n");
>>  	if (record__auxtrace_read_snapshot_all(rec) < 0) {
>> -		auxtrace_snapshot_err = -1;
>> +		trigger_error(&auxtrace_snapshot_trigger);
>>  	} else {
>> -		auxtrace_snapshot_err = auxtrace_record__snapshot_finish(rec->itr);
>> -		if (!auxtrace_snapshot_err)
>> -			auxtrace_snapshot_enable();
>> +		if (auxtrace_record__snapshot_finish(rec->itr))
>> +			trigger_error(&auxtrace_snapshot_trigger);
>> +		else
>> +			trigger_ready(&auxtrace_snapshot_trigger);
>>  	}
>>  }
>>  
>> @@ -686,7 +652,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>>  
>>  	if (rec->opts.auxtrace_snapshot_mode) {
>>  		signal(SIGUSR2, snapshot_sig_handler);
>> -		auxtrace_snapshot_on();
>> +		trigger_on(&auxtrace_snapshot_trigger);
>>  	} else {
>>  		signal(SIGUSR2, SIG_IGN);
>>  	}
>> @@ -815,21 +781,21 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>>  		perf_evlist__enable(rec->evlist);
>>  	}
>>  
>> -	auxtrace_snapshot_enable();
>> +	trigger_ready(&auxtrace_snapshot_trigger);
>>  	for (;;) {
>>  		unsigned long long hits = rec->samples;
>>  
>>  		if (record__mmap_read_all(rec) < 0) {
>> -			auxtrace_snapshot_disable();
>> +			trigger_error(&auxtrace_snapshot_trigger);
>>  			err = -1;
>>  			goto out_child;
>>  		}
>>  
>>  		if (auxtrace_record__snapshot_started) {
>>  			auxtrace_record__snapshot_started = 0;
>> -			if (!auxtrace_snapshot_err)
>> +			if (!trigger_is_error(&auxtrace_snapshot_trigger))
>>  				record__read_auxtrace_snapshot(rec);
>> -			if (auxtrace_snapshot_err) {
>> +			if (trigger_is_error(&auxtrace_snapshot_trigger)) {
>>  				pr_err("AUX area tracing snapshot failed\n");
>>  				err = -1;
>>  				goto out_child;
>> @@ -858,12 +824,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>>  		 * disable events in this case.
>>  		 */
>>  		if (done && !disabled && !target__none(&opts->target)) {
>> -			auxtrace_snapshot_disable();
>> +			trigger_off(&auxtrace_snapshot_trigger);
>>  			perf_evlist__disable(rec->evlist);
>>  			disabled = true;
>>  		}
>>  	}
>> -	auxtrace_snapshot_disable();
>> +	trigger_off(&auxtrace_snapshot_trigger);
>>  
>>  	if (forks && workload_exec_errno) {
>>  		char msg[STRERR_BUFSIZE];
>> @@ -1445,9 +1411,10 @@ out_symbol_exit:
>>  
>>  static void snapshot_sig_handler(int sig __maybe_unused)
>>  {
>> -	if (!auxtrace_snapshot_is_enabled())
>> -		return;
>> -	auxtrace_snapshot_disable();
>> -	auxtrace_snapshot_err = auxtrace_record__snapshot_start(record.itr);
>> -	auxtrace_record__snapshot_started = 1;
>> +	if (trigger_is_ready(&auxtrace_snapshot_trigger)) {
>> +		trigger_hit(&auxtrace_snapshot_trigger);
>> +		auxtrace_record__snapshot_started = 1;
>> +		if (auxtrace_record__snapshot_start(record.itr))
>> +			trigger_error(&auxtrace_snapshot_trigger);
>> +	}
>>  }
>> -- 
>> 1.8.3.4
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 3/7] perf record: Split output into multiple files via '--switch-output'
  2016-04-20 18:59 ` [PATCH v6 3/7] perf record: Split output into multiple files via '--switch-output' Wang Nan
@ 2016-04-27 21:32   ` Arnaldo Carvalho de Melo
  2016-04-29  4:56     ` Wangnan (F)
  2016-05-01  7:39   ` [tip:perf/core] " tip-bot for Wang Nan
  1 sibling, 1 reply; 20+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-04-27 21:32 UTC (permalink / raw)
  To: Wang Nan
  Cc: jolsa, namhyung, linux-kernel, pi3orama, Adrian Hunter,
	Jiri Olsa, Masami Hiramatsu, Zefan Li, He Kuang,
	Arnaldo Carvalho de Melo

Em Wed, Apr 20, 2016 at 06:59:50PM +0000, Wang Nan escreveu:
> Allow 'perf record' to split its output into multiple files.
> 
> For example:

I squashed:

->  360   T 04/20 Wang Nan        (1.7K) ├─>[PATCH v6 6/7]
perf record: Re-synthesize tracking events after output switching

Into this patch, so that we don't have the problem in the bisection
history where samples don't get resolved to the existing threads not
synthesized in the perf.data.N where N > the first timestamp.

Please holler if you disagree, I doubt you will tho :-)

- Arnaldo

 
>   # ~/perf record -a --timestamp-filename --switch-output &
>   [1] 10763
>   # kill -s SIGUSR2 10763
>   [ perf record: dump data: Woken up 1 times ]
>   # [ perf record: Dump perf.data.2015122622314468 ]
> 
>   # kill -s SIGUSR2 10763
>   [ perf record: dump data: Woken up 1 times ]
>   # [ perf record: Dump perf.data.2015122622314762 ]
> 
>   # kill -s SIGUSR2 10763
>   [ perf record: dump data: Woken up 1 times ]
>   #[ perf record: Dump perf.data.2015122622315171 ]
> 
>   # fg
>   perf record -a --timestamp-filename --switch-output
>   ^C[ perf record: Woken up 1 times to write data ]
>   [ perf record: Dump perf.data.2015122622315513 ]
>   [ perf record: Captured and wrote 0.014 MB perf.data.<timestamp> (296 samples) ]
> 
>   # ls -l
>   total 920
>   -rw------- 1 root root 797692 Dec 26 22:31 perf.data.2015122622314468
>   -rw------- 1 root root  59960 Dec 26 22:31 perf.data.2015122622314762
>   -rw------- 1 root root  59912 Dec 26 22:31 perf.data.2015122622315171
>   -rw------- 1 root root  19220 Dec 26 22:31 perf.data.2015122622315513
> 
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Zefan Li <lizefan@huawei.com>
> Cc: pi3orama@163.com
> Link: http://lkml.kernel.org/r/1460643725-167413-3-git-send-email-wangnan0@huawei.com
> Signed-off-by: He Kuang <hekuang@huawei.com>
> [ Added man page entry ]
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/Documentation/perf-record.txt |  8 ++++++++
>  tools/perf/builtin-record.c              | 33 ++++++++++++++++++++++++++++++--
>  2 files changed, 39 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
> index 19aa175..a77a431 100644
> --- a/tools/perf/Documentation/perf-record.txt
> +++ b/tools/perf/Documentation/perf-record.txt
> @@ -347,6 +347,14 @@ Configure all used events to run in kernel space.
>  --all-user::
>  Configure all used events to run in user space.
>  
> +--switch-output::
> +Generate multiple perf.data files, timestamp prefixed, switching to a new one
> +when receiving a SIGUSR2.
> +
> +A possible use case is to, given an external event, slice the perf.data file
> +that gets then processed, possibly via a perf script, to decide if that
> +particular perf.data snapshot should be kept or not.
> +
>  SEE ALSO
>  --------
>  linkperf:perf-stat[1], linkperf:perf-list[1]
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index f4710c8..72246e2 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -58,6 +58,7 @@ struct record {
>  	bool			no_buildid_cache_set;
>  	bool			buildid_all;
>  	bool			timestamp_filename;
> +	bool			switch_output;
>  	unsigned long long	samples;
>  };
>  
> @@ -130,6 +131,7 @@ static volatile int child_finished;
>  
>  static volatile int auxtrace_record__snapshot_started;
>  static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
> +static DEFINE_TRIGGER(switch_output_trigger);
>  
>  static void sig_handler(int sig)
>  {
> @@ -650,9 +652,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>  	signal(SIGINT, sig_handler);
>  	signal(SIGTERM, sig_handler);
>  
> -	if (rec->opts.auxtrace_snapshot_mode) {
> +	if (rec->opts.auxtrace_snapshot_mode || rec->switch_output) {
>  		signal(SIGUSR2, snapshot_sig_handler);
> -		trigger_on(&auxtrace_snapshot_trigger);
> +		if (rec->opts.auxtrace_snapshot_mode)
> +			trigger_on(&auxtrace_snapshot_trigger);
> +		if (rec->switch_output)
> +			trigger_on(&switch_output_trigger);
>  	} else {
>  		signal(SIGUSR2, SIG_IGN);
>  	}
> @@ -782,11 +787,13 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>  	}
>  
>  	trigger_ready(&auxtrace_snapshot_trigger);
> +	trigger_ready(&switch_output_trigger);
>  	for (;;) {
>  		unsigned long long hits = rec->samples;
>  
>  		if (record__mmap_read_all(rec) < 0) {
>  			trigger_error(&auxtrace_snapshot_trigger);
> +			trigger_error(&switch_output_trigger);
>  			err = -1;
>  			goto out_child;
>  		}
> @@ -802,6 +809,22 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>  			}
>  		}
>  
> +		if (trigger_is_hit(&switch_output_trigger)) {
> +			trigger_ready(&switch_output_trigger);
> +
> +			if (!quiet)
> +				fprintf(stderr, "[ perf record: dump data: Woken up %ld times ]\n",
> +					waking);
> +			waking = 0;
> +			fd = record__switch_output(rec, false);
> +			if (fd < 0) {
> +				pr_err("Failed to switch to new file\n");
> +				trigger_error(&switch_output_trigger);
> +				err = fd;
> +				goto out_child;
> +			}
> +		}
> +
>  		if (hits == rec->samples) {
>  			if (done || draining)
>  				break;
> @@ -830,6 +853,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>  		}
>  	}
>  	trigger_off(&auxtrace_snapshot_trigger);
> +	trigger_off(&switch_output_trigger);
>  
>  	if (forks && workload_exec_errno) {
>  		char msg[STRERR_BUFSIZE];
> @@ -1263,6 +1287,8 @@ struct option __record_options[] = {
>  		    "Record build-id of all DSOs regardless of hits"),
>  	OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
>  		    "append timestamp to output filename"),
> +	OPT_BOOLEAN(0, "switch-output", &record.switch_output,
> +		    "Switch output when receive SIGUSR2"),
>  	OPT_END()
>  };
>  
> @@ -1417,4 +1443,7 @@ static void snapshot_sig_handler(int sig __maybe_unused)
>  		if (auxtrace_record__snapshot_start(record.itr))
>  			trigger_error(&auxtrace_snapshot_trigger);
>  	}
> +
> +	if (trigger_is_ready(&switch_output_trigger))
> +		trigger_hit(&switch_output_trigger);
>  }
> -- 
> 1.8.3.4

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping
  2016-04-20 18:59 [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Wang Nan
                   ` (7 preceding siblings ...)
  2016-04-22 10:30 ` [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Jiri Olsa
@ 2016-04-27 21:40 ` Arnaldo Carvalho de Melo
  8 siblings, 0 replies; 20+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-04-27 21:40 UTC (permalink / raw)
  To: Wang Nan
  Cc: jolsa, namhyung, linux-kernel, pi3orama, Adrian Hunter, He Kuang,
	Jiri Olsa, Masami Hiramatsu, Zefan Li

Em Wed, Apr 20, 2016 at 06:59:47PM +0000, Wang Nan escreveu:
> v5 -> v6: Improve trigger class: rename (Suggested by Namhyung Kim)
>           toggle -> hit; don't generate functions for each trigger,
> 	  use generic functions instead.
> 
> 	  Patch cleanup: switch auxtrace_snapshot to trigger in a
> 	  isolated patch (2/7).

Applied to my perf/core branch, please check if all is well as I merged
two patches into one to avoid missing synthesized entries in the
bisection history.

- Arnaldo

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 3/7] perf record: Split output into multiple files via '--switch-output'
  2016-04-27 21:32   ` Arnaldo Carvalho de Melo
@ 2016-04-29  4:56     ` Wangnan (F)
  0 siblings, 0 replies; 20+ messages in thread
From: Wangnan (F) @ 2016-04-29  4:56 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: jolsa, namhyung, linux-kernel, pi3orama, Adrian Hunter,
	Jiri Olsa, Masami Hiramatsu, Zefan Li, He Kuang,
	Arnaldo Carvalho de Melo



On 2016/4/28 5:32, Arnaldo Carvalho de Melo wrote:
> Em Wed, Apr 20, 2016 at 06:59:50PM +0000, Wang Nan escreveu:
>> Allow 'perf record' to split its output into multiple files.
>>
>> For example:
> I squashed:
>
> ->  360   T 04/20 Wang Nan        (1.7K) ├─>[PATCH v6 6/7]
> perf record: Re-synthesize tracking events after output switching
>
> Into this patch, so that we don't have the problem in the bisection
> history where samples don't get resolved to the existing threads not
> synthesized in the perf.data.N where N > the first timestamp.
>
> Please holler if you disagree, I doubt you will tho :-)

Sorry for the late. I'm okay for your work.

Thank you.

> - Arnaldo
>
>   
>>    # ~/perf record -a --timestamp-filename --switch-output &
>>    [1] 10763
>>    # kill -s SIGUSR2 10763
>>    [ perf record: dump data: Woken up 1 times ]
>>    # [ perf record: Dump perf.data.2015122622314468 ]
>>
>>    # kill -s SIGUSR2 10763
>>    [ perf record: dump data: Woken up 1 times ]
>>    # [ perf record: Dump perf.data.2015122622314762 ]
>>
>>    # kill -s SIGUSR2 10763
>>    [ perf record: dump data: Woken up 1 times ]
>>    #[ perf record: Dump perf.data.2015122622315171 ]
>>
>>    # fg
>>    perf record -a --timestamp-filename --switch-output
>>    ^C[ perf record: Woken up 1 times to write data ]
>>    [ perf record: Dump perf.data.2015122622315513 ]
>>    [ perf record: Captured and wrote 0.014 MB perf.data.<timestamp> (296 samples) ]
>>
>>    # ls -l
>>    total 920
>>    -rw------- 1 root root 797692 Dec 26 22:31 perf.data.2015122622314468
>>    -rw------- 1 root root  59960 Dec 26 22:31 perf.data.2015122622314762
>>    -rw------- 1 root root  59912 Dec 26 22:31 perf.data.2015122622315171
>>    -rw------- 1 root root  19220 Dec 26 22:31 perf.data.2015122622315513
>>
>> Signed-off-by: Wang Nan <wangnan0@huawei.com>
>> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>> Cc: Adrian Hunter <adrian.hunter@intel.com>
>> Cc: Jiri Olsa <jolsa@kernel.org>
>> Cc: Masami Hiramatsu <mhiramat@kernel.org>
>> Cc: Namhyung Kim <namhyung@kernel.org>
>> Cc: Zefan Li <lizefan@huawei.com>
>> Cc: pi3orama@163.com
>> Link: http://lkml.kernel.org/r/1460643725-167413-3-git-send-email-wangnan0@huawei.com
>> Signed-off-by: He Kuang <hekuang@huawei.com>
>> [ Added man page entry ]
>> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>> ---
>>   tools/perf/Documentation/perf-record.txt |  8 ++++++++
>>   tools/perf/builtin-record.c              | 33 ++++++++++++++++++++++++++++++--
>>   2 files changed, 39 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
>> index 19aa175..a77a431 100644
>> --- a/tools/perf/Documentation/perf-record.txt
>> +++ b/tools/perf/Documentation/perf-record.txt
>> @@ -347,6 +347,14 @@ Configure all used events to run in kernel space.
>>   --all-user::
>>   Configure all used events to run in user space.
>>   
>> +--switch-output::
>> +Generate multiple perf.data files, timestamp prefixed, switching to a new one
>> +when receiving a SIGUSR2.
>> +
>> +A possible use case is to, given an external event, slice the perf.data file
>> +that gets then processed, possibly via a perf script, to decide if that
>> +particular perf.data snapshot should be kept or not.
>> +
>>   SEE ALSO
>>   --------
>>   linkperf:perf-stat[1], linkperf:perf-list[1]
>> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
>> index f4710c8..72246e2 100644
>> --- a/tools/perf/builtin-record.c
>> +++ b/tools/perf/builtin-record.c
>> @@ -58,6 +58,7 @@ struct record {
>>   	bool			no_buildid_cache_set;
>>   	bool			buildid_all;
>>   	bool			timestamp_filename;
>> +	bool			switch_output;
>>   	unsigned long long	samples;
>>   };
>>   
>> @@ -130,6 +131,7 @@ static volatile int child_finished;
>>   
>>   static volatile int auxtrace_record__snapshot_started;
>>   static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
>> +static DEFINE_TRIGGER(switch_output_trigger);
>>   
>>   static void sig_handler(int sig)
>>   {
>> @@ -650,9 +652,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>>   	signal(SIGINT, sig_handler);
>>   	signal(SIGTERM, sig_handler);
>>   
>> -	if (rec->opts.auxtrace_snapshot_mode) {
>> +	if (rec->opts.auxtrace_snapshot_mode || rec->switch_output) {
>>   		signal(SIGUSR2, snapshot_sig_handler);
>> -		trigger_on(&auxtrace_snapshot_trigger);
>> +		if (rec->opts.auxtrace_snapshot_mode)
>> +			trigger_on(&auxtrace_snapshot_trigger);
>> +		if (rec->switch_output)
>> +			trigger_on(&switch_output_trigger);
>>   	} else {
>>   		signal(SIGUSR2, SIG_IGN);
>>   	}
>> @@ -782,11 +787,13 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>>   	}
>>   
>>   	trigger_ready(&auxtrace_snapshot_trigger);
>> +	trigger_ready(&switch_output_trigger);
>>   	for (;;) {
>>   		unsigned long long hits = rec->samples;
>>   
>>   		if (record__mmap_read_all(rec) < 0) {
>>   			trigger_error(&auxtrace_snapshot_trigger);
>> +			trigger_error(&switch_output_trigger);
>>   			err = -1;
>>   			goto out_child;
>>   		}
>> @@ -802,6 +809,22 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>>   			}
>>   		}
>>   
>> +		if (trigger_is_hit(&switch_output_trigger)) {
>> +			trigger_ready(&switch_output_trigger);
>> +
>> +			if (!quiet)
>> +				fprintf(stderr, "[ perf record: dump data: Woken up %ld times ]\n",
>> +					waking);
>> +			waking = 0;
>> +			fd = record__switch_output(rec, false);
>> +			if (fd < 0) {
>> +				pr_err("Failed to switch to new file\n");
>> +				trigger_error(&switch_output_trigger);
>> +				err = fd;
>> +				goto out_child;
>> +			}
>> +		}
>> +
>>   		if (hits == rec->samples) {
>>   			if (done || draining)
>>   				break;
>> @@ -830,6 +853,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
>>   		}
>>   	}
>>   	trigger_off(&auxtrace_snapshot_trigger);
>> +	trigger_off(&switch_output_trigger);
>>   
>>   	if (forks && workload_exec_errno) {
>>   		char msg[STRERR_BUFSIZE];
>> @@ -1263,6 +1287,8 @@ struct option __record_options[] = {
>>   		    "Record build-id of all DSOs regardless of hits"),
>>   	OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
>>   		    "append timestamp to output filename"),
>> +	OPT_BOOLEAN(0, "switch-output", &record.switch_output,
>> +		    "Switch output when receive SIGUSR2"),
>>   	OPT_END()
>>   };
>>   
>> @@ -1417,4 +1443,7 @@ static void snapshot_sig_handler(int sig __maybe_unused)
>>   		if (auxtrace_record__snapshot_start(record.itr))
>>   			trigger_error(&auxtrace_snapshot_trigger);
>>   	}
>> +
>> +	if (trigger_is_ready(&switch_output_trigger))
>> +		trigger_hit(&switch_output_trigger);
>>   }
>> -- 
>> 1.8.3.4

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf tools: Introduce trigger class
  2016-04-20 18:59 ` [PATCH v6 1/7] perf tools: Introduce trigger class Wang Nan
@ 2016-05-01  7:39   ` tip-bot for Wang Nan
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Wang Nan @ 2016-05-01  7:39 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, lizefan, mingo, jolsa, mhiramat, acme, hpa, linux-kernel,
	adrian.hunter, wangnan0, hekuang, namhyung

Commit-ID:  3dcc4436fa6f09ce093ff59bf8477c3059dc46df
Gitweb:     http://git.kernel.org/tip/3dcc4436fa6f09ce093ff59bf8477c3059dc46df
Author:     Wang Nan <wangnan0@huawei.com>
AuthorDate: Wed, 20 Apr 2016 18:59:48 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 28 Apr 2016 09:58:58 -0300

perf tools: Introduce trigger class

Use 'trigger' to model operations which need to be executed when an
event (a signal, for example) is observed.

States and transits:

 OFF--(on)--> READY --(hit)--> HIT
		^               |
		|            (ready)
		|               |
		 \_____________/

is_hit and is_ready are two key functions to query the state of a
trigger. is_hit means the event already happen; is_ready means the
trigger is waiting for the event.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1461178794-40467-2-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/trigger.h | 94 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/tools/perf/util/trigger.h b/tools/perf/util/trigger.h
new file mode 100644
index 0000000..e97d701
--- /dev/null
+++ b/tools/perf/util/trigger.h
@@ -0,0 +1,94 @@
+#ifndef __TRIGGER_H_
+#define __TRIGGER_H_ 1
+
+#include "util/debug.h"
+#include "asm/bug.h"
+
+/*
+ * Use trigger to model operations which need to be executed when
+ * an event (a signal, for example) is observed.
+ *
+ * States and transits:
+ *
+ *
+ *  OFF--(on)--> READY --(hit)--> HIT
+ *                 ^               |
+ *                 |            (ready)
+ *                 |               |
+ *                  \_____________/
+ *
+ * is_hit and is_ready are two key functions to query the state of
+ * a trigger. is_hit means the event already happen; is_ready means the
+ * trigger is waiting for the event.
+ */
+
+struct trigger {
+	volatile enum {
+		TRIGGER_ERROR		= -2,
+		TRIGGER_OFF		= -1,
+		TRIGGER_READY		= 0,
+		TRIGGER_HIT		= 1,
+	} state;
+	const char *name;
+};
+
+#define TRIGGER_WARN_ONCE(t, exp) \
+	WARN_ONCE(t->state != exp, "trigger '%s' state transist error: %d in %s()\n", \
+		  t->name, t->state, __func__)
+
+static inline bool trigger_is_available(struct trigger *t)
+{
+	return t->state >= 0;
+}
+
+static inline bool trigger_is_error(struct trigger *t)
+{
+	return t->state <= TRIGGER_ERROR;
+}
+
+static inline void trigger_on(struct trigger *t)
+{
+	TRIGGER_WARN_ONCE(t, TRIGGER_OFF);
+	t->state = TRIGGER_READY;
+}
+
+static inline void trigger_ready(struct trigger *t)
+{
+	if (!trigger_is_available(t))
+		return;
+	t->state = TRIGGER_READY;
+}
+
+static inline void trigger_hit(struct trigger *t)
+{
+	if (!trigger_is_available(t))
+		return;
+	TRIGGER_WARN_ONCE(t, TRIGGER_READY);
+	t->state = TRIGGER_HIT;
+}
+
+static inline void trigger_off(struct trigger *t)
+{
+	if (!trigger_is_available(t))
+		return;
+	t->state = TRIGGER_OFF;
+}
+
+static inline void trigger_error(struct trigger *t)
+{
+	t->state = TRIGGER_ERROR;
+}
+
+static inline bool trigger_is_ready(struct trigger *t)
+{
+	return t->state == TRIGGER_READY;
+}
+
+static inline bool trigger_is_hit(struct trigger *t)
+{
+	return t->state == TRIGGER_HIT;
+}
+
+#define DEFINE_TRIGGER(n) \
+struct trigger n = {.state = TRIGGER_OFF, .name = #n}
+#endif

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf tools: Derive trigger class from auxtrace_snapshot
  2016-04-20 18:59 ` [PATCH v6 2/7] perf tools: Derive trigger class from auxtrace_snapshot Wang Nan
  2016-04-26 13:54   ` Arnaldo Carvalho de Melo
@ 2016-05-01  7:39   ` tip-bot for Wang Nan
  1 sibling, 0 replies; 20+ messages in thread
From: tip-bot for Wang Nan @ 2016-05-01  7:39 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, wangnan0, hekuang, adrian.hunter, jolsa,
	namhyung, tglx, mingo, mhiramat, lizefan

Commit-ID:  5f9cf5992cfb9d9763fb92f755642dda8f9e844f
Gitweb:     http://git.kernel.org/tip/5f9cf5992cfb9d9763fb92f755642dda8f9e844f
Author:     Wang Nan <wangnan0@huawei.com>
AuthorDate: Wed, 20 Apr 2016 18:59:49 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 28 Apr 2016 09:58:58 -0300

perf tools: Derive trigger class from auxtrace_snapshot

auxtrace_snapshot_state matches the trigger model. Use trigger to
implement it. auxtrace_snapshot_state and auxtrace_snapshot_err are
absorbed.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1461178794-40467-3-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-record.c | 73 +++++++++++++--------------------------------
 1 file changed, 20 insertions(+), 53 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index bd95933..f4710c8 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -34,6 +34,7 @@
 #include "util/parse-regs-options.h"
 #include "util/llvm-utils.h"
 #include "util/bpf-loader.h"
+#include "util/trigger.h"
 #include "asm/bug.h"
 
 #include <unistd.h>
@@ -127,44 +128,8 @@ static volatile int done;
 static volatile int signr = -1;
 static volatile int child_finished;
 
-static volatile enum {
-	AUXTRACE_SNAPSHOT_OFF = -1,
-	AUXTRACE_SNAPSHOT_DISABLED = 0,
-	AUXTRACE_SNAPSHOT_ENABLED = 1,
-} auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_OFF;
-
-static inline void
-auxtrace_snapshot_on(void)
-{
-	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
-}
-
-static inline void
-auxtrace_snapshot_enable(void)
-{
-	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
-		return;
-	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_ENABLED;
-}
-
-static inline void
-auxtrace_snapshot_disable(void)
-{
-	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
-		return;
-	auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
-}
-
-static inline bool
-auxtrace_snapshot_is_enabled(void)
-{
-	if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
-		return false;
-	return auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_ENABLED;
-}
-
-static volatile int auxtrace_snapshot_err;
 static volatile int auxtrace_record__snapshot_started;
+static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
 
 static void sig_handler(int sig)
 {
@@ -282,11 +247,12 @@ static void record__read_auxtrace_snapshot(struct record *rec)
 {
 	pr_debug("Recording AUX area tracing snapshot\n");
 	if (record__auxtrace_read_snapshot_all(rec) < 0) {
-		auxtrace_snapshot_err = -1;
+		trigger_error(&auxtrace_snapshot_trigger);
 	} else {
-		auxtrace_snapshot_err = auxtrace_record__snapshot_finish(rec->itr);
-		if (!auxtrace_snapshot_err)
-			auxtrace_snapshot_enable();
+		if (auxtrace_record__snapshot_finish(rec->itr))
+			trigger_error(&auxtrace_snapshot_trigger);
+		else
+			trigger_ready(&auxtrace_snapshot_trigger);
 	}
 }
 
@@ -686,7 +652,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 
 	if (rec->opts.auxtrace_snapshot_mode) {
 		signal(SIGUSR2, snapshot_sig_handler);
-		auxtrace_snapshot_on();
+		trigger_on(&auxtrace_snapshot_trigger);
 	} else {
 		signal(SIGUSR2, SIG_IGN);
 	}
@@ -815,21 +781,21 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 		perf_evlist__enable(rec->evlist);
 	}
 
-	auxtrace_snapshot_enable();
+	trigger_ready(&auxtrace_snapshot_trigger);
 	for (;;) {
 		unsigned long long hits = rec->samples;
 
 		if (record__mmap_read_all(rec) < 0) {
-			auxtrace_snapshot_disable();
+			trigger_error(&auxtrace_snapshot_trigger);
 			err = -1;
 			goto out_child;
 		}
 
 		if (auxtrace_record__snapshot_started) {
 			auxtrace_record__snapshot_started = 0;
-			if (!auxtrace_snapshot_err)
+			if (!trigger_is_error(&auxtrace_snapshot_trigger))
 				record__read_auxtrace_snapshot(rec);
-			if (auxtrace_snapshot_err) {
+			if (trigger_is_error(&auxtrace_snapshot_trigger)) {
 				pr_err("AUX area tracing snapshot failed\n");
 				err = -1;
 				goto out_child;
@@ -858,12 +824,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 		 * disable events in this case.
 		 */
 		if (done && !disabled && !target__none(&opts->target)) {
-			auxtrace_snapshot_disable();
+			trigger_off(&auxtrace_snapshot_trigger);
 			perf_evlist__disable(rec->evlist);
 			disabled = true;
 		}
 	}
-	auxtrace_snapshot_disable();
+	trigger_off(&auxtrace_snapshot_trigger);
 
 	if (forks && workload_exec_errno) {
 		char msg[STRERR_BUFSIZE];
@@ -1445,9 +1411,10 @@ out_symbol_exit:
 
 static void snapshot_sig_handler(int sig __maybe_unused)
 {
-	if (!auxtrace_snapshot_is_enabled())
-		return;
-	auxtrace_snapshot_disable();
-	auxtrace_snapshot_err = auxtrace_record__snapshot_start(record.itr);
-	auxtrace_record__snapshot_started = 1;
+	if (trigger_is_ready(&auxtrace_snapshot_trigger)) {
+		trigger_hit(&auxtrace_snapshot_trigger);
+		auxtrace_record__snapshot_started = 1;
+		if (auxtrace_record__snapshot_start(record.itr))
+			trigger_error(&auxtrace_snapshot_trigger);
+	}
 }

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf record: Split output into multiple files via '--switch-output'
  2016-04-20 18:59 ` [PATCH v6 3/7] perf record: Split output into multiple files via '--switch-output' Wang Nan
  2016-04-27 21:32   ` Arnaldo Carvalho de Melo
@ 2016-05-01  7:39   ` tip-bot for Wang Nan
  1 sibling, 0 replies; 20+ messages in thread
From: tip-bot for Wang Nan @ 2016-05-01  7:39 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, mhiramat, wangnan0, acme, hekuang, linux-kernel,
	adrian.hunter, lizefan, mingo, tglx, jolsa, namhyung

Commit-ID:  3c1cb7e3723caad9b4c1b2f816d86d8605296a4b
Gitweb:     http://git.kernel.org/tip/3c1cb7e3723caad9b4c1b2f816d86d8605296a4b
Author:     Wang Nan <wangnan0@huawei.com>
AuthorDate: Wed, 20 Apr 2016 18:59:50 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 28 Apr 2016 09:58:59 -0300

perf record: Split output into multiple files via '--switch-output'

Allow 'perf record' to split its output into multiple files.

For example:

  # ~/perf record -a --timestamp-filename --switch-output &
  [1] 10763
  # kill -s SIGUSR2 10763
  [ perf record: dump data: Woken up 1 times ]
  # [ perf record: Dump perf.data.2015122622314468 ]

  # kill -s SIGUSR2 10763
  [ perf record: dump data: Woken up 1 times ]
  # [ perf record: Dump perf.data.2015122622314762 ]

  # kill -s SIGUSR2 10763
  [ perf record: dump data: Woken up 1 times ]
  #[ perf record: Dump perf.data.2015122622315171 ]

  # fg
  perf record -a --timestamp-filename --switch-output
  ^C[ perf record: Woken up 1 times to write data ]
  [ perf record: Dump perf.data.2015122622315513 ]
  [ perf record: Captured and wrote 0.014 MB perf.data.<timestamp> (296 samples) ]

  # ls -l
  total 920
  -rw------- 1 root root 797692 Dec 26 22:31 perf.data.2015122622314468
  -rw------- 1 root root  59960 Dec 26 22:31 perf.data.2015122622314762
  -rw------- 1 root root  59912 Dec 26 22:31 perf.data.2015122622315171
  -rw------- 1 root root  19220 Dec 26 22:31 perf.data.2015122622315513

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1461178794-40467-4-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
[ Added man page entry, used the re-synthesize patch in this series as a fixup ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-record.txt |  8 +++++++
 tools/perf/builtin-record.c              | 40 ++++++++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 19aa175..a77a431 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -347,6 +347,14 @@ Configure all used events to run in kernel space.
 --all-user::
 Configure all used events to run in user space.
 
+--switch-output::
+Generate multiple perf.data files, timestamp prefixed, switching to a new one
+when receiving a SIGUSR2.
+
+A possible use case is to, given an external event, slice the perf.data file
+that gets then processed, possibly via a perf script, to decide if that
+particular perf.data snapshot should be kept or not.
+
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f4710c8..8ebe953 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -58,6 +58,7 @@ struct record {
 	bool			no_buildid_cache_set;
 	bool			buildid_all;
 	bool			timestamp_filename;
+	bool			switch_output;
 	unsigned long long	samples;
 };
 
@@ -130,6 +131,7 @@ static volatile int child_finished;
 
 static volatile int auxtrace_record__snapshot_started;
 static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
+static DEFINE_TRIGGER(switch_output_trigger);
 
 static void sig_handler(int sig)
 {
@@ -498,6 +500,8 @@ record__finish_output(struct record *rec)
 	return;
 }
 
+static int record__synthesize(struct record *rec);
+
 static int
 record__switch_output(struct record *rec, bool at_exit)
 {
@@ -526,6 +530,11 @@ record__switch_output(struct record *rec, bool at_exit)
 	if (!quiet)
 		fprintf(stderr, "[ perf record: Dump %s.%s ]\n",
 			file->path, timestamp);
+
+	/* Output tracking events */
+	if (!at_exit)
+		record__synthesize(rec);
+
 	return fd;
 }
 
@@ -650,9 +659,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 	signal(SIGINT, sig_handler);
 	signal(SIGTERM, sig_handler);
 
-	if (rec->opts.auxtrace_snapshot_mode) {
+	if (rec->opts.auxtrace_snapshot_mode || rec->switch_output) {
 		signal(SIGUSR2, snapshot_sig_handler);
-		trigger_on(&auxtrace_snapshot_trigger);
+		if (rec->opts.auxtrace_snapshot_mode)
+			trigger_on(&auxtrace_snapshot_trigger);
+		if (rec->switch_output)
+			trigger_on(&switch_output_trigger);
 	} else {
 		signal(SIGUSR2, SIG_IGN);
 	}
@@ -782,11 +794,13 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 	}
 
 	trigger_ready(&auxtrace_snapshot_trigger);
+	trigger_ready(&switch_output_trigger);
 	for (;;) {
 		unsigned long long hits = rec->samples;
 
 		if (record__mmap_read_all(rec) < 0) {
 			trigger_error(&auxtrace_snapshot_trigger);
+			trigger_error(&switch_output_trigger);
 			err = -1;
 			goto out_child;
 		}
@@ -802,6 +816,22 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 			}
 		}
 
+		if (trigger_is_hit(&switch_output_trigger)) {
+			trigger_ready(&switch_output_trigger);
+
+			if (!quiet)
+				fprintf(stderr, "[ perf record: dump data: Woken up %ld times ]\n",
+					waking);
+			waking = 0;
+			fd = record__switch_output(rec, false);
+			if (fd < 0) {
+				pr_err("Failed to switch to new file\n");
+				trigger_error(&switch_output_trigger);
+				err = fd;
+				goto out_child;
+			}
+		}
+
 		if (hits == rec->samples) {
 			if (done || draining)
 				break;
@@ -830,6 +860,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 		}
 	}
 	trigger_off(&auxtrace_snapshot_trigger);
+	trigger_off(&switch_output_trigger);
 
 	if (forks && workload_exec_errno) {
 		char msg[STRERR_BUFSIZE];
@@ -1263,6 +1294,8 @@ struct option __record_options[] = {
 		    "Record build-id of all DSOs regardless of hits"),
 	OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
 		    "append timestamp to output filename"),
+	OPT_BOOLEAN(0, "switch-output", &record.switch_output,
+		    "Switch output when receive SIGUSR2"),
 	OPT_END()
 };
 
@@ -1417,4 +1450,7 @@ static void snapshot_sig_handler(int sig __maybe_unused)
 		if (auxtrace_record__snapshot_start(record.itr))
 			trigger_error(&auxtrace_snapshot_trigger);
 	}
+
+	if (trigger_is_ready(&switch_output_trigger))
+		trigger_hit(&switch_output_trigger);
 }

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf record: Force enable --timestamp-filename when --switch-output is provided
  2016-04-20 18:59 ` [PATCH v6 4/7] perf record: Force enable --timestamp-filename when --switch-output is provided Wang Nan
@ 2016-05-01  7:40   ` tip-bot for Wang Nan
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Wang Nan @ 2016-05-01  7:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, lizefan, mhiramat, jolsa, hekuang, adrian.hunter,
	tglx, wangnan0, hpa, linux-kernel, namhyung

Commit-ID:  eca857ab381858450ec2f91f5aaae7f2f7a7a180
Gitweb:     http://git.kernel.org/tip/eca857ab381858450ec2f91f5aaae7f2f7a7a180
Author:     Wang Nan <wangnan0@huawei.com>
AuthorDate: Wed, 20 Apr 2016 18:59:51 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 28 Apr 2016 09:58:59 -0300

perf record: Force enable --timestamp-filename when --switch-output is provided

Without this patch, the last output doesn't have timestamp appended if
--timestamp-filename is not explicitly provided. For example:

  # perf record -a --switch-output &
  [1] 11224
  # kill -s SIGUSR2 11224
  [ perf record: dump data: Woken up 1 times ]
  # [ perf record: Dump perf.data.2015122622372823 ]

  # fg
  perf record -a --switch-output
  ^C[ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.027 MB perf.data (540 samples) ]

  # ls -l
  total 836
  -rw------- 1 root root  33256 Dec 26 22:37 perf.data   <---- *Odd*
  -rw------- 1 root root 817156 Dec 26 22:37 perf.data.2015122622372823

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1461178794-40467-5-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
[ Updated man page, that also got an entry for --timestamp-filename ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-record.txt | 5 +++++
 tools/perf/builtin-record.c              | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index a77a431..79a8a14 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -347,6 +347,9 @@ Configure all used events to run in kernel space.
 --all-user::
 Configure all used events to run in user space.
 
+--timestamp-filename
+Append timestamp to output file name.
+
 --switch-output::
 Generate multiple perf.data files, timestamp prefixed, switching to a new one
 when receiving a SIGUSR2.
@@ -355,6 +358,8 @@ A possible use case is to, given an external event, slice the perf.data file
 that gets then processed, possibly via a perf script, to decide if that
 particular perf.data snapshot should be kept or not.
 
+Implies --timestamp-filename.
+
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-list[1]
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 8ebe953..80b805b 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1351,6 +1351,9 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
 		return -EINVAL;
 	}
 
+	if (rec->switch_output)
+		rec->timestamp_filename = true;
+
 	if (!rec->itr) {
 		rec->itr = auxtrace_record__init(rec->evlist, &err);
 		if (err)

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf record: Disable buildid cache options by default in switch output mode
  2016-04-20 18:59 ` [PATCH v6 5/7] perf record: Disable buildid cache options by default in switch output mode Wang Nan
@ 2016-05-01  7:40   ` tip-bot for Wang Nan
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Wang Nan @ 2016-05-01  7:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: adrian.hunter, tglx, wangnan0, acme, lizefan, mingo, mhiramat,
	namhyung, hpa, jolsa, hekuang, linux-kernel

Commit-ID:  0c1d46a8796e8309f1ca693e5cad6f318e4b8159
Gitweb:     http://git.kernel.org/tip/0c1d46a8796e8309f1ca693e5cad6f318e4b8159
Author:     Wang Nan <wangnan0@huawei.com>
AuthorDate: Wed, 20 Apr 2016 18:59:52 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 28 Apr 2016 09:58:59 -0300

perf record: Disable buildid cache options by default in switch output mode

The cost of buildid cache processing is high: reading all events in
output perf.data, opening each elf file to read buildids then copying
them into ~/.debug directory. In switch output mode, these heavy works
block perf from receiving perf events for too long.

Enable no-buildid and no-buildid-cache by default if --switch-output is
provided. Still allow user use --no-no-buildid to explicitly enable
buildid in this case.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1461178794-40467-6-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
[ Updated man page ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-record.txt |  2 +-
 tools/perf/builtin-record.c              | 30 +++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 79a8a14..8dbee83 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -358,7 +358,7 @@ A possible use case is to, given an external event, slice the perf.data file
 that gets then processed, possibly via a perf script, to decide if that
 particular perf.data snapshot should be kept or not.
 
-Implies --timestamp-filename.
+Implies --timestamp-filename, --no-buildid and --no-buildid-cache.
 
 SEE ALSO
 --------
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 80b805b..178b49e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1387,8 +1387,36 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
 "If some relocation was applied (e.g. kexec) symbols may be misresolved\n"
 "even with a suitable vmlinux or kallsyms file.\n\n");
 
-	if (rec->no_buildid_cache || rec->no_buildid)
+	if (rec->no_buildid_cache || rec->no_buildid) {
 		disable_buildid_cache();
+	} else if (rec->switch_output) {
+		/*
+		 * In 'perf record --switch-output', disable buildid
+		 * generation by default to reduce data file switching
+		 * overhead. Still generate buildid if they are required
+		 * explicitly using
+		 *
+		 *  perf record --signal-trigger --no-no-buildid \
+		 *              --no-no-buildid-cache
+		 *
+		 * Following code equals to:
+		 *
+		 * if ((rec->no_buildid || !rec->no_buildid_set) &&
+		 *     (rec->no_buildid_cache || !rec->no_buildid_cache_set))
+		 *         disable_buildid_cache();
+		 */
+		bool disable = true;
+
+		if (rec->no_buildid_set && !rec->no_buildid)
+			disable = false;
+		if (rec->no_buildid_cache_set && !rec->no_buildid_cache)
+			disable = false;
+		if (disable) {
+			rec->no_buildid = true;
+			rec->no_buildid_cache = true;
+			disable_buildid_cache();
+		}
+	}
 
 	if (rec->evlist->nr_entries == 0 &&
 	    perf_evlist__add_default(rec->evlist) < 0) {

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf record: Generate tracking events for process forked by perf
  2016-04-20 18:59 ` [PATCH v6 7/7] perf record: Generate tracking events for process forked by perf Wang Nan
@ 2016-05-01  7:41   ` tip-bot for Wang Nan
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Wang Nan @ 2016-05-01  7:41 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, jolsa, mingo, mhiramat, tglx, wangnan0,
	namhyung, hekuang, lizefan, adrian.hunter, acme

Commit-ID:  be7b0c9e376e93a00b6c8631e2721e9dc7c6a1fa
Gitweb:     http://git.kernel.org/tip/be7b0c9e376e93a00b6c8631e2721e9dc7c6a1fa
Author:     Wang Nan <wangnan0@huawei.com>
AuthorDate: Wed, 20 Apr 2016 18:59:54 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 28 Apr 2016 09:58:59 -0300

perf record: Generate tracking events for process forked by perf

With 'perf record --switch-output' without -a, record__synthesize() in
record__switch_output() won't generate tracking events because there's
no thread_map in evlist. Which causes newly created perf.data doesn't
contain map and comm information.

This patch creates a fake thread_map and directly call
perf_event__synthesize_thread_map() for those events.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1461178794-40467-8-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-record.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 178b49e..f3679c4 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -500,6 +500,23 @@ record__finish_output(struct record *rec)
 	return;
 }
 
+static int record__synthesize_workload(struct record *rec)
+{
+	struct {
+		struct thread_map map;
+		struct thread_map_data map_data;
+	} thread_map;
+
+	thread_map.map.nr = 1;
+	thread_map.map.map[0].pid = rec->evlist->workload.pid;
+	thread_map.map.map[0].comm = NULL;
+	return perf_event__synthesize_thread_map(&rec->tool, &thread_map.map,
+						 process_synthesized_event,
+						 &rec->session->machines.host,
+						 rec->opts.sample_address,
+						 rec->opts.proc_map_timeout);
+}
+
 static int record__synthesize(struct record *rec);
 
 static int
@@ -532,9 +549,21 @@ record__switch_output(struct record *rec, bool at_exit)
 			file->path, timestamp);
 
 	/* Output tracking events */
-	if (!at_exit)
+	if (!at_exit) {
 		record__synthesize(rec);
 
+		/*
+		 * In 'perf record --switch-output' without -a,
+		 * record__synthesize() in record__switch_output() won't
+		 * generate tracking events because there's no thread_map
+		 * in evlist. Which causes newly created perf.data doesn't
+		 * contain map and comm information.
+		 * Create a fake thread_map and directly call
+		 * perf_event__synthesize_thread_map() for those events.
+		 */
+		if (target__none(&rec->opts.target))
+			record__synthesize_workload(rec);
+	}
 	return fd;
 }
 

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2016-05-01  7:41 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-20 18:59 [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Wang Nan
2016-04-20 18:59 ` [PATCH v6 1/7] perf tools: Introduce trigger class Wang Nan
2016-05-01  7:39   ` [tip:perf/core] " tip-bot for Wang Nan
2016-04-20 18:59 ` [PATCH v6 2/7] perf tools: Derive trigger class from auxtrace_snapshot Wang Nan
2016-04-26 13:54   ` Arnaldo Carvalho de Melo
2016-04-27  9:10     ` Adrian Hunter
2016-05-01  7:39   ` [tip:perf/core] " tip-bot for Wang Nan
2016-04-20 18:59 ` [PATCH v6 3/7] perf record: Split output into multiple files via '--switch-output' Wang Nan
2016-04-27 21:32   ` Arnaldo Carvalho de Melo
2016-04-29  4:56     ` Wangnan (F)
2016-05-01  7:39   ` [tip:perf/core] " tip-bot for Wang Nan
2016-04-20 18:59 ` [PATCH v6 4/7] perf record: Force enable --timestamp-filename when --switch-output is provided Wang Nan
2016-05-01  7:40   ` [tip:perf/core] " tip-bot for Wang Nan
2016-04-20 18:59 ` [PATCH v6 5/7] perf record: Disable buildid cache options by default in switch output mode Wang Nan
2016-05-01  7:40   ` [tip:perf/core] " tip-bot for Wang Nan
2016-04-20 18:59 ` [PATCH v6 6/7] perf record: Re-synthesize tracking events after output switching Wang Nan
2016-04-20 18:59 ` [PATCH v6 7/7] perf record: Generate tracking events for process forked by perf Wang Nan
2016-05-01  7:41   ` [tip:perf/core] " tip-bot for Wang Nan
2016-04-22 10:30 ` [PATCH v6 0/7] perf tools: Use SIGUSR2 control data dumpping Jiri Olsa
2016-04-27 21:40 ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.