Skip to content

Commit bfacbe3

Browse files
olsajiriacmel
authored andcommitted
perf record: Add switch-output time option argument
It's now possible to specify the threshold time for perf.data like: $ perf record --switch-output=30s ... Once it's reached, the current data are dumped in to the perf.data.<timestamp> file and session does on. $ perf record --switch-output=30s ... [ perf record: dump data: Woken up 44 times ] [ perf record: Dump perf.data.2017010213043746 ] ... The time is expected to be a number with appended unit character - s/m/h/d. Signed-off-by: Jiri Olsa <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Acked-by: Wang Nan <[email protected]> Cc: David Ahern <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 0c58244 commit bfacbe3

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

tools/perf/Documentation/perf-record.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ based on 'mode' value:
427427
"signal" - when receiving a SIGUSR2 (default value) or
428428
<size> - when reaching the size threshold, size is expected to
429429
be a number with appended unit character - B/K/M/G
430+
<time> - when reaching the time threshold, size is expected to
431+
be a number with appended unit character - s/m/h/d
430432

431433
Note: the precision of the size threshold hugely depends
432434
on your configuration - the number and size of your ring

tools/perf/builtin-record.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct switch_output {
5050
bool enabled;
5151
bool signal;
5252
unsigned long size;
53+
unsigned long time;
5354
const char *str;
5455
bool set;
5556
};
@@ -91,6 +92,12 @@ static bool switch_output_size(struct record *rec)
9192
(rec->bytes_written >= rec->switch_output.size);
9293
}
9394

95+
static bool switch_output_time(struct record *rec)
96+
{
97+
return rec->switch_output.time &&
98+
trigger_is_ready(&switch_output_trigger);
99+
}
100+
94101
static int record__write(struct record *rec, void *bf, size_t size)
95102
{
96103
if (perf_data_file__write(rec->session->file, bf, size) < 0) {
@@ -737,6 +744,7 @@ static void workload_exec_failed_signal(int signo __maybe_unused,
737744
}
738745

739746
static void snapshot_sig_handler(int sig);
747+
static void alarm_sig_handler(int sig);
740748

741749
int __weak
742750
perf_event__synth_time_conv(const struct perf_event_mmap_page *pc __maybe_unused,
@@ -1068,6 +1076,10 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
10681076
err = fd;
10691077
goto out_child;
10701078
}
1079+
1080+
/* re-arm the alarm */
1081+
if (rec->switch_output.time)
1082+
alarm(rec->switch_output.time);
10711083
}
10721084

10731085
if (hits == rec->samples) {
@@ -1404,6 +1416,13 @@ static int switch_output_setup(struct record *rec)
14041416
{ .tag = 'G', .mult = 1 << 30 },
14051417
{ .tag = 0 },
14061418
};
1419+
static struct parse_tag tags_time[] = {
1420+
{ .tag = 's', .mult = 1 },
1421+
{ .tag = 'm', .mult = 60 },
1422+
{ .tag = 'h', .mult = 60*60 },
1423+
{ .tag = 'd', .mult = 60*60*24 },
1424+
{ .tag = 0 },
1425+
};
14071426
unsigned long val;
14081427

14091428
if (!s->set)
@@ -1422,6 +1441,14 @@ static int switch_output_setup(struct record *rec)
14221441
goto enabled;
14231442
}
14241443

1444+
val = parse_tag_value(s->str, tags_time);
1445+
if (val != (unsigned long) -1) {
1446+
s->time = val;
1447+
pr_debug("switch-output with %s time threshold (%lu seconds)\n",
1448+
s->str, s->time);
1449+
goto enabled;
1450+
}
1451+
14251452
return -1;
14261453

14271454
enabled:
@@ -1602,8 +1629,8 @@ static struct option __record_options[] = {
16021629
OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
16031630
"append timestamp to output filename"),
16041631
OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str,
1605-
&record.switch_output.set, "signal,size",
1606-
"Switch output when receive SIGUSR2 or cross size threshold",
1632+
&record.switch_output.set, "signal,size,time",
1633+
"Switch output when receive SIGUSR2 or cross size,time threshold",
16071634
"signal"),
16081635
OPT_BOOLEAN(0, "dry-run", &dry_run,
16091636
"Parse options then exit"),
@@ -1667,6 +1694,11 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
16671694
return -EINVAL;
16681695
}
16691696

1697+
if (rec->switch_output.time) {
1698+
signal(SIGALRM, alarm_sig_handler);
1699+
alarm(rec->switch_output.time);
1700+
}
1701+
16701702
if (!rec->itr) {
16711703
rec->itr = auxtrace_record__init(rec->evlist, &err);
16721704
if (err)
@@ -1819,3 +1851,11 @@ static void snapshot_sig_handler(int sig __maybe_unused)
18191851
if (switch_output_signal(rec))
18201852
trigger_hit(&switch_output_trigger);
18211853
}
1854+
1855+
static void alarm_sig_handler(int sig __maybe_unused)
1856+
{
1857+
struct record *rec = &record;
1858+
1859+
if (switch_output_time(rec))
1860+
trigger_hit(&switch_output_trigger);
1861+
}

0 commit comments

Comments
 (0)