!8 minwidth now accepts a percentage of time with %

From: @maskinghk 
Reviewed-by: @chenwei_kernel 
Signed-off-by: @chenwei_kernel
This commit is contained in:
openeuler-ci-bot 2025-04-21 01:37:46 +00:00 committed by Gitee
commit 3a4fcefcf2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 96 additions and 1 deletions

View File

@ -0,0 +1,89 @@
From b8989aab9a0815d44014f993127390200ecd23c7 Mon Sep 17 00:00:00 2001
From: Ben Olson <matthew.olson@intel.com>
Date: Tue, 17 Oct 2023 15:31:51 -0500
Subject: [PATCH] minwidth now accepts a percentage of time with %
---
README.md | 3 ++-
flamegraph.pl | 26 ++++++++++++++++++++++----
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 1aa3ecda..ee1b3eee 100644
--- a/README.md
+++ b/README.md
@@ -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")
diff --git a/flamegraph.pl b/flamegraph.pl
index d2172b61..c5a7bc3d 100755
--- a/flamegraph.pl
+++ b/flamegraph.pl
@@ -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
@@ -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")
@@ -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,
@@ -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
@@ -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) {

View File

@ -7,10 +7,13 @@
Name: flamegraph Name: flamegraph
Version: 1.0 Version: 1.0
Summary: Stack trace visualizer Summary: Stack trace visualizer
Release: 1 Release: 2
License: CDDL-1.0 License: CDDL-1.0
URL: http://www.brendangregg.com/flamegraphs.html URL: http://www.brendangregg.com/flamegraphs.html
Source0: https://github.com/brendangregg/FlameGraph/FlameGraph-%{commit}.tar.gz Source0: https://github.com/brendangregg/FlameGraph/FlameGraph-%{commit}.tar.gz
Patch1: 0001-minwidth-now-accepts-a-percentage-of-time-with-%.patch
BuildArch: noarch BuildArch: noarch
BuildRequires: help2man BuildRequires: help2man
BuildRequires: perl-generators BuildRequires: perl-generators
@ -151,5 +154,8 @@ cp -p *.1 %{buildroot}%{_mandir}/man1
%{_mandir}/man1/stackcollapse-xdebug.php.1* %{_mandir}/man1/stackcollapse-xdebug.php.1*
%changelog %changelog
* Fri Apr 18 2025 maxin <maxin@xfusion.com> - 1.0-2
- minwidth now accepts a percentage of time with %
* Sat Aug 20 2022 zhujunhao <zhujunhao11@huawei.com> - 1.0-1 * Sat Aug 20 2022 zhujunhao <zhujunhao11@huawei.com> - 1.0-1
- init package - init package