Permalink
Browse files

Merge pull request #14 from timbunce/timemax

Add --total option to enable visualization of time spent not within a sub
  • Loading branch information...
2 parents f67e67e + a434db9 commit 19eac6316bb8c9afb620a4bc92e4cacd99b712e9 @brendangregg committed Mar 25, 2013
Showing with 11 additions and 2 deletions.
  1. +11 −2 flamegraph.pl
View
@@ -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,14 +77,14 @@
'nametype=s' => \$nametype,
'countname=s' => \$countname,
'nameattr=s' => \$nameattrfile,
+ 'total=s' => \$timemax,
) or exit 1;
# internals
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;

0 comments on commit 19eac63

Please sign in to comment.