File perf.spec of Package perf.27729

#
# spec file for package perf
#
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           perf
%define version %(rpm -q --qf '%{VERSION}' kernel-source)
Version:        %{version}
Release:        0
Summary:        Performance Monitoring Tools for Linux
License:        GPL-2.0-only
Group:          Development/Tools/Debuggers
Url:            https://perf.wiki.kernel.org/
BuildRequires:  asciidoc
BuildRequires:  audit-devel
BuildRequires:  binutils-devel
BuildRequires:  bison
BuildRequires:  fdupes
BuildRequires:  flex
BuildRequires:  gtk2-devel
BuildRequires:  kernel-source >= 2.6.31
BuildRequires:  libdw-devel
BuildRequires:  libelf-devel
BuildRequires:  OpenCSD-devel
BuildRequires:  python3-devel
BuildRequires:  xz-devel
%ifarch aarch64 ia64 x86_64 ppc64 ppc64le ppc %sparc
BuildRequires:  libnuma-devel
%endif
%ifarch s390x s390
%define         _perf_unwind NO_LIBUNWIND=1
%else
%define         _perf_unwind %{nil}
BuildRequires:  libunwind-devel
%endif
BuildRequires:  newt-devel
BuildRequires:  openssl-devel
BuildRequires:  xmlto
BuildRequires:  zlib-devel
# dl_open requirement so not autodetected
%ifarch ppc64 ppc64le
Requires:       libebl
%endif
%{perl_requires}
%{?libperl_requires}
# upstream patches
Patch1:         perf-tools-Remove-repipe-argument-from-perf_session__new.patch
Patch2:         perf-tools-Pass-a-fd-to-perf_file_header__read_pipe.patch
Patch3:         perf-inject-Fix-output-from-a-pipe-to-a-file.patch
Patch4:         perf-inject-Fix-output-from-a-file-to-a-pipe.patch
Patch5:         perf-env-Track-kernel-64-bit-mode-in-environment.patch
Patch6:         perf-env-Add-perf_env__cpuid-perf_env__-nr_-pmu_mappings.patch
Patch7:         perf-report-Add-tools-arch-x86-include-asm-amd-ibs.h.patch
Patch8:         perf-report-Add-support-to-print-a-textual-representation-of-IBS-raw-sample-data.patch
Patch9:         perf-tools-Add-an-option-to-build-without-libbfd.patch
Patch10:        perf-tests-attr-Add-missing-topdown-metrics-events.patch
Patch11:        perf-evsel-don-t-set-exclude_guest-by-default.patch
Patch12:        perf-bpf-Avoid-memory-leak-from-perf_env__insert_btf.patch
Patch13:        perf-tests-Remove-bash-construct-from-record-zstd_comp_decomp.sh.patch
Patch14:        perf-bench-Fix-two-memory-leaks-detected-with-ASan.patch
Patch15:        perf-tools-Fix-SMT-detection-fast-read-path.patch
Patch16:        tools-build-Remove-needless-libpython-version-feature-check-that-breaks-test-all-fast-path.patch
Patch17:        perf-bpf-Fix-building-perf-with-BUILD_BPF_SKEL-1-by-default-in-more-distros.patch
Patch18:        perf-bpf_skel-Do-not-use-typedef-to-avoid-error-on-old-clang.patch
Patch19:        perf-intel-pt-Fix-some-PGE-packet-generation-enable-control-flow-packets-usage.patch
Patch20:        perf-intel-pt-Fix-sync-state-when-a-PSB-synchronization-packet-is-found.patch
Patch21:        perf-intel-pt-Fix-intel_pt_fup_event-assumptions-about-setting-state-type.patch
Patch22:        perf-intel-pt-Fix-state-setting-when-receiving-overflow-OVF-packet.patch
Patch23:        perf-intel-pt-Fix-next-err-value-walking-trace.patch
Patch24:        perf-intel-pt-Fix-missing-instruction-events-with-q-option.patch
Patch25:        perf-intel-pt-Fix-error-timestamp-setting-on-the-decoder-error-path.patch
Patch26:        perf-inject-Fix-segfault-due-to-close-without-open.patch
Patch27:        perf-inject-Fix-segfault-due-to-perf_data__fd-without-open.patch
Patch28:        perf-intel-pt-Fix-parsing-of-VM-time-correlation-arguments.patch
Patch29:        perf-script-Fix-CPU-filtering-of-a-script-s-switch-events.patch
Patch30:        perf-scripts-python-intel-pt-events.py-Fix-printing-of-switch-events.patch
Patch31:        perf-script-Fix-hex-dump-character-output.patch
Patch32:        perf-evsel-Improve-error-message-for-uncore-events.patch
Patch33:        perf-probe-Fix-ppc64-perf-probe-add-events-failed-case.patch
Patch34:        perf-evsel-Override-attr-sample_period-for-non-libpfm4-events.patch
Patch35:        perf-stat-Fix-display-of-grouped-aliased-events.patch
Patch36:        perf-bpf-Defer-freeing-string-after-possible-strlen-on-it.patch
Patch37:        perf-data-Fix-double-free-in-perf_session__delete.patch
Patch38:        perf-symbols-Fix-symbol-size-calculation-condition.patch
Patch39:        perf-evsel-Make-evsel__env-always-return-a-valid-env.patch
Patch40:        perf-stat-Fix-forked-applications-enablement-of-counters.patch
Patch41:        perf-python-Add-perf_env-stubs-that-will-be-needed-in-evsel__open_strerror.patch
Patch42:        perf-evsel-Improve-AMD-IBS-Instruction-Based-Sampling-error-handling-messages.patch
Patch43:        perf-arm-spe-Fix-perf-report-mem-mode.patch
Patch44:        perf-tools-Fix-perf-s-libperf_print-callback.patch
Patch45:        perf-session-Remap-buf-if-there-is-no-space-for-event.patch
Patch46:        perf-tools-Fix-misleading-add-event-PMU-debug-message.patch
Patch47:        perf-bench-Fix-numa-testcase-to-check-if-CPU-used-to-bind-task-is-online.patch
Patch48:        perf-bench-Fix-numa-bench-to-fix-usage-of-affinity-for-machines-with-CPUs-1K.patch
Patch49:        perf-script-Always-allow-field-data_src-for-auxtrace.patch
Patch50:        perf-report-Set-PERF_SAMPLE_DATA_SRC-bit-for-Arm-SPE-event.patch
Patch51:        perf-arm-spe-Fix-addresses-of-synthesized-SPE-events.patch
Patch52:        perf-evlist-Keep-topdown-counters-in-weak-group.patch
Patch53:        perf-header-Add-ability-to-keep-feature-sections.patch
Patch54:        libperf-Add-preadn.patch
Patch55:        perf-inject-Keep-some-features-sections-from-input-file.patch
Patch56:        perf-evlist-Extend-arch_evsel__must_be_in_group-to-support-hybrid-systems.patch
Patch57:        perf-record-ibs-Warn-about-sampling-period-skew.patch
Patch58:        perf-pmu-Parse-pmu-caps-sysfs-only-once.patch
Patch59:        perf-header-Pass-cpu-pmu-name-while-printing-caps.patch
Patch60:        perf-header-Store-PMU-caps-in-an-array-of-strings.patch
Patch61:        perf-header-Record-non-CPU-PMU-capabilities.patch
Patch62:        perf-tool-ibs-Sync-AMD-IBS-header-file.patch
Patch63:        perf-script-ibs-Support-new-IBS-bits-in-raw-trace-dump.patch
Patch64:        tools-build-Add-feature-test-for-init_disassemble_info-API-changes.patch
Patch65:        tools-build-Don-t-display-disassembler-four-args-feature-test.patch
Patch66:        tools-include-add-dis-asm-compat.h-to-handle-version-differences.patch
Patch67:        tools-perf-Fix-compilation-error-with-new-binutils.patch
# non upstream patches

Requires:       kernel >= 2.6.31
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
This package provides a userspace tool 'perf', which monitors performance for
either unmodified binaries or the entire system. It requires a Linux kernel
which includes the Performance Counters for Linux (PCL) subsystem (>= 2.6.31).
This subsystem utilizes the Performance Monitoring Unit (PMU) / hardware
counters of the underlying cpu architecture (if supported).

%package devel
Summary:        Development headers for perf
Group:          Development/Libraries/Other
Requires:       %{name} = %{version}

%description devel
Development headers for perf. 

%prep
# copy necessary files from kernel-source since we need to modify them
(cd /usr/src/linux ; tar -cf - COPYING CREDITS README tools include scripts Kbuild Makefile arch/*/{include,lib,Makefile} lib) | tar -xf - 
chmod +x tools/perf/util/generate-cmdlist.sh

%autopatch -p1

# don't error out on deprecated definitions in gtk2.h
sed -i 's@ignored "-Wstrict-prototypes"@&\n#pragma GCC diagnostic ignored "-Wdeprecated-declarations"@' tools/build/feature/test-gtk2.c

%build
cd tools/perf
export WERROR=0
# PASS rpm optflags as EXTRA_FLAGS,  passing as CFLAGS overrides and breaks build
make %{?_smp_mflags} -f Makefile.perf feature-libbfd-liberty=1 feature-disassembler-four-args=1 V=1 VF=1 GTK2=1 CORESIGHT=1 PYTHON=python3 EXTRA_CFLAGS="%{optflags}" ASCIIDOC8=1 prefix=/usr libdir=%{_libdir} perfexecdir=lib/%{name}-core %{_perf_unwind} tipdir=share/doc/packages/perf all
make %{?_smp_mflags} -f Makefile.perf V=1 VF=1 GTK2=1 CORESIGHT=1 PYTHON=python3 EXTRA_CFLAGS="%{optflags}" ASCIIDOC8=1 prefix=/usr libdir=%{_libdir} perfexecdir=lib/%{name}-core %{_perf_unwind} tipdir=share/doc/packages/perf doc

%install
cd tools/perf
export WERROR=0
make -f Makefile.perf GTK2=1 CORESIGHT=1 PYTHON=python3 EXTRA_CFLAGS="%{optflags}" prefix=/usr libdir=%{_libdir} perfexecdir=lib/%{name}-core DESTDIR=%{buildroot} %{_perf_unwind} tipdir=share/doc/packages/perf install
make -f Makefile.perf GTK2=1 CORESIGHT=1 PYTHON=python3 EXTRA_CFLAGS="%{optflags}" prefix=/usr libdir=%{_libdir} perfexecdir=lib/%{name}-core DESTDIR=%{buildroot} install %{_perf_unwind} tipdir=share/doc/packages/perf install-doc
mkdir -p %{buildroot}/%{_docdir}/perf/examples/bpf
mv %{buildroot}/usr/lib/perf/examples/bpf/* %{buildroot}/%{_docdir}/perf/examples/bpf

%fdupes %{buildroot}/%{_prefix}/lib/%{name}-core

%files
%defattr(-, root, root)
%attr(0644, root, root) %doc COPYING CREDITS README tools/perf/design.txt
%attr(0644, root, root) %doc %{_docdir}/perf/tips.txt
%{_bindir}/perf
%{_bindir}/trace
%{_libdir}/libperf-gtk.so
%ifnarch armv7l
%dir %{_libdir}/traceevent
%dir %{_libdir}/traceevent/plugins
%{_libdir}/traceevent/plugins/plugin_*.so
%endif
%attr(0644, -, -) %{_sysconfdir}/bash_completion.d/perf
%{_libexecdir}/%{name}-core
%{_datarootdir}/%{name}-core
%{_mandir}/man1/perf*
%dir /usr/lib/perf

%files devel
%dir %{_includedir}/perf/
%attr(0644, root, root) %{_includedir}/perf/*.h
%dir /usr/lib/perf/include
%dir /usr/lib/perf/include/bpf
%attr(0644, root, root) /usr/lib/perf/include/bpf/*.h
%dir /usr/lib/perf/include/bpf/linux
%attr(0644, root, root) /usr/lib/perf/include/bpf/linux/*.h
%dir %{_docdir}/perf/examples
%dir %{_docdir}/perf/examples/bpf
%attr(0644, root, root) %{_docdir}/perf/examples/bpf/*

%changelog
openSUSE Build Service is sponsored by