Skip to content
This repository

Add --factor option to scale the presented values. #18

Merged
merged 2 commits into from over 1 year ago

2 participants

Tim Bunce Brendan Gregg
Tim Bunce

The flamegraph processing requires the addition of many values.
Using floating-point values causes cumulative errors. These are
most noticable when --total is used because otherwise the graph
self-scales to the width.

This patch adds a --factor option that scales the presented values.
So instead of providing floating point values in the data, the data can
be provided as integers and the result scaled to suit using --factor.

p.s The problem with floats in severe enough that I'd recommend removing
support for them. Just change the regex back to \d+.

timbunce added some commits
Tim Bunce timbunce Add --factor option to scale the presented values.
The flamegraph processing requires the addition of many values.
Using floating-point values causes cumulative errors. These are
most noticable when --total is used because otherwise the graph
self-scales to the width.

This patch adds a --factor option that scales the presented values.
So instead of providing floating point values in the data, the data can
be provided as integers and the result scaled to suit using --factor.

p.s The problem with floats in severe enough that I'd recommend removing
support for them. Just change the regex back to \d+.
cfad672
Tim Bunce timbunce Only warn about --total being smaller if it's significantly so (e.g.,…
… not rounding etc)
489672a
Brendan Gregg brendangregg merged commit 4952f87 into from
Brendan Gregg
Owner

Thanks; yes, we can drop floating point if it is a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Mar 30, 2013
Tim Bunce timbunce Add --factor option to scale the presented values.
The flamegraph processing requires the addition of many values.
Using floating-point values causes cumulative errors. These are
most noticable when --total is used because otherwise the graph
self-scales to the width.

This patch adds a --factor option that scales the presented values.
So instead of providing floating point values in the data, the data can
be provided as integers and the result scaled to suit using --factor.

p.s The problem with floats in severe enough that I'd recommend removing
support for them. Just change the regex back to \d+.
cfad672
Mar 31, 2013
Tim Bunce timbunce Only warn about --total being smaller if it's significantly so (e.g.,…
… not rounding etc)
489672a
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 5 additions and 2 deletions. Show diff stats Hide diff stats

  1. +5 2 flamegraph.pl
7 flamegraph.pl
@@ -66,6 +66,7 @@
66 66 my $countname = "samples"; # what are the counts in the data?
67 67 my $nameattrfile; # file holding function attributes
68 68 my $timemax; # (override the) sum of the counts
  69 +my $factor = 1; # factor to scale counts by
69 70
70 71 GetOptions(
71 72 'fonttype=s' => \$fonttype,
@@ -78,6 +79,7 @@
78 79 'countname=s' => \$countname,
79 80 'nameattr=s' => \$nameattrfile,
80 81 'total=s' => \$timemax,
  82 + 'factor=f' => \$factor,
81 83 ) or exit 1;
82 84
83 85
@@ -247,7 +249,8 @@ sub flow {
247 249 die "ERROR: No stack counts found\n" unless $time;
248 250
249 251 if ($timemax and $timemax < $time) {
250   - warn "Specified --total $timemax is less than actual total $time, so ignored\n";
  252 + warn "Specified --total $timemax is less than actual total $time, so ignored\n"
  253 + if $timemax/$time > 0.02; # only warn is significant (e.g., not rounding etc)
251 254 undef $timemax;
252 255 }
253 256 $timemax ||= $time;
@@ -303,7 +306,7 @@ sub flow {
303 306 my $y1 = $imageheight - $ypad2 - ($depth + 1) * $frameheight + 1;
304 307 my $y2 = $imageheight - $ypad2 - $depth * $frameheight;
305 308
306   - my $samples = sprintf "%.0f", $etime - $stime;
  309 + my $samples = sprintf "%.0f", ($etime - $stime) * $factor;
307 310 (my $samples_txt = $samples) # add commas per perlfaq5
308 311 =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
309 312

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.