aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-01-29 12:17:20 +0100
committerLudovic Courtès <ludo@gnu.org>2018-01-29 18:06:47 +0100
commit23fecf8f3d2469a3de4f7ffae16224b0d21cc265 (patch)
treeea97ae0bcebbca263ceb08e8c85b810d122b80fb /src
parentfcd1bc13bce741a96a315ed0b0d06dc8e88519f9 (diff)
downloadcuirass-23fecf8f3d2469a3de4f7ffae16224b0d21cc265.tar
cuirass-23fecf8f3d2469a3de4f7ffae16224b0d21cc265.tar.gz
cuirass: Log resource usage statistics regularly.
* src/cuirass/logging.scm (log-monitoring-stats): New procedure. * bin/cuirass.in (main): Add a fiber that calls it regularly.
Diffstat (limited to 'src')
-rw-r--r--src/cuirass/logging.scm15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/cuirass/logging.scm b/src/cuirass/logging.scm
index 9574b23..12d156c 100644
--- a/src/cuirass/logging.scm
+++ b/src/cuirass/logging.scm
@@ -19,10 +19,13 @@
(define-module (cuirass logging)
#:use-module (srfi srfi-19)
#:use-module (ice-9 format)
+ #:use-module (ice-9 threads)
+ #:use-module (ice-9 ftw)
#:export (current-logging-port
current-logging-procedure
log-message
- with-time-logging))
+ with-time-logging
+ log-monitoring-stats))
(define current-logging-port
(make-parameter (current-error-port)))
@@ -61,3 +64,13 @@
(define-syntax-rule (with-time-logging name exp ...)
"Log under NAME the time taken to evaluate EXP."
(call-with-time-logging name (lambda () exp ...)))
+
+(define (log-monitoring-stats)
+ "Log info about useful metrics: heap size, number of threads, etc."
+ (log-message "heap: ~,2f MiB; threads: ~a; file descriptors: ~a"
+ (/ (assoc-ref (gc-stats) 'heap-size) (expt 2. 20))
+ (length (all-threads))
+ (length
+ (scandir "/proc/self/fd"
+ (lambda (file)
+ (not (member file '("." ".."))))))))