From a434db9a5b29e19ffb32e9e222ac0f4c8bb58897 Mon Sep 17 00:00:00 2001 From: Tim Bunce Date: Mon, 25 Mar 2013 22:45:18 +0000 Subject: [PATCH] Add --total option to enable visualization of time spent not within a sub. --- flamegraph.pl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/flamegraph.pl b/flamegraph.pl index e505901a..7ddaf40d 100755 --- a/flamegraph.pl +++ b/flamegraph.pl @@ -65,6 +65,7 @@ my $nametype = "Function:"; # what are the names in the data? my $countname = "samples"; # what are the counts in the data? my $nameattrfile; # file holding function attributes +my $timemax; # (override the) sum of the counts GetOptions( 'fonttype=s' => \$fonttype, @@ -76,6 +77,7 @@ 'nametype=s' => \$nametype, 'countname=s' => \$countname, 'nameattr=s' => \$nameattrfile, + 'total=s' => \$timemax, ) or exit 1; @@ -83,7 +85,6 @@ my $ypad1 = $fontsize * 4; # pad top, include title my $ypad2 = $fontsize * 2 + 10; # pad bottom, include labels my $xpad = 10; # pad lefm and right -my $timemax = 0; my $depthmax = 0; my %Events; my %nameattr; @@ -243,7 +244,13 @@ sub flow { } flow($last, [], $time); warn "Ignored $ignored lines with invalid format\n" if $ignored; -$timemax = $time or die "ERROR: No stack counts found\n"; +die "ERROR: No stack counts found\n" unless $time; + +if ($timemax and $timemax < $time) { + warn "Specified --total $timemax is less than actual total $time, so ignored\n"; + undef $timemax; +} +$timemax ||= $time; # Draw canvas my $widthpertime = ($imagewidth - 2 * $xpad) / $timemax; @@ -286,6 +293,8 @@ sub flow { die "missing start for $id" if !defined $Node{$id}->{stime}; my $stime = $Node{$id}->{stime}; + $etime = $timemax if $func eq "" and $depth == 0; + my $x1 = $xpad + $stime * $widthpertime; my $x2 = $xpad + $etime * $widthpertime; my $width = $x2 - $x1;