summaryrefslogtreecommitdiff
path: root/module/statprof.scm
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2014-02-21 21:56:01 +0100
committerAndy Wingo <wingo@pobox.com>2014-02-21 21:56:01 +0100
commit4eb1fb9b8a926710a1040e483104dd8abb6f18e4 (patch)
tree70d0823d9f5e6e3f307109092fe56702cf726289 /module/statprof.scm
parent45a7de8268b71b8ce41a2a360c830a825ce06949 (diff)
downloadguile-4eb1fb9b8a926710a1040e483104dd8abb6f18e4.tar.gz
statprof-reset creates a new state
* module/statprof.scm (fresh-profiler-state): New helper. (ensure-profiler-state): Use it. (accumulate-time): No need to add 0.0 here. (statprof-reset): Create a new state instead of mutating the existing one.
Diffstat (limited to 'module/statprof.scm')
-rw-r--r--module/statprof.scm32
1 files changed, 16 insertions, 16 deletions
diff --git a/module/statprof.scm b/module/statprof.scm
index ede00928f..8a55b5f8d 100644
--- a/module/statprof.scm
+++ b/module/statprof.scm
@@ -194,9 +194,15 @@
(define profiler-state (make-parameter #f))
+(define* (fresh-profiler-state #:key (count-calls? #f)
+ (sampling-frequency '(0 . 10000))
+ (full-stacks? #f))
+ (make-state 0.0 #f 0 sampling-frequency #f 0 count-calls? 0.0 #f '()
+ (make-hash-table) #f))
+
(define (ensure-profiler-state)
(or (profiler-state)
- (let ((state (make-state #f #f #f #f #f 0 #t 0 #f '() #f #f)))
+ (let ((state (fresh-profiler-state)))
(profiler-state state)
state)))
@@ -227,7 +233,6 @@
(define (accumulate-time state stop-time)
(set-accumulated-time! state
(+ (accumulated-time state)
- 0.0
(- stop-time (last-start-time state)))))
(define (get-call-data proc)
@@ -410,20 +415,15 @@ data. If @var{full-stacks?} is true, collect all sampled stacks into a
list for later analysis.
Enables traps and debugging as necessary."
- (define state (ensure-profiler-state))
- (if (positive? (profile-level state))
- (error "Can't reset profiler while profiler is running."))
- (set-count-calls?! state count-calls?)
- (set-accumulated-time! state 0)
- (set-last-start-time! state #f)
- (set-sample-count! state 0)
- (set-sampling-frequency! state (cons sample-seconds sample-microseconds))
- (set-remaining-prof-time! state #f)
- (set-procedure-data! state (make-hash-table 131))
- (set-record-full-stacks?! state full-stacks?)
- (set-stacks! state '())
- (sigaction SIGPROF profile-signal-handler)
- #t)
+ (when (and (profiler-state) (positive? (profile-level (profiler-state))))
+ (error "Can't reset profiler while profiler is running."))
+ (let ((state (fresh-profiler-state #:count-calls? count-calls?
+ #:sampling-frequency
+ (cons sample-seconds sample-microseconds)
+ #:full-stacks? full-stacks?)))
+ (profiler-state state)
+ (sigaction SIGPROF profile-signal-handler)
+ #t))
(define (statprof-fold-call-data proc init)
"Fold @var{proc} over the call-data accumulated by statprof. Cannot be