Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 91 lines (80 sloc) 2.615 kb
8b171a6 new stack folders
Brendan Gregg authored
1 #!/usr/bin/perl -w
2 #
3 # stackcolllapse-perf.pl collapse perf samples into single lines.
4 #
5 # Parses a list of multiline stacks generated by "perf script", and
e51f401 comments for comma to semicolon change
Brendan Gregg authored
6 # outputs a semicolon separated stack followed by a space and a count.
8b171a6 new stack folders
Brendan Gregg authored
7 # If memory addresses (+0xd) are present, they are stripped, and resulting
8 # identical stacks are colased with their counts summed.
9 #
10 # USAGE: ./stackcollapse-perf.pl infile > outfile
11 #
12 # Example input:
13 #
14 # swapper 0 [000] 158665.570607: cpu-clock:
15 # ffffffff8103ce3b native_safe_halt ([kernel.kallsyms])
16 # ffffffff8101c6a3 default_idle ([kernel.kallsyms])
17 # ffffffff81013236 cpu_idle ([kernel.kallsyms])
18 # ffffffff815bf03e rest_init ([kernel.kallsyms])
19 # ffffffff81aebbfe start_kernel ([kernel.kallsyms].init.text)
20 # [...]
21 #
22 # Example output:
23 #
e51f401 comments for comma to semicolon change
Brendan Gregg authored
24 # start_kernel;rest_init;cpu_idle;default_idle;native_safe_halt 1
8b171a6 new stack folders
Brendan Gregg authored
25 #
26 # Input may be created and processed using:
27 #
28 # perf record -a -g -F 997 sleep 60
29 # perf script | ./stackcollapse-perf.pl > out.stacks-folded
30 #
31 # Copyright 2012 Joyent, Inc. All rights reserved.
32 # Copyright 2012 Brendan Gregg. All rights reserved.
33 #
34 # CDDL HEADER START
35 #
36 # The contents of this file are subject to the terms of the
37 # Common Development and Distribution License (the "License").
38 # You may not use this file except in compliance with the License.
39 #
40 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
41 # or http://www.opensolaris.org/os/licensing.
42 # See the License for the specific language governing permissions
43 # and limitations under the License.
44 #
45 # When distributing Covered Code, include this CDDL HEADER in each
46 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
47 # If applicable, add the following below this CDDL HEADER, with the
48 # fields enclosed by brackets "[]" replaced with your own identifying
49 # information: Portions Copyright [yyyy] [name of copyright owner]
50 #
51 # CDDL HEADER END
52 #
53 # 02-Mar-2012 Brendan Gregg Created this.
54
55 use strict;
56
57 my %collapsed;
58
59 sub remember_stack {
60 my ($stack, $count) = @_;
61 $collapsed{$stack} += $count;
62 }
63
64 my @stack;
65
66 foreach (<>) {
67 next if m/^#/;
68 chomp;
69
70 if (m/^$/) {
02b07ad Use a semicolon to separate frames
Ryan Stone authored
71 remember_stack(join(";", @stack), 1) if @stack;
8b171a6 new stack folders
Brendan Gregg authored
72 undef @stack;
73 next;
74 }
75
76 # Note the details skipped below, and customize as desired
77
78 next if m/:.*:/; # skip summary lines
79
80 if (/^\s*\w+ (\w+) (\S+)/) {
81 my ($func, $mod) = ($1, $2);
82 next if $func =~ /\(/; # skip process names
83 next unless $mod =~ /kernel/; # skip non-kernel
84 unshift @stack, $func;
85 }
86 }
87
88 foreach my $k (sort { $a cmp $b } keys %collapsed) {
89 printf "$k $collapsed{$k}\n";
90 }
Something went wrong with that request. Please try again.