Created
December 5, 2014 03:15
-
-
Save wangweij/92e00769c4980ca1e7c1 to your computer and use it in GitHub Desktop.
A small program to translate -agentlib:hprof=cpu=times,depth=999 output to folded Flame Graphs format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
$stage = 1; | |
while (<STDIN>) { | |
if ($stage == 1) { | |
if (/TRACE (\d+)/) { | |
if ($line ne '') { | |
$cpu{$id} = $line; | |
} | |
$id = $1; | |
$line = ''; | |
} elsif (/CPU TIME.*BEGIN/) { | |
$cpu{$id} = $line; | |
$stage = 2; | |
} elsif (/^\s+(.*?)\(/) { | |
if ($line ne '') { | |
$line = "$1;$line"; | |
} else { | |
$line = $1; | |
} | |
} | |
} else { | |
if (/\s(\d+)\.(\d+)%\s.*%.*\s(3\d\d\d\d\d)\s/) { | |
print $cpu{$3}." ".$1.$2."\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A more sophisticated python tool at https://github.com/cykl/hprof2flamegraph.