brendangregg / FlameGraph

Stack trace visualizer
http://www.brendangregg.com/flamegraphs.html
17.38k stars 1.97k forks source link

Supporting real number for samples data #324

Open Bojun-Seo opened 11 months ago

Bojun-Seo commented 11 months ago

FlameGraph shows the number of samples in specific backtrace. Since it is the "number" of samples, it is an integer. But it can be expanded to real number. So I suggest to support real number for samples data. For example, think about the data like followings,

foo;bar;baz 0.156
foo;foo;bar;baz 0.98
foo;foo;foo;bar;baz 0.343
foo;foo;foo;foo;bar;baz 0.888

Every number of samples in flamegraph output svg file is 0 with the data.

I can see five decimal places of data if I change the code like followings.

$ git diff
diff --git a/flamegraph.pl b/flamegraph.pl
index 8c917ec..5855196 100755
--- a/flamegraph.pl
+++ b/flamegraph.pl
@@ -1233,7 +1233,7 @@ while (my ($id, $node) = each %Node) {

        # Add commas per perlfaq5:
        # https://perldoc.perl.org/perlfaq5#How-can-I-output-my-numbers-with-commas-added?
-       my $samples = sprintf "%.0f", ($etime - $stime) * $factor;
+       my $samples = sprintf "%.5f", ($etime - $stime) * $factor;
        (my $samples_txt = $samples)
                =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;