gnu: Add emacs-exec-path-from-shell.
[jackhill/guix/guix.git] / guix / profiling.scm
CommitLineData
03870da8
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
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.
10;;;
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.
15;;;
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/>.
18
19(define-module (guix profiling)
20 #:use-module (ice-9 match)
21 #:export (profiled?
22 register-profiling-hook!))
23
24;;; Commentary:
25;;;
26;;; Basic support for Guix-specific profiling.
27;;;
28;;; Code:
29
30(define profiled?
31 (let ((profiled
32 (or (and=> (getenv "GUIX_PROFILING") string-tokenize)
33 '())))
34 (lambda (component)
35 "Return true if COMPONENT profiling is active."
36 (member component profiled))))
37
38(define %profiling-hooks
39 ;; List of profiling hooks.
40 (map (match-lambda
41 ("after-gc" after-gc-hook)
42 ((or "exit" #f) exit-hook))
43 (or (and=> (getenv "GUIX_PROFILING_EVENTS") string-tokenize)
44 '("exit"))))
45
46(define (register-profiling-hook! component thunk)
47 "Register THUNK as a profiling hook for COMPONENT, a string such as
48\"rpc\"."
49 (when (profiled? component)
50 (for-each (lambda (hook)
51 (add-hook! hook thunk))
52 %profiling-hooks)))