Skip to content

Commit

Permalink
minwidth now accepts a percentage of time with %
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-olson-intel committed Oct 18, 2023
1 parent d9fcc27 commit b8989aa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ USAGE: ./flamegraph.pl [options] infile > outfile.svg
--subtitle TEXT # second level title (optional)
--width NUM # width of image (default 1200)
--height NUM # height of each frame (default 16)
--minwidth NUM # omit smaller functions (default 0.1 pixels)
--minwidth NUM # omit smaller functions. In pixels or use "%" for
# percentage of time (default 0.1 pixels)
--fonttype FONT # font type (default "Verdana")
--fontsize NUM # font size (default 12)
--countname TEXT # count type label (default "samples")
Expand Down
26 changes: 22 additions & 4 deletions flamegraph.pl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
my $frameheight = 16; # max height is dynamic
my $fontsize = 12; # base text size
my $fontwidth = 0.59; # avg width relative to fontsize
my $minwidth = 0.1; # min function width, pixels
my $minwidth = 0.1; # min function width, pixels or percentage of time
my $nametype = "Function:"; # what are the names in the data?
my $countname = "samples"; # what are the counts in the data?
my $colors = "hot"; # color theme
Expand Down Expand Up @@ -134,7 +134,8 @@ sub usage {
--subtitle TEXT # second level title (optional)
--width NUM # width of image (default 1200)
--height NUM # height of each frame (default 16)
--minwidth NUM # omit smaller functions (default 0.1 pixels)
--minwidth NUM # omit smaller functions. In pixels or use "%" for
# percentage of time (default 0.1 pixels)
--fonttype FONT # font type (default "Verdana")
--fontsize NUM # font size (default 12)
--countname TEXT # count type label (default "samples")
Expand Down Expand Up @@ -165,7 +166,7 @@ sub usage {
'encoding=s' => \$encoding,
'fontsize=f' => \$fontsize,
'fontwidth=f' => \$fontwidth,
'minwidth=f' => \$minwidth,
'minwidth=s' => \$minwidth,
'title=s' => \$titletext,
'subtitle=s' => \$subtitletext,
'nametype=s' => \$nametype,
Expand Down Expand Up @@ -224,6 +225,16 @@ sub usage {
die "Notes string can't contain < or >"
}

# Ensure minwidth is a valid floating-point number,
# print usage string if not
my $minwidth_f;
if ($minwidth =~ /^([0-9.]+)%?$/) {
$minwidth_f = $1;
} else {
warn "Value '$minwidth' is invalid for minwidth, expected a float.\n";
usage();
}

# background colors:
# - yellow gradient: default (hot, java, js, perl)
# - green gradient: mem
Expand Down Expand Up @@ -703,7 +714,14 @@ sub flow {
$timemax ||= $time;

my $widthpertime = ($imagewidth - 2 * $xpad) / $timemax;
my $minwidth_time = $minwidth / $widthpertime;

# Treat as a percentage of time if the string ends in a "%".
my $minwidth_time;
if ($minwidth =~ /%$/) {
$minwidth_time = $timemax * $minwidth_f / 100;
} else {
$minwidth_time = $minwidth_f / $widthpertime;
}

# prune blocks that are too narrow and determine max depth
while (my ($id, $node) = each %Node) {
Expand Down

0 comments on commit b8989aa

Please sign in to comment.