diff --git a/pkgs/os-specific/linux/kernel/perf/default.nix b/pkgs/os-specific/linux/kernel/perf/default.nix index 969d1e2bb65..e3a387b8115 100644 --- a/pkgs/os-specific/linux/kernel/perf/default.nix +++ b/pkgs/os-specific/linux/kernel/perf/default.nix @@ -1,11 +1,58 @@ -{ lib, stdenv, fetchpatch, kernel, elfutils, python2, python3, python3Packages, 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 +{ lib +, stdenv +, fetchpatch +, fetchurl +, kernel +, elfutils +, python2 +, python3 +, python3Packages +, 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 , zlib -, withGtk ? false, gtk2 -, withZstd ? true, zstd -, withLibcap ? true, libcap +, withGtk ? false +, gtk2 +, withZstd ? true +, zstd +, withLibcap ? true +, libcap }: +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 stdenv.mkDerivation { pname = "perf-linux"; @@ -20,6 +67,14 @@ stdenv.mkDerivation { ./5.19-binutils-2.39-support.patch ]; + postPatch = '' + patchShebangs scripts tools/perf/pmu-events/jevents.py + + substituteInPlace tools/perf/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" + ''; + preConfigure = '' cd tools/perf @@ -35,26 +90,45 @@ stdenv.mkDerivation { fi ''; - makeFlags = ["prefix=$(out)" "WERROR=0"] ++ kernel.makeFlags; + makeFlags = [ "prefix=$(out)" "WERROR=0" ] ++ kernel.makeFlags; hardeningDisable = [ "format" ]; # perf refers both to newt and slang nativeBuildInputs = [ - asciidoc xmlto docbook_xsl docbook_xml_dtd_45 libxslt - flex bison libiberty audit makeWrapper pkg-config python3 + asciidoc + xmlto + docbook_xsl + docbook_xml_dtd_45 + libxslt + flex + bison + libiberty + audit + makeWrapper + pkg-config + python3 ]; + buildInputs = [ - elfutils newt slang libunwind zlib openssl systemtap.stapBuild numactl - python3 perl + elfutils + newt + slang + libunwind + zlib + openssl + systemtap.stapBuild + numactl + python3 + perl ] ++ (if (lib.versionAtLeast kernel.version "5.19") - then [ libbfd libopcodes ] - else [ libbfd_2_38 libopcodes_2_38 ]) - ++ lib.optional withGtk gtk2 - ++ (if (lib.versionAtLeast kernel.version "4.19") then [ python3 ] else [ python2 ]) - ++ lib.optional withZstd zstd - ++ lib.optional withLibcap libcap - ++ lib.optional (lib.versionAtLeast kernel.version "6.0") python3Packages.setuptools; + then [ libbfd libopcodes ] + else [ libbfd_2_38 libopcodes_2_38 ]) + ++ lib.optional withGtk gtk2 + ++ (if (lib.versionAtLeast kernel.version "4.19") then [ python3 ] else [ python2 ]) + ++ lib.optional withZstd zstd + ++ lib.optional withLibcap libcap + ++ lib.optional (lib.versionAtLeast kernel.version "6.0") python3Packages.setuptools; NIX_CFLAGS_COMPILE = toString [ "-Wno-error=cpp" @@ -63,10 +137,6 @@ stdenv.mkDerivation { "-Wno-error=stringop-truncation" ]; - postPatch = '' - patchShebangs scripts tools/perf/pmu-events/jevents.py - ''; - doCheck = false; # requires "sparse" doInstallCheck = false; # same