perf tools: Add switch-output size and time threshold options
Jiri Olsa
reviewerv2 cover perf tools: Add switch-output size and time threshold options
hi,
adding a way to configure switch data output
for size and time, like:
$ sudo perf record -e 'sched:*' --switch-output=10M -avg callchain: type FP switch-output with 10M size threshold mmap size 528384B [ perf record: dump data: Woken up 37 times ] [ perf record: Dump perf.data.2017010309135512 ] [ perf record: dump data: Woken up 39 times ] [ perf record: Dump perf.data.2017010309135771 ] [ perf record: dump data: Woken up 38 times ] [ perf record: Dump perf.data.2017010309140005 ] ^C[ perf record: Woken up 16 times to write data ] [ perf record: Dump perf.data.2017010309140111 ] [ perf record: Captured and wrote 4.748 MB perf.data.<timestamp> ] ...
the default for switch-output option stays and does the SIGUSR2 output switch
v2 changes:
- some patches already accepted
- add warning for switched size lower than ring buffer wakeup size
- got Wang Nan's Tested-by, but did not include it
due to changes I made in v2
Also available in:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/fixes
thanks,
jirka
---
Jiri Olsa (6):
perf tools: Add unit_number__scnprint function
perf record: Add struct switch_output
perf record: Change switch-output option to take optional argument perf record: Add switch-output size option argument perf record: Add switch-output size warning
perf record: Add switch-output time option argument
tools/perf/Documentation/perf-record.txt | 14 +++++++-- tools/perf/builtin-record.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 +++ tools/perf/tests/tests.h | 1 + tools/perf/tests/unit_number__scnprint.c | 37 ++++++++++++++++++++++ tools/perf/util/evlist.c | 10 ++++-- tools/perf/util/evlist.h | 2 ++ tools/perf/util/util.c | 13 ++++++++ tools/perf/util/util.h | 1 + 10 files changed, 219 insertions(+), 18 deletions(-) create mode 100644 tools/perf/tests/unit_number__scnprint.c
Jiri Olsa
reviewerPATCH 1/6 perf tools: Add unit_number__scnprint function
Adding unit_number__scnprint function to display
size units and use it in -m option info message.
Before:
$ perf record -m 10M ls rounding mmap pages size to 16777216 bytes (4096 pages) ...
After:
$ perf record -m 10M ls rounding mmap pages size to 16M (4096 pages) ...
--- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 ++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/unit_number__scnprint.c | 37 ++++++++++++++++++++++++++++++++ tools/perf/util/evlist.c | 8 +++++-- tools/perf/util/util.c | 13 +++++++++++ tools/perf/util/util.h | 1 + 7 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tools/perf/tests/unit_number__scnprint.c
tools/perf/tests/Build +1 -0
@@ -44,6 +44,7 @@ perf-y += is_printable_array.o perf-y += bitmap.o perf-y += perf-hooks.o perf-y += clang.o +perf-y += unit_number__scnprint.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir)
tools/perf/tests/builtin-test.c +4 -0
@@ -247,6 +247,10 @@ static struct test generic_tests[] = { } }, { + .desc = "unit_number__scnprint", + .func = test__unit_number__scnprint, + }, + { .func = NULL, }, };
tools/perf/tests/tests.h +1 -0
@@ -96,6 +96,7 @@ int test__perf_hooks(int subtest);int test__clang (int subtest);const char *test__clang_subtest_get_desc (int subtest);int test__clang_subtest_get_nr (void ); +int test__unit_number__scnprint (int subtest);#if defined(__arm__) || defined(__aarch64__)#ifdef HAVE_DWARF_UNWIND_SUPPORT
tools/perf/tests/unit_number__scnprint.c new file +37 -0
@@ -0,0 +1,37 @@ +#include <linux/compiler.h> +#include <linux/types.h> +#include "tests.h" +#include "util.h" +#include "debug.h" + +int test__unit_number__scnprint (int subtest__maybe_unused ) +{ +struct { +u64 n; +const char *str; + } test[] = { + {1 ,"1B" }, + {10 *1024 ,"10K" }, + {20 *1024 *1024 ,"20M" }, + {30 *1024 *1024 *1024ULL ,"30G" }, + {0 ,"0B" }, + {0 ,NULL }, + }; +unsigned i =0 ; + +while (test[i].str) { +char buf[100 ]; + +unit_number__scnprint (buf,sizeof (buf), test[i].n); + +pr_debug ("n %" PRIu64", str '%s', buf '%s'\n" , + test[i].n, test[i].str, buf); + +if (strcmp (test[i].str, buf)) +return TEST_FAIL ; + + i++; + } + +return TEST_OK ; +}
tools/perf/util/evlist.c +6 -2
@@ -1224,12 +1224,16 @@ static long parse_pages_arg(const char *str, unsigned long min,if (pages ==0 && min ==0 ) {/* leave number of pages at 0 */ }else if (!is_power_of_2 (pages)) { +char buf[100 ]; +/* round pages up to next power of 2 */ pages =roundup_pow_of_two (pages);if (!pages)return -EINVAL ; -pr_info ("rounding mmap pages size to %lu bytes (%lu pages)\n" , - pages * page_size, pages); + +unit_number__scnprint (buf,sizeof (buf), pages * page_size); +pr_info ("rounding mmap pages size to %s (%lu pages)\n" , + buf, pages); }if (pages > max)
tools/perf/util/util.c +13 -0
@@ -789,3 +789,16 @@ int is_printable_array(char *p, unsigned int len) }return 1 ; } + +int unit_number__scnprint (char *buf,size_t size,u64 n) +{ +char unit[4 ] ="BKMG" ; +int i =0 ; + +while (((n /1024 ) >1 ) && (i <3 )) { + n /=1024 ; + i++; + } + +return scnprintf (buf, size,"%" PRIu64"%c" , n, unit[i]); +}
tools/perf/util/util.h +1 -0
@@ -363,4 +363,5 @@ int is_printable_array(char *p, unsigned int len);int timestamp__scnprintf_usec (u64 timestamp,char *buf,size_t sz); +int unit_number__scnprint (char *buf,size_t size,u64 n);#endif /* GIT_COMPAT_UTIL_H */
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 1/6] perf tools: Add unit_number__scnprint function
Em Mon, Jan 09, 2017 at 10:51:55AM +0100, Jiri Olsa escreveu:
Quoted 1 line
Adding
unit_number__scnprintfunction to display
Renaming to unit_number__scnprintf() for consistency.
- Arnaldo
Quoted 167 lines
size units and use it in -m option info message.
Before:
$ perf record -m 10M ls rounding mmap pages size to 16777216 bytes (4096 pages) ...After:
$ perf record -m 10M ls rounding mmap pages size to 16M (4096 pages) ...Signed-off-by Jiri Olsa <[email protected]>Cc David Ahern <[email protected]>Cc Namhyung Kim <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Wang Nan <[email protected]>--- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 ++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/unit_number__scnprint.c | 37 ++++++++++++++++++++++++++++++++ tools/perf/util/evlist.c | 8 +++++-- tools/perf/util/util.c | 13 +++++++++++ tools/perf/util/util.h | 1 + 7 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tools/perf/tests/unit_number__scnprint.ctools/perf/tests/Build +1
-0@@ -44,6 +44,7 @@ perf-y += is_printable_array.o perf-y += bitmap.o perf-y += perf-hooks.o perf-y += clang.o +perf-y += unit_number__scnprint.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir)tools/perf/tests/builtin-test.c +4
-0@@ -247,6 +247,10 @@ static struct test generic_tests[] = { } }, { + .desc = "unit_number__scnprint", + .func = test__unit_number__scnprint, + }, + { .func = NULL, }, };tools/perf/tests/tests.h +1
-0@@ -96,6 +96,7 @@ int test__perf_hooks(int subtest);int test__clang (int subtest);const char *test__clang_subtest_get_desc (int subtest);int test__clang_subtest_get_nr (void ); +int test__unit_number__scnprint (int subtest);#if defined(__arm__) || defined(__aarch64__)#ifdef HAVE_DWARF_UNWIND_SUPPORT tools/perf/tests/unit_number__scnprint.c new file +37
-0@@ -0,0 +1,37 @@ +#include <linux/compiler.h> +#include <linux/types.h> +#include "tests.h" +#include "util.h" +#include "debug.h" + +int test__unit_number__scnprint (int subtest__maybe_unused ) +{ +struct { +u64 n; +const char *str; + } test[] = { + {1 ,"1B" }, + {10 *1024 ,"10K" }, + {20 *1024 *1024 ,"20M" }, + {30 *1024 *1024 *1024ULL ,"30G" }, + {0 ,"0B" }, + {0 ,NULL }, + }; +unsigned i =0 ; + +while (test[i].str) { +char buf[100 ]; + +unit_number__scnprint (buf,sizeof (buf), test[i].n); + +pr_debug ("n %" PRIu64", str '%s', buf '%s'\n" , + test[i].n, test[i].str, buf); + +if (strcmp (test[i].str, buf)) +return TEST_FAIL ; + + i++; + } + +return TEST_OK ; +}tools/perf/util/evlist.c +6
-2@@ -1224,12 +1224,16 @@ static long parse_pages_arg(const char *str, unsigned long min,if (pages ==0 && min ==0 ) {/* leave number of pages at 0 */ }else if (!is_power_of_2 (pages)) { +char buf[100 ]; +/* round pages up to next power of 2 */ pages =roundup_pow_of_two (pages);if (!pages)return -EINVAL ; -pr_info ("rounding mmap pages size to %lu bytes (%lu pages)\n" , - pages * page_size, pages); + +unit_number__scnprint (buf,sizeof (buf), pages * page_size); +pr_info ("rounding mmap pages size to %s (%lu pages)\n" , + buf, pages); }if (pages > max)tools/perf/util/util.c +13
-0@@ -789,3 +789,16 @@ int is_printable_array(char *p, unsigned int len) }return 1 ; } + +int unit_number__scnprint (char *buf,size_t size,u64 n) +{ +char unit[4 ] ="BKMG" ; +int i =0 ; + +while (((n /1024 ) >1 ) && (i <3 )) { + n /=1024 ; + i++; + } + +return scnprintf (buf, size,"%" PRIu64"%c" , n, unit[i]); +}tools/perf/util/util.h +1
-0@@ -363,4 +363,5 @@ int is_printable_array(char *p, unsigned int len);int timestamp__scnprintf_usec (u64 timestamp,char *buf,size_t sz); +int unit_number__scnprint (char *buf,size_t size,u64 n);#endif /* GIT_COMPAT_UTIL_H */ Signature · 1 line
2.7.4
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Add unit_number__scnprintf function
In reply to Jiri Olsaperf tools: Add unit_number__scnprintf function
Commit-ID: 9808143ba2e54818a3cf445d9b69b3f5f15451ee Gitweb: http://git.kernel.org/tip/9808143ba2e54818a3cf445d9b69b3f5f15451ee Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 9 Jan 2017 10:51:55 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jan 2017 16:48:01 -0300
perf tools: Add unit_number__scnprintf function
Add unit_number__scnprintf function to display size units and use it in -m option info message.
Before:
$ perf record -m 10M ls rounding mmap pages size to 16777216 bytes (4096 pages) ...
After:
$ perf record -m 10M ls rounding mmap pages size to 16M (4096 pages) ...
--- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 ++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/unit_number__scnprintf.c | 37 +++++++++++++++++++++++++++++++ tools/perf/util/evlist.c | 8 +++++-- tools/perf/util/util.c | 13 +++++++++++ tools/perf/util/util.h | 1 + 7 files changed, 63 insertions(+), 2 deletions(-)
tools/perf/tests/Build +1 -0
@@ -44,6 +44,7 @@ perf-y += is_printable_array.o perf-y += bitmap.o perf-y += perf-hooks.o perf-y += clang.o +perf-y += unit_number__scnprintf.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir)
tools/perf/tests/builtin-test.c +4 -0
@@ -247,6 +247,10 @@ static struct test generic_tests[] = { } }, { + .desc = "unit_number__scnprintf", + .func = test__unit_number__scnprint, + }, + { .func = NULL, }, };
tools/perf/tests/tests.h +1 -0
@@ -96,6 +96,7 @@ int test__perf_hooks(int subtest);int test__clang (int subtest);const char *test__clang_subtest_get_desc (int subtest);int test__clang_subtest_get_nr (void ); +int test__unit_number__scnprint (int subtest);#if defined(__arm__) || defined(__aarch64__)#ifdef HAVE_DWARF_UNWIND_SUPPORT
tools/perf/tests/unit_number__scnprintf.c new file +37 -0
@@ -0,0 +1,37 @@ +#include <linux/compiler.h> +#include <linux/types.h> +#include "tests.h" +#include "util.h" +#include "debug.h" + +int test__unit_number__scnprint (int subtest__maybe_unused ) +{ +struct { +u64 n; +const char *str; + } test[] = { + {1 ,"1B" }, + {10 *1024 ,"10K" }, + {20 *1024 *1024 ,"20M" }, + {30 *1024 *1024 *1024ULL ,"30G" }, + {0 ,"0B" }, + {0 ,NULL }, + }; +unsigned i =0 ; + +while (test[i].str) { +char buf[100 ]; + +unit_number__scnprintf (buf,sizeof (buf), test[i].n); + +pr_debug ("n %" PRIu64", str '%s', buf '%s'\n" , + test[i].n, test[i].str, buf); + +if (strcmp (test[i].str, buf)) +return TEST_FAIL ; + + i++; + } + +return TEST_OK ; +}
tools/perf/util/evlist.c +6 -2
@@ -1224,12 +1224,16 @@ static long parse_pages_arg(const char *str, unsigned long min,if (pages ==0 && min ==0 ) {/* leave number of pages at 0 */ }else if (!is_power_of_2 (pages)) { +char buf[100 ]; +/* round pages up to next power of 2 */ pages =roundup_pow_of_two (pages);if (!pages)return -EINVAL ; -pr_info ("rounding mmap pages size to %lu bytes (%lu pages)\n" , - pages * page_size, pages); + +unit_number__scnprintf (buf,sizeof (buf), pages * page_size); +pr_info ("rounding mmap pages size to %s (%lu pages)\n" , + buf, pages); }if (pages > max)
tools/perf/util/util.c +13 -0
@@ -789,3 +789,16 @@ int is_printable_array(char *p, unsigned int len) }return 1 ; } + +int unit_number__scnprintf (char *buf,size_t size,u64 n) +{ +char unit[4 ] ="BKMG" ; +int i =0 ; + +while (((n /1024 ) >1 ) && (i <3 )) { + n /=1024 ; + i++; + } + +return scnprintf (buf, size,"%" PRIu64"%c" , n, unit[i]); +}
tools/perf/util/util.h +1 -0
@@ -363,4 +363,5 @@ int is_printable_array(char *p, unsigned int len);int timestamp__scnprintf_usec (u64 timestamp,char *buf,size_t sz); +int unit_number__scnprintf (char *buf,size_t size,u64 n);#endif /* GIT_COMPAT_UTIL_H */
Jiri Olsa
reviewerPATCH 2/6 perf record: Add struct switch_output
In reply to Jiri OlsaNext patches will add more --switch-output option arguments, so preparing the data holder.
--- tools/perf/builtin-record.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
tools/perf/builtin-record.c +10 -6
@@ -46,6 +46,10 @@#include <asm/bug.h> #include <linux/time64.h> +struct switch_output { +bool signal; +}; +struct record {struct perf_tool tool;struct record_opts opts;
@@ -62,7 +66,7 @@ struct record {bool no_buildid_cache_set;bool buildid_all;bool timestamp_filename; -bool switch_output; +struct switch_output switch_output;unsigned long long samples; };
@@ -842,11 +846,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) { +if (rec->opts.auxtrace_snapshot_mode || rec->switch_output.signal) {signal (SIGUSR2 , snapshot_sig_handler);if (rec->opts.auxtrace_snapshot_mode)trigger_on (&auxtrace_snapshot_trigger); -if (rec->switch_output) +if (rec->switch_output.signal)trigger_on (&switch_output_trigger); }else {signal (SIGUSR2 ,SIG_IGN );
@@ -1519,7 +1523,7 @@ static struct option __record_options[] = { "Record build-id of all DSOs regardless of hits"),OPT_BOOLEAN (0 ,"timestamp-filename" , &record.timestamp_filename,"append timestamp to output filename" ), -OPT_BOOLEAN (0 ,"switch-output" , &record.switch_output, +OPT_BOOLEAN (0 ,"switch-output" , &record.switch_output.signal,"Switch output when receive SIGUSR2" ),OPT_BOOLEAN (0 ,"dry-run" , &dry_run, "Parse options then exit"),
@@ -1578,7 +1582,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)return -EINVAL ; } -if (rec->switch_output) +if (rec->switch_output.signal) rec->timestamp_filename = true;if (!rec->itr) {
@@ -1629,7 +1633,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) { + }else if (rec->switch_output.signal) {/* * In 'perf record --switch-output', disable buildid * generation by default to reduce data file switching
Signature · 1 line
2.7.4
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf record: Add struct switch_output
perf record: Add struct switch_output
Commit-ID: 1b43b70484a9617de5fe2c12e64bea006010ac1c Gitweb: http://git.kernel.org/tip/1b43b70484a9617de5fe2c12e64bea006010ac1c Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 9 Jan 2017 10:51:56 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jan 2017 16:48:01 -0300
perf record: Add struct switch_output
Next patches will add more --switch-output option arguments, so preparing the data holder.
--- tools/perf/builtin-record.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
tools/perf/builtin-record.c +10 -6
@@ -46,6 +46,10 @@#include <asm/bug.h> #include <linux/time64.h> +struct switch_output { +bool signal; +}; +struct record {struct perf_tool tool;struct record_opts opts;
@@ -62,7 +66,7 @@ struct record {bool no_buildid_cache_set;bool buildid_all;bool timestamp_filename; -bool switch_output; +struct switch_output switch_output;unsigned long long samples; };
@@ -842,11 +846,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) { +if (rec->opts.auxtrace_snapshot_mode || rec->switch_output.signal) {signal (SIGUSR2 , snapshot_sig_handler);if (rec->opts.auxtrace_snapshot_mode)trigger_on (&auxtrace_snapshot_trigger); -if (rec->switch_output) +if (rec->switch_output.signal)trigger_on (&switch_output_trigger); }else {signal (SIGUSR2 ,SIG_IGN );
@@ -1519,7 +1523,7 @@ static struct option __record_options[] = { "Record build-id of all DSOs regardless of hits"),OPT_BOOLEAN (0 ,"timestamp-filename" , &record.timestamp_filename,"append timestamp to output filename" ), -OPT_BOOLEAN (0 ,"switch-output" , &record.switch_output, +OPT_BOOLEAN (0 ,"switch-output" , &record.switch_output.signal,"Switch output when receive SIGUSR2" ),OPT_BOOLEAN (0 ,"dry-run" , &dry_run, "Parse options then exit"),
@@ -1578,7 +1582,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)return -EINVAL ; } -if (rec->switch_output) +if (rec->switch_output.signal) rec->timestamp_filename = true;if (!rec->itr) {
@@ -1629,7 +1633,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) { + }else if (rec->switch_output.signal) {/* * In 'perf record --switch-output', disable buildid * generation by default to reduce data file switching
Jiri Olsa
reviewerPATCH 3/6 perf record: Change switch-output option to take optional argument
In reply to Jiri OlsaNext patches will add --switch-output option arguments, changing the option to allow that and adding its default value to 'signal'.
--- tools/perf/builtin-record.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +26 -2
@@ -48,6 +48,8 @@struct switch_output {bool signal; +const char *str; +bool set; };struct record {
@@ -1356,6 +1358,22 @@ static int record__parse_mmap_pages(const struct option *opt,return ret; } +static int switch_output_setup (struct record *rec) +{ +struct switch_output *s = &rec->switch_output; + +if (!s->set) +return 0 ; + +if (!strcmp (s->str,"signal" )) { + s->signal = true; +pr_debug ("switch-output with SIGUSR2 signal\n" ); +return 0 ; + } + +return -1 ; +} +static const char *const __record_usage[] = {"perf record [<options>] [<command>]" ,"perf record [<options>] -- <command> [<options>]" ,
@@ -1523,8 +1541,9 @@ static struct option __record_options[] = { "Record build-id of all DSOs regardless of hits"),OPT_BOOLEAN (0 ,"timestamp-filename" , &record.timestamp_filename,"append timestamp to output filename" ), -OPT_BOOLEAN (0 ,"switch-output" , &record.switch_output.signal, -"Switch output when receive SIGUSR2" ), +OPT_STRING_OPTARG_SET (0 ,"switch-output" , &record.switch_output.str, + &record.switch_output.set,"signal" , +"Switch output when receive SIGUSR2" ,"signal" ),OPT_BOOLEAN (0 ,"dry-run" , &dry_run,"Parse options then exit" ),OPT_END ()
@@ -1582,6 +1601,11 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)return -EINVAL ; } +if (switch_output_setup (rec)) { +parse_options_usage (record_usage, record_options,"switch-output" ,0 ); +return -EINVAL ; + } +if (rec->switch_output.signal) rec->timestamp_filename = true;
Signature · 1 line
2.7.4
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf record: Change switch-output option to take optional argument
perf record: Change switch-output option to take optional argument
Commit-ID: cb4e1ebb6a398ff5b0067034b0d16566af4d78e8 Gitweb: http://git.kernel.org/tip/cb4e1ebb6a398ff5b0067034b0d16566af4d78e8 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 9 Jan 2017 10:51:57 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jan 2017 16:48:01 -0300
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'.
--- tools/perf/builtin-record.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +26 -2
@@ -48,6 +48,8 @@struct switch_output {bool signal; +const char *str; +bool set; };struct record {
@@ -1356,6 +1358,22 @@ out_free:return ret; } +static int switch_output_setup (struct record *rec) +{ +struct switch_output *s = &rec->switch_output; + +if (!s->set) +return 0 ; + +if (!strcmp (s->str,"signal" )) { + s->signal = true; +pr_debug ("switch-output with SIGUSR2 signal\n" ); +return 0 ; + } + +return -1 ; +} +static const char *const __record_usage[] = {"perf record [<options>] [<command>]" ,"perf record [<options>] -- <command> [<options>]" ,
@@ -1523,8 +1541,9 @@ static struct option __record_options[] = { "Record build-id of all DSOs regardless of hits"),OPT_BOOLEAN (0 ,"timestamp-filename" , &record.timestamp_filename,"append timestamp to output filename" ), -OPT_BOOLEAN (0 ,"switch-output" , &record.switch_output.signal, -"Switch output when receive SIGUSR2" ), +OPT_STRING_OPTARG_SET (0 ,"switch-output" , &record.switch_output.str, + &record.switch_output.set,"signal" , +"Switch output when receive SIGUSR2" ,"signal" ),OPT_BOOLEAN (0 ,"dry-run" , &dry_run,"Parse options then exit" ),OPT_END ()
@@ -1582,6 +1601,11 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)return -EINVAL ; } +if (switch_output_setup (rec)) { +parse_options_usage (record_usage, record_options,"switch-output" ,0 ); +return -EINVAL ; + } +if (rec->switch_output.signal) rec->timestamp_filename = true;
Jiri Olsa
reviewerPATCH 4/6 perf record: Add switch-output size option argument
In reply to Jiri OlsaIt'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.
--- tools/perf/Documentation/perf-record.txt | 12 +++++- tools/perf/builtin-record.c | 67 +++++++++++++++++++++++++------- 2 files changed, 63 insertions(+), 16 deletions(-)
tools/perf/Documentation/perf-record.txt +10 -2
@@ -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
tools/perf/builtin-record.c +53 -14
145 lines not on this page · raw message
Signature · 1 line
2.7.4
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf record: Add switch-output size option argument
perf record: Add switch-output size option argument
Commit-ID: dc0c6127c231d4d264570497a916fa19740c915b Gitweb: http://git.kernel.org/tip/dc0c6127c231d4d264570497a916fa19740c915b Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 9 Jan 2017 10:51:58 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jan 2017 16:48:02 -0300
perf record: Add switch-output size option argument
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.
--- tools/perf/Documentation/perf-record.txt | 12 +++++- tools/perf/builtin-record.c | 67 +++++++++++++++++++++++++------- 2 files changed, 63 insertions(+), 16 deletions(-)
tools/perf/Documentation/perf-record.txt +10 -2
@@ -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
tools/perf/builtin-record.c +53 -14
145 lines not on this page · raw message
Jiri Olsa
reviewerPATCH 5/6 perf record: Add switch-output size warning
In reply to Jiri OlsaAdding switch-output size warning if the requested size of lower than the wakeup ring buffer size.
$ perf record --switch-output=1K ls WARNING: switch-output data size lower than wakeup kernel buffer size (258K) expect bigger perf.data sizes ...
--- tools/perf/builtin-record.c | 21 +++++++++++++++++++++ tools/perf/util/evlist.c | 2 +- tools/perf/util/evlist.h | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-)
tools/perf/builtin-record.c +21 -0
@@ -1377,6 +1377,23 @@ static int record__parse_mmap_pages(const struct option *opt,return ret; } +static void switch_output_size_warn (struct record *rec) +{ +u64 wakeup_size =perf_evlist__mmap_size (rec->opts.mmap_pages); +struct switch_output *s = &rec->switch_output; + + wakeup_size /=2 ; + +if (s->size < wakeup_size) { +char buf[100 ]; + +unit_number__scnprint (buf,sizeof (buf), wakeup_size); +pr_warning ("WARNING: switch-output data size lower than " +"wakeup kernel buffer size (%s) " +"expect bigger perf.data sizes\n" , buf); + } +} +static int switch_output_setup (struct record *rec) {struct switch_output *s = &rec->switch_output;
@@ -1410,6 +1427,10 @@ static int switch_output_setup(struct record *rec) enabled: rec->timestamp_filename = true; s->enabled = true; + +if (s->size && !rec->opts.no_buffering) +switch_output_size_warn (rec); +return 0 ; }
tools/perf/util/evlist.c +1 -1
@@ -1184,7 +1184,7 @@ unsigned long perf_event_mlock_kb_in_pages(void)return pages; } -static size_t perf_evlist__mmap_size (unsigned long pages) +size_t perf_evlist__mmap_size (unsigned long pages) {if (pages ==UINT_MAX ) pages =perf_event_mlock_kb_in_pages ();
tools/perf/util/evlist.h +2 -0
@@ -218,6 +218,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages, bool overwrite);void perf_evlist__munmap (struct perf_evlist *evlist); +size_t perf_evlist__mmap_size (unsigned long pages); +void perf_evlist__disable (struct perf_evlist *evlist);void perf_evlist__enable (struct perf_evlist *evlist);void perf_evlist__toggle_enable (struct perf_evlist *evlist);
Signature · 1 line
2.7.4
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf record: Add switch-output size warning
perf record: Add switch-output size warning
Commit-ID: 0c5824498e8bd5b7d30dc03448cd89efaee4bead Gitweb: http://git.kernel.org/tip/0c5824498e8bd5b7d30dc03448cd89efaee4bead Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 9 Jan 2017 10:51:59 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jan 2017 16:48:02 -0300
perf record: Add switch-output size warning
Adding switch-output size warning if the requested size of lower than the wakeup ring buffer size.
$ perf record --switch-output=1K ls WARNING: switch-output data size lower than wakeup kernel buffer size (258K) expect bigger perf.data sizes ...
--- tools/perf/builtin-record.c | 21 +++++++++++++++++++++ tools/perf/util/evlist.c | 2 +- tools/perf/util/evlist.h | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-)
tools/perf/builtin-record.c +21 -0
@@ -1377,6 +1377,23 @@ out_free:return ret; } +static void switch_output_size_warn (struct record *rec) +{ +u64 wakeup_size =perf_evlist__mmap_size (rec->opts.mmap_pages); +struct switch_output *s = &rec->switch_output; + + wakeup_size /=2 ; + +if (s->size < wakeup_size) { +char buf[100 ]; + +unit_number__scnprintf (buf,sizeof (buf), wakeup_size); +pr_warning ("WARNING: switch-output data size lower than " +"wakeup kernel buffer size (%s) " +"expect bigger perf.data sizes\n" , buf); + } +} +static int switch_output_setup (struct record *rec) {struct switch_output *s = &rec->switch_output;
@@ -1410,6 +1427,10 @@ static int switch_output_setup(struct record *rec) enabled: rec->timestamp_filename = true; s->enabled = true; + +if (s->size && !rec->opts.no_buffering) +switch_output_size_warn (rec); +return 0 ; }
tools/perf/util/evlist.c +1 -1
@@ -1184,7 +1184,7 @@ unsigned long perf_event_mlock_kb_in_pages(void)return pages; } -static size_t perf_evlist__mmap_size (unsigned long pages) +size_t perf_evlist__mmap_size (unsigned long pages) {if (pages ==UINT_MAX ) pages =perf_event_mlock_kb_in_pages ();
tools/perf/util/evlist.h +2 -0
@@ -218,6 +218,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages, bool overwrite);void perf_evlist__munmap (struct perf_evlist *evlist); +size_t perf_evlist__mmap_size (unsigned long pages); +void perf_evlist__disable (struct perf_evlist *evlist);void perf_evlist__enable (struct perf_evlist *evlist);void perf_evlist__toggle_enable (struct perf_evlist *evlist);
Jiri Olsa
reviewerPATCH 6/6 perf record: Add switch-output time option argument
In reply to Jiri OlsaIt'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.
--- tools/perf/Documentation/perf-record.txt | 2 ++ tools/perf/builtin-record.c | 44 ++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-record.txt +2 -0
@@ -427,6 +427,8 @@ 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 + <time> - when reaching the time threshold, size is expected to + be a number with appended unit character - s/m/h/d Note: the precision of the size threshold hugely depends on your configuration - the number and size of your ring
tools/perf/builtin-record.c +42 -2
95 lines not on this page · raw message
Signature · 1 line
2.7.4
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf record: Add switch-output time option argument
perf record: Add switch-output time option argument
Commit-ID: bfacbe3bf2443c805aec4c04ecb558d03d0d3ebc Gitweb: http://git.kernel.org/tip/bfacbe3bf2443c805aec4c04ecb558d03d0d3ebc Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 9 Jan 2017 10:52:00 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jan 2017 16:48:02 -0300
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.
--- tools/perf/Documentation/perf-record.txt | 2 ++ tools/perf/builtin-record.c | 44 ++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-record.txt +2 -0
@@ -427,6 +427,8 @@ 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 + <time> - when reaching the time threshold, size is expected to + be a number with appended unit character - s/m/h/d Note: the precision of the size threshold hugely depends on your configuration - the number and size of your ring
tools/perf/builtin-record.c +42 -2
95 lines not on this page · raw message