Skip to content

Commit cb4e1eb

Browse files
olsajiriacmel
authored andcommitted
perf record: Change switch-output option to take optional argument
Next patches will add --switch-output option arguments, changing the option to allow that and adding its default value to 'signal'. Signed-off-by: Jiri Olsa <[email protected]> Acked-by: Wang Nan <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[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 1b43b70 commit cb4e1eb

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

tools/perf/builtin-record.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
struct switch_output {
5050
bool signal;
51+
const char *str;
52+
bool set;
5153
};
5254

5355
struct record {
@@ -1356,6 +1358,22 @@ static int record__parse_mmap_pages(const struct option *opt,
13561358
return ret;
13571359
}
13581360

1361+
static int switch_output_setup(struct record *rec)
1362+
{
1363+
struct switch_output *s = &rec->switch_output;
1364+
1365+
if (!s->set)
1366+
return 0;
1367+
1368+
if (!strcmp(s->str, "signal")) {
1369+
s->signal = true;
1370+
pr_debug("switch-output with SIGUSR2 signal\n");
1371+
return 0;
1372+
}
1373+
1374+
return -1;
1375+
}
1376+
13591377
static const char * const __record_usage[] = {
13601378
"perf record [<options>] [<command>]",
13611379
"perf record [<options>] -- <command> [<options>]",
@@ -1523,8 +1541,9 @@ static struct option __record_options[] = {
15231541
"Record build-id of all DSOs regardless of hits"),
15241542
OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
15251543
"append timestamp to output filename"),
1526-
OPT_BOOLEAN(0, "switch-output", &record.switch_output.signal,
1527-
"Switch output when receive SIGUSR2"),
1544+
OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str,
1545+
&record.switch_output.set, "signal",
1546+
"Switch output when receive SIGUSR2", "signal"),
15281547
OPT_BOOLEAN(0, "dry-run", &dry_run,
15291548
"Parse options then exit"),
15301549
OPT_END()
@@ -1582,6 +1601,11 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
15821601
return -EINVAL;
15831602
}
15841603

1604+
if (switch_output_setup(rec)) {
1605+
parse_options_usage(record_usage, record_options, "switch-output", 0);
1606+
return -EINVAL;
1607+
}
1608+
15851609
if (rec->switch_output.signal)
15861610
rec->timestamp_filename = true;
15871611

0 commit comments

Comments
 (0)