2022-11-21 17:40:18 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchpatch
|
|
|
|
, fetchurl
|
|
|
|
, kernel
|
|
|
|
, elfutils
|
|
|
|
, python3
|
|
|
|
, perl
|
|
|
|
, newt
|
|
|
|
, slang
|
|
|
|
, asciidoc
|
|
|
|
, xmlto
|
|
|
|
, makeWrapper
|
|
|
|
, docbook_xsl
|
|
|
|
, docbook_xml_dtd_45
|
|
|
|
, libxslt
|
|
|
|
, flex
|
|
|
|
, bison
|
|
|
|
, pkg-config
|
|
|
|
, libunwind
|
|
|
|
, binutils-unwrapped
|
|
|
|
, libiberty
|
|
|
|
, audit
|
|
|
|
, libbfd
|
|
|
|
, libbfd_2_38
|
|
|
|
, libopcodes
|
|
|
|
, libopcodes_2_38
|
|
|
|
, openssl
|
|
|
|
, systemtap
|
|
|
|
, numactl
|
2021-07-04 02:40:35 +00:00
|
|
|
, zlib
|
2022-11-21 17:40:18 +00:00
|
|
|
, babeltrace
|
|
|
|
, withGtk ? false
|
|
|
|
, gtk2
|
|
|
|
, withZstd ? true
|
|
|
|
, zstd
|
|
|
|
, withLibcap ? true
|
|
|
|
, libcap
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
2022-11-21 17:40:18 +00:00
|
|
|
let
|
|
|
|
d3-flame-graph-templates = stdenv.mkDerivation rec {
|
|
|
|
pname = "d3-flame-graph-templates";
|
|
|
|
version = "4.1.3";
|
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "https://registry.npmjs.org/d3-flame-graph/-/d3-flame-graph-${version}.tgz";
|
|
|
|
sha256 = "sha256-W5/Vh5jarXUV224aIiTB2TnBFYT3naEIcG2945QjY8Q=";
|
|
|
|
};
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
install -D -m 0755 -t $out/share/d3-flame-graph/ ./dist/templates/*
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
2022-01-19 23:45:15 +00:00
|
|
|
pname = "perf-linux";
|
|
|
|
version = kernel.version;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
inherit (kernel) src;
|
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
postPatch = ''
|
|
|
|
# Linux scripts
|
|
|
|
patchShebangs scripts
|
2022-08-21 13:32:41 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
cd tools/perf
|
|
|
|
|
|
|
|
for x in util/build-id.c util/dso.c; do
|
|
|
|
substituteInPlace $x --replace /usr/lib/debug /run/current-system/sw/lib/debug
|
|
|
|
done
|
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
'' + lib.optionalString (lib.versionAtLeast kernel.version "5.8") ''
|
|
|
|
substituteInPlace scripts/python/flamegraph.py \
|
|
|
|
--replace "/usr/share/d3-flame-graph/d3-flamegraph-base.html" \
|
|
|
|
"${d3-flame-graph-templates}/share/d3-flame-graph/d3-flamegraph-base.html"
|
|
|
|
|
|
|
|
'' + lib.optionalString (lib.versionAtLeast kernel.version "6.0") ''
|
|
|
|
patchShebangs pmu-events/jevents.py
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
makeFlags = [ "prefix=$(out)" "WERROR=0" ] ++ kernel.makeFlags;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
hardeningDisable = [ "format" ];
|
|
|
|
|
|
|
|
# perf refers both to newt and slang
|
|
|
|
nativeBuildInputs = [
|
2022-11-21 17:40:18 +00:00
|
|
|
asciidoc
|
|
|
|
xmlto
|
|
|
|
docbook_xsl
|
|
|
|
docbook_xml_dtd_45
|
|
|
|
libxslt
|
|
|
|
flex
|
|
|
|
bison
|
|
|
|
libiberty
|
|
|
|
audit
|
|
|
|
makeWrapper
|
|
|
|
pkg-config
|
|
|
|
python3
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
2022-11-21 17:40:18 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
buildInputs = [
|
2022-11-21 17:40:18 +00:00
|
|
|
elfutils
|
|
|
|
newt
|
|
|
|
slang
|
|
|
|
libunwind
|
|
|
|
zlib
|
|
|
|
openssl
|
|
|
|
systemtap.stapBuild
|
|
|
|
numactl
|
|
|
|
python3
|
|
|
|
perl
|
|
|
|
babeltrace
|
2022-09-09 14:08:57 +00:00
|
|
|
] ++ (if (lib.versionAtLeast kernel.version "5.19")
|
2022-11-21 17:40:18 +00:00
|
|
|
then [ libbfd libopcodes ]
|
|
|
|
else [ libbfd_2_38 libopcodes_2_38 ])
|
|
|
|
++ lib.optional withGtk gtk2
|
|
|
|
++ lib.optional withZstd zstd
|
|
|
|
++ lib.optional withLibcap libcap
|
|
|
|
++ lib.optional (lib.versionAtLeast kernel.version "6.0") python3.pkgs.setuptools;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
NIX_CFLAGS_COMPILE = toString [
|
|
|
|
"-Wno-error=cpp"
|
|
|
|
"-Wno-error=bool-compare"
|
|
|
|
"-Wno-error=deprecated-declarations"
|
|
|
|
"-Wno-error=stringop-truncation"
|
|
|
|
];
|
|
|
|
|
|
|
|
doCheck = false; # requires "sparse"
|
|
|
|
|
|
|
|
installFlags = [ "install" "install-man" "ASCIIDOC8=1" "prefix=$(out)" ];
|
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
# TODO: Add completions based on perf-completion.sh
|
|
|
|
postInstall = ''
|
2022-11-04 12:27:35 +00:00
|
|
|
# Same as perf. Remove.
|
|
|
|
rm -f $out/bin/trace
|
|
|
|
'';
|
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
separateDebugInfo = true;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
preFixup = ''
|
2022-10-30 15:09:59 +00:00
|
|
|
# Pull in 'objdump' into PATH to make annotations work.
|
|
|
|
# The embeded Python interpreter will search PATH to calculate the Python path configuration(Should be fixed by upstream).
|
|
|
|
# Add python.interpreter to PATH for now.
|
2020-04-24 23:36:52 +00:00
|
|
|
wrapProgram $out/bin/perf \
|
2022-11-21 17:40:18 +00:00
|
|
|
--prefix PATH : ${lib.makeBinPath [ binutils-unwrapped python3 ]}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
homepage = "https://perf.wiki.kernel.org/";
|
|
|
|
description = "Linux tools to profile with performance counters";
|
2022-08-21 13:32:41 +00:00
|
|
|
maintainers = with maintainers; [ viric ];
|
|
|
|
platforms = platforms.linux;
|
2021-05-28 09:39:13 +00:00
|
|
|
broken = kernel.kernelOlder "5";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|