Skip to content
This repository
Browse code

Merge pull request #9 from timbunce/options

Add options for tunables. Add more tunables. Commify sample count.
  • Loading branch information...
commit e0fbd11f39863059ab8f4748dcd5937afbd662e0 2 parents fae51b8 + c1059bc
Brendan Gregg authored March 17, 2013

Showing 1 changed file with 27 additions and 7 deletions. Show diff stats Hide diff stats

  1. 34  flamegraph.pl
34  flamegraph.pl
@@ -47,17 +47,35 @@
47 47
 #
48 48
 # CDDL HEADER END
49 49
 #
  50
+# 17-Mar-2013   Tim Bunce       Added options and more tunables.
50 51
 # 15-Dec-2011	Dave Pacheco	Support for frames with whitespace.
51 52
 # 10-Sep-2011	Brendan Gregg	Created this.
52 53
 
53 54
 use strict;
54 55
 
  56
+use Getopt::Long;
  57
+
55 58
 # tunables
56 59
 my $fonttype = "Verdana";
57 60
 my $imagewidth = 1200;		# max width, pixels
58 61
 my $frameheight = 16;		# max height is dynamic
59 62
 my $fontsize = 12;		# base text size
60 63
 my $minwidth = 0.1;		# min function width, pixels
  64
+my $titletext = "Flame Graph";  # centered heading
  65
+my $nametype = "Function:";     # what are the names in the data?
  66
+my $countname = "samples";      # what are the counts in the data?
  67
+
  68
+GetOptions(
  69
+    'fonttype=s'   => \$fonttype,
  70
+    'width=i'      => \$imagewidth,
  71
+    'height=i'     => \$frameheight,
  72
+    'fontsize=i'   => \$fontsize,
  73
+    'minwidth=f'   => \$minwidth,
  74
+    'title=s'      => \$titletext,
  75
+    'nametype=s'   => \$nametype,
  76
+    'countname=s'  => \$countname,
  77
+) or exit 1;
  78
+
61 79
 
62 80
 # internals
63 81
 my $ypad1 = $fontsize * 4;	# pad top, include title
@@ -203,7 +221,7 @@ sub flow {
203 221
 <![CDATA[
204 222
 	var details;
205 223
 	function init(evt) { details = document.getElementById("details").firstChild; }
206  
-	function s(info) { details.nodeValue = info; }
  224
+	function s(info) { details.nodeValue = "$nametype " + info; }
207 225
 	function c() { details.nodeValue = ' '; }
208 226
 ]]>
209 227
 </script>
@@ -216,16 +234,14 @@ sub flow {
216 234
 	$im->colorAllocate(40, 40, 40),
217 235
 	$im->colorAllocate(160, 160, 160),
218 236
     );
219  
-$im->stringTTF($black, $fonttype, $fontsize + 5, 0.0, int($imagewidth / 2), $fontsize * 2, "Flame Graph", "middle");
220  
-$im->stringTTF($black, $fonttype, $fontsize, 0.0, $xpad, $imageheight - ($ypad2 / 2), 'Function:');
221  
-$im->stringTTF($black, $fonttype, $fontsize, 0.0, $xpad + 60, $imageheight - ($ypad2 / 2), " ", "", 'id="details"');
  237
+$im->stringTTF($black, $fonttype, $fontsize + 5, 0.0, int($imagewidth / 2), $fontsize * 2, $titletext, "middle");
  238
+$im->stringTTF($black, $fonttype, $fontsize, 0.0, $xpad, $imageheight - ($ypad2 / 2), " ", "", 'id="details"');
222 239
 
223 240
 # Draw frames
224 241
 foreach my $id (keys %Node) {
225 242
 	my ($func, $depth, $etime) = split "--", $id;
226 243
 	die "missing start for $id" if !defined $Node{$id}->{stime};
227 244
 	my $stime = $Node{$id}->{stime};
228  
-	my $samples = $etime - $stime;
229 245
 
230 246
 	my $x1 = $xpad + $stime * $widthpertime;
231 247
 	my $x2 = $xpad + $etime * $widthpertime;
@@ -235,16 +251,20 @@ sub flow {
235 251
 	my $y1 = $imageheight - $ypad2 - ($depth + 1) * $frameheight + 1;
236 252
 	my $y2 = $imageheight - $ypad2 - $depth * $frameheight;
237 253
 
  254
+	my $samples = $etime - $stime;
  255
+        (my $samples_txt = $samples) # add commas per perlfaq5
  256
+            =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
  257
+
238 258
 	my $info;
239 259
 	if ($func eq "" and $depth == 0) {
240  
-		$info = "all samples ($samples samples, 100%)";
  260
+		$info = "all ($samples_txt $countname, 100%)";
241 261
 	} else {
242 262
 		my $pct = sprintf "%.2f", ((100 * $samples) / $timemax);
243 263
 		my $escaped_func = $func;
244 264
 		$escaped_func =~ s/&/&amp;/g;
245 265
 		$escaped_func =~ s/</&lt;/g;
246 266
 		$escaped_func =~ s/>/&gt;/g;
247  
-		$info = "$escaped_func ($samples samples, $pct%)";
  267
+		$info = "$escaped_func ($samples_txt $countname, $pct%)";
248 268
 	}
249 269
 	$im->filledRectangle($x1, $y1, $x2, $y2, color("hot"), 'rx="2" ry="2" onmouseover="s(' . "'$info'" . ')" onmouseout="c()"');
250 270
 

0 notes on commit e0fbd11

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