@@ -1,143 +0,0 @@
1−{ stdenv, autoreconfHook, coreutils, fetchFromGitHub, fetchpatch, pkgconfig, procps
2−# pyflame needs one python version per ABI
3−# are currently supported
4−# * 2.6 or 2.7 for 2.x ABI
5−# * 3.4 or 3.5 for 3.{4,5} ABI
6−# * 3.6 for 3.6 ABI
7−# * 3.7 for 3.7+ ABI
8−# to disable support for an ABI, make the corresponding argument null
9−, python2, python35, python36, python37, python3
10−}:
11−stdenv.mkDerivation rec {
12− pname = "pyflame";
13− version = "1.6.7";
14− src = fetchFromGitHub {
15− owner = "uber";
16− repo = "pyflame";
17− rev = "v${version}";
18− sha256 = "0hz1ryimh0w8zyxx4y8chcn54d6b02spflj5k9rcg26an2chkg2w";
19− };
20−
21− # Uber's abandoned this since Jun 2018, so we have to patch a lot.
22− # Yay.
23− patches = let
24− # "Add support for Python3.7 (#151)":
25− py37-support = [ # https://github.com/uber/pyflame/pull/153
26− (fetchpatch { # "Add support for python3.7"
27− url = "https://github.com/uber/pyflame/commit/5ee674c4b09a29b82a0e2d7a4ce064fea3df1f4c.patch";
28− sha256 = "19v0yl8frbsq1dkvcmr1zsxf9v75bs8hvlkiv2x8cwylndvz2g5n";
29− })
30− (fetchpatch { # "Add python3.7 to travis test matrix"
31− url = "https://github.com/uber/pyflame/commit/610b5281502ff6d57471e84071f17a33d30f3bcf.patch";
32− sha256 = "13kwzrz0zwmdiirg061wvz7zvdl2w9dnrc81xbkxpm1hh8h0mi9z";
33− })
34− (fetchpatch { # "Update ppa and Ubuntu version"
35− url = "https://github.com/uber/pyflame/commit/ec82a43c90da64815a87d4e3fe2a12ec3c93dc38.patch";
36− sha256 = "1rrcsj5095ns5iyk6ij9kylv8hsrflxjld7b4s5dbpk8jqkf3ndi";
37− })
38− (fetchpatch { # "Clang-Format"
39− url = "https://github.com/uber/pyflame/commit/fb81e40398d6209c38d49d0b6758d9581b3c2bba.patch";
40− sha256 = "024namalrsai8ppl87lqsalfgd2fbqsnbkhpg8q93bvsdxldwc6r";
41− })
42− ];
43−
44− # "Fix pyflame for code compiled with ld -z separate-code":
45− separate-code-support = [ # https://github.com/uber/pyflame/pull/170
46− (fetchpatch { # "Fix for code compiled with ld -z separate-code"
47− url = "https://github.com/uber/pyflame/commit/739a77d9b9abf9599f633d49c9ec98a201bfe058.patch";
48− sha256 = "03xhdysr5s73bw3a7nj2h45dylj9a4c1f1i3xqm1nngpd6arq4y6";
49− })
50− ];
51−
52− # "Improve PtraceSeize error output"
53− full-ptrace-seize-errors = [ # https://github.com/uber/pyflame/pull/152
54− (fetchpatch { # "Print whole error output from PtraceSeize"
55− url = "https://github.com/uber/pyflame/commit/4b0e2c1b442b0f0c6ac5f56471359cea9886aa0f.patch";
56− sha256 = "0nkqs5zszf78cna0bavcdg18g7rdmn72li3091ygpkgxn77cnvis";
57− })
58− (fetchpatch { # "Print whole error for PtraceSeize"
59− url = "https://github.com/uber/pyflame/commit/1abb23abe4912c4a27553f0b3b5c934753f41f6d.patch";
60− sha256 = "07razp9rlq3s92j8a3iak3qk2h4x4xwz4y915h52ivvnxayscj89";
61− })
62− ];
63− in stdenv.lib.concatLists [
64− py37-support
65− # Without this, tests will leak memory and run forever.
66− separate-code-support
67− full-ptrace-seize-errors
68− ];
69−
70− nativeBuildInputs = [ autoreconfHook pkgconfig procps ];
71− buildInputs = [ python37 python36 python2 python35 ];
72−
73− postPatch = ''
74− patchShebangs .
75−
76− # some tests will fail in the sandbox
77− substituteInPlace tests/test_end_to_end.py \
78− --replace 'skipif(IS_DOCKER' 'skipif(True'
79−
80− # don't use patchShebangs here to be explicit about the python version
81− substituteInPlace utils/flame-chart-json \
82− --replace '#!usr/bin/env python' '#!${python3.interpreter}'
83−
84− # Many tests require the build machine to have kernel.yama.ptrace_scope = 0,
85− # but hardened machines have it set to 1. On build machines that cannot run
86− # these tests, skip them to avoid breaking the build.
87− if [[ $(sysctl -n kernel.yama.ptrace_scope || echo 0) != "0" ]]; then
88− for test in \
89− test_monitor \
90− test_non_gil \
91− test_threaded \
92− test_unthreaded \
93− test_legacy_pid_handling \
94− test_exclude_idle \
95− test_exit_early \
96− test_sample_not_python \
97− test_include_ts \
98− test_include_ts_exclude_idle \
99− test_thread_dump \
100− test_no_line_numbers \
101− test_utf8_output; do
102−
103− substituteInPlace tests/test_end_to_end.py \
104− --replace "def $test(" "\
105−@pytest.mark.skip('build machine had kernel.yama.ptrace_scope != 0')
106−def $test("
107− done
108− fi
109− '';
110−
111− postInstall = ''
112− install -D utils/flame-chart-json $out/bin/flame-chart-json
113− '';
114−
115− doCheck = true;
116− # reproduces the logic of their test script, but without downloading pytest
117− # from the internet with pip
118− checkPhase = let inherit (stdenv) lib; in
119− lib.concatMapStringsSep "\n" (python: ''
120− set -x
121− PYMAJORVERSION=${lib.substring 0 1 python.version} \
122− PATH=${lib.makeBinPath [ coreutils ]}\
123− PYTHONPATH= \
124− ${python.pkgs.pytest}/bin/pytest -v tests/
125− set +x
126− '') (lib.filter (x: x != null) buildInputs);
127−
128− meta = with stdenv.lib; {
129− description = "A ptracing profiler for Python ";
130− longDescription = ''
131− Pyflame is a high performance profiling tool that generates flame graphs
132− for Python. Pyflame uses the Linux ptrace(2) system call to collect
133− profiling information. It can take snapshots of the Python call stack
134− without explicit instrumentation, meaning you can profile a program
135− without modifying its source code.
136− '';
137− homepage = https://github.com/uber/pyflame;
138− license = licenses.asl20;
139− maintainers = [ maintainers.symphorien ];
140− # arm: https://github.com/uber/pyflame/issues/136
141− platforms = [ "i686-linux" "x86_64-linux" ];
142− };
143−}