perf: Add option to specify time window of interest
v2 cover perf: Add option to specify time window of interest
This series allows users to collect data and analyze a time window of interest within the file.
v2
- renamed perf_time to perf_time_interval
- changed ../perf.h to perf.h in patch 1
David Ahern (6):
perf tool: Add time-based utility functions
perf tool: Move parse_nsec_time to time-utils.c
perf script: Add option to specify time window of interest perf sched timehist: Add option to specify time window of interest perf kmem: Add option to specify time window of interest perf report: Add option to specify time window of interest
tools/perf/Documentation/perf-kmem.txt | 7 ++ tools/perf/Documentation/perf-report.txt | 7 ++ tools/perf/Documentation/perf-sched.txt | 8 +++ tools/perf/Documentation/perf-script.txt | 7 ++ tools/perf/builtin-kmem.c | 24 +++++++ tools/perf/builtin-report.c | 14 +++- tools/perf/builtin-sched.c | 51 +++++++++++-- tools/perf/builtin-script.c | 15 +++- tools/perf/util/Build | 1 + tools/perf/util/time-utils.c | 118 +++++++++++++++++++++++++++++++ tools/perf/util/time-utils.h | 14 ++++ tools/perf/util/util.c | 33 --------- tools/perf/util/util.h | 2 - 13 files changed, 258 insertions(+), 43 deletions(-) create mode 100644 tools/perf/util/time-utils.c create mode 100644 tools/perf/util/time-utils.h
Signature · 1 line
2.7.4 (Apple Git-66)
PATCH v2 1/6 perf tool: Add time-based utility functions
Add function to parse a user time string of the form <start>,<stop> where start and stop are time in sec.nsec format. Both start and stop times are optional.
Add function to determine if a sample time is within a given time time window of interest.
--- tools/perf/util/Build | 1 + tools/perf/util/time-utils.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/time-utils.h | 12 +++++++ 3 files changed, 98 insertions(+) create mode 100644 tools/perf/util/time-utils.c create mode 100644 tools/perf/util/time-utils.h
tools/perf/util/Build +1 -0
@@ -87,6 +87,7 @@ libperf-y += help-unknown-cmd.o libperf-y += mem-events.o libperf-y += vsprintf.o libperf-y += drv_configs.o +libperf-y += time-utils.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/time-utils.c new file +85 -0
85 lines not on this page · raw message
tools/perf/util/time-utils.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _TIME_UTILS_H_ +#define _TIME_UTILS_H_ + +struct perf_time_interval { +u64 start, end; +}; + +int perf_time__parse_str (struct perf_time_interval *ptime,const char *ostr); + +bool perf_time__skip_sample (struct perf_time_interval *ptime,u64 timestamp); + +#endif
Signature · 1 line
2.7.4 (Apple Git-66)
tip-bot for David Ahern
merge bot[tip:perf/core] perf tools: Add time-based utility functions
perf tools: Add time-based utility functions
Commit-ID: fdf9dc4b34f5f40919370c4601eccfd0db726aa5 Gitweb: http://git.kernel.org/tip/fdf9dc4b34f5f40919370c4601eccfd0db726aa5 Author: David Ahern <[email protected]> AuthorDate: Tue, 29 Nov 2016 10:15:41 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 1 Dec 2016 13:02:32 -0300
perf tools: Add time-based utility functions
Add function to parse a user time string of the form <start>,<stop> where start and stop are time in sec.nsec format. Both start and stop times are optional.
Add function to determine if a sample time is within a given time time window of interest.
--- tools/perf/util/Build | 1 + tools/perf/util/time-utils.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/time-utils.h | 12 +++++++ 3 files changed, 98 insertions(+)
tools/perf/util/Build +1 -0
@@ -87,6 +87,7 @@ libperf-y += help-unknown-cmd.o libperf-y += mem-events.o libperf-y += vsprintf.o libperf-y += drv_configs.o +libperf-y += time-utils.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/time-utils.c new file +85 -0
85 lines not on this page · raw message
tools/perf/util/time-utils.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _TIME_UTILS_H_ +#define _TIME_UTILS_H_ + +struct perf_time_interval { +u64 start, end; +}; + +int perf_time__parse_str (struct perf_time_interval *ptime,const char *ostr); + +bool perf_time__skip_sample (struct perf_time_interval *ptime,u64 timestamp); + +#endif
PATCH v2 2/6 perf tool: Move parse_nsec_time to time-utils.c
In reply to David AhernCode move only; no functional change intended.
--- tools/perf/util/time-utils.c | 35 ++++++++++++++++++++++++++++++++++- tools/perf/util/time-utils.h | 2 ++ tools/perf/util/util.c | 33 --------------------------------- tools/perf/util/util.h | 2 -- 4 files changed, 36 insertions(+), 36 deletions(-)
tools/perf/util/time-utils.c +34 -1
@@ -1,5 +1,6 @@#include <string.h> #include <sys/time.h> +#include <linux/time64.h> #include <time.h> #include <errno.h> #include <inttypes.h>
@@ -7,7 +8,39 @@#include "perf.h" #include "debug.h" #include "time-utils.h" -#include "util.h" + +int parse_nsec_time (const char *str,u64 *ptime) +{ +u64 time_sec, time_nsec; +char *end; + + time_sec =strtoul (str, &end,10 ); +if (*end !='.' && *end !='\0' ) +return -1 ; + +if (*end =='.' ) { +int i; +char nsec_buf[10 ]; + +if (strlen (++end) >9 ) +return -1 ; + +strncpy (nsec_buf, end,9 ); + nsec_buf[9 ] ='\0' ; + +/* make it nsec precision */ +for (i =strlen (nsec_buf); i <9 ; i++) + nsec_buf[i] ='0' ; + + time_nsec =strtoul (nsec_buf, &end,10 ); +if (*end !='\0' ) +return -1 ; + }else + time_nsec =0 ; + + *ptime = time_sec *NSEC_PER_SEC + time_nsec; +return 0 ; +}static int parse_timestr_sec_nsec (struct perf_time_interval *ptime,char *start_str,char *end_str)
tools/perf/util/time-utils.h +2 -0
@@ -5,6 +5,8 @@ struct perf_time_interval {u64 start, end; }; +int parse_nsec_time (const char *str,u64 *ptime); +int perf_time__parse_str (struct perf_time_interval *ptime,const char *ostr);bool perf_time__skip_sample (struct perf_time_interval *ptime,u64 timestamp);
tools/perf/util/util.c +0 -33
@@ -400,39 +400,6 @@ void sighandler_dump_stack(int sig)raise (sig); } -int parse_nsec_time (const char *str,u64 *ptime) -{ -u64 time_sec, time_nsec; -char *end; - - time_sec =strtoul (str, &end,10 ); -if (*end !='.' && *end !='\0' ) -return -1 ; - -if (*end =='.' ) { -int i; -char nsec_buf[10 ]; - -if (strlen (++end) >9 ) -return -1 ; - -strncpy (nsec_buf, end,9 ); - nsec_buf[9 ] ='\0' ; - -/* make it nsec precision */ -for (i =strlen (nsec_buf); i <9 ; i++) - nsec_buf[i] ='0' ; - - time_nsec =strtoul (nsec_buf, &end,10 ); -if (*end !='\0' ) -return -1 ; - }else - time_nsec =0 ; - - *ptime = time_sec *NSEC_PER_SEC + time_nsec; -return 0 ; -} -int timestamp__scnprintf_usec (u64 timestamp,char *buf,size_t sz) {u64 sec = timestamp /NSEC_PER_SEC ;
tools/perf/util/util.h +0 -2
@@ -179,8 +179,6 @@ static inline void *zalloc(size_t size)#undef tolower#undef toupper -int parse_nsec_time (const char *str,u64 *ptime); -extern unsigned char sane_ctype[256 ];#define GIT_SPACE 0x01#define GIT_DIGIT 0x02
Signature · 1 line
2.7.4 (Apple Git-66)
tip-bot for David Ahern
merge bot[tip:perf/core] perf tools: Move parse_nsec_time to time-utils.c
perf tools: Move parse_nsec_time to time-utils.c
Commit-ID: c284d669a20d408b70ce0dc9b2d995971f5fe0c7 Gitweb: http://git.kernel.org/tip/c284d669a20d408b70ce0dc9b2d995971f5fe0c7 Author: David Ahern <[email protected]> AuthorDate: Tue, 29 Nov 2016 10:15:42 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 1 Dec 2016 13:02:39 -0300
perf tools: Move parse_nsec_time to time-utils.c
Code move only; no functional change intended.
Committer notes:
Fix the build on Ubuntu 16.04 x86-64 cross-compiling to S/390, with this set of auto-detected features:
... dwarf: [ on ] ... dwarf_getlocations: [ on ] ... glibc: [ on ]
... gtk2: [ OFF ]
... libaudit: [ OFF ]
... libbfd: [ OFF ]
... libelf: [ on ]
... libnuma: [ OFF ]
... numa_num_possible_cpus: [ OFF ]
... libperl: [ OFF ]
... libpython: [ OFF ]
... libslang: [ OFF ]
... libcrypto: [ OFF ]
... libunwind: [ OFF ]
... libdw-dwarf-unwind: [ on ]
... zlib: [ on ]
... lzma: [ OFF ]
... get_cpuid: [ OFF ]
... bpf: [ on ]
Where it was failing with:
CC /tmp/build/perf/util/time-utils.o
util/time-utils.c: In function 'parse_nsec_time':
util/time-utils.c:17:13: error: implicit declaration of function 'strtoul' [-Werror=implicit-function-declaration]
time_sec = strtoul(str, &end, 10);
^
util/time-utils.c:17:2: error: nested extern declaration of 'strtoul' [-Werror=nested-externs]
time_sec = strtoul(str, &end, 10);
^
util/time-utils.c: In function 'perf_time__parse_str':
util/time-utils.c:93:2: error: implicit declaration of function 'free' [-Werror=implicit-function-declaration]
free(str);
^ util/time-utils.c:93:2: error: incompatible implicit declaration of built-in function 'free' [-Werror] util/time-utils.c:93:2: note: include '<stdlib.h>' or provide a declaration of 'free'
Do as suggested and add a '#include <stdlib.h>' to get the free() and strtoul() declarations and fix the build.
--- tools/perf/util/time-utils.c | 36 +++++++++++++++++++++++++++++++++++- tools/perf/util/time-utils.h | 2 ++ tools/perf/util/util.c | 33 --------------------------------- tools/perf/util/util.h | 2 -- 4 files changed, 37 insertions(+), 36 deletions(-)
tools/perf/util/time-utils.c +35 -1
@@ -1,5 +1,7 @@ +#include <stdlib.h> #include <string.h> #include <sys/time.h> +#include <linux/time64.h> #include <time.h> #include <errno.h> #include <inttypes.h>
@@ -7,7 +9,39 @@#include "perf.h" #include "debug.h" #include "time-utils.h" -#include "util.h" + +int parse_nsec_time (const char *str,u64 *ptime) +{ +u64 time_sec, time_nsec; +char *end; + + time_sec =strtoul (str, &end,10 ); +if (*end !='.' && *end !='\0' ) +return -1 ; + +if (*end =='.' ) { +int i; +char nsec_buf[10 ]; + +if (strlen (++end) >9 ) +return -1 ; + +strncpy (nsec_buf, end,9 ); + nsec_buf[9 ] ='\0' ; + +/* make it nsec precision */ +for (i =strlen (nsec_buf); i <9 ; i++) + nsec_buf[i] ='0' ; + + time_nsec =strtoul (nsec_buf, &end,10 ); +if (*end !='\0' ) +return -1 ; + }else + time_nsec =0 ; + + *ptime = time_sec *NSEC_PER_SEC + time_nsec; +return 0 ; +}static int parse_timestr_sec_nsec (struct perf_time_interval *ptime,char *start_str,char *end_str)
tools/perf/util/time-utils.h +2 -0
@@ -5,6 +5,8 @@ struct perf_time_interval {u64 start, end; }; +int parse_nsec_time (const char *str,u64 *ptime); +int perf_time__parse_str (struct perf_time_interval *ptime,const char *ostr);bool perf_time__skip_sample (struct perf_time_interval *ptime,u64 timestamp);
tools/perf/util/util.c +0 -33
@@ -400,39 +400,6 @@ void sighandler_dump_stack(int sig)raise (sig); } -int parse_nsec_time (const char *str,u64 *ptime) -{ -u64 time_sec, time_nsec; -char *end; - - time_sec =strtoul (str, &end,10 ); -if (*end !='.' && *end !='\0' ) -return -1 ; - -if (*end =='.' ) { -int i; -char nsec_buf[10 ]; - -if (strlen (++end) >9 ) -return -1 ; - -strncpy (nsec_buf, end,9 ); - nsec_buf[9 ] ='\0' ; - -/* make it nsec precision */ -for (i =strlen (nsec_buf); i <9 ; i++) - nsec_buf[i] ='0' ; - - time_nsec =strtoul (nsec_buf, &end,10 ); -if (*end !='\0' ) -return -1 ; - }else - time_nsec =0 ; - - *ptime = time_sec *NSEC_PER_SEC + time_nsec; -return 0 ; -} -int timestamp__scnprintf_usec (u64 timestamp,char *buf,size_t sz) {u64 sec = timestamp /NSEC_PER_SEC ;
tools/perf/util/util.h +0 -2
@@ -179,8 +179,6 @@ static inline void *zalloc(size_t size)#undef tolower#undef toupper -int parse_nsec_time (const char *str,u64 *ptime); -extern unsigned char sane_ctype[256 ];#define GIT_SPACE 0x01#define GIT_DIGIT 0x02
PATCH v2 3/6 perf script: Add option to specify time window of interest
In reply to David AhernAdd option to allow user to control analysis window. e.g., collect data for some amount of time and analyze a segment of interest within that window.
--- tools/perf/Documentation/perf-script.txt | 7 +++++++ tools/perf/builtin-script.c | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-script.txt +7 -0
@@ -292,6 +292,13 @@ include::itrace.txt[] --force:: Don't do ownership validation. +--time:: + Only analyze samples within given time window: <start>,<stop>. Times + have the format seconds.microseconds. If start is not given (i.e., time + string is ',x.y') then analysis starts at the beginning of the file. If + stop time is not given (i.e, time string is 'x.y,') then analysis goes + to end of file. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +14 -1
@@ -22,6 +22,7 @@#include "util/thread_map.h" #include "util/stat.h" #include "util/thread-stack.h" +#include "util/time-utils.h" #include <linux/bitmap.h> #include <linux/stringify.h> #include <linux/time64.h>
@@ -833,6 +834,8 @@ struct perf_script {struct cpu_map *cpus;struct thread_map *threads;int name_width; +const char *time_str; +struct perf_time_interval ptime; };static int perf_evlist__max_name_len (struct perf_evlist *evlist)
@@ -1014,6 +1017,9 @@ static int process_sample_event(struct perf_tool *tool, struct perf_script *scr = container_of(tool, struct perf_script, tool);struct addr_location al; +if (perf_time__skip_sample (&scr->ptime, sample->time)) +return 0 ; +if (debug_mode) {if (sample->time < last_timestamp) { pr_err("Samples misordered, previous: %" PRIu64
@@ -2186,7 +2192,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) "Enable symbol demangling"),OPT_BOOLEAN (0 ,"demangle-kernel" , &symbol_conf.demangle_kernel,"Enable kernel symbol demangling" ), - +OPT_STRING (0 ,"time" , &script.time_str,"str" , +"Time span of interest (start,stop)" ), OPT_END() };const char *const script_subcommands[] = {"record" ,"report" ,NULL };
@@ -2465,6 +2472,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)if (err <0 ) goto out_delete; +/* needs to be parsed after looking up reference time */ +if (perf_time__parse_str (&script.ptime, script.time_str) !=0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } + err =__cmd_script (&script);flush_scripting ();
Signature · 1 line
2.7.4 (Apple Git-66)
tip-bot for David Ahern
merge bot[tip:perf/core] perf script: Add option to specify time window of interest
perf script: Add option to specify time window of interest
Commit-ID: a91f4c473fa1655a2a5f1ceba46f76a95eef35bb Gitweb: http://git.kernel.org/tip/a91f4c473fa1655a2a5f1ceba46f76a95eef35bb Author: David Ahern <[email protected]> AuthorDate: Tue, 29 Nov 2016 10:15:43 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 1 Dec 2016 13:02:45 -0300
perf script: Add option to specify time window of interest
Add option to allow user to control analysis window. e.g., collect data for some amount of time and analyze a segment of interest within that window.
Committer notes:
Testing it:
# perf evlist -v
cycles:ppp: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1
#
# perf script --hide-call-graph | head -15
swapper 0 [0] 9693.370039: 1 cycles:ppp: ffffffffb90072ad x86_pmu_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [0] 9693.370044: 1 cycles:ppp: ffffffffb900ca1b intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [0] 9693.370046: 7 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [0] 9693.370048: 126 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [0] 9693.370049: 2701 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [0] 9693.370051: 58823 cycles:ppp: ffffffffb90cd2e0 idle_cpu (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [1] 9693.370059: 1 cycles:ppp: ffffffffb91a713a ctx_resched (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [1] 9693.370062: 1 cycles:ppp: ffffffffb900ca1b intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [1] 9693.370064: 13 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [1] 9693.370065: 250 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [1] 9693.370067: 5269 cycles:ppp: ffffffffb902fe79 sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [1] 9693.370069: 114602 cycles:ppp: ffffffffb90c1c5a atomic_notifier_call_chain (.../4.8.8-300.fc25.x86_64/vmlinux)
perf 5124 [2] 9693.370076: 1 cycles:ppp: ffffffffb91a76c1 __perf_event_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
perf 5124 [2] 9693.370091: 1 cycles:ppp: ffffffffb900ca1b intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
perf 5124 [2] 9693.370095: 3 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
#
# perf script --hide-call-graph --time ,9693.370048
swapper 0 [0] 9693.370039: 1 cycles:ppp: ffffffffb90072ad x86_pmu_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [0] 9693.370044: 1 cycles:ppp: ffffffffb900ca1b intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [0] 9693.370046: 7 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
# perf script --hide-call-graph --time 9693.370064,9693.370076
swapper 0 [1] 9693.370064: 13 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [1] 9693.370065: 250 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [1] 9693.370067: 5269 cycles:ppp: ffffffffb902fe79 sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper 0 [1] 9693.370069: 114602 cycles:ppp: ffffffffb90c1c5a atomic_notifier_call_chain (.../4.8.8-300.fc25.x86_64/vmlinux)
#--- tools/perf/Documentation/perf-script.txt | 7 +++++++ tools/perf/builtin-script.c | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-script.txt +7 -0
@@ -292,6 +292,13 @@ include::itrace.txt[] --force:: Don't do ownership validation. +--time:: + Only analyze samples within given time window: <start>,<stop>. Times + have the format seconds.microseconds. If start is not given (i.e., time + string is ',x.y') then analysis starts at the beginning of the file. If + stop time is not given (i.e, time string is 'x.y,') then analysis goes + to end of file. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +14 -1
@@ -22,6 +22,7 @@#include "util/thread_map.h" #include "util/stat.h" #include "util/thread-stack.h" +#include "util/time-utils.h" #include <linux/bitmap.h> #include <linux/stringify.h> #include <linux/time64.h>
@@ -833,6 +834,8 @@ struct perf_script {struct cpu_map *cpus;struct thread_map *threads;int name_width; +const char *time_str; +struct perf_time_interval ptime; };static int perf_evlist__max_name_len (struct perf_evlist *evlist)
@@ -1014,6 +1017,9 @@ static int process_sample_event(struct perf_tool *tool, struct perf_script *scr = container_of(tool, struct perf_script, tool);struct addr_location al; +if (perf_time__skip_sample (&scr->ptime, sample->time)) +return 0 ; +if (debug_mode) {if (sample->time < last_timestamp) { pr_err("Samples misordered, previous: %" PRIu64
@@ -2186,7 +2192,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) "Enable symbol demangling"),OPT_BOOLEAN (0 ,"demangle-kernel" , &symbol_conf.demangle_kernel,"Enable kernel symbol demangling" ), - +OPT_STRING (0 ,"time" , &script.time_str,"str" , +"Time span of interest (start,stop)" ), OPT_END() };const char *const script_subcommands[] = {"record" ,"report" ,NULL };
@@ -2465,6 +2472,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)if (err <0 ) goto out_delete; +/* needs to be parsed after looking up reference time */ +if (perf_time__parse_str (&script.ptime, script.time_str) !=0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } + err =__cmd_script (&script);flush_scripting ();
PATCH v2 4/6 perf sched timehist: Add option to specify time window of interest
In reply to David AhernAdd option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.
--- tools/perf/Documentation/perf-sched.txt | 8 ++++++ tools/perf/builtin-sched.c | 51 +++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-sched.txt +8 -0
@@ -132,6 +132,14 @@ OPTIONS for 'perf sched timehist' --migrations:: Show migration events. +--time:: + Only analyze samples within given time window: <start>,<stop>. Times + have the format seconds.microseconds. If start is not given (i.e., time + string is ',x.y') then analysis starts at the beginning of the file. If + stop time is not given (i.e, time string is 'x.y,') then analysis goes + to end of file. + + SEE ALSO -------- linkperf:perf-record[1]
tools/perf/builtin-sched.c +45 -6
108 lines not on this page · raw message
Signature · 1 line
2.7.4 (Apple Git-66)
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 4/6] perf sched timehist: Add option to specify time window of interest
Em Tue, Nov 29, 2016 at 10:15:44AM -0700, David Ahern escreveu:
Quoted 2 lines
Add option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.
Trying to test this I got:
[root@jouet ~]# perf sched timehist
No trace sample to read. Did you call 'perf record -R'? [root@jouet ~]#
Could you please provide a better error message?
The perf.data file had this:
[root@jouet ~]# perf evlist -v
cycles:ppp: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 [root@jouet ~]#
- Arnaldo
Quoted 147 lines
Signed-off-by David Ahern <[email protected]>--- tools/perf/Documentation/perf-sched.txt | 8 ++++++ tools/perf/builtin-sched.c | 51 +++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 6 deletions(-)tools/perf/Documentation/perf-sched.txt +8
-0@@ -132,6 +132,14 @@ OPTIONS for 'perf sched timehist' --migrations:: Show migration events. +--time:: + Only analyze samples within given time window: <start>,<stop>. Times + have the format seconds.microseconds. If start is not given (i.e., time + string is ',x.y') then analysis starts at the beginning of the file. If + stop time is not given (i.e, time string is 'x.y,') then analysis goes + to end of file. + + SEE ALSO -------- linkperf:perf-record[1]tools/perf/builtin-sched.c +45
-6@@ -15,6 +15,7 @@#include "util/color.h" #include "util/stat.h" #include "util/callchain.h" +#include "util/time-utils.h" #include <subcmd/parse-options.h> #include "util/trace-event.h" @@ -205,6 +206,8 @@ struct perf_sched {bool show_wakeups;bool show_migrations;u64 skipped_samples; +const char *time_str; +struct perf_time_interval ptime; };/* per thread run time data */ @@ -1837,13 +1840,14 @@ static void timehist_header(struct perf_sched *sched)static void timehist_print_sample (struct perf_sched *sched,struct perf_sample *sample,struct addr_location *al, -struct thread *thread) +struct thread *thread, +u64 t) {struct thread_runtime *tr =thread__priv (thread);u32 max_cpus = sched->max_cpu +1 ;char tstr[64 ]; -timestamp__scnprintf_usec (sample->time, tstr,sizeof (tstr)); +timestamp__scnprintf_usec (t, tstr,sizeof (tstr));printf ("%15s [%04d] " , tstr, sample->cpu);if (sched->show_cpu_visual) {@@ -2194,7 +2198,8 @@ static int timehist_sched_wakeup_event(struct perf_tool *tool, tr->ready_to_run = sample->time;/* show wakeups if requested */ -if (sched->show_wakeups) +if (sched->show_wakeups && + !perf_time__skip_sample (&sched->ptime, sample->time))timehist_print_wakeup_event (sched, sample, machine, thread);return 0 ;@@ -2288,10 +2293,11 @@ static int timehist_sched_change_event(struct perf_tool *tool, struct machine *machine) { struct perf_sched *sched = container_of(tool, struct perf_sched, tool); +struct perf_time_interval *ptime = &sched->ptime;struct addr_location al;struct thread *thread;struct thread_runtime *tr =NULL ; -u64 tprev; +u64 tprev, t = sample->time;int rc =0 ;if (machine__resolve (machine, &al, sample) <0 ) {@@ -2318,9 +2324,35 @@ static int timehist_sched_change_event(struct perf_tool *tool, tprev =perf_evsel__get_time (evsel, sample->cpu); -timehist_update_runtime_stats (tr, sample->time, tprev); +/* +* If start time given: +* - sample time is under window user cares about - skip sample +* - tprev is under window user cares about - reset to start of window +*/ +if (ptime->start && ptime->start > t) + goto out; + +if (ptime->start > tprev) + tprev = ptime->start; + +/* +* If end time given: +* - previous sched event is out of window - we are done +* - sample time is beyond window user cares about - reset it +* to close out stats for time window interest +*/ +if (ptime->end) { +if (tprev > ptime->end) + goto out; + +if (t > ptime->end) + t = ptime->end; + } + +timehist_update_runtime_stats (tr, t, tprev); +if (!sched->summary_only) -timehist_print_sample (sched, sample, &al, thread); +timehist_print_sample (sched, sample, &al, thread, t); out:if (tr) {@@ -2583,6 +2615,11 @@ static int perf_sched__timehist(struct perf_sched *sched)symbol__init (&session->header.env); +if (perf_time__parse_str (&sched->ptime, sched->time_str) !=0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } +if (timehist_check_attr (sched, evlist) !=0 ) goto out;@@ -2997,6 +3034,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN ('w' ,"wakeups" , &sched.show_wakeups,"Show wakeup events" ),OPT_BOOLEAN ('M' ,"migrations" , &sched.show_migrations,"Show migration events" ),OPT_BOOLEAN ('V' ,"cpu-visual" , &sched.show_cpu_visual,"Add CPU visual" ), +OPT_STRING (0 ,"time" , &sched.time_str,"str" , +"Time span for analysis (start,stop)" ), OPT_PARENT(sched_options) };Signature · 1 line
2.7.4 (Apple Git-66)
Re: [PATCH v2 4/6] perf sched timehist: Add option to specify time window of interest
Quoted 10 lines · Arnaldo Carvalho de Melo
Em Tue, Nov 29, 2016 at 10:15:44AM -0700, David Ahern escreveu:
Quoted 2 lines
Add option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.
Trying to test this I got:
[root@jouet ~]# perf sched timehist
No trace sample to read. Did you call 'perf record -R'? [root@jouet ~]#Could you please provide a better error message?
sure, but that error is unrelated to this patch set.
Quoted 6 lines
The perf.data file had this:
[root@jouet ~]# perf evlist -v
cycles:ppp: size: 112, {sample_period,sample_freq}: 4000,sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1,precise_ip: 3,sample_id_all: 1,exclude_guest: 1, mmap2: 1,comm_exec: 1 [root@jouet ~]#
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 4/6] perf sched timehist: Add option to specify time window of interest
Em Tue, Nov 29, 2016 at 11:58:03AM -0700, David Ahern escreveu:
Quoted 6 lines · Arnaldo Carvalho de Melo
Quoted 5 lines
Em Tue, Nov 29, 2016 at 10:15:44AM -0700, David Ahern escreveu:
Quoted 2 lines
Add option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.
Trying to test this I got:
Quoted 7 lines
Quoted 5 lines
[root@jouet ~]# perf sched timehist
No trace sample to read. Did you call 'perf record -R'? [root@jouet ~]#Could you please provide a better error message?
sure, but that error is unrelated to this patch set.
I haven't said it was... 8-) This patchset is processed and pushed out, just doing a 'make -C tools/perf build-test' + perf test + build on lots of containers pass before sending a pull req to Ingo,
- Arnaldo
Quoted 6 lines
Quoted 6 lines
The perf.data file had this:
[root@jouet ~]# perf evlist -v
cycles:ppp: size: 112, {sample_period,sample_freq}: 4000,sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1,precise_ip: 3,sample_id_all: 1,exclude_guest: 1, mmap2: 1,comm_exec: 1 [root@jouet ~]#
tip-bot for David Ahern
merge bot[tip:perf/core] perf sched timehist: Add option to specify time window of interest
In reply to David Ahernperf sched timehist: Add option to specify time window of interest
Commit-ID: 853b74071110bed344bad1ca9d8de27731b1c574 Gitweb: http://git.kernel.org/tip/853b74071110bed344bad1ca9d8de27731b1c574 Author: David Ahern <[email protected]> AuthorDate: Tue, 29 Nov 2016 10:15:44 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 1 Dec 2016 13:02:52 -0300
perf sched timehist: Add option to specify time window of interest
Add option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.
Committer notes:
Testing it:
# perf sched record -a usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 1.593 MB perf.data (25 samples) ]
#
# perf sched timehist | head -18
Samples do not have callchains.
time cpu task name wait time sch delay run time
[tid/pid] (msec) (msec) (msec)
------------- ------ --------------- --------- --------- --------
19818.635579 [0002] <idle> 0.000 0.000 0.000
19818.635613 [0000] perf[9116] 0.000 0.000 0.000
19818.635676 [0000] <idle> 0.000 0.000 0.063
19818.635678 [0000] rcuos/2[29] 0.000 0.002 0.001
19818.635696 [0002] perf[9117] 0.000 0.004 0.116
19818.635702 [0000] <idle> 0.001 0.000 0.024
19818.635709 [0002] migration/2[25] 0.000 0.003 0.012
19818.636263 [0000] usleep[9117] 0.005 0.000 0.560
19818.636316 [0000] <idle> 0.560 0.000 0.053
19818.636358 [0002] <idle> 0.129 0.000 0.649
19818.636358 [0000] usleep[9117] 0.053 0.002 0.042
# # perf sched timehist --time 19818.635696,
Samples do not have callchains.
time cpu task name wait time sch delay run time
[tid/pid] (msec) (msec) (msec)
------------- ------ --------------- -------- --------- ---------
19818.635696 [0002] perf[9117] 0.000 0.120 0.000
19818.635702 [0000] <idle> 0.019 0.000 0.006
19818.635709 [0002] migration/2[25] 0.000 0.003 0.012
19818.636263 [0000] usleep[9117] 0.005 0.000 0.560
19818.636316 [0000] <idle> 0.560 0.000 0.053
19818.636358 [0002] <idle> 0.129 0.000 0.649
19818.636358 [0000] usleep[9117] 0.053 0.002 0.042
#
# perf sched timehist --time 19818.635696,19818.635709
Samples do not have callchains.
time cpu task name wait time sch delay run time
[tid/pid] (msec) (msec) (msec)
------------- ------ --------------- --------- --------- ---------
19818.635696 [0002] perf[9117] 0.000 0.120 0.000
19818.635702 [0000] <idle> 0.019 0.000 0.006
19818.635709 [0002] migration/2[25] 0.000 0.003 0.012
19818.635709 [0000] usleep[9117] 0.005 0.000 0.006
#--- tools/perf/Documentation/perf-sched.txt | 8 ++++++ tools/perf/builtin-sched.c | 51 +++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-sched.txt +8 -0
@@ -132,6 +132,14 @@ OPTIONS for 'perf sched timehist' --migrations:: Show migration events. +--time:: + Only analyze samples within given time window: <start>,<stop>. Times + have the format seconds.microseconds. If start is not given (i.e., time + string is ',x.y') then analysis starts at the beginning of the file. If + stop time is not given (i.e, time string is 'x.y,') then analysis goes + to end of file. + + SEE ALSO -------- linkperf:perf-record[1]
tools/perf/builtin-sched.c +45 -6
108 lines not on this page · raw message
PATCH v2 5/6 perf kmem: Add option to specify time window of interest
In reply to David AhernAdd option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.
--- tools/perf/Documentation/perf-kmem.txt | 7 +++++++ tools/perf/builtin-kmem.c | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
tools/perf/Documentation/perf-kmem.txt +7 -0
@@ -61,6 +61,13 @@ OPTIONS default, but this option shows live (currently allocated) pages instead. (This option works with --page option only) +--time:: + Only analyze samples within given time window: <start>,<stop>. Times + have the format seconds.microseconds. If start is not given (i.e., time + string is ',x.y') then analysis starts at the beginning of the file. If + stop time is not given (i.e, time string is 'x.y,') then analysis goes + to end of file. + SEE ALSO -------- linkperf:perf-record[1]
tools/perf/builtin-kmem.c +24 -0
@@ -11,6 +11,7 @@#include "util/session.h" #include "util/tool.h" #include "util/callchain.h" +#include "util/time-utils.h" #include <subcmd/parse-options.h> #include "util/trace-event.h"
@@ -66,6 +67,10 @@ static struct rb_root root_caller_sorted;static unsigned long total_requested, total_allocated, total_freed;static unsigned long nr_allocs, nr_cross_allocs; +/* filters for controlling start and stop of time of analysis */ +static struct perf_time_interval ptime; +const char *time_str; +static int insert_alloc_stat (unsigned long call_site,unsigned long ptr,int bytes_req,int bytes_alloc,int cpu) {
@@ -912,6 +917,15 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel,return 0 ; } +static bool perf_kmem__skip_sample (struct perf_sample *sample) +{ +/* skip sample based on time? */ +if (perf_time__skip_sample (&ptime, sample->time)) +return true; + +return false; +} +typedef int (*tracepoint_handler )(struct perf_evsel *evsel,struct perf_sample *sample);
@@ -931,6 +945,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,return -1 ; } +if (perf_kmem__skip_sample (sample)) +return 0 ; +dump_printf (" ... thread: %s:%d\n" ,thread__comm_str (thread), thread->tid);if (evsel->handler !=NULL ) {
@@ -1894,6 +1911,8 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)OPT_CALLBACK_NOOPT (0 ,"page" ,NULL ,NULL ,"Analyze page allocator" , parse_page_opt),OPT_BOOLEAN (0 ,"live" , &live_page,"Show live page stat" ), +OPT_STRING (0 ,"time" , &time_str,"str" , +"Time span of interest (start,stop)" ), OPT_END() };const char *const kmem_subcommands[] = {"record" ,"stat" ,NULL };
@@ -1954,6 +1973,11 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)symbol__init (&session->header.env); +if (perf_time__parse_str (&ptime, time_str) !=0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } +if (!strcmp (argv[0 ],"stat" )) {setlocale (LC_ALL ,"" );
Signature · 1 line
2.7.4 (Apple Git-66)
tip-bot for David Ahern
merge bot[tip:perf/core] perf kmem: Add option to specify time window of interest
perf kmem: Add option to specify time window of interest
Commit-ID: 2a865bd8dddd44315c88bf922761e4fd3374d046 Gitweb: http://git.kernel.org/tip/2a865bd8dddd44315c88bf922761e4fd3374d046 Author: David Ahern <[email protected]> AuthorDate: Tue, 29 Nov 2016 10:15:45 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 1 Dec 2016 13:03:02 -0300
perf kmem: Add option to specify time window of interest
Add option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.
Committer notes:
Testing it:
# perf kmem record usleep 1
[ perf record: Woken up 0 times to write data ]
[ perf record: Captured and wrote 1.540 MB perf.data (2049 samples) ]
# perf evlist
kmem:kmalloc
kmem:kmalloc_node
kmem:kfree
kmem:kmem_cache_alloc
kmem:kmem_cache_alloc_node
kmem:kmem_cache_free
# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events
#
# # Use 'perf script' to get a first approach, select a chunk for then using
# # with 'perf kmem stat --time'
#
# perf script | tail -15
usleep 9889 [0] 20119.782088: kmem:kmem_cache_free: (selinux_file_free_security+0x27) call_site=ffffffffb936aa07 ptr=0xffff888a1df49fc0
perf 9888 [3] 20119.782088: kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
perf 9888 [3] 20119.782089: kmem:kmem_cache_alloc: (jbd2__journal_start+0x72) call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
perf 9888 [3] 20119.782090: kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
perf 9888 [3] 20119.782090: kmem:kmem_cache_alloc: (jbd2__journal_start+0x72) call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
usleep 9889 [0] 20119.782091: kmem:kmem_cache_alloc: (__sigqueue_alloc+0x4a) call_site=ffffffffb90ad33a ptr=0xffff8889f071f6e0 bytes_req=160 bytes_alloc=160 gfp_flags=GFP_ATOMIC|__GFP_NOTRACK
perf 9888 [3] 20119.782091: kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
perf 9888 [3] 20119.782093: kmem:kmem_cache_free: (__sigqueue_free.part.17+0x33) call_site=ffffffffb90ad3f3 ptr=0xffff8889f071f6e0
perf 9888 [3] 20119.782098: kmem:kmem_cache_alloc: (jbd2__journal_start+0x72) call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
perf 9888 [3] 20119.782098: kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
perf 9888 [3] 20119.782099: kmem:kmem_cache_alloc: (jbd2__journal_start+0x72) call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
perf 9888 [3] 20119.782100: kmem:kmem_cache_alloc: (alloc_buffer_head+0x21) call_site=ffffffffb9287cc1 ptr=0xffff8889b12722d8 bytes_req=104 bytes_alloc=104 gfp_flags=GFP_NOFS|__GFP_ZERO
perf 9888 [3] 20119.782101: kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
perf 9888 [3] 20119.782102: kmem:kmem_cache_alloc: (jbd2__journal_start+0x72) call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
perf 9888 [3] 20119.782103: kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
#
# # stats for the whole perf.data file, i.e. no interval specified
#
# perf kmem stat SUMMARY (SLAB allocator)
========================
Total bytes requested: 172,628
Total bytes allocated: 173,088
Total bytes freed: 161,280
Net total bytes allocated: 11,808
Total bytes wasted on internal fragmentation: 460 Internal fragmentation: 0.265761%
Cross CPU allocations: 0/851
#
# # stats for an end open interval, after a certain time:
#
# perf kmem stat --time 20119.782088,
SUMMARY (SLAB allocator)
========================
Total bytes requested: 552
Total bytes allocated: 552
Total bytes freed: 448
Net total bytes allocated: 104
Total bytes wasted on internal fragmentation: 0
Internal fragmentation: 0.000000%
Cross CPU allocations: 0/8
#
--- tools/perf/Documentation/perf-kmem.txt | 7 +++++++ tools/perf/builtin-kmem.c | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
tools/perf/Documentation/perf-kmem.txt +7 -0
@@ -61,6 +61,13 @@ OPTIONS default, but this option shows live (currently allocated) pages instead. (This option works with --page option only) +--time:: + Only analyze samples within given time window: <start>,<stop>. Times + have the format seconds.microseconds. If start is not given (i.e., time + string is ',x.y') then analysis starts at the beginning of the file. If + stop time is not given (i.e, time string is 'x.y,') then analysis goes + to end of file. + SEE ALSO -------- linkperf:perf-record[1]
tools/perf/builtin-kmem.c +24 -0
@@ -11,6 +11,7 @@#include "util/session.h" #include "util/tool.h" #include "util/callchain.h" +#include "util/time-utils.h" #include <subcmd/parse-options.h> #include "util/trace-event.h"
@@ -66,6 +67,10 @@ static struct rb_root root_caller_sorted;static unsigned long total_requested, total_allocated, total_freed;static unsigned long nr_allocs, nr_cross_allocs; +/* filters for controlling start and stop of time of analysis */ +static struct perf_time_interval ptime; +const char *time_str; +static int insert_alloc_stat (unsigned long call_site,unsigned long ptr,int bytes_req,int bytes_alloc,int cpu) {
@@ -912,6 +917,15 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel,return 0 ; } +static bool perf_kmem__skip_sample (struct perf_sample *sample) +{ +/* skip sample based on time? */ +if (perf_time__skip_sample (&ptime, sample->time)) +return true; + +return false; +} +typedef int (*tracepoint_handler )(struct perf_evsel *evsel,struct perf_sample *sample);
@@ -931,6 +945,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,return -1 ; } +if (perf_kmem__skip_sample (sample)) +return 0 ; +dump_printf (" ... thread: %s:%d\n" ,thread__comm_str (thread), thread->tid);if (evsel->handler !=NULL ) {
@@ -1894,6 +1911,8 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)OPT_CALLBACK_NOOPT (0 ,"page" ,NULL ,NULL ,"Analyze page allocator" , parse_page_opt),OPT_BOOLEAN (0 ,"live" , &live_page,"Show live page stat" ), +OPT_STRING (0 ,"time" , &time_str,"str" , +"Time span of interest (start,stop)" ), OPT_END() };const char *const kmem_subcommands[] = {"record" ,"stat" ,NULL };
@@ -1954,6 +1973,11 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)symbol__init (&session->header.env); +if (perf_time__parse_str (&ptime, time_str) !=0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } +if (!strcmp (argv[0 ],"stat" )) {setlocale (LC_ALL ,"" );
PATCH v2 6/6 perf report: Add option to specify time window of interest
In reply to David AhernAdd option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.
--- tools/perf/Documentation/perf-report.txt | 7 +++++++ tools/perf/builtin-report.c | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +7 -0
@@ -382,6 +382,13 @@ OPTIONS --header-only:: Show only perf.data header (forces --stdio). +--time:: + Only analyze samples within given time window: <start>,<stop>. Times + have the format seconds.microseconds. If start is not given (i.e., time + string is ',x.y') then analysis starts at the beginning of the file. If + stop time is not given (i.e, time string is 'x.y,') then analysis goes + to end of file. + --itrace:: Options for decoding instruction tracing data. The options are:
tools/perf/builtin-report.c +13 -1
@@ -36,7 +36,7 @@#include "util/hist.h" #include "util/data.h" #include "arch/common.h" - +#include "util/time-utils.h" #include "util/auxtrace.h" #include <dlfcn.h>
@@ -59,6 +59,8 @@ struct report {const char *pretty_printing_style;const char *cpu_list;const char *symbol_filter_str; +const char *time_str; +struct perf_time_interval ptime;float min_percent;u64 nr_entries;u64 queue_size;
@@ -158,6 +160,9 @@ static int process_sample_event(struct perf_tool *tool, };int ret =0 ; +if (perf_time__skip_sample (&rep->ptime, sample->time)) +return 0 ; +if (machine__resolve (machine, &al, sample) <0 ) {pr_debug ("problem processing %d event, skipping it.\n" , event->header.type);
@@ -830,6 +835,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)OPT_CALLBACK_DEFAULT (0 ,"stdio-color" ,NULL ,"mode" ,"'always' (default), 'never' or 'auto' only applicable to --stdio mode" , stdio__config_color,"always" ), +OPT_STRING (0 ,"time" , &report.time_str,"str" , +"Time span of interest (start,stop)" ),OPT_END () }; struct perf_data_file file = {
@@ -1015,6 +1022,11 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)if (symbol__init (&session->header.env) <0 ) goto error; +if (perf_time__parse_str (&report.ptime, report.time_str) !=0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } +sort__setup_elide (stdout); ret =__cmd_report (&report);
Signature · 1 line
2.7.4 (Apple Git-66)
tip-bot for David Ahern
merge bot[tip:perf/core] perf report: Add option to specify time window of interest
perf report: Add option to specify time window of interest
Commit-ID: 46690a8051e4b5901a49080443a17a270e0bd8a2 Gitweb: http://git.kernel.org/tip/46690a8051e4b5901a49080443a17a270e0bd8a2 Author: David Ahern <[email protected]> AuthorDate: Tue, 29 Nov 2016 10:15:46 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 1 Dec 2016 13:03:10 -0300
perf report: Add option to specify time window of interest
Add option to allow user to control analysis window. e.g., collect data for time window and analyze a segment of interest within that window.
Committer notes:
Testing it:
Using the perf.data file captured via 'perf kmem record':
# perf report --header-only
# ========
# captured on: Tue Nov 29 16:01:53 2016
# hostname : jouet
# os release : 4.8.8-300.fc25.x86_64
# perf version : 4.9.rc6.g5a6aca
# arch : x86_64
# nrcpus online : 4
# nrcpus avail : 4
# cpudesc : Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
# cpuid : GenuineIntel,6,61,4
# total memory : 20254660 kB
# cmdline : /home/acme/bin/perf kmem record usleep 1
# event : name = kmem:kmalloc, , id = { 931980, 931981, 931982, 931983 }, type = 2, size = 112, config = 0x1b9, { sample_period, sample_freq } = 1, sample_typ
# event : name = kmem:kmalloc_node, , id = { 931984, 931985, 931986, 931987 }, type = 2, size = 112, config = 0x1b7, { sample_period, sample_freq } = 1, sampl
# event : name = kmem:kfree, , id = { 931988, 931989, 931990, 931991 }, type = 2, size = 112, config = 0x1b5, { sample_period, sample_freq } = 1, sample_type
# event : name = kmem:kmem_cache_alloc, , id = { 931992, 931993, 931994, 931995 }, type = 2, size = 112, config = 0x1b8, { sample_period, sample_freq } = 1, s
# event : name = kmem:kmem_cache_alloc_node, , id = { 931996, 931997, 931998, 931999 }, type = 2, size = 112, config = 0x1b6, { sample_period, sample_freq } =
# event : name = kmem:kmem_cache_free, , id = { 932000, 932001, 932002, 932003 }, type = 2, size = 112, config = 0x1b4, { sample_period, sample_freq } = 1, sa
# HEADER_CPU_TOPOLOGY info available, use -I to display
# HEADER_NUMA_TOPOLOGY info available, use -I to display
# pmu mappings: cpu = 4, intel_pt = 7, intel_bts = 6, uncore_arb = 13, cstate_pkg = 15, breakpoint = 5, uncore_cbox_1 = 12, power = 9, software = 1, uncore_im
# HEADER_CACHE info available, use -I to display
# missing features: HEADER_BRANCH_STACK HEADER_GROUP_DESC HEADER_AUXTRACE HEADER_STAT
# ========
#
# # Looking at just the histogram entries for the first event:
#
# perf report | head -33
# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 40 of event 'kmem:kmalloc'
# Event count (approx.): 40
#
# Overhead Trace output
# ........ ...............................................................................................................
#
37.50% call_site=ffffffffb91ad3c7 ptr=0xffff88895fc05000 bytes_req=4096 bytes_alloc=4096 gfp_flags=GFP_KERNEL
10.00% call_site=ffffffffb9258416 ptr=0xffff888a1dc61f00 bytes_req=240 bytes_alloc=256 gfp_flags=GFP_KERNEL|__GFP_ZERO
7.50% call_site=ffffffffb9258416 ptr=0xffff888a2640ac00 bytes_req=240 bytes_alloc=256 gfp_flags=GFP_KERNEL|__GFP_ZERO
2.50% call_site=ffffffffb92759ba ptr=0xffff888a26776000 bytes_req=4096 bytes_alloc=4096 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb9276864 ptr=0xffff8886f6b82600 bytes_req=136 bytes_alloc=192 gfp_flags=GFP_KERNEL|__GFP_ZERO
2.50% call_site=ffffffffb9276903 ptr=0xffff888aefcf0460 bytes_req=32 bytes_alloc=32 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb92ad0ce ptr=0xffff888756c98a00 bytes_req=392 bytes_alloc=512 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb92ad0ce ptr=0xffff888756c9ba00 bytes_req=504 bytes_alloc=512 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb92ad301 ptr=0xffff888a31747600 bytes_req=128 bytes_alloc=128 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb92ad511 ptr=0xffff888a9d26a2a0 bytes_req=28 bytes_alloc=32 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb936a7fb ptr=0xffff88873e8c11a0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb936a7fb ptr=0xffff88873e8c12c0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb936a7fb ptr=0xffff88873e8c1540 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb936a7fb ptr=0xffff88873e8c15a0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb936a7fb ptr=0xffff88873e8c15e0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb936a7fb ptr=0xffff88873e8c16e0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb936a7fb ptr=0xffff88873e8c1c20 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb936a7fb ptr=0xffff888a9d26a2a0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
2.50% call_site=ffffffffb9373e66 ptr=0xffff8889f1931240 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO
2.50% call_site=ffffffffb9373e66 ptr=0xffff8889f1931980 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO
2.50% call_site=ffffffffb9373e66 ptr=0xffff8889f1931a00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO #
# # And then limiting using the example for 'perf kmem stat --time' used # # in the previous changeset committer note we see that there were no # # kmem:kmalloc in that last part of the file, but there were some # # kmem:kmem_cache_alloc ones:
#
# perf report --time 20119.782088, --stdio # # Total Lost Samples: 0 # # Samples: 0 of event 'kmem:kmalloc' # Event count (approx.): 0 # # Overhead Trace output # ........ ............ #
# Samples: 0 of event 'kmem:kmalloc_node'
# Event count (approx.): 0
#
# Overhead Trace output
# ........ ............ #
# Samples: 0 of event 'kmem:kfree'
# Event count (approx.): 0
#
# Overhead Trace output
# ........ ............ #
# Samples: 8 of event 'kmem:kmem_cache_alloc'
# Event count (approx.): 8
#
# Overhead Trace output
# ........ ..................................................................................................................
#
75.00% call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
12.50% call_site=ffffffffb90ad33a ptr=0xffff8889f071f6e0 bytes_req=160 bytes_alloc=160 gfp_flags=GFP_ATOMIC|__GFP_NOTRACK
12.50% call_site=ffffffffb9287cc1 ptr=0xffff8889b12722d8 bytes_req=104 bytes_alloc=104 gfp_flags=GFP_NOFS|__GFP_ZERO
#--- tools/perf/Documentation/perf-report.txt | 7 +++++++ tools/perf/builtin-report.c | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +7 -0
@@ -382,6 +382,13 @@ OPTIONS --header-only:: Show only perf.data header (forces --stdio). +--time:: + Only analyze samples within given time window: <start>,<stop>. Times + have the format seconds.microseconds. If start is not given (i.e., time + string is ',x.y') then analysis starts at the beginning of the file. If + stop time is not given (i.e, time string is 'x.y,') then analysis goes + to end of file. + --itrace:: Options for decoding instruction tracing data. The options are:
tools/perf/builtin-report.c +13 -1
@@ -36,7 +36,7 @@#include "util/hist.h" #include "util/data.h" #include "arch/common.h" - +#include "util/time-utils.h" #include "util/auxtrace.h" #include <dlfcn.h>
@@ -59,6 +59,8 @@ struct report {const char *pretty_printing_style;const char *cpu_list;const char *symbol_filter_str; +const char *time_str; +struct perf_time_interval ptime;float min_percent;u64 nr_entries;u64 queue_size;
@@ -158,6 +160,9 @@ static int process_sample_event(struct perf_tool *tool, };int ret =0 ; +if (perf_time__skip_sample (&rep->ptime, sample->time)) +return 0 ; +if (machine__resolve (machine, &al, sample) <0 ) {pr_debug ("problem processing %d event, skipping it.\n" , event->header.type);
@@ -830,6 +835,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)OPT_CALLBACK_DEFAULT (0 ,"stdio-color" ,NULL ,"mode" ,"'always' (default), 'never' or 'auto' only applicable to --stdio mode" , stdio__config_color,"always" ), +OPT_STRING (0 ,"time" , &report.time_str,"str" , +"Time span of interest (start,stop)" ),OPT_END () }; struct perf_data_file file = {
@@ -1015,6 +1022,11 @@ repeat:if (symbol__init (&session->header.env) <0 ) goto error; +if (perf_time__parse_str (&report.ptime, report.time_str) !=0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } +sort__setup_elide (stdout); ret =__cmd_report (&report);
Em Tue, Nov 29, 2016 at 10:15:40AM -0700, David Ahern escreveu:
Quoted 6 lines
This series allows users to collect data and analyze a time window of interest within the file.
v2
- renamedperf_timetoperf_time_interval
- changed../perf.htoperf.hin patch 1
Thanks, applied and pushed out to acme/perf/core.
- Arnaldo
Quoted 27 lines
David Ahern (6):
perf tool: Add time-based utility functions
perf tool: Moveparse_nsec_timetotime-utils.c
perf script: Add option to specify time window of interest perf sched timehist: Add option to specify time window of interest perf kmem: Add option to specify time window of interest perf report: Add option to specify time window of interesttools/perf/Documentation/perf-kmem.txt | 7 ++ tools/perf/Documentation/perf-report.txt | 7 ++ tools/perf/Documentation/perf-sched.txt | 8 +++ tools/perf/Documentation/perf-script.txt | 7 ++ tools/perf/builtin-kmem.c | 24 +++++++ tools/perf/builtin-report.c | 14 +++- tools/perf/builtin-sched.c | 51 +++++++++++-- tools/perf/builtin-script.c | 15 +++- tools/perf/util/Build | 1 + tools/perf/util/time-utils.c | 118 +++++++++++++++++++++++++++++++ tools/perf/util/time-utils.h | 14 ++++ tools/perf/util/util.c | 33 --------- tools/perf/util/util.h | 2 - 13 files changed, 258 insertions(+), 43 deletions(-) create mode 100644 tools/perf/util/time-utils.c create mode 100644 tools/perf/util/time-utils.hSignature · 1 line
2.7.4 (Apple Git-66)
Hi David and Arnaldo,
Quoted 9 lines · Arnaldo Carvalho de Melo
Em Tue, Nov 29, 2016 at 10:15:40AM -0700, David Ahern escreveu:
Quoted 6 lines
This series allows users to collect data and analyze a time window of interest within the file.
v2
- renamedperf_timetoperf_time_interval
- changed../perf.htoperf.hin patch 1Thanks, applied and pushed out to acme/perf/core.
If it's not too late:
Thanks
Namhyung
Quoted 29 lines
Quoted 28 lines
David Ahern (6):
perf tool: Add time-based utility functions
perf tool: Moveparse_nsec_timetotime-utils.c
perf script: Add option to specify time window of interest perf sched timehist: Add option to specify time window of interest perf kmem: Add option to specify time window of interest perf report: Add option to specify time window of interesttools/perf/Documentation/perf-kmem.txt | 7 ++ tools/perf/Documentation/perf-report.txt | 7 ++ tools/perf/Documentation/perf-sched.txt | 8 +++ tools/perf/Documentation/perf-script.txt | 7 ++ tools/perf/builtin-kmem.c | 24 +++++++ tools/perf/builtin-report.c | 14 +++- tools/perf/builtin-sched.c | 51 +++++++++++-- tools/perf/builtin-script.c | 15 +++- tools/perf/util/Build | 1 + tools/perf/util/time-utils.c | 118 +++++++++++++++++++++++++++++++ tools/perf/util/time-utils.h | 14 ++++ tools/perf/util/util.c | 33 --------- tools/perf/util/util.h | 2 - 13 files changed, 258 insertions(+), 43 deletions(-) create mode 100644 tools/perf/util/time-utils.c create mode 100644 tools/perf/util/time-utils.h--
2.7.4 (Apple Git-66)
Signature · 2 lines
Thanks, Namhyung Kim
Arnaldo Carvalho de Melo
maintainerEm Wed, Nov 30, 2016 at 02:26:48PM +0900, Namhyung Kim escreveu:
Quoted 11 lines
Hi David and Arnaldo,
Quoted 8 lines · Arnaldo Carvalho de Melo
Em Tue, Nov 29, 2016 at 10:15:40AM -0700, David Ahern escreveu:
Quoted 6 lines
This series allows users to collect data and analyze a time window of interest within the file.
v2
- renamedperf_timetoperf_time_interval
- changed../perf.htoperf.hin patch 1
Quoted 5 lines
Quoted 1 line
Thanks, applied and pushed out to acme/perf/core.
If it's not too late:
Acked-by Namhyung Kim <[email protected]>
Thanks, will add them, appreciated, as always!
- Arnaldo
Quoted 38 lines
Thanks
NamhyungQuoted 29 lines
Quoted 28 lines
David Ahern (6):
perf tool: Add time-based utility functions
perf tool: Moveparse_nsec_timetotime-utils.c
perf script: Add option to specify time window of interest perf sched timehist: Add option to specify time window of interest perf kmem: Add option to specify time window of interest perf report: Add option to specify time window of interesttools/perf/Documentation/perf-kmem.txt | 7 ++ tools/perf/Documentation/perf-report.txt | 7 ++ tools/perf/Documentation/perf-sched.txt | 8 +++ tools/perf/Documentation/perf-script.txt | 7 ++ tools/perf/builtin-kmem.c | 24 +++++++ tools/perf/builtin-report.c | 14 +++- tools/perf/builtin-sched.c | 51 +++++++++++-- tools/perf/builtin-script.c | 15 +++- tools/perf/util/Build | 1 + tools/perf/util/time-utils.c | 118 +++++++++++++++++++++++++++++++ tools/perf/util/time-utils.h | 14 ++++ tools/perf/util/util.c | 33 --------- tools/perf/util/util.h | 2 - 13 files changed, 258 insertions(+), 43 deletions(-) create mode 100644 tools/perf/util/time-utils.c create mode 100644 tools/perf/util/time-utils.h--
2.7.4 (Apple Git-66)Signature · 2 lines
Thanks, Namhyung Kim