Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1380098 > unrolled thread
| Started by | Wang Nan <wangnan0@huawei.com> |
|---|---|
| First post | 2016-04-15 20:30 +0200 |
| Last post | 2016-04-15 20:30 +0200 |
| Articles | 7 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH v3 0/6] perf tools: Use SIGUSR2 control data dumpping Wang Nan <wangnan0@huawei.com> - 2016-04-15 20:30 +0200
[PATCH v3 1/6] perf tools: Derive trigger class from auxtrace_snapshot Wang Nan <wangnan0@huawei.com> - 2016-04-15 20:30 +0200
Re: [PATCH v3 1/6] perf tools: Derive trigger class from auxtrace_snapshot Jiri Olsa <jolsa@redhat.com> - 2016-04-17 14:00 +0200
Re: [PATCH v3 1/6] perf tools: Derive trigger class from auxtrace_snapshot "Wangnan (F)" <wangnan0@huawei.com> - 2016-04-18 04:40 +0200
Re: [PATCH v3 1/6] perf tools: Derive trigger class from auxtrace_snapshot Jiri Olsa <jolsa@redhat.com> - 2016-04-17 14:00 +0200
[PATCH v3 5/6] perf record: Re-synthesize tracking events after output switching Wang Nan <wangnan0@huawei.com> - 2016-04-15 20:30 +0200
[PATCH v3 3/6] perf record: Force enable --timestamp-filename when --switch-output is provided Wang Nan <wangnan0@huawei.com> - 2016-04-15 20:30 +0200
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-04-15 20:30 +0200 |
| Subject | [PATCH v3 0/6] perf tools: Use SIGUSR2 control data dumpping |
| Message-ID | <rogFb-7ma-13@gated-at.bofh.it> |
v2 -> v3: Improve naming in trigger. Absorb auxtrace_record__snapshot_started
and auxtrace_snapshot_err using trigger.
Cc: Wang Nan <wangnan0@huawei.com>
Cc: 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
Wang Nan (6):
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 | 176 +++++++++++++++++++++----------
tools/perf/util/trigger.h | 103 ++++++++++++++++++
3 files changed, 235 insertions(+), 57 deletions(-)
create mode 100644 tools/perf/util/trigger.h
--
1.8.3.4
[toc] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-04-15 20:30 +0200 |
| Subject | [PATCH v3 1/6] perf tools: Derive trigger class from auxtrace_snapshot |
| Message-ID | <rogFc-7ma-35@gated-at.bofh.it> |
| In reply to | #1380098 |
Create a new class named 'trigger' to model the state of a trigger and
implement auxtrace_snapshot with it.
auxtrace_record__snapshot_started and auxtrace_snapshot_err are absorbed.
'trigger' defines 4 state transitioning functions ('on', 'released',
'toggle' and 'colddown') and 2 state query function ('is_released') and
('is_toggled'). The state 'ON' and 'OFF' take higher priority than
'RELEASED' and 'TOGGLED'. A trigger must be 'on' before 'enable' and
'disable' take effect. A trigger can be colddown after being triggered.
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
Link: http://lkml.kernel.org/r/1460643725-167413-2-git-send-email-wangnan0@huawei.com
[ Moved the trigger definitions to trigger.h ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-record.c | 73 ++++++++-----------------------
tools/perf/util/trigger.h | 103 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 122 insertions(+), 54 deletions(-)
create mode 100644 tools/perf/util/trigger.h
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3239a6e..cfaa2df 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,7 @@ 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, OFF);
static void sig_handler(int sig)
{
@@ -282,11 +246,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;
+ auxtrace_snapshot_error();
} else {
- auxtrace_snapshot_err = auxtrace_record__snapshot_finish(rec->itr);
- if (!auxtrace_snapshot_err)
- auxtrace_snapshot_enable();
+ if (auxtrace_record__snapshot_finish(rec->itr))
+ auxtrace_snapshot_error();
+ else
+ auxtrace_snapshot_release();
}
}
@@ -815,21 +780,21 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
perf_evlist__enable(rec->evlist);
}
- auxtrace_snapshot_enable();
+ auxtrace_snapshot_release();
for (;;) {
unsigned long long hits = rec->samples;
if (record__mmap_read_all(rec) < 0) {
- auxtrace_snapshot_disable();
+ auxtrace_snapshot_error();
err = -1;
goto out_child;
}
- if (auxtrace_record__snapshot_started) {
- auxtrace_record__snapshot_started = 0;
- if (!auxtrace_snapshot_err)
+ if (auxtrace_snapshot_is_toggled()) {
+ auxtrace_snapshot_colddown();
+ if (!auxtrace_snapshot_is_error())
record__read_auxtrace_snapshot(rec);
- if (auxtrace_snapshot_err) {
+ if (auxtrace_snapshot_is_error()) {
pr_err("AUX area tracing snapshot failed\n");
err = -1;
goto out_child;
@@ -858,12 +823,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();
+ auxtrace_snapshot_off();
perf_evlist__disable(rec->evlist);
disabled = true;
}
}
- auxtrace_snapshot_disable();
+ auxtrace_snapshot_off();
if (forks && workload_exec_errno) {
char msg[STRERR_BUFSIZE];
@@ -1442,9 +1407,9 @@ out_symbol_exit:
static void snapshot_sig_handler(int sig __maybe_unused)
{
- if (!auxtrace_snapshot_is_enabled())
+ if (!auxtrace_snapshot_is_released())
return;
- auxtrace_snapshot_disable();
- auxtrace_snapshot_err = auxtrace_record__snapshot_start(record.itr);
- auxtrace_record__snapshot_started = 1;
+ auxtrace_snapshot_toggle();
+ if (auxtrace_record__snapshot_start(record.itr))
+ auxtrace_snapshot_error();
}
diff --git a/tools/perf/util/trigger.h b/tools/perf/util/trigger.h
new file mode 100644
index 0000000..162c1c8
--- /dev/null
+++ b/tools/perf/util/trigger.h
@@ -0,0 +1,103 @@
+#ifndef __TRIGGER_H_
+#define __TRIGGER_H_ 1
+
+struct trigger {
+ volatile enum {
+ TRIGGER_OFF = -1,
+ TRIGGER_RELEASED = 0,
+ TRIGGER_TOGGLED = 1,
+ TRIGGER_COLDDOWN = 2,
+ } state;
+ volatile bool error;
+};
+
+static inline void trigger_on(struct trigger *s)
+{
+ if (s->error)
+ return;
+ s->state = TRIGGER_RELEASED;
+}
+
+static inline void trigger_release(struct trigger *s)
+{
+ if (s->error)
+ return;
+ if (s->state != TRIGGER_OFF)
+ s->state = TRIGGER_RELEASED;
+}
+
+static inline void trigger_toggle(struct trigger *s)
+{
+ if (s->error)
+ return;
+ if (s->state != TRIGGER_OFF)
+ s->state = TRIGGER_TOGGLED;
+}
+
+static inline void trigger_colddown(struct trigger *s)
+{
+ if (s->error)
+ return;
+ if (s->state == TRIGGER_TOGGLED)
+ s->state = TRIGGER_COLDDOWN;
+}
+
+static inline void trigger_off(struct trigger *s)
+{
+ if (s->error)
+ return;
+ if (s->state != TRIGGER_OFF)
+ s->state = TRIGGER_OFF;
+}
+
+static inline void trigger_error(struct trigger *s)
+{
+ if (s->error)
+ return;
+ trigger_off(s);
+ s->error = true;
+}
+
+static inline bool trigger_is_released(struct trigger *s)
+{
+ if (s->error)
+ return false;
+ if (s->state != TRIGGER_OFF)
+ return s->state == TRIGGER_RELEASED;
+ return false;
+}
+
+static inline bool trigger_is_toggled(struct trigger *s)
+{
+ if (s->error)
+ return false;
+ if (s->state != TRIGGER_OFF)
+ return s->state == TRIGGER_TOGGLED;
+ return false;
+}
+
+static inline bool trigger_is_error(struct trigger *s)
+{
+ return s->error;
+}
+
+#define __TRIGGER_VAR(n) n##_state
+#define __DEF_TRIGGER_VOID_FUNC(n, op) \
+static inline void n##_##op(void) {trigger_##op(&__TRIGGER_VAR(n)); }
+
+#define __DEF_TRIGGER_FUNC(n, type, op) \
+static inline type n##_##op(void) {return trigger_##op(&__TRIGGER_VAR(n)); }
+
+#define DEFINE_TRIGGER(n, def) \
+struct trigger n##_state = {.state = TRIGGER_##def, .error = false,};\
+__DEF_TRIGGER_VOID_FUNC(n, on) \
+__DEF_TRIGGER_VOID_FUNC(n, release) \
+__DEF_TRIGGER_VOID_FUNC(n, toggle) \
+__DEF_TRIGGER_VOID_FUNC(n, colddown) \
+__DEF_TRIGGER_VOID_FUNC(n, off) \
+__DEF_TRIGGER_VOID_FUNC(n, error) \
+__DEF_TRIGGER_FUNC(n, bool, is_released) \
+__DEF_TRIGGER_FUNC(n, bool, is_toggled) \
+__DEF_TRIGGER_FUNC(n, bool, is_error)
+
+#endif
--
1.8.3.4
[toc] | [prev] | [next] | [standalone]
| From | Jiri Olsa <jolsa@redhat.com> |
|---|---|
| Date | 2016-04-17 14:00 +0200 |
| Subject | Re: [PATCH v3 1/6] perf tools: Derive trigger class from auxtrace_snapshot |
| Message-ID | <roTwR-3EK-13@gated-at.bofh.it> |
| In reply to | #1380099 |
On Fri, Apr 15, 2016 at 06:20:15PM +0000, Wang Nan wrote:
> Create a new class named 'trigger' to model the state of a trigger and
> implement auxtrace_snapshot with it.
>
> auxtrace_record__snapshot_started and auxtrace_snapshot_err are absorbed.
>
> 'trigger' defines 4 state transitioning functions ('on', 'released',
> 'toggle' and 'colddown') and 2 state query function ('is_released') and
> ('is_toggled'). The state 'ON' and 'OFF' take higher priority than
> 'RELEASED' and 'TOGGLED'. A trigger must be 'on' before 'enable' and
> 'disable' take effect. A trigger can be colddown after being triggered.
what's the COLDDOWN state for?
could you please document all the transitions of this state machine
in the change log and the trigger.h file?
thanks,
jirka
[toc] | [prev] | [next] | [standalone]
| From | "Wangnan (F)" <wangnan0@huawei.com> |
|---|---|
| Date | 2016-04-18 04:40 +0200 |
| Subject | Re: [PATCH v3 1/6] perf tools: Derive trigger class from auxtrace_snapshot |
| Message-ID | <rp7gu-6ho-35@gated-at.bofh.it> |
| In reply to | #1380735 |
On 2016/4/17 19:50, Jiri Olsa wrote:
> On Fri, Apr 15, 2016 at 06:20:15PM +0000, Wang Nan wrote:
>> Create a new class named 'trigger' to model the state of a trigger and
>> implement auxtrace_snapshot with it.
>>
>> auxtrace_record__snapshot_started and auxtrace_snapshot_err are absorbed.
>>
>> 'trigger' defines 4 state transitioning functions ('on', 'released',
>> 'toggle' and 'colddown') and 2 state query function ('is_released') and
>> ('is_toggled'). The state 'ON' and 'OFF' take higher priority than
>> 'RELEASED' and 'TOGGLED'. A trigger must be 'on' before 'enable' and
>> 'disable' take effect. A trigger can be colddown after being triggered.
> what's the COLDDOWN state for?
COLDDOWN is for auxtrace_record__snapshot_started. Once signal received,
auxtrace subsystem doesn't process following signal, until
record__read_auxtrace_snapshot finished successful. Mapping to trigger,
once the state of a trigger moves to 'TRIGGERED', there must be a state
neither RELEASED nor ERROR, which disallow triggering, but allow transiting
to RELEASED.
> could you please document all the transitions of this state machine
> in the change log and the trigger.h file?
Will do. Thank you.
> thanks,
> jirka
[toc] | [prev] | [next] | [standalone]
| From | Jiri Olsa <jolsa@redhat.com> |
|---|---|
| Date | 2016-04-17 14:00 +0200 |
| Subject | Re: [PATCH v3 1/6] perf tools: Derive trigger class from auxtrace_snapshot |
| Message-ID | <roTwS-3EK-23@gated-at.bofh.it> |
| In reply to | #1380099 |
On Fri, Apr 15, 2016 at 06:20:15PM +0000, Wang Nan wrote:
SNIP
> +
> +#define __TRIGGER_VAR(n) n##_state
> +#define __DEF_TRIGGER_VOID_FUNC(n, op) \
> +static inline void n##_##op(void) {trigger_##op(&__TRIGGER_VAR(n)); }
> +
> +#define __DEF_TRIGGER_FUNC(n, type, op) \
> +static inline type n##_##op(void) {return trigger_##op(&__TRIGGER_VAR(n)); }
> +
> +#define DEFINE_TRIGGER(n, def) \
> +struct trigger n##_state = {.state = TRIGGER_##def, .error = false,};\
> +__DEF_TRIGGER_VOID_FUNC(n, on) \
> +__DEF_TRIGGER_VOID_FUNC(n, release) \
> +__DEF_TRIGGER_VOID_FUNC(n, toggle) \
> +__DEF_TRIGGER_VOID_FUNC(n, colddown) \
> +__DEF_TRIGGER_VOID_FUNC(n, off) \
> +__DEF_TRIGGER_VOID_FUNC(n, error) \
> +__DEF_TRIGGER_FUNC(n, bool, is_released) \
> +__DEF_TRIGGER_FUNC(n, bool, is_toggled) \
> +__DEF_TRIGGER_FUNC(n, bool, is_error)
hum, it gets the impression that __DEF_TRIGGER_FUNC is generic
but it's not, right? __DEF_TRIGGER_BOOL_FUNC might suit better
without the bool type as an argument
thanks,
jirka
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-04-15 20:30 +0200 |
| Subject | [PATCH v3 5/6] perf record: Re-synthesize tracking events after output switching |
| Message-ID | <rogFc-7ma-39@gated-at.bofh.it> |
| In reply to | #1380098 |
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 53bb02a..0772544 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
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2016-04-15 20:30 +0200 |
| Subject | [PATCH v3 3/6] perf record: Force enable --timestamp-filename when --switch-output is provided |
| Message-ID | <rogFd-7ma-49@gated-at.bofh.it> |
| In reply to | #1380098 |
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 5cb1e3d..b7e75b0 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1341,6 +1341,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
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web