Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add options for tunables. Add more tunables. Commify sample count. #9

Merged
merged 1 commit into from

2 participants

@timbunce

Per issue #8 I'm working on integrating flame graphs into Perl's Devel::NYTProf profiler.

I've implemented a few features that would help people typing to do similar integrations.

@brendangregg

thanks!

@brendangregg brendangregg merged commit e0fbd11 into brendangregg:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 7 deletions.
  1. +27 −7 flamegraph.pl
View
34 flamegraph.pl
@@ -47,17 +47,35 @@
#
# CDDL HEADER END
#
+# 17-Mar-2013 Tim Bunce Added options and more tunables.
# 15-Dec-2011 Dave Pacheco Support for frames with whitespace.
# 10-Sep-2011 Brendan Gregg Created this.
use strict;
+use Getopt::Long;
+
# tunables
my $fonttype = "Verdana";
my $imagewidth = 1200; # max width, pixels
my $frameheight = 16; # max height is dynamic
my $fontsize = 12; # base text size
my $minwidth = 0.1; # min function width, pixels
+my $titletext = "Flame Graph"; # centered heading
+my $nametype = "Function:"; # what are the names in the data?
+my $countname = "samples"; # what are the counts in the data?
+
+GetOptions(
+ 'fonttype=s' => \$fonttype,
+ 'width=i' => \$imagewidth,
+ 'height=i' => \$frameheight,
+ 'fontsize=i' => \$fontsize,
+ 'minwidth=f' => \$minwidth,
+ 'title=s' => \$titletext,
+ 'nametype=s' => \$nametype,
+ 'countname=s' => \$countname,
+) or exit 1;
+
# internals
my $ypad1 = $fontsize * 4; # pad top, include title
@@ -203,7 +221,7 @@ sub flow {
<![CDATA[
var details;
function init(evt) { details = document.getElementById("details").firstChild; }
- function s(info) { details.nodeValue = info; }
+ function s(info) { details.nodeValue = "$nametype " + info; }
function c() { details.nodeValue = ' '; }
]]>
</script>
@@ -216,16 +234,14 @@ sub flow {
$im->colorAllocate(40, 40, 40),
$im->colorAllocate(160, 160, 160),
);
-$im->stringTTF($black, $fonttype, $fontsize + 5, 0.0, int($imagewidth / 2), $fontsize * 2, "Flame Graph", "middle");
-$im->stringTTF($black, $fonttype, $fontsize, 0.0, $xpad, $imageheight - ($ypad2 / 2), 'Function:');
-$im->stringTTF($black, $fonttype, $fontsize, 0.0, $xpad + 60, $imageheight - ($ypad2 / 2), " ", "", 'id="details"');
+$im->stringTTF($black, $fonttype, $fontsize + 5, 0.0, int($imagewidth / 2), $fontsize * 2, $titletext, "middle");
+$im->stringTTF($black, $fonttype, $fontsize, 0.0, $xpad, $imageheight - ($ypad2 / 2), " ", "", 'id="details"');
# Draw frames
foreach my $id (keys %Node) {
my ($func, $depth, $etime) = split "--", $id;
die "missing start for $id" if !defined $Node{$id}->{stime};
my $stime = $Node{$id}->{stime};
- my $samples = $etime - $stime;
my $x1 = $xpad + $stime * $widthpertime;
my $x2 = $xpad + $etime * $widthpertime;
@@ -235,16 +251,20 @@ sub flow {
my $y1 = $imageheight - $ypad2 - ($depth + 1) * $frameheight + 1;
my $y2 = $imageheight - $ypad2 - $depth * $frameheight;
+ my $samples = $etime - $stime;
+ (my $samples_txt = $samples) # add commas per perlfaq5
+ =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
+
my $info;
if ($func eq "" and $depth == 0) {
- $info = "all samples ($samples samples, 100%)";
+ $info = "all ($samples_txt $countname, 100%)";
} else {
my $pct = sprintf "%.2f", ((100 * $samples) / $timemax);
my $escaped_func = $func;
$escaped_func =~ s/&/&amp;/g;
$escaped_func =~ s/</&lt;/g;
$escaped_func =~ s/>/&gt;/g;
- $info = "$escaped_func ($samples samples, $pct%)";
+ $info = "$escaped_func ($samples_txt $countname, $pct%)";
}
$im->filledRectangle($x1, $y1, $x2, $y2, color("hot"), 'rx="2" ry="2" onmouseover="s(' . "'$info'" . ')" onmouseout="c()"');
Something went wrong with that request. Please try again.