|
66 | 66 | (define (analyze-contract-samples |
67 | 67 | contract-samples |
68 | 68 | samples |
| 69 | + #:report-space-efficient? [report-space-efficient? #f] |
69 | 70 | #:module-graph-view-file [module-graph-view-file #f] |
70 | 71 | #:boundary-view-file [boundary-view-file #f] |
71 | 72 | #:boundary-view-key-file [boundary-view-key-file #f]) |
72 | 73 | (define correlated (correlate-contract-samples contract-samples samples)) |
73 | | - (print-breakdown correlated) |
| 74 | + (print-breakdown correlated #:report-space-efficient? report-space-efficient?) |
74 | 75 | (when module-graph-view-file |
75 | 76 | (module-graph-view correlated module-graph-view-file)) |
76 | 77 | (when boundary-view-file |
|
81 | 82 | ;; Break down contract checking time by contract, then by callee and by chain |
82 | 83 | ;; of callers. |
83 | 84 |
|
84 | | -(define (print-breakdown correlated [show-by-caller? #f]) |
| 85 | +(define (/. num den) (/ num (max den 1) 1.0)) |
| 86 | + |
| 87 | +(define (print-breakdown correlated |
| 88 | + [show-by-caller? #f] |
| 89 | + #:report-space-efficient? [report-space-efficient? #f]) |
85 | 90 | (match-define (contract-profile |
86 | 91 | total-time live-contract-samples all-blames regular-profile) |
87 | 92 | correlated) |
88 | 93 |
|
89 | 94 | (define total-contract-time (samples-time live-contract-samples)) |
90 | | - (define contract-ratio (/ total-contract-time (max total-time 1) 1.0)) |
| 95 | + (define contract-ratio (/. total-contract-time total-time)) |
91 | 96 | (printf "Running time is ~a% contracts\n" |
92 | 97 | (~r (* 100 contract-ratio) #:precision 2)) |
93 | 98 | (printf "~a/~a ms\n\n" |
94 | 99 | (~r total-contract-time #:precision 0) |
95 | 100 | total-time) |
| 101 | + (define (only-space-efficient samples) |
| 102 | + (filter contract-sample-space-efficient? samples)) |
| 103 | + (define space-efficient-samples (only-space-efficient live-contract-samples)) |
| 104 | + (when report-space-efficient? |
| 105 | + (define total-space-efficient-time (samples-time space-efficient-samples)) |
| 106 | + (define space-efficient-ratio |
| 107 | + (/. total-space-efficient-time total-contract-time)) |
| 108 | + (printf "(of those, ~a% (~a/~a ms) are space-efficient)\n\n" |
| 109 | + (~r (* 100 space-efficient-ratio) #:precision 2) |
| 110 | + (~r total-space-efficient-time #:precision 0) |
| 111 | + (~r total-contract-time #:precision 0))) |
96 | 112 |
|
97 | 113 | (define shorten-source |
98 | 114 | (make-srcloc-shortener all-blames blame-source)) |
|
105 | 121 | #:limit-prefix? #t |
106 | 122 | #:width (- location-width 1)))) |
107 | 123 | (define (format-samples-time s) |
108 | | - (format "~a ms" (~r (samples-time s) #:precision 2))) |
| 124 | + (define total-time (samples-time s)) |
| 125 | + (format "~a ms~a" |
| 126 | + (~r total-time #:precision 2) |
| 127 | + (if report-space-efficient? |
| 128 | + (format " (~a% space-efficient)" |
| 129 | + (~r (* 100 (/. (samples-time (only-space-efficient s)) |
| 130 | + total-time)) |
| 131 | + #:precision 2)) |
| 132 | + ""))) |
109 | 133 |
|
110 | 134 | (define samples-by-contract |
111 | 135 | (sort (group-by (lambda (x) (blame-contract (contract-sample-blame x))) |
|
178 | 202 | (~optional (~seq #:boundary-view-file boundary-view-file:expr) |
179 | 203 | #:defaults ([boundary-view-file #'#f])) |
180 | 204 | (~optional (~seq #:boundary-view-key-file boundary-view-key-file:expr) |
181 | | - #:defaults ([boundary-view-key-file #'#f]))) |
| 205 | + #:defaults ([boundary-view-key-file #'#f])) |
| 206 | + (~optional (~seq #:report-space-efficient? report-space-efficient?:expr) |
| 207 | + #:defaults ([report-space-efficient? #'#f]))) |
182 | 208 | ... |
183 | 209 | body:expr ...) |
184 | 210 | #`(let ([sampler (create-sampler |
|
212 | 238 | samples |
213 | 239 | #:module-graph-view-file module-graph-view-file |
214 | 240 | #:boundary-view-file boundary-view-file |
215 | | - #:boundary-view-key-file boundary-view-key-file))))])) |
| 241 | + #:boundary-view-key-file boundary-view-key-file |
| 242 | + #:report-space-efficient? report-space-efficient?))))])) |
216 | 243 |
|
217 | 244 | (define (contract-profile-thunk f |
218 | 245 | #:module-graph-view-file [module-graph-view-file #f] |
219 | 246 | #:boundary-view-file [boundary-view-file #f] |
220 | | - #:boundary-view-key-file [boundary-view-key-file #f]) |
| 247 | + #:boundary-view-key-file [boundary-view-key-file #f] |
| 248 | + #:report-space-efficient? [report-space-efficient? #f]) |
221 | 249 | (contract-profile/user |
222 | 250 | #:module-graph-view-file module-graph-view-file |
223 | 251 | #:boundary-view-file boundary-view-file |
224 | 252 | #:boundary-view-key-file boundary-view-key-file |
| 253 | + #:report-space-efficient? report-space-efficient? |
225 | 254 | (f))) |
0 commit comments