From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@kernel.org>,
David Ahern <dsahern@gmail.com>,
Namhyung Kim <namhyung@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 10/13] perf record: Add switch-output size option argument
Date: Wed, 11 Jan 2017 17:22:08 -0300 [thread overview]
Message-ID: <20170111202211.32137-11-acme@kernel.org> (raw)
In-Reply-To: <20170111202211.32137-1-acme@kernel.org>
From: Jiri Olsa <jolsa@kernel.org>
It's now possible to specify the threshold size for perf.data like:
$ perf record --switch-output=2G ...
Once it's reached, the current data are dumped in to the
perf.data.<timestamp> file and session does on.
$ perf record --switch-output=2G ...
[ perf record: dump data: Woken up 7244 times ]
[ perf record: Dump perf.data.2017010214093746 ]
...
The size is expected to be a number with appended unit character -
B/K/M/G.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1483955520-29063-5-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Documentation/perf-record.txt | 12 +++++-
tools/perf/builtin-record.c | 67 +++++++++++++++++++++++++-------
2 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 5054d9147f0f..3d55d2fd48b3 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -421,9 +421,17 @@ Configure all used events to run in user space.
--timestamp-filename
Append timestamp to output file name.
---switch-output::
+--switch-output[=mode]::
Generate multiple perf.data files, timestamp prefixed, switching to a new one
-when receiving a SIGUSR2.
+based on 'mode' value:
+ "signal" - when receiving a SIGUSR2 (default value) or
+ <size> - when reaching the size threshold, size is expected to
+ be a number with appended unit character - B/K/M/G
+
+ Note: the precision of the size threshold hugely depends
+ on your configuration - the number and size of your ring
+ buffers (-m). It is generally more precise for higher sizes
+ (like >5M), for lower values expect different sizes.
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
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 2bf811acaf8d..3fa64492ee62 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -47,7 +47,9 @@
#include <linux/time64.h>
struct switch_output {
+ bool enabled;
bool signal;
+ unsigned long size;
const char *str;
bool set;
};
@@ -72,6 +74,23 @@ struct record {
unsigned long long samples;
};
+static volatile int auxtrace_record__snapshot_started;
+static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
+static DEFINE_TRIGGER(switch_output_trigger);
+
+static bool switch_output_signal(struct record *rec)
+{
+ return rec->switch_output.signal &&
+ trigger_is_ready(&switch_output_trigger);
+}
+
+static bool switch_output_size(struct record *rec)
+{
+ return rec->switch_output.size &&
+ trigger_is_ready(&switch_output_trigger) &&
+ (rec->bytes_written >= rec->switch_output.size);
+}
+
static int record__write(struct record *rec, void *bf, size_t size)
{
if (perf_data_file__write(rec->session->file, bf, size) < 0) {
@@ -80,6 +99,10 @@ static int record__write(struct record *rec, void *bf, size_t size)
}
rec->bytes_written += size;
+
+ if (switch_output_size(rec))
+ trigger_hit(&switch_output_trigger);
+
return 0;
}
@@ -199,10 +222,6 @@ static volatile int done;
static volatile int signr = -1;
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)
{
if (sig == SIGCHLD)
@@ -848,11 +867,11 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
signal(SIGTERM, sig_handler);
signal(SIGSEGV, sigsegv_handler);
- if (rec->opts.auxtrace_snapshot_mode || rec->switch_output.signal) {
+ if (rec->opts.auxtrace_snapshot_mode || rec->switch_output.enabled) {
signal(SIGUSR2, snapshot_sig_handler);
if (rec->opts.auxtrace_snapshot_mode)
trigger_on(&auxtrace_snapshot_trigger);
- if (rec->switch_output.signal)
+ if (rec->switch_output.enabled)
trigger_on(&switch_output_trigger);
} else {
signal(SIGUSR2, SIG_IGN);
@@ -1361,6 +1380,14 @@ static int record__parse_mmap_pages(const struct option *opt,
static int switch_output_setup(struct record *rec)
{
struct switch_output *s = &rec->switch_output;
+ static struct parse_tag tags_size[] = {
+ { .tag = 'B', .mult = 1 },
+ { .tag = 'K', .mult = 1 << 10 },
+ { .tag = 'M', .mult = 1 << 20 },
+ { .tag = 'G', .mult = 1 << 30 },
+ { .tag = 0 },
+ };
+ unsigned long val;
if (!s->set)
return 0;
@@ -1368,10 +1395,22 @@ static int switch_output_setup(struct record *rec)
if (!strcmp(s->str, "signal")) {
s->signal = true;
pr_debug("switch-output with SIGUSR2 signal\n");
- return 0;
+ goto enabled;
+ }
+
+ val = parse_tag_value(s->str, tags_size);
+ if (val != (unsigned long) -1) {
+ s->size = val;
+ pr_debug("switch-output with %s size threshold\n", s->str);
+ goto enabled;
}
return -1;
+
+enabled:
+ rec->timestamp_filename = true;
+ s->enabled = true;
+ return 0;
}
static const char * const __record_usage[] = {
@@ -1542,8 +1581,9 @@ static struct option __record_options[] = {
OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
"append timestamp to output filename"),
OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str,
- &record.switch_output.set, "signal",
- "Switch output when receive SIGUSR2", "signal"),
+ &record.switch_output.set, "signal,size",
+ "Switch output when receive SIGUSR2 or cross size threshold",
+ "signal"),
OPT_BOOLEAN(0, "dry-run", &dry_run,
"Parse options then exit"),
OPT_END()
@@ -1606,9 +1646,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
return -EINVAL;
}
- if (rec->switch_output.signal)
- rec->timestamp_filename = true;
-
if (!rec->itr) {
rec->itr = auxtrace_record__init(rec->evlist, &err);
if (err)
@@ -1657,7 +1694,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
if (rec->no_buildid_cache || rec->no_buildid) {
disable_buildid_cache();
- } else if (rec->switch_output.signal) {
+ } else if (rec->switch_output.enabled) {
/*
* In 'perf record --switch-output', disable buildid
* generation by default to reduce data file switching
@@ -1749,6 +1786,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
static void snapshot_sig_handler(int sig __maybe_unused)
{
+ struct record *rec = &record;
+
if (trigger_is_ready(&auxtrace_snapshot_trigger)) {
trigger_hit(&auxtrace_snapshot_trigger);
auxtrace_record__snapshot_started = 1;
@@ -1756,6 +1795,6 @@ static void snapshot_sig_handler(int sig __maybe_unused)
trigger_error(&auxtrace_snapshot_trigger);
}
- if (trigger_is_ready(&switch_output_trigger))
+ if (switch_output_signal(rec))
trigger_hit(&switch_output_trigger);
}
--
2.9.3
next prev parent reply other threads:[~2017-01-11 20:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-11 20:21 [GIT PULL 00/13] perf/core improvements and fixes Arnaldo Carvalho de Melo
2017-01-11 20:21 ` [PATCH 01/13] perf jvmti: Create libdir directory before installing libperf-jvmti.so Arnaldo Carvalho de Melo
2017-01-11 20:22 ` [PATCH 02/13] tools lib subcmd: Add missing linux/kernel.h include to subcmd.h Arnaldo Carvalho de Melo
2017-01-11 20:22 ` [PATCH 03/13] perf machine: Add a kallsyms loading constructor Arnaldo Carvalho de Melo
2017-01-11 20:22 ` [PATCH 04/13] perf kallsyms: Introduce tool to look for extended symbol information on the running kernel Arnaldo Carvalho de Melo
2017-01-11 20:22 ` [PATCH 05/13] perf trace: Allow specifying list of syscalls and events in -e/--expr/--event Arnaldo Carvalho de Melo
2017-01-11 20:22 ` [PATCH 06/13] perf evlist: Fix typo in perf_evlist__start_workload() Arnaldo Carvalho de Melo
2017-01-11 20:22 ` [PATCH 07/13] perf tools: Add unit_number__scnprintf function Arnaldo Carvalho de Melo
2017-01-11 20:22 ` [PATCH 08/13] perf record: Add struct switch_output Arnaldo Carvalho de Melo
2017-01-11 20:22 ` [PATCH 09/13] perf record: Change switch-output option to take optional argument Arnaldo Carvalho de Melo
2017-01-11 20:22 ` Arnaldo Carvalho de Melo [this message]
2017-01-11 20:22 ` [PATCH 11/13] perf record: Add switch-output size warning Arnaldo Carvalho de Melo
2017-01-11 20:22 ` [PATCH 12/13] perf record: Add switch-output time option argument Arnaldo Carvalho de Melo
2017-01-11 20:22 ` [PATCH 13/13] tools: Sync x86's vmx.h with the kernel Arnaldo Carvalho de Melo
2017-01-12 8:25 ` [GIT PULL 00/13] perf/core improvements and fixes Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170111202211.32137-11-acme@kernel.org \
--to=acme@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=dsahern@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is 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.