Factor out the concept of interesting callers.

This commit is contained in:
Vincent St-Amour 2012-09-18 16:14:28 -04:00
parent c66654e9c8
commit bba3d66fb1

View File

@ -222,36 +222,49 @@
(list evt)) (list evt))
site)))) site))))
;; Some sites are especially interesting if we have profile data. ;; Some callers are especially interesting if we have profile data.
;; If the function under consideration takes a large portion of the ;; If the function under consideration takes a large portion of the
;; total time for a given call site, and is not inlined there, may ;; total time of a given caller, we consider this case interesting.
;; be worth reporting. ;; This serves as a building block for more interesting patterns, such
;; returns: `(,caller-profile-node . ,call-site-log-entries) OR #f ;; as `key-sites' below.
(define interesting-sites ;; returns: caller-profile-node OR #f
(define interesting-callers
(and profile-entry (and profile-entry
(filter values (filter values
(for/list ([site (in-list inlining-sites)] (for/list ([edge (node-callers profile-entry)])
;; Not inlined enough at that call site. ;; Does this edge take a "large enough" proportion of
#:when (counts-as-a-missed-opt? site)) ;; the caller's total time?
(define caller-node (edge-caller edge))
(and (> (edge-caller-time edge)
(* (node-total caller-node) 0.5))
caller-node)))))
;; As above, but consed in front of the inlining info for that caller.
(define interesting-callers+sites
(and profile-entry
(filter values
(for/list ([site (in-list inlining-sites)])
(match (inlining-event-where-loc (match (inlining-event-where-loc
(inliner-log-entry-inlining-event (car site))) (inliner-log-entry-inlining-event (car site)))
[`(,caller-path ,caller-line ,caller-col) [`(,caller-path ,caller-line ,caller-col)
(define caller-node (define caller-node
(pos->node (cons caller-line caller-col))) (pos->node (cons caller-line caller-col)))
(define edge (and (memq caller-node interesting-callers)
(for/first ([e (node-callers profile-entry)]
#:when (eq? (edge-caller e)
caller-node))
e))
;; Does this edge take a "large enough" proportion of
;; the caller's total time?
(and edge caller-node
(> (edge-caller-time edge)
(* (node-total caller-node) 0.5))
(cons caller-node site))] (cons caller-node site))]
[_ ; can't parse that, give up [_ ; can't parse that, give up
#f]))))) #f])))))
;; If the function under consideration takes a large portion of the
;; total time for a given call site, and is not inlined there, we can
;; recommend that the user take a closer look at that specific site.
;; returns: `(,caller-profile-node . ,call-site-log-entries) OR #f
(define key-sites
(and profile-entry
(for/list ([site (in-list interesting-callers+sites)]
;; Not inlined enough at that call site.
#:when (counts-as-a-missed-opt? (cdr site)))
site)))
(define pruned-log (apply append inlining-sites)) (define pruned-log (apply append inlining-sites))
(define recommendation (define recommendation
@ -289,14 +302,14 @@
(when (and profile (not inside-hot-function?)) (when (and profile (not inside-hot-function?))
(prune)) (prune))
(cond [(and profile (not (null? interesting-sites))) (cond [(and profile (not (null? key-sites)))
;; Inlining was not satisfactory for some call sites where we ;; Inlining was not satisfactory for some call sites where we
;; accounted for a good portion of the caller's total time. ;; accounted for a good portion of the caller's total time.
(emit-near-miss (emit-near-miss
(format "Key call site~a: ~a" (format "Key call site~a: ~a"
(if (> (length interesting-sites) 1) "s" "") (if (> (length key-sites) 1) "s" "")
(string-join (string-join
(for/list ([site (in-list interesting-sites)]) (for/list ([site (in-list key-sites)])
(define node (car site)) (define node (car site))
(format "~a ~a:~a" (format "~a ~a:~a"
(node-id node) (node-id node)
@ -304,7 +317,7 @@
(node-col node))) (node-col node)))
", ")) ", "))
;; only compute badness for the interesting sites ;; only compute badness for the interesting sites
(group-badness (apply append (map cdr interesting-sites))))] (group-badness (apply append (map cdr key-sites))))]
[(counts-as-a-missed-opt? pruned-log) [(counts-as-a-missed-opt? pruned-log)
;; Overall inlining ratio is not satisfactory. ;; Overall inlining ratio is not satisfactory.
(emit-near-miss #f (group-badness pruned-log))] (emit-near-miss #f (group-badness pruned-log))]