Prune profile info to only keep hot functions.
This commit is contained in:
parent
f6b60b2f90
commit
c7f8eff883
|
@ -6,6 +6,7 @@
|
|||
|
||||
(provide generate-profile
|
||||
node-source node-line node-col node-pos node-span
|
||||
prune-profile
|
||||
(all-from-out profile/analyzer))
|
||||
|
||||
(define ((mk accessor) node)
|
||||
|
@ -41,3 +42,27 @@
|
|||
(equal? (and src (srcloc-source src)) res-mpi))
|
||||
(define orig-profile (analyze-samples snapshots))
|
||||
(filter right-file? (profile-nodes orig-profile)))
|
||||
|
||||
|
||||
;; In some cases, we only want to consider "hot" functions for further
|
||||
;; analysis. `prune-profile' prunes non-hot functions from the profile.
|
||||
;; To determine what is hot, we pick, in order, the hottest functions
|
||||
;; (by self time. total time could be used, but may not work as well)
|
||||
;; until our picks cover `total-relative-time-cutoff' (e.g. half) of
|
||||
;; the total running time.
|
||||
(define total-relative-time-cutoff .95) ; picked arbitrarily, subject to tweaking
|
||||
(define (prune-profile profile)
|
||||
(define total-time (profile-total-time profile))
|
||||
(define target-time (* total-time total-relative-time-cutoff))
|
||||
(define sorted-nodes (sort (profile-nodes profile) > #:key node-self))
|
||||
(define top-nodes
|
||||
(let loop ([nodes sorted-nodes] [res '()] [sum 0])
|
||||
;; The last function we pick can go beyond the target.
|
||||
;; O/w, if we had a single function, taking up 100% time, it would
|
||||
;; be discarded.
|
||||
(cond [(or (null? nodes) (> sum target-time))
|
||||
res]
|
||||
[else
|
||||
(define h (car nodes))
|
||||
(loop (cdr nodes) (cons h res) (+ sum (node-self h)))])))
|
||||
top-nodes)
|
||||
|
|
Loading…
Reference in New Issue
Block a user