Skip to content

Instantly share code, notes, and snippets.

@wangweij
Created December 5, 2014 03:15
Show Gist options
  • Save wangweij/92e00769c4980ca1e7c1 to your computer and use it in GitHub Desktop.
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.
#! /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";
}
}
}
@wangweij
Copy link
Author

wangweij commented Dec 5, 2014

A more sophisticated python tool at https://github.com/cykl/hprof2flamegraph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment