[PATCH 14/19] perf script: Add option to specify time window of interest

2016-12-01 Thread Arnaldo Carvalho de Melo
From: David Ahern 

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
swapper0 [0] 9693.370039:  1 cycles:ppp: b90072ad 
x86_pmu_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370044:  1 cycles:ppp: b900ca1b 
intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370046:  7 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370048:126 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370049:   2701 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370051:  58823 cycles:ppp: b90cd2e0 idle_cpu 
(.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370059:  1 cycles:ppp: b91a713a 
ctx_resched (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370062:  1 cycles:ppp: b900ca1b 
intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370064: 13 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370065:250 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370067:   5269 cycles:ppp: b902fe79 
sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370069: 114602 cycles:ppp: b90c1c5a 
atomic_notifier_call_chain (.../4.8.8-300.fc25.x86_64/vmlinux)
   perf 5124 [2] 9693.370076:  1 cycles:ppp: b91a76c1 
__perf_event_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
   perf 5124 [2] 9693.370091:  1 cycles:ppp: b900ca1b 
intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
   perf 5124 [2] 9693.370095:  3 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
  #
  # perf script --hide-call-graph --time ,9693.370048
swapper0 [0] 9693.370039:  1 cycles:ppp: b90072ad 
x86_pmu_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370044:  1 cycles:ppp: b900ca1b 
intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370046:  7 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
  # perf script --hide-call-graph --time 9693.370064,9693.370076
swapper0 [1] 9693.370064: 13 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370065:250 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370067:   5269 cycles:ppp: b902fe79 
sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370069: 114602 cycles:ppp: b90c1c5a 
atomic_notifier_call_chain (.../4.8.8-300.fc25.x86_64/vmlinux)
  #

Signed-off-by: David Ahern 
Tested-by: Arnaldo Carvalho de Melo 
Acked-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1480439746-42695-4-git-send-email-dsah...@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-script.txt |  7 +++
 tools/perf/builtin-script.c  | 15 ++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-script.txt 
b/tools/perf/Documentation/perf-script.txt
index 0f6ee09f7256..5dc5c6a09ac4 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -292,6 +292,13 @@ include::itrace.txt[]
 --force::
Don't do ownership validation.
 
+--time::
+   Only analyze samples within given time window: ,. 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],
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 066b4bf73780..2f3ff69fc4e7 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -22,6 +22,7 @@
 #include "util/thread_map.h"
 #include "util/stat.h"
 #include "util/thread-stack.h"

[PATCH 14/19] perf script: Add option to specify time window of interest

2016-12-01 Thread Arnaldo Carvalho de Melo
From: David Ahern 

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
swapper0 [0] 9693.370039:  1 cycles:ppp: b90072ad 
x86_pmu_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370044:  1 cycles:ppp: b900ca1b 
intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370046:  7 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370048:126 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370049:   2701 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370051:  58823 cycles:ppp: b90cd2e0 idle_cpu 
(.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370059:  1 cycles:ppp: b91a713a 
ctx_resched (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370062:  1 cycles:ppp: b900ca1b 
intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370064: 13 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370065:250 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370067:   5269 cycles:ppp: b902fe79 
sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370069: 114602 cycles:ppp: b90c1c5a 
atomic_notifier_call_chain (.../4.8.8-300.fc25.x86_64/vmlinux)
   perf 5124 [2] 9693.370076:  1 cycles:ppp: b91a76c1 
__perf_event_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
   perf 5124 [2] 9693.370091:  1 cycles:ppp: b900ca1b 
intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
   perf 5124 [2] 9693.370095:  3 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
  #
  # perf script --hide-call-graph --time ,9693.370048
swapper0 [0] 9693.370039:  1 cycles:ppp: b90072ad 
x86_pmu_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370044:  1 cycles:ppp: b900ca1b 
intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [0] 9693.370046:  7 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
  # perf script --hide-call-graph --time 9693.370064,9693.370076
swapper0 [1] 9693.370064: 13 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370065:250 cycles:ppp: b902fd93 
native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370067:   5269 cycles:ppp: b902fe79 
sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
swapper0 [1] 9693.370069: 114602 cycles:ppp: b90c1c5a 
atomic_notifier_call_chain (.../4.8.8-300.fc25.x86_64/vmlinux)
  #

Signed-off-by: David Ahern 
Tested-by: Arnaldo Carvalho de Melo 
Acked-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1480439746-42695-4-git-send-email-dsah...@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-script.txt |  7 +++
 tools/perf/builtin-script.c  | 15 ++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-script.txt 
b/tools/perf/Documentation/perf-script.txt
index 0f6ee09f7256..5dc5c6a09ac4 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -292,6 +292,13 @@ include::itrace.txt[]
 --force::
Don't do ownership validation.
 
+--time::
+   Only analyze samples within given time window: ,. 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],
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 066b4bf73780..2f3ff69fc4e7 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -22,6 +22,7 @@
 #include "util/thread_map.h"
 #include "util/stat.h"
 #include "util/thread-stack.h"
+#include "util/time-utils.h"
 #include 
 #include 
 #include 
@@ -833,6 +834,8 @@ struct perf_script {
struct cpu_map  *cpus;