1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2021 Olivier Dion <olivier.dion@polymtl.ca>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu packages instrumentation)
20 #:use-module (gnu packages base)
21 #:use-module (gnu packages bison)
22 #:use-module (gnu packages boost)
23 #:use-module (gnu packages datastructures)
24 #:use-module (gnu packages documentation)
25 #:use-module (gnu packages elf)
26 #:use-module (gnu packages engineering)
27 #:use-module (gnu packages flex)
28 #:use-module (gnu packages glib)
29 #:use-module (gnu packages haskell-xyz)
30 #:use-module (gnu packages libunwind)
31 #:use-module (gnu packages linux)
32 #:use-module (gnu packages llvm)
33 #:use-module (gnu packages lua)
34 #:use-module (gnu packages man)
35 #:use-module (gnu packages ncurses)
36 #:use-module (gnu packages perl)
37 #:use-module (gnu packages pkg-config)
38 #:use-module (gnu packages popt)
39 #:use-module (gnu packages python)
40 #:use-module (gnu packages python-xyz)
41 #:use-module (gnu packages sphinx)
42 #:use-module (gnu packages swig)
43 #:use-module (gnu packages tbb)
44 #:use-module (gnu packages xml)
45 #:use-module (guix platform)
46 #:use-module (guix build-system cmake)
47 #:use-module (guix build-system copy)
48 #:use-module (guix build-system gnu)
49 #:use-module (guix download)
50 #:use-module (guix gexp)
51 #:use-module (guix git-download)
52 #:use-module ((guix licenses) #:prefix license:)
53 #:use-module (guix packages)
54 #:use-module (srfi srfi-26)
55 #:use-module (guix utils))
57 (define-public babeltrace
63 (uri (string-append "https://www.efficios.com/files/babeltrace/babeltrace2-"
66 (base32 "1jlv925pr7hykc48mdvbmqm4ipy1r11xwzapa6fdpdfshmk12kvp"))))
68 (build-system gnu-build-system)
71 `(#:tests? #f ; FIXME - When Python's bindings are enabled, tests do not
74 ,#~(list (string-append "LDFLAGS=-Wl,-rpath=" #$output "/lib"))
76 '("--enable-debug-info"
78 "--enable-python-bindings"
79 "--enable-python-plugins")
81 (modify-phases %standard-phases
82 ;; These are recommended in the project's README for a development
83 ;; build configuration.
84 (add-before 'configure 'set-environment-variables
86 (setenv "BABELTRACE_DEV_MODE" "1")
87 (setenv "BABELTRACE_MINIMAL_LOG_LEVEL" "TRACE"))))))
90 ;; NOTE - elfutils is used for the LTTng debug information filter
91 ;; component class. This can be moved to `native-inputs` if
92 ;; `--enable-debug-info` is replaced by `--disable-debug-info` in
93 ;; `#:configure-flags`.
96 ;; NOTE - python-3 is set here for generating the bindings. Users need to
97 ;; install python-3 in their profile in order to use these bindings.
107 (home-page "https://babeltrace.org/")
108 (synopsis "Trace manipulation toolkit")
109 (description "Babeltrace 2 is a framework for viewing, converting,
110 transforming, and analyzing traces. It is also the reference parser
111 implementation of the Common Trace Format (CTF), produced by tools such as
112 LTTng and barectf. This package provides a library with a C API, Python 3
113 bindings, and the command-line tool @command{babeltrace2}.")
114 (license license:expat)))
116 (define-public dyninst
119 ;; Newer versions are not promoted on main home page.
120 ;; Upgrade to 12.0.1 if anyone require a newer version.
125 (url "https://github.com/dyninst/dyninst")
126 (commit (string-append "v" version))))
127 (file-name (git-file-name name version))
129 (base32 "1m04pg824rqx647wvk9xl33ri8i6mm0vmrz9924li25dxbr4zqd5"))))
131 (build-system cmake-build-system)
134 ;; STERILE_BUILD: Do not download/build third-party dependencies from
137 (list "-DSTERILE_BUILD=ON")
138 ;; NOTE: dyninst needs to search for shared libraries that are linked
139 ;; against the instrumented binary in order to rebuild the entire
140 ;; program. For this purpose, one can use LD_LIBRARY_PATH or
141 ;; DYNISNT_REWRITER_PATHS environment variables to add paths for dyinst
142 ;; to search. However, dyninst also tries to be smart by executing
143 ;; ldconfig, which is not portable. If ldconfig is not available on
144 ;; the system, dyinst wrongly assumes that the shared libraries can not
145 ;; be found, even though it can. This bad logic is still there with
146 ;; newer versions of dyinst. Thus, this substitution makes the bad
147 ;; code path unreachable.
149 (modify-phases %standard-phases
150 (add-after 'unpack 'patch-bad-logic
152 (substitute* "dyninstAPI/src/linux.C"
153 (("if\\(\\!fgets\\(buffer, 512, ldconfig\\)\\)")
154 "fgets(buffer, 512, ldconfig); if (false)")))))))
156 (list elfutils boost tbb-2020))
157 (home-page "https://dyninst.org/")
158 (synopsis "Dynamic instrumentation")
159 (description "Dyninst is a collection of libraries for instrumenting,
160 analyzing and editing binaries. It can attach to an existing program or
161 create a new one out of an ELF file for analysis or modification. It come
162 with a handful of C++ libraries.")
163 (license license:lgpl2.1+)))
165 (define-public flamegraph
166 ;; No new version since 2019, but there's still some new important commits.
167 (let ((commit "810687f180f3c4929b5d965f54817a5218c9d89b")
171 (version (git-version "1.0" revision commit))
175 (url "https://github.com/brendangregg/FlameGraph")
177 (file-name (git-file-name name version))
180 "1lg02mxzdsm9szn4vcmx76c1bw9gqmxqk8n6v63v03036sc83s22"))))
181 (build-system copy-build-system)
184 ',(map (cut list <> "bin/")
187 "stackcollapse-perf.pl"
188 "stackcollapse-pmc.pl"
189 "stackcollapse-stap.pl"
190 "stackcollapse-instruments.pl"
191 "stackcollapse-vtune.pl"
192 "stackcollapse-jstack.pl"
193 "stackcollapse-gdb.pl"
194 "stackcollapse-go.pl"
195 "stackcollapse-vsprof.pl"
196 "stackcollapse-wcp.pl"))))
198 (home-page "http://www.brendangregg.com/flamegraphs.html")
199 (synopsis "Stack trace visualizer")
200 (description "Flamegraph is a collection of scripts that generate
201 interactive SVGs out of traces genated from various tracing tools. It comes
202 with the script @command{flamegraph.pl} and many stackcollapse scripts.")
203 (license license:cddl1.0))))
205 (define-public lttng-ust
211 (uri (string-append "https://lttng.org/files/lttng-ust/"
212 "lttng-ust-" version ".tar.bz2"))
215 "1p7d94r275yvby6zqfxaswdl1q46zxbc8x5rkhnjxrp1d41byrsn"))))
216 (build-system gnu-build-system)
220 (list liburcu)) ;headers of liburcu are used by headers of lttng
222 (list python-3 pkg-config))
223 (home-page "https://lttng.org/")
224 (synopsis "LTTng userspace tracer libraries")
225 (description "The user space tracing library, liblttng-ust, is the LTTng
226 user space tracer. It receives commands from a session daemon, for example to
227 enable and disable specific instrumentation points, and writes event records
228 to ring buffers shared with a consumer daemon.")
229 (license (list license:lgpl2.1 license:expat))))
231 (define-public lttng-tools
237 (uri (string-append "https://lttng.org/files/lttng-tools/"
238 "lttng-tools-" version ".tar.bz2"))
241 "1gfp9y24lpaiz4lcmbp30yd400jmh99mlay9gb8pz9qd080bmlnf"))))
242 (build-system gnu-build-system)
244 `( ;; FIXME - Currently there's a segmentation fault by swig when enabling
245 ;; Python's bindings. Thus, bindings are disable here. Replace
246 ;; `disable` by `enable` in #:configure-flags when this is fixed.
247 #:configure-flags '("--disable-python-bindings")
248 ;; FIXME - Tests are disabled for now because one test hangs
249 ;; indefinetely. Also, parallel testing is not possible because of how
250 ;; the lttng-daemon handles sessions. Thus, keep parallel testing
251 ;; disabled even after tests are enabled!
255 (modify-phases %standard-phases
256 (add-before 'configure 'set-environment-variables
258 (setenv "HOME" "/tmp")
259 (setenv "LTTNG_HOME" "/tmp")))
260 ;; We don't put (which "man") here because LTTng uses execlp.
261 (add-after 'unpack 'patch-default-man-path
263 (substitute* "src/common/defaults.h"
264 (("/usr/bin/man") "man")))))))
265 ;; NOTE - Users have to install python-3 in their profile to use the
266 ;; bindings. We don't put it in the inputs, because the rest of the tools
267 ;; can work without it.
269 (list liburcu popt numactl))
271 (list kmod module-init-tools))
285 (home-page "https://lttng.org/")
286 (synopsis "LTTng userspace tracer libraries")
287 (description "The lttng-tools project provides a session
288 daemon @code{lttng-sessiond} that acts as a tracing registry, the @command{lttng} command
289 line for tracing control, a @code{lttng-ctl} library for tracing control and a
290 @code{lttng-relayd} for network streaming.")
291 (license (list license:gpl2 license:lgpl2.1))))
293 (define-public uftrace
300 (url "https://github.com/namhyung/uftrace")
301 (commit (string-append "v" version))))
302 (file-name (git-file-name name version))
304 (base32 "0gk0hv3rnf5czvazz1prg21rf9qlniz42g5b389n8a29hqj4q6xr"))))
305 (build-system gnu-build-system)
309 (string-append "CC=" ,(cc-for-target)))
310 ;; runtest hang at some point -- probably dues to
311 ;; failed socket connection -- but we want to keep the
312 ;; unit tests. Change the target to "test" when fixed.
313 #:test-target "unittest"
315 (modify-phases %standard-phases
317 (lambda* (#:key outputs target #:allow-other-keys)
318 (let ((arch ,(platform-linux-architecture
319 (lookup-platform-by-target-or-system
320 (or (%current-target-system)
321 (%current-system))))))
324 ((string=? arch "arm64") "aarch64")
327 (setenv "CROSS_COMPILE" (string-append target "-"))))
328 (setenv "SHELL" (which "sh"))
329 (invoke "./configure"
330 (string-append "--prefix="
331 (assoc-ref outputs "out"))))))))
342 (home-page "https://github.com/namhyung/uftrace")
343 (synopsis "Function graph tracer for C/C++/Rust")
344 (description "uftrace is a tool for tracing and analyzing the execution of
345 programs written in C/C++. It is heavily inspired by the ftrace framework of
346 the Linux kernel, while supporting userspace programs. It supports various
347 kind of commands and filters to help analysis of the program execution and
348 performance. It provides the command @command{uftrace}. User that want to do
349 scripting need to install python-3 or luajit in their profile.")
350 (license license:gpl2)))