Skip to content
Browse files

Merge pull request #17 from timbunce/imageheight

Calculate depthmax after pruning nodes based on minwidth.
  • Loading branch information...
2 parents 607b32b + 7933cbc commit b346b810781b0944cd02d436e770632e30ba9439 @brendangregg committed Apr 3, 2013
Showing with 20 additions and 8 deletions.
  1. +20 −8 flamegraph.pl
View
28 flamegraph.pl
@@ -200,7 +200,6 @@ sub flow {
my $len_a = @$last - 1;
my $len_b = @$this - 1;
- $depthmax = $len_b if $len_b > $depthmax;
my $i = 0;
my $len_same;
@@ -252,8 +251,23 @@ sub flow {
}
$timemax ||= $time;
-# Draw canvas
my $widthpertime = ($imagewidth - 2 * $xpad) / $timemax;
+my $minwidth_time = $minwidth / $widthpertime;
+
+# prune blocks that are too narrow and determine max depth
+while (my ($id, $node) = each %Node) {
+ my ($func, $depth, $etime) = split ";", $id;
+ my $stime = $node->{stime};
+ die "missing start for $id" if not defined $stime;
+
+ if (($etime-$stime) < $minwidth_time) {
+ delete $Node{$id};
+ next;
+ }
+ $depthmax = $depth if $depth > $depthmax;
+}
+
+# Draw canvas
my $imageheight = ($depthmax * $frameheight) + $ypad1 + $ypad2;
my $im = SVG->new();
$im->header($imagewidth, $imageheight);
@@ -288,18 +302,15 @@ sub flow {
$im->stringTTF($black, $fonttype, $fontsize, 0.0, $xpad, $imageheight - ($ypad2 / 2), " ", "", 'id="details"');
# Draw frames
-foreach my $id (keys %Node) {
+
+while (my ($id, $node) = each %Node) {
my ($func, $depth, $etime) = split ";", $id;
- die "missing start for $id" if !defined $Node{$id}->{stime};
- my $stime = $Node{$id}->{stime};
+ my $stime = $node->{stime};
$etime = $timemax if $func eq "" and $depth == 0;
my $x1 = $xpad + $stime * $widthpertime;
my $x2 = $xpad + $etime * $widthpertime;
- my $width = $x2 - $x1;
- next if $width < $minwidth;
-
my $y1 = $imageheight - $ypad2 - ($depth + 1) * $frameheight + 1;
my $y2 = $imageheight - $ypad2 - $depth * $frameheight;
@@ -327,6 +338,7 @@ sub flow {
$im->filledRectangle($x1, $y1, $x2, $y2, color("hot"), 'rx="2" ry="2"');
+ my $width = $x2 - $x1;
if ($width > 50) {
my $chars = int($width / (0.7 * $fontsize));
my $text = substr $func, 0, $chars;

0 comments on commit b346b81

Please sign in to comment.
Something went wrong with that request. Please try again.