# Upstream has only made one release, but there have been lots of bug fixes
# since, so we use a git checkout.
%global commit      810687f180f3c4929b5d965f54817a5218c9d89b
%global date        20210830
%global forgeurl    https://github.com/brendangregg/FlameGraph
	
Name:           flamegraph
Version:        1.0
Summary:        Stack trace visualizer
Release:        1
License:        CDDL-1.0
URL:            http://www.brendangregg.com/flamegraphs.html
Source0:        https://github.com/brendangregg/FlameGraph/FlameGraph-%{commit}.tar.gz
BuildArch:      noarch
BuildRequires:  help2man
BuildRequires:  perl-generators
BuildRequires:  perl(Getopt::Long)
BuildRequires:  perl(open)
BuildRequires:  php-cli
	
%description
Flame graphs visualize profiled code.  Stack samples can be captured
using Linux perf_events, FreeBSD pmcstat (hwpmc), DTrace, SystemTap, and
many other profilers.  This package contains only the visualizer script,
flamegraph.pl.
	
%package        demos
Summary:        Demos of graphs produced by flamegraph
	
%description    demos
Demonstration graphs produced by flamegraph.
	
%package        stackcollapse
Summary:        Stack collapsers and support scripts
License:        CDDL-1.0 AND Apache-2.0 AND BSD-2-Clause AND GPL-2.0-or-later
Requires:       %{name} = %{version}-%{release}
	
%description    stackcollapse
A set of scripts that collapse stack traces produced by various tools
for consumption by flamegraph, as well as some miscellaneous support
scripts.
	
%package        stackcollapse-perf
Summary:        Stack collapser for perf output
License:        CDDL-1.0 AND Apache-2.0
Requires:       %{name} = %{version}-%{release}
Requires:       binutils
	
%description    stackcollapse-perf
Scripts for collapsing perf output for consumption by flamegraph.
	
%package        stackcollapse-php
Summary:        Stack collapser for PHP
License:        GPL-2.0-or-later
Requires:       %{name} = %{version}-%{release}
	
%description    stackcollapse-php
A script for collapsing PHP trace output for consumption by flamegraph.
 
%prep
%autosetup -n FlameGraph-%{commit}
	
fixtimestamp() {
  touch -r $1.orig $1
  rm -f $1.orig
}
	
# Do not use env
sed -i.orig 's,bin/env ,bin/,' stackcollapse-pmc.pl
fixtimestamp stackcollapse-pmc.pl
	
# Fix end of line encodings
sed -i.orig 's/\r//' stackcollapse-vtune.pl
fixtimestamp stackcollapse-vtune.pl
	
# Add a missing executable bit
chmod a+x stackcollapse-vtune.pl
	
%build
# Build man pages.  Some scripts produce no useful output with --help.
HELP2MANFLAGS="-N --version-string=%{version} --no-discard-stderr"
for fil in aix-perf.pl difffolded.pl files.pl flamegraph.pl range-perf.pl \
           stackcollapse-elfutils.pl stackcollapse-go.pl \
           stackcollapse-java-exceptions.pl stackcollapse-jstack.pl \
           stackcollapse-perf.pl stackcollapse-xdebug.php; do
  help2man $HELP2MANFLAGS ./$fil > $fil.1
done
	
%install
# Install the scripts
mkdir -p %{buildroot}%{_bindir}
cp -p *.{awk,php,pl} jmaps %{buildroot}%{_bindir}
	
# Install the man pages
mkdir -p %{buildroot}%{_mandir}/man1
cp -p *.1 %{buildroot}%{_mandir}/man1
	
%check
./test.sh
	
%files
%doc README.md
%license docs/cddl1.txt
%{_bindir}/flamegraph.pl
%{_mandir}/man1/flamegraph.pl.1*
	
%files          demos
%doc demos/*
	
%files          stackcollapse
%{_bindir}/difffolded.pl
%{_bindir}/files.pl
%{_bindir}/jmaps
%{_bindir}/stackcollapse.pl
%{_bindir}/stackcollapse-aix.pl
%{_bindir}/stackcollapse-bpftrace.pl
%{_bindir}/stackcollapse-elfutils.pl
%{_bindir}/stackcollapse-gdb.pl
%{_bindir}/stackcollapse-go.pl
%{_bindir}/stackcollapse-instruments.pl
%{_bindir}/stackcollapse-java-exceptions.pl
%{_bindir}/stackcollapse-jstack.pl
%{_bindir}/stackcollapse-ljp.awk
%{_bindir}/stackcollapse-pmc.pl
%{_bindir}/stackcollapse-recursive.pl
%{_bindir}/stackcollapse-sample.awk
%{_bindir}/stackcollapse-stap.pl
%{_bindir}/stackcollapse-vsprof.pl
%{_bindir}/stackcollapse-vtune.pl
%{_bindir}/stackcollapse-wcp.pl
%{_mandir}/man1/difffolded.pl.1*
%{_mandir}/man1/files.pl.1*
%{_mandir}/man1/stackcollapse-elfutils.pl.1*
%{_mandir}/man1/stackcollapse-go.pl.1*
%{_mandir}/man1/stackcollapse-java-exceptions.pl.1*
%{_mandir}/man1/stackcollapse-jstack.pl.1*
%{_mandir}/man1/stackcollapse-perf.pl.1*
 
%files          stackcollapse-perf
%{_bindir}/aix-perf.pl
%{_bindir}/pkgsplit-perf.pl
%{_bindir}/range-perf.pl
%{_bindir}/stackcollapse-perf.pl
%{_bindir}/stackcollapse-perf-sched.awk
%{_mandir}/man1/aix-perf.pl.1*
%{_mandir}/man1/range-perf.pl.1*
%{_mandir}/man1/stackcollapse-perf.pl.1*
	
%files          stackcollapse-php
%{_bindir}/stackcollapse-xdebug.php
%{_mandir}/man1/stackcollapse-xdebug.php.1*
	
%changelog
* Sat Aug 20 2022 zhujunhao <zhujunhao11@huawei.com> - 1.0-1
- init package
