stackcollapse-recursive.pl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. my %stacks;
  36. while(<>) {
  37. chomp;
  38. my ($stack_, $value) = (/^(.*)\s+?(\d+(?:\.\d*)?)$/);
  39. if ($stack_) {
  40. my @stack = split(/;/, $stack_);
  41. my @result = ();
  42. my $i;
  43. my $last="";
  44. for($i=0; $i!=@stack; ++$i) {
  45. if(!($stack[$i] eq $last)) {
  46. $result[@result] = $stack[$i];
  47. $last = $stack[$i];
  48. }
  49. }
  50. $stacks{join(";", @result)} += $value;
  51. }
  52. }
  53. foreach my $k (sort { $a cmp $b } keys %stacks) {
  54. print "$k $stacks{$k}\n";
  55. }