Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 85 lines (75 sloc) 2.336 kb
8b171a6 new stack folders
Brendan Gregg authored
1 #!/usr/bin/perl -w
2 #
3 # stackcolllapse-stap.pl collapse multiline SystemTap stacks
4 # into single lines.
5 #
6 # Parses a multiline stack followed by a number on a separate line, and
e51f401 comments for comma to semicolon change
Brendan Gregg authored
7 # outputs a semicolon separated stack followed by a space and the number.
8b171a6 new stack folders
Brendan Gregg authored
8 # If memory addresses (+0xd) are present, they are stripped, and resulting
9 # identical stacks are colased with their counts summed.
10 #
11 # USAGE: ./stackcollapse.pl infile > outfile
12 #
13 # Example input:
14 #
15 # 0xffffffff8103ce3b : native_safe_halt+0xb/0x10 [kernel]
16 # 0xffffffff8101c6a3 : default_idle+0x53/0x1d0 [kernel]
17 # 0xffffffff81013236 : cpu_idle+0xd6/0x120 [kernel]
18 # 0xffffffff815bf03e : rest_init+0x72/0x74 [kernel]
19 # 0xffffffff81aebbfe : start_kernel+0x3ba/0x3c5 [kernel]
20 # 2404
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 2404
8b171a6 new stack folders
Brendan Gregg authored
25 #
26 # Input may contain many stacks as generated from SystemTap.
27 #
28 # Copyright 2011 Joyent, Inc. All rights reserved.
29 # Copyright 2011 Brendan Gregg. All rights reserved.
30 #
31 # CDDL HEADER START
32 #
33 # The contents of this file are subject to the terms of the
34 # Common Development and Distribution License (the "License").
35 # You may not use this file except in compliance with the License.
36 #
37 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5b8b413 fixing dead links
Brendan Gregg authored
38 # or http://opensource.org/licenses/CDDL-1.0.
8b171a6 new stack folders
Brendan Gregg authored
39 # See the License for the specific language governing permissions
40 # and limitations under the License.
41 #
42 # When distributing Covered Code, include this CDDL HEADER in each
43 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
44 # If applicable, add the following below this CDDL HEADER, with the
45 # fields enclosed by brackets "[]" replaced with your own identifying
46 # information: Portions Copyright [yyyy] [name of copyright owner]
47 #
48 # CDDL HEADER END
49 #
50 # 16-Feb-2012 Brendan Gregg Created this.
51
52 use strict;
53
54 my %collapsed;
55
56 sub remember_stack {
57 my ($stack, $count) = @_;
58 $collapsed{$stack} += $count;
59 }
60
61 my @stack;
62
63 foreach (<>) {
64 chomp;
65
66 if (m/^\s*(\d+)+$/) {
02b07ad Use a semicolon to separate frames
Ryan Stone authored
67 remember_stack(join(";", @stack), $1);
8b171a6 new stack folders
Brendan Gregg authored
68 @stack = ();
69 next;
70 }
71
72 next if (m/^\s*$/);
73
74 my $frame = $_;
75 $frame =~ s/^\s*//;
2672d89 handle c++ in func names
Brendan Gregg authored
76 $frame =~ s/\+[^+]*$//;
8b171a6 new stack folders
Brendan Gregg authored
77 $frame =~ s/.* : //;
78 $frame = "-" if $frame eq "";
79 unshift @stack, $frame;
80 }
81
82 foreach my $k (sort { $a cmp $b } keys %collapsed) {
83 printf "$k $collapsed{$k}\n";
84 }
Something went wrong with that request. Please try again.