Skip to content

Commit 144d4bc

Browse files
committed
Sample and plumb through space-efficient mark.
1 parent 19a66d6 commit 144d4bc

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

main.rkt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@
99

1010
(define limit-dots " ... ")
1111

12-
;; (listof (U blame? (cons blame? blame-party) #f)) profile-samples
12+
;; using dynamic-require, to also work on versions that don't have it
13+
(define space-efficient-key
14+
(dynamic-require '(lib "racket/contract/combinator")
15+
'space-efficient-contract-continuation-mark-key
16+
(lambda _ #f)))
17+
18+
;; (listof (U (vector (U blame? (cons blame? blame-party)) boolean?) #f))
19+
;; profile-samples
1320
;; -> contract-profile?
21+
;; boolean denotes whether the sampled contract was space-efficient
1422
(define (correlate-contract-samples contract-samples time+samples)
1523
;; car of time+samples is total time, car of each sample is thread id
1624
;; for now, we just assume a single thread. fix this eventually.
@@ -26,17 +34,18 @@
2634
;; If the sampler was stopped after recording a contract sample, but
2735
;; before recording the corresponding time sample, the two lists may
2836
;; be of different lengths. That's ok, just drop the extra sample.
29-
(for/list ([-blame (in-list contract-samples)]
30-
[s (in-list samples)]
31-
#:when -blame)
37+
(for/list ([c-s (in-list contract-samples)]
38+
[s (in-list samples)]
39+
#:when c-s)
40+
(match-define `#(,-blame ,space-efficient?) c-s)
3241
;; In some cases, blame information is missing a party, in which.
3342
;; case the contract system provides a pair of the incomplete blame
3443
;; and the missing party. We combine the two here.
3544
(define blame
3645
(if (pair? -blame)
3746
(blame-add-missing-party (car -blame) (cdr -blame))
3847
-blame))
39-
(contract-sample blame s)))
48+
(contract-sample blame space-efficient? s)))
4049
(define all-blames
4150
(set->list (for/set ([c-s (in-list live-contract-samples)])
4251
(define b (contract-sample-blame c-s))
@@ -172,8 +181,12 @@
172181
#:defaults ([boundary-view-key-file #'#f])))
173182
...
174183
body:expr ...)
175-
#`(let ([sampler (create-sampler (current-thread) 0.005 (current-custodian)
176-
(list contract-continuation-mark-key))])
184+
#`(let ([sampler (create-sampler
185+
(current-thread) 0.005 (current-custodian)
186+
(list contract-continuation-mark-key
187+
(or space-efficient-key
188+
;; won't be found, so we'll just get `#f`s
189+
(gensym))))])
177190
(begin0 (begin body ...)
178191
(let ()
179192
(sampler 'stop)
@@ -193,7 +206,7 @@
193206
;; (contract-profile (for/fold ([acc 0])
194207
;; ([i (in-range 10000000)])
195208
;; (+ acc (vector-ref v 0) (vector-ref w 0))))
196-
(and (not (empty? s)) (vector-ref (car s) 0))))
209+
(and (not (empty? s)) (car s))))
197210
(analyze-contract-samples
198211
contract-samples
199212
samples

module-graph-view.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
[edge-samples (hash)])
2323
([s (in-list live-contract-samples)])
2424
(match-define (contract-sample blame
25+
space-efficient?
2526
(list sample-time stack-trace ...))
2627
s)
2728
(when (empty? stack-trace)

utils.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
(struct contract-sample
88
(blame
9+
space-efficient?
910
;; from regular profiler
1011
profile-sample))
1112

0 commit comments

Comments
 (0)