-
Notifications
You must be signed in to change notification settings - Fork 0
/
coach.rkt
38 lines (30 loc) · 1.45 KB
/
coach.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#lang racket
(require unstable/list json)
(require "structs.rkt" "parsing.rkt" "reports.rkt"
"property-reports.rkt" "element-reports.rkt")
;; generate-reports : (listof optimization-event?) -> (listof report?)
;; Takes a list of ungrouped events, and produces a list of near misses to be
;; shown to the user, sorted by badness.
(define (generate-reports all-events)
;; Only consider optimization events in code that was sampled.
(define live-events
(filter (lambda (e) (> (optimization-event-profile-weight e) 0))
all-events))
(define all-reports
(append (property-events->reports (filter property-event? live-events))
(element-events->reports (filter element-event? live-events))))
(sort all-reports > #:key report-badness))
(module+ main
(define log-file (vector-ref (current-command-line-arguments) 0))
(define profile (with-input-from-file log-file read-json))
(define compiles (profile->compiles profile))
(define all-events (append-map compile-events compiles))
(define sorted-reports (generate-reports all-events))
;; do pruning based on badness (profile weight + merging)
;; keep only top N
;; TODO could prune differently. e.g. take up to X% of the total badness
;; or take reports until we reach a cutoff point (e.g. next is less than
;; 10% of the badness of the previous one)
(define hot-reports (take sorted-reports (min 5 (length sorted-reports))))
(for-each display hot-reports)
)