diff options
author | Wang Nan <wangnan0@huawei.com> | 2016-04-13 04:21:07 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-14 08:00:39 -0400 |
commit | ecfd7a9c044e98fc3da8937e652080bc5abe7918 (patch) | |
tree | e5ffe3e2f38414a6dc3bfd55ff9d965adb611a50 /tools/perf | |
parent | c0bdc1c461dd5b2e492c0746708a3e0da6b13515 (diff) |
perf record: Add '--timestamp-filename' option to append timestamp to output file name
This option appends current timestamp to the output file name.
For example:
# perf record -a --timestamp-filename
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Dump perf.data.2015122622265847 ]
[ perf record: Captured and wrote 0.742 MB perf.data.<timestamp> (90 samples) ]
# ls
perf.data.201512262226584
The timestamp will be useful for identifying each perf.data after the
'perf record' support for generating multiple output files gets
introduced.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.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/1460535673-159866-5-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/builtin-record.c | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 480033fb9b20..3239a6ec9d23 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -56,6 +56,7 @@ struct record { | |||
56 | bool no_buildid_cache; | 56 | bool no_buildid_cache; |
57 | bool no_buildid_cache_set; | 57 | bool no_buildid_cache_set; |
58 | bool buildid_all; | 58 | bool buildid_all; |
59 | bool timestamp_filename; | ||
59 | unsigned long long samples; | 60 | unsigned long long samples; |
60 | }; | 61 | }; |
61 | 62 | ||
@@ -531,6 +532,37 @@ record__finish_output(struct record *rec) | |||
531 | return; | 532 | return; |
532 | } | 533 | } |
533 | 534 | ||
535 | static int | ||
536 | record__switch_output(struct record *rec, bool at_exit) | ||
537 | { | ||
538 | struct perf_data_file *file = &rec->file; | ||
539 | int fd, err; | ||
540 | |||
541 | /* Same Size: "2015122520103046"*/ | ||
542 | char timestamp[] = "InvalidTimestamp"; | ||
543 | |||
544 | rec->samples = 0; | ||
545 | record__finish_output(rec); | ||
546 | err = fetch_current_timestamp(timestamp, sizeof(timestamp)); | ||
547 | if (err) { | ||
548 | pr_err("Failed to get current timestamp\n"); | ||
549 | return -EINVAL; | ||
550 | } | ||
551 | |||
552 | fd = perf_data_file__switch(file, timestamp, | ||
553 | rec->session->header.data_offset, | ||
554 | at_exit); | ||
555 | if (fd >= 0 && !at_exit) { | ||
556 | rec->bytes_written = 0; | ||
557 | rec->session->header.data_size = 0; | ||
558 | } | ||
559 | |||
560 | if (!quiet) | ||
561 | fprintf(stderr, "[ perf record: Dump %s.%s ]\n", | ||
562 | file->path, timestamp); | ||
563 | return fd; | ||
564 | } | ||
565 | |||
534 | static volatile int workload_exec_errno; | 566 | static volatile int workload_exec_errno; |
535 | 567 | ||
536 | /* | 568 | /* |
@@ -865,11 +897,22 @@ out_child: | |||
865 | /* this will be recalculated during process_buildids() */ | 897 | /* this will be recalculated during process_buildids() */ |
866 | rec->samples = 0; | 898 | rec->samples = 0; |
867 | 899 | ||
868 | if (!err) | 900 | if (!err) { |
869 | record__finish_output(rec); | 901 | if (!rec->timestamp_filename) { |
902 | record__finish_output(rec); | ||
903 | } else { | ||
904 | fd = record__switch_output(rec, true); | ||
905 | if (fd < 0) { | ||
906 | status = fd; | ||
907 | goto out_delete_session; | ||
908 | } | ||
909 | } | ||
910 | } | ||
870 | 911 | ||
871 | if (!err && !quiet) { | 912 | if (!err && !quiet) { |
872 | char samples[128]; | 913 | char samples[128]; |
914 | const char *postfix = rec->timestamp_filename ? | ||
915 | ".<timestamp>" : ""; | ||
873 | 916 | ||
874 | if (rec->samples && !rec->opts.full_auxtrace) | 917 | if (rec->samples && !rec->opts.full_auxtrace) |
875 | scnprintf(samples, sizeof(samples), | 918 | scnprintf(samples, sizeof(samples), |
@@ -877,9 +920,9 @@ out_child: | |||
877 | else | 920 | else |
878 | samples[0] = '\0'; | 921 | samples[0] = '\0'; |
879 | 922 | ||
880 | fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s ]\n", | 923 | fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s%s ]\n", |
881 | perf_data_file__size(file) / 1024.0 / 1024.0, | 924 | perf_data_file__size(file) / 1024.0 / 1024.0, |
882 | file->path, samples); | 925 | file->path, postfix, samples); |
883 | } | 926 | } |
884 | 927 | ||
885 | out_delete_session: | 928 | out_delete_session: |
@@ -1249,6 +1292,8 @@ struct option __record_options[] = { | |||
1249 | "file", "vmlinux pathname"), | 1292 | "file", "vmlinux pathname"), |
1250 | OPT_BOOLEAN(0, "buildid-all", &record.buildid_all, | 1293 | OPT_BOOLEAN(0, "buildid-all", &record.buildid_all, |
1251 | "Record build-id of all DSOs regardless of hits"), | 1294 | "Record build-id of all DSOs regardless of hits"), |
1295 | OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename, | ||
1296 | "append timestamp to output filename"), | ||
1252 | OPT_END() | 1297 | OPT_END() |
1253 | }; | 1298 | }; |
1254 | 1299 | ||