diff options
author | mfilitov <mfilitov@yandex-team.com> | 2024-08-23 13:23:47 +0300 |
---|---|---|
committer | mfilitov <mfilitov@yandex-team.com> | 2024-08-23 13:38:30 +0300 |
commit | 5741cf990d59e786aee8074fc01db7655490bcfd (patch) | |
tree | 7161f63ec7c981a5547c63001dcb6c3fe66d9dcf /contrib/tools/flame-graph/stackcollapse-java-exceptions.pl | |
parent | 10ac4b53185c5638e7dae756765beb5f60019451 (diff) | |
download | ydb-5741cf990d59e786aee8074fc01db7655490bcfd.tar.gz |
Try adding flamegraph with simple copy
6d3bfb2f6ddb8ad122ad37485ce2d0ac8346e0ee
Diffstat (limited to 'contrib/tools/flame-graph/stackcollapse-java-exceptions.pl')
-rwxr-xr-x | contrib/tools/flame-graph/stackcollapse-java-exceptions.pl | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/contrib/tools/flame-graph/stackcollapse-java-exceptions.pl b/contrib/tools/flame-graph/stackcollapse-java-exceptions.pl new file mode 100755 index 0000000000..19badbca6c --- /dev/null +++ b/contrib/tools/flame-graph/stackcollapse-java-exceptions.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl -w +# +# stackcolllapse-java-exceptions.pl collapse java exceptions (found in logs) into single lines. +# +# Parses Java error stacks found in a log file and outputs them as +# single lines, with methods separated by semicolons, and then a space and an +# occurrence count. Inspired by stackcollapse-jstack.pl except that it does +# not act as a performance profiler. +# +# It can be useful if a Java process dumps a lot of different stacks in its logs +# and you want to quickly identify the biggest culprits. +# +# USAGE: ./stackcollapse-java-exceptions.pl infile > outfile +# +# Copyright 2018 Paul de Verdiere. All rights reserved. + +use strict; +use Getopt::Long; + +# tunables +my $shorten_pkgs = 0; # shorten package names +my $no_pkgs = 0; # really shorten package names!! +my $help = 0; + +sub usage { + die <<USAGE_END; +USAGE: $0 [options] infile > outfile\n + --shorten-pkgs : shorten package names + --no-pkgs : suppress package names (makes SVG much more readable) + +USAGE_END +} + +GetOptions( + 'shorten-pkgs!' => \$shorten_pkgs, + 'no-pkgs!' => \$no_pkgs, + 'help' => \$help, +) or usage(); +$help && usage(); + +my %collapsed; + +sub remember_stack { + my ($stack, $count) = @_; + $collapsed{$stack} += $count; +} + +my @stack; + +foreach (<>) { + chomp; + + if (/^\s*at ([^\(]*)/) { + my $func = $1; + if ($shorten_pkgs || $no_pkgs) { + my ($pkgs, $clsFunc) = ( $func =~ m/(.*\.)([^.]+\.[^.]+)$/ ); + $pkgs =~ s/(\w)\w*/$1/g; + $func = $no_pkgs ? $clsFunc: $pkgs . $clsFunc; + } + unshift @stack, $func; + } elsif (@stack ) { + next if m/.*waiting on .*/; + remember_stack(join(";", @stack), 1) if @stack; + undef @stack; + } +} + +remember_stack(join(";", @stack), 1) if @stack; + +foreach my $k (sort { $a cmp $b } keys %collapsed) { + print "$k $collapsed{$k}\n"; +} |