stackcollapse-recursive.pl (1569B)
1 #!/usr/bin/perl -ws 2 # 3 # stackcollapse-recursive Collapse direct recursive backtraces 4 # 5 # Post-process a stack list and merge direct recursive calls: 6 # 7 # Example input: 8 # 9 # main;recursive;recursive;recursive;helper 1 10 # 11 # Output: 12 # 13 # main;recursive;helper 1 14 # 15 # Copyright 2014 Gabriel Corona. All rights reserved. 16 # 17 # CDDL HEADER START 18 # 19 # The contents of this file are subject to the terms of the 20 # Common Development and Distribution License (the "License"). 21 # You may not use this file except in compliance with the License. 22 # 23 # You can obtain a copy of the license at docs/cddl1.txt or 24 # http://opensource.org/licenses/CDDL-1.0. 25 # See the License for the specific language governing permissions 26 # and limitations under the License. 27 # 28 # When distributing Covered Code, include this CDDL HEADER in each 29 # file and include the License file at docs/cddl1.txt. 30 # If applicable, add the following below this CDDL HEADER, with the 31 # fields enclosed by brackets "[]" replaced with your own identifying 32 # information: Portions Copyright [yyyy] [name of copyright owner] 33 # 34 # CDDL HEADER END 35 36 my %stacks; 37 38 while(<>) { 39 chomp; 40 my ($stack_, $value) = (/^(.*)\s+?(\d+(?:\.\d*)?)$/); 41 if ($stack_) { 42 my @stack = split(/;/, $stack_); 43 44 my @result = (); 45 my $i; 46 my $last=""; 47 for($i=0; $i!=@stack; ++$i) { 48 if(!($stack[$i] eq $last)) { 49 $result[@result] = $stack[$i]; 50 $last = $stack[$i]; 51 } 52 } 53 54 $stacks{join(";", @result)} += $value; 55 } 56 } 57 58 foreach my $k (sort { $a cmp $b } keys %stacks) { 59 print "$k $stacks{$k}\n"; 60 }