|
@@ -47,7 +47,9 @@
|
|
#include <linux/time64.h>
|
|
#include <linux/time64.h>
|
|
|
|
|
|
struct switch_output {
|
|
struct switch_output {
|
|
|
|
+ bool enabled;
|
|
bool signal;
|
|
bool signal;
|
|
|
|
+ unsigned long size;
|
|
const char *str;
|
|
const char *str;
|
|
bool set;
|
|
bool set;
|
|
};
|
|
};
|
|
@@ -72,6 +74,23 @@ struct record {
|
|
unsigned long long samples;
|
|
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)
|
|
static int record__write(struct record *rec, void *bf, size_t size)
|
|
{
|
|
{
|
|
if (perf_data_file__write(rec->session->file, bf, size) < 0) {
|
|
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;
|
|
rec->bytes_written += size;
|
|
|
|
+
|
|
|
|
+ if (switch_output_size(rec))
|
|
|
|
+ trigger_hit(&switch_output_trigger);
|
|
|
|
+
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -199,10 +222,6 @@ static volatile int done;
|
|
static volatile int signr = -1;
|
|
static volatile int signr = -1;
|
|
static volatile int child_finished;
|
|
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)
|
|
static void sig_handler(int sig)
|
|
{
|
|
{
|
|
if (sig == SIGCHLD)
|
|
if (sig == SIGCHLD)
|
|
@@ -848,11 +867,11 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
|
|
signal(SIGTERM, sig_handler);
|
|
signal(SIGTERM, sig_handler);
|
|
signal(SIGSEGV, sigsegv_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);
|
|
signal(SIGUSR2, snapshot_sig_handler);
|
|
if (rec->opts.auxtrace_snapshot_mode)
|
|
if (rec->opts.auxtrace_snapshot_mode)
|
|
trigger_on(&auxtrace_snapshot_trigger);
|
|
trigger_on(&auxtrace_snapshot_trigger);
|
|
- if (rec->switch_output.signal)
|
|
|
|
|
|
+ if (rec->switch_output.enabled)
|
|
trigger_on(&switch_output_trigger);
|
|
trigger_on(&switch_output_trigger);
|
|
} else {
|
|
} else {
|
|
signal(SIGUSR2, SIG_IGN);
|
|
signal(SIGUSR2, SIG_IGN);
|
|
@@ -1361,6 +1380,14 @@ out_free:
|
|
static int switch_output_setup(struct record *rec)
|
|
static int switch_output_setup(struct record *rec)
|
|
{
|
|
{
|
|
struct switch_output *s = &rec->switch_output;
|
|
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)
|
|
if (!s->set)
|
|
return 0;
|
|
return 0;
|
|
@@ -1368,10 +1395,22 @@ static int switch_output_setup(struct record *rec)
|
|
if (!strcmp(s->str, "signal")) {
|
|
if (!strcmp(s->str, "signal")) {
|
|
s->signal = true;
|
|
s->signal = true;
|
|
pr_debug("switch-output with SIGUSR2 signal\n");
|
|
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;
|
|
return -1;
|
|
|
|
+
|
|
|
|
+enabled:
|
|
|
|
+ rec->timestamp_filename = true;
|
|
|
|
+ s->enabled = true;
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
static const char * const __record_usage[] = {
|
|
static const char * const __record_usage[] = {
|
|
@@ -1542,8 +1581,9 @@ static struct option __record_options[] = {
|
|
OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
|
|
OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
|
|
"append timestamp to output filename"),
|
|
"append timestamp to output filename"),
|
|
OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str,
|
|
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,
|
|
OPT_BOOLEAN(0, "dry-run", &dry_run,
|
|
"Parse options then exit"),
|
|
"Parse options then exit"),
|
|
OPT_END()
|
|
OPT_END()
|
|
@@ -1606,9 +1646,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
|
|
- if (rec->switch_output.signal)
|
|
|
|
- rec->timestamp_filename = true;
|
|
|
|
-
|
|
|
|
if (!rec->itr) {
|
|
if (!rec->itr) {
|
|
rec->itr = auxtrace_record__init(rec->evlist, &err);
|
|
rec->itr = auxtrace_record__init(rec->evlist, &err);
|
|
if (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) {
|
|
if (rec->no_buildid_cache || rec->no_buildid) {
|
|
disable_buildid_cache();
|
|
disable_buildid_cache();
|
|
- } else if (rec->switch_output.signal) {
|
|
|
|
|
|
+ } else if (rec->switch_output.enabled) {
|
|
/*
|
|
/*
|
|
* In 'perf record --switch-output', disable buildid
|
|
* In 'perf record --switch-output', disable buildid
|
|
* generation by default to reduce data file switching
|
|
* generation by default to reduce data file switching
|
|
@@ -1749,6 +1786,8 @@ out:
|
|
|
|
|
|
static void snapshot_sig_handler(int sig __maybe_unused)
|
|
static void snapshot_sig_handler(int sig __maybe_unused)
|
|
{
|
|
{
|
|
|
|
+ struct record *rec = &record;
|
|
|
|
+
|
|
if (trigger_is_ready(&auxtrace_snapshot_trigger)) {
|
|
if (trigger_is_ready(&auxtrace_snapshot_trigger)) {
|
|
trigger_hit(&auxtrace_snapshot_trigger);
|
|
trigger_hit(&auxtrace_snapshot_trigger);
|
|
auxtrace_record__snapshot_started = 1;
|
|
auxtrace_record__snapshot_started = 1;
|
|
@@ -1756,6 +1795,6 @@ static void snapshot_sig_handler(int sig __maybe_unused)
|
|
trigger_error(&auxtrace_snapshot_trigger);
|
|
trigger_error(&auxtrace_snapshot_trigger);
|
|
}
|
|
}
|
|
|
|
|
|
- if (trigger_is_ready(&switch_output_trigger))
|
|
|
|
|
|
+ if (switch_output_signal(rec))
|
|
trigger_hit(&switch_output_trigger);
|
|
trigger_hit(&switch_output_trigger);
|
|
}
|
|
}
|