mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 19:50:24 +02:00
statprof: when/unless instead of if.
* module/statprof.scm: Use when or unless instead of if, where appropriate.
This commit is contained in:
parent
d20dd74eca
commit
cad444e31a
1 changed files with 100 additions and 107 deletions
|
@ -258,8 +258,8 @@
|
||||||
(hit-count-call? #f)
|
(hit-count-call? #f)
|
||||||
(state (existing-profiler-state)))
|
(state (existing-profiler-state)))
|
||||||
|
|
||||||
(if (record-full-stacks? state)
|
(when (record-full-stacks? state)
|
||||||
(set-stacks! state (cons stack (stacks state))))
|
(set-stacks! state (cons stack (stacks state))))
|
||||||
|
|
||||||
(set-sample-count! state (+ (sample-count state) 1))
|
(set-sample-count! state (+ (sample-count state) 1))
|
||||||
;; Now accumulate stats for the whole stack.
|
;; Now accumulate stats for the whole stack.
|
||||||
|
@ -301,40 +301,38 @@
|
||||||
|
|
||||||
;; FIXME: with-statprof should be able to set an outer frame for the
|
;; FIXME: with-statprof should be able to set an outer frame for the
|
||||||
;; stack cut
|
;; stack cut
|
||||||
(if (positive? (profile-level state))
|
(when (positive? (profile-level state))
|
||||||
(let* ((stop-time (get-internal-run-time))
|
(let* ((stop-time (get-internal-run-time))
|
||||||
;; cut down to the signal handler. note that this will only
|
;; cut down to the signal handler. note that this will only
|
||||||
;; work if statprof.scm is compiled; otherwise we get
|
;; work if statprof.scm is compiled; otherwise we get
|
||||||
;; `eval' on the stack instead, because if it's not
|
;; `eval' on the stack instead, because if it's not
|
||||||
;; compiled, profile-signal-handler is a thunk that
|
;; compiled, profile-signal-handler is a thunk that
|
||||||
;; tail-calls eval. perhaps we should always compile the
|
;; tail-calls eval. perhaps we should always compile the
|
||||||
;; signal handler instead...
|
;; signal handler instead...
|
||||||
(stack (or (make-stack #t profile-signal-handler)
|
(stack (or (make-stack #t profile-signal-handler)
|
||||||
(pk 'what! (make-stack #t))))
|
(pk 'what! (make-stack #t))))
|
||||||
(inside-apply-trap? (sample-stack-procs stack)))
|
(inside-apply-trap? (sample-stack-procs stack)))
|
||||||
|
|
||||||
(if (not inside-apply-trap?)
|
(unless inside-apply-trap?
|
||||||
(begin
|
;; disabling here is just a little more efficient, but
|
||||||
;; disabling here is just a little more efficient, but
|
;; not necessary given inside-profiler?. We can't just
|
||||||
;; not necessary given inside-profiler?. We can't just
|
;; disable unconditionally at the top of this function
|
||||||
;; disable unconditionally at the top of this function
|
;; and eliminate inside-profiler? because it seems to
|
||||||
;; and eliminate inside-profiler? because it seems to
|
;; confuse guile wrt re-enabling the trap when
|
||||||
;; confuse guile wrt re-enabling the trap when
|
;; count-call finishes.
|
||||||
;; count-call finishes.
|
(when (count-calls? state)
|
||||||
(if (count-calls? state)
|
(set-vm-trace-level! (1- (vm-trace-level))))
|
||||||
(set-vm-trace-level! (1- (vm-trace-level))))
|
(accumulate-time state stop-time))
|
||||||
(accumulate-time state stop-time)))
|
|
||||||
|
|
||||||
(setitimer ITIMER_PROF
|
(setitimer ITIMER_PROF
|
||||||
0 0
|
0 0
|
||||||
(car (sampling-frequency state))
|
(car (sampling-frequency state))
|
||||||
(cdr (sampling-frequency state)))
|
(cdr (sampling-frequency state)))
|
||||||
|
|
||||||
(if (not inside-apply-trap?)
|
(unless inside-apply-trap?
|
||||||
(begin
|
(set-last-start-time! state (get-internal-run-time))
|
||||||
(set-last-start-time! state (get-internal-run-time))
|
(when (count-calls? state)
|
||||||
(if (count-calls? state)
|
(set-vm-trace-level! (1+ (vm-trace-level)))))))
|
||||||
(set-vm-trace-level! (1+ (vm-trace-level))))))))
|
|
||||||
|
|
||||||
(set-inside-profiler?! state #f))
|
(set-inside-profiler?! state #f))
|
||||||
|
|
||||||
|
@ -344,16 +342,15 @@
|
||||||
(define (count-call frame)
|
(define (count-call frame)
|
||||||
(define state (existing-profiler-state))
|
(define state (existing-profiler-state))
|
||||||
|
|
||||||
(if (not (inside-profiler? state))
|
(unless (inside-profiler? state)
|
||||||
(begin
|
(accumulate-time state (get-internal-run-time))
|
||||||
(accumulate-time state (get-internal-run-time))
|
|
||||||
|
|
||||||
(and=> (frame-procedure frame)
|
(and=> (frame-procedure frame)
|
||||||
(lambda (proc)
|
(lambda (proc)
|
||||||
(inc-call-data-call-count!
|
(inc-call-data-call-count!
|
||||||
(get-call-data proc))))
|
(get-call-data proc))))
|
||||||
|
|
||||||
(set-last-start-time! state (get-internal-run-time)))))
|
(set-last-start-time! state (get-internal-run-time))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
@ -370,25 +367,26 @@ than @code{statprof-stop}, @code{#f} otherwise."
|
||||||
;; signals here, but if I'm wrong, please let me know.
|
;; signals here, but if I'm wrong, please let me know.
|
||||||
(define state (ensure-profiler-state))
|
(define state (ensure-profiler-state))
|
||||||
(set-profile-level! state (+ (profile-level state) 1))
|
(set-profile-level! state (+ (profile-level state) 1))
|
||||||
(if (= (profile-level state) 1)
|
(when (= (profile-level state) 1)
|
||||||
(let* ((rpt (remaining-prof-time state))
|
(let* ((rpt (remaining-prof-time state))
|
||||||
(use-rpt? (and rpt
|
(use-rpt? (and rpt
|
||||||
(or (positive? (car rpt))
|
(or (positive? (car rpt))
|
||||||
(positive? (cdr rpt))))))
|
(positive? (cdr rpt))))))
|
||||||
(set-remaining-prof-time! state #f)
|
(set-remaining-prof-time! state #f)
|
||||||
(set-last-start-time! state (get-internal-run-time))
|
;; FIXME: Use per-thread run time.
|
||||||
(set-gc-time-taken! state
|
(set-last-start-time! state (get-internal-run-time))
|
||||||
(cdr (assq 'gc-time-taken (gc-stats))))
|
(set-gc-time-taken! state
|
||||||
(if use-rpt?
|
(cdr (assq 'gc-time-taken (gc-stats))))
|
||||||
(setitimer ITIMER_PROF 0 0 (car rpt) (cdr rpt))
|
(if use-rpt?
|
||||||
(setitimer ITIMER_PROF
|
(setitimer ITIMER_PROF 0 0 (car rpt) (cdr rpt))
|
||||||
0 0
|
(setitimer ITIMER_PROF
|
||||||
(car (sampling-frequency state))
|
0 0
|
||||||
(cdr (sampling-frequency state))))
|
(car (sampling-frequency state))
|
||||||
(if (count-calls? state)
|
(cdr (sampling-frequency state))))
|
||||||
(add-hook! (vm-apply-hook) count-call))
|
(when (count-calls? state)
|
||||||
(set-vm-trace-level! (1+ (vm-trace-level)))
|
(add-hook! (vm-apply-hook) count-call))
|
||||||
#t)))
|
(set-vm-trace-level! (1+ (vm-trace-level)))
|
||||||
|
#t)))
|
||||||
|
|
||||||
;; Do not call this from statprof internal functions -- user only.
|
;; Do not call this from statprof internal functions -- user only.
|
||||||
(define (statprof-stop)
|
(define (statprof-stop)
|
||||||
|
@ -397,19 +395,18 @@ than @code{statprof-stop}, @code{#f} otherwise."
|
||||||
;; signals here, but if I'm wrong, please let me know.
|
;; signals here, but if I'm wrong, please let me know.
|
||||||
(define state (ensure-profiler-state))
|
(define state (ensure-profiler-state))
|
||||||
(set-profile-level! state (- (profile-level state) 1))
|
(set-profile-level! state (- (profile-level state) 1))
|
||||||
(if (zero? (profile-level state))
|
(when (zero? (profile-level state))
|
||||||
(begin
|
(set-gc-time-taken! state
|
||||||
(set-gc-time-taken! state
|
(- (cdr (assq 'gc-time-taken (gc-stats)))
|
||||||
(- (cdr (assq 'gc-time-taken (gc-stats)))
|
(gc-time-taken state)))
|
||||||
(gc-time-taken state)))
|
(set-vm-trace-level! (1- (vm-trace-level)))
|
||||||
(set-vm-trace-level! (1- (vm-trace-level)))
|
(when (count-calls? state)
|
||||||
(if (count-calls? state)
|
(remove-hook! (vm-apply-hook) count-call))
|
||||||
(remove-hook! (vm-apply-hook) count-call))
|
;; I believe that we need to do this before getting the time
|
||||||
;; I believe that we need to do this before getting the time
|
;; (unless we want to make things even more complicated).
|
||||||
;; (unless we want to make things even more complicated).
|
(set-remaining-prof-time! state (setitimer ITIMER_PROF 0 0 0 0))
|
||||||
(set-remaining-prof-time! state (setitimer ITIMER_PROF 0 0 0 0))
|
(accumulate-time state (get-internal-run-time))
|
||||||
(accumulate-time state (get-internal-run-time))
|
(set-last-start-time! state #f)))
|
||||||
(set-last-start-time! state #f))))
|
|
||||||
|
|
||||||
(define* (statprof-reset sample-seconds sample-microseconds count-calls?
|
(define* (statprof-reset sample-seconds sample-microseconds count-calls?
|
||||||
#:optional full-stacks?)
|
#:optional full-stacks?)
|
||||||
|
@ -568,14 +565,14 @@ statistics.@code{}"
|
||||||
|
|
||||||
(statprof-fold-call-data
|
(statprof-fold-call-data
|
||||||
(lambda (data prior-value)
|
(lambda (data prior-value)
|
||||||
(if (and (count-calls? state)
|
(when (and (count-calls? state)
|
||||||
(zero? (call-data-call-count data))
|
(zero? (call-data-call-count data))
|
||||||
(positive? (call-data-cum-sample-count data)))
|
(positive? (call-data-cum-sample-count data)))
|
||||||
(simple-format #t
|
(simple-format #t
|
||||||
"==[~A ~A ~A]\n"
|
"==[~A ~A ~A]\n"
|
||||||
(call-data-name data)
|
(call-data-name data)
|
||||||
(call-data-call-count data)
|
(call-data-call-count data)
|
||||||
(call-data-cum-sample-count data))))
|
(call-data-cum-sample-count data))))
|
||||||
#f)
|
#f)
|
||||||
(simple-format #t "Total time: ~A\n" (statprof-accumulated-time))
|
(simple-format #t "Total time: ~A\n" (statprof-accumulated-time))
|
||||||
(simple-format #t "Sample count: ~A\n" (statprof-sample-count)))
|
(simple-format #t "Sample count: ~A\n" (statprof-sample-count)))
|
||||||
|
@ -686,10 +683,9 @@ whole call tree, for later analysis. Use @code{statprof-fetch-stacks} or
|
||||||
(statprof-start))
|
(statprof-start))
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let lp ((i loop))
|
(let lp ((i loop))
|
||||||
(if (not (zero? i))
|
(unless (zero? i)
|
||||||
(begin
|
(thunk)
|
||||||
(thunk)
|
(lp (1- i)))))
|
||||||
(lp (1- i))))))
|
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(statprof-stop)
|
(statprof-stop)
|
||||||
(statprof-display)
|
(statprof-display)
|
||||||
|
@ -752,8 +748,8 @@ whole call tree, for later analysis. Use @code{statprof-fetch-stacks} or
|
||||||
(define state (ensure-profiler-state))
|
(define state (ensure-profiler-state))
|
||||||
|
|
||||||
(define (reset)
|
(define (reset)
|
||||||
(if (positive? (profile-level state))
|
(when (positive? (profile-level state))
|
||||||
(error "Can't reset profiler while profiler is running."))
|
(error "Can't reset profiler while profiler is running."))
|
||||||
(set-accumulated-time! state 0)
|
(set-accumulated-time! state 0)
|
||||||
(set-last-start-time! state #f)
|
(set-last-start-time! state #f)
|
||||||
(set-sample-count! state 0)
|
(set-sample-count! state 0)
|
||||||
|
@ -783,25 +779,23 @@ whole call tree, for later analysis. Use @code{statprof-fetch-stacks} or
|
||||||
|
|
||||||
(define (start)
|
(define (start)
|
||||||
(set-profile-level! state (+ (profile-level state) 1))
|
(set-profile-level! state (+ (profile-level state) 1))
|
||||||
(if (= (profile-level state) 1)
|
(when (= (profile-level state) 1)
|
||||||
(begin
|
(set-remaining-prof-time! state #f)
|
||||||
(set-remaining-prof-time! state #f)
|
(set-last-start-time! state (get-internal-run-time))
|
||||||
(set-last-start-time! state (get-internal-run-time))
|
(set-gc-time-taken! state (cdr (assq 'gc-time-taken (gc-stats))))
|
||||||
(set-gc-time-taken! state (cdr (assq 'gc-time-taken (gc-stats))))
|
(add-hook! after-gc-hook gc-callback)
|
||||||
(add-hook! after-gc-hook gc-callback)
|
(set-vm-trace-level! (1+ (vm-trace-level)))
|
||||||
(set-vm-trace-level! (1+ (vm-trace-level)))
|
#t))
|
||||||
#t)))
|
|
||||||
|
|
||||||
(define (stop)
|
(define (stop)
|
||||||
(set-profile-level! state (- (profile-level state) 1))
|
(set-profile-level! state (- (profile-level state) 1))
|
||||||
(if (zero? (profile-level state))
|
(when (zero? (profile-level state))
|
||||||
(begin
|
(set-gc-time-taken! state
|
||||||
(set-gc-time-taken! state
|
(- (cdr (assq 'gc-time-taken (gc-stats)))
|
||||||
(- (cdr (assq 'gc-time-taken (gc-stats)))
|
(gc-time-taken state)))
|
||||||
(gc-time-taken state)))
|
(remove-hook! after-gc-hook gc-callback)
|
||||||
(remove-hook! after-gc-hook gc-callback)
|
(accumulate-time state (get-internal-run-time))
|
||||||
(accumulate-time state (get-internal-run-time))
|
(set-last-start-time! state #f)))
|
||||||
(set-last-start-time! state #f))))
|
|
||||||
|
|
||||||
(dynamic-wind
|
(dynamic-wind
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
@ -809,10 +803,9 @@ whole call tree, for later analysis. Use @code{statprof-fetch-stacks} or
|
||||||
(start))
|
(start))
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let lp ((i loop))
|
(let lp ((i loop))
|
||||||
(if (not (zero? i))
|
(unless (zero? i)
|
||||||
(begin
|
(thunk)
|
||||||
(thunk)
|
(lp (1- i)))))
|
||||||
(lp (1- i))))))
|
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(stop)
|
(stop)
|
||||||
(statprof-display)
|
(statprof-display)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue