From 74764af7403f8f0832a0cecedf4e13e66408ebd9 Mon Sep 17 00:00:00 2001 From: Brendan Gregg Date: Thu, 23 Feb 2017 16:01:47 -0800 Subject: [PATCH] range-perf.pl: add options for different timestamps --- range-perf.pl | 121 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 80 insertions(+), 41 deletions(-) diff --git a/range-perf.pl b/range-perf.pl index bfa156a7..0fca6dec 100755 --- a/range-perf.pl +++ b/range-perf.pl @@ -28,69 +28,108 @@ # 21-Feb-2017 Brendan Gregg Created this. use strict; +use Getopt::Long; +use POSIX 'floor'; sub usage { die < \$timeraw, + 'timezerosecs' => \$timezerosecs, +) or usage(); + if (@ARGV < 2 || $ARGV[0] eq "-h" || $ARGV[0] eq "--help") { usage(); exit; } -my $start = $ARGV[0]; +my $begin = $ARGV[0]; my $end = $ARGV[1]; +# +# Parsing +# +# IP only examples: +# +# java 52025 [026] 99161.926202: cycles: +# java 14341 [016] 252732.474759: cycles: 7f36571947c0 nmethod::is_nmethod() const (/... +# java 14514 [022] 28191.353083: cpu-clock: 7f92b4fdb7d4 Ljava_util_List$size$0;::call (/tmp/perf-11936.map) +# swapper 0 [002] 6035557.056977: 10101010 cpu-clock: ffffffff810013aa xen_hypercall_sched_op+0xa (/lib/modules/4.9-virtual/build/vmlinux) +# bash 25370 603are 6036.991603: 10101010 cpu-clock: 4b931e [unknown] (/bin/bash) +# bash 25370/25370 6036036.799684: cpu-clock: 4b913b [unknown] (/bin/bash) +# other combinations are possible. +# +# Stack examples (-g): +# +# swapper 0 [021] 28648.467059: cpu-clock: +# ffffffff810013aa xen_hypercall_sched_op ([kernel.kallsyms]) +# ffffffff8101cb2f default_idle ([kernel.kallsyms]) +# ffffffff8101d406 arch_cpu_idle ([kernel.kallsyms]) +# ffffffff810bf475 cpu_startup_entry ([kernel.kallsyms]) +# ffffffff81010228 cpu_bringup_and_idle ([kernel.kallsyms]) +# +# java 14375 [022] 28648.467079: cpu-clock: +# 7f92bdd98965 Ljava/io/OutputStream;::write (/tmp/perf-11936.map) +# 7f8808cae7a8 [unknown] ([unknown]) +# +# swapper 0 [005] 5076.836336: cpu-clock: +# ffffffff81051586 native_safe_halt ([kernel.kallsyms]) +# ffffffff8101db4f default_idle ([kernel.kallsyms]) +# ffffffff8101e466 arch_cpu_idle ([kernel.kallsyms]) +# ffffffff810c2b31 cpu_startup_entry ([kernel.kallsyms]) +# ffffffff810427cd start_secondary ([kernel.kallsyms]) +# +# swapper 0 [002] 6034779.719110: 10101010 cpu-clock: +# 2013aa xen_hypercall_sched_op+0xfe20000a (/lib/modules/4.9-virtual/build/vmlinux) +# a72f0e default_idle+0xfe20001e (/lib/modules/4.9-virtual/build/vmlinux) +# 2392bf arch_cpu_idle+0xfe20000f (/lib/modules/4.9-virtual/build/vmlinux) +# a73333 default_idle_call+0xfe200023 (/lib/modules/4.9-virtual/build/vmlinux) +# 2c91a4 cpu_startup_entry+0xfe2001c4 (/lib/modules/4.9-virtual/build/vmlinux) +# 22b64a cpu_bringup_and_idle+0xfe20002a (/lib/modules/4.9-virtual/build/vmlinux) +# +# bash 25370/25370 6035935.188539: cpu-clock: +# b9218 [unknown] (/bin/bash) +# 2037fe8 [unknown] ([unknown]) +# other combinations are possible. +# +# This regexp matches the event line, and puts time in $1, and the event name +# in $2: +# +my $event_regexp = qr/ +([0-9\.]+): *\S* *(\S+):/; + my $line; -my $begin = 0; +my $start = 0; my $ok = 0; -my ($cpu, $ts, $event); +my $time; while (1) { - # skip comments - $line = ; last unless defined $line; - next if $line =~ /^#/; + next if $line =~ /^#/; # skip comments + + if ($line =~ $event_regexp) { + my ($ts, $event) = ($1, $2, $3); + $start = $ts if $start == 0; - # - # Parsing - # - # ip only examples: - # - # java 52025 [026] 99161.926202: cycles: - # java 14341 [016] 252732.474759: cycles: 7f36571947c0 nmethod::is_nmethod() const (/... - # java 14514 [022] 28191.353083: cpu-clock: 7f92b4fdb7d4 Ljava_util_List$size$0;::call (/tmp/perf-11936.map) - # - # stack examples (-g): - # - # swapper 0 [021] 28648.467059: cpu-clock: - # ffffffff810013aa xen_hypercall_sched_op ([kernel.kallsyms]) - # ffffffff8101cb2f default_idle ([kernel.kallsyms]) - # ffffffff8101d406 arch_cpu_idle ([kernel.kallsyms]) - # ffffffff810bf475 cpu_startup_entry ([kernel.kallsyms]) - # ffffffff81010228 cpu_bringup_and_idle ([kernel.kallsyms]) - # - # java 14375 [022] 28648.467079: cpu-clock: - # 7f92bdd98965 Ljava/io/OutputStream;::write (/tmp/perf-11936.map) - # 7f8808cae7a8 [unknown] ([unknown]) - # - # swapper 0 [005] 5076.836336: cpu-clock: - # ffffffff81051586 native_safe_halt ([kernel.kallsyms]) - # ffffffff8101db4f default_idle ([kernel.kallsyms]) - # ffffffff8101e466 arch_cpu_idle ([kernel.kallsyms]) - # ffffffff810c2b31 cpu_startup_entry ([kernel.kallsyms]) - # ffffffff810427cd start_secondary ([kernel.kallsyms]) - # - if ($line =~ / \d+ \[(\d+)\] +(\S+): (\S+):/) { - ($cpu, $ts, $event) = ($1, $2, $3); - $begin = $ts if $begin == 0; + if ($timezerosecs) { + $time = $ts - floor($start); + } elsif (!$timeraw) { + $time = $ts - $start; + } else { + $time = $ts; # raw times + } - my $time = $ts - $begin; - $ok = 1 if $time >= $start; + $ok = 1 if $time >= $begin; + # assume samples are in time order: exit if $time > $end; }