Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib
2, stdenv
3, fetchpatch
4, fetchurl
5, kernel
6, elfutils
7, python3
8, perl
9, newt
10, slang
11, asciidoc
12, xmlto
13, makeWrapper
14, docbook_xsl
15, docbook_xml_dtd_45
16, libxslt
17, flex
18, bison
19, pkg-config
20, libunwind
21, binutils-unwrapped
22, libiberty
23, audit
24, libbfd
25, libbfd_2_38
26, libopcodes
27, libopcodes_2_38
28, openssl
29, systemtap
30, numactl
31, zlib
32, babeltrace
33, withGtk ? false
34, gtk2
35, withZstd ? true
36, zstd
37, withLibcap ? true
38, libcap
39}:
40let
41 d3-flame-graph-templates = stdenv.mkDerivation rec {
42 pname = "d3-flame-graph-templates";
43 version = "4.1.3";
44
45 src = fetchurl {
46 url = "https://registry.npmjs.org/d3-flame-graph/-/d3-flame-graph-${version}.tgz";
47 sha256 = "sha256-W5/Vh5jarXUV224aIiTB2TnBFYT3naEIcG2945QjY8Q=";
48 };
49
50 installPhase = ''
51 install -D -m 0755 -t $out/share/d3-flame-graph/ ./dist/templates/*
52 '';
53 };
54in
55
56stdenv.mkDerivation {
57 pname = "perf-linux";
58 version = kernel.version;
59
60 inherit (kernel) src;
61
62 postPatch = ''
63 # Linux scripts
64 patchShebangs scripts
65
66 cd tools/perf
67
68 for x in util/build-id.c util/dso.c; do
69 substituteInPlace $x --replace /usr/lib/debug /run/current-system/sw/lib/debug
70 done
71
72 '' + lib.optionalString (lib.versionAtLeast kernel.version "5.8") ''
73 substituteInPlace scripts/python/flamegraph.py \
74 --replace "/usr/share/d3-flame-graph/d3-flamegraph-base.html" \
75 "${d3-flame-graph-templates}/share/d3-flame-graph/d3-flamegraph-base.html"
76
77 '' + lib.optionalString (lib.versionAtLeast kernel.version "6.0") ''
78 patchShebangs pmu-events/jevents.py
79 '';
80
81 makeFlags = [ "prefix=$(out)" "WERROR=0" "ASCIIDOC8=1" ] ++ kernel.makeFlags
82 ++ lib.optional (!withGtk) "NO_GTK2=1"
83 ++ lib.optional (!withZstd) "NO_LIBZSTD=1"
84 ++ lib.optional (!withLibcap) "NO_LIBCAP=1";
85
86 hardeningDisable = [ "format" ];
87
88 # perf refers both to newt and slang
89 nativeBuildInputs = [
90 asciidoc
91 xmlto
92 docbook_xsl
93 docbook_xml_dtd_45
94 libxslt
95 flex
96 bison
97 libiberty
98 audit
99 makeWrapper
100 pkg-config
101 python3
102 ];
103
104 buildInputs = [
105 elfutils
106 newt
107 slang
108 libunwind
109 zlib
110 openssl
111 systemtap.stapBuild
112 numactl
113 python3
114 perl
115 babeltrace
116 ] ++ (if (lib.versionAtLeast kernel.version "5.19")
117 then [ libbfd libopcodes ]
118 else [ libbfd_2_38 libopcodes_2_38 ])
119 ++ lib.optional withGtk gtk2
120 ++ lib.optional withZstd zstd
121 ++ lib.optional withLibcap libcap
122 ++ lib.optional (lib.versionAtLeast kernel.version "6.0") python3.pkgs.setuptools;
123
124 NIX_CFLAGS_COMPILE = toString [
125 "-Wno-error=cpp"
126 "-Wno-error=bool-compare"
127 "-Wno-error=deprecated-declarations"
128 "-Wno-error=stringop-truncation"
129 ];
130
131 doCheck = false; # requires "sparse"
132
133 installTargets = [ "install" "install-man" ];
134
135 # TODO: Add completions based on perf-completion.sh
136 postInstall = ''
137 # Same as perf. Remove.
138 rm -f $out/bin/trace
139 '';
140
141 separateDebugInfo = true;
142
143 preFixup = ''
144 # Pull in 'objdump' into PATH to make annotations work.
145 # The embeded Python interpreter will search PATH to calculate the Python path configuration(Should be fixed by upstream).
146 # Add python.interpreter to PATH for now.
147 wrapProgram $out/bin/perf \
148 --prefix PATH : ${lib.makeBinPath [ binutils-unwrapped python3 ]}
149 '';
150
151 meta = with lib; {
152 homepage = "https://perf.wiki.kernel.org/";
153 description = "Linux tools to profile with performance counters";
154 maintainers = with maintainers; [ viric ];
155 platforms = platforms.linux;
156 broken = kernel.kernelOlder "5";
157 };
158}