File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 4848(define (current-timestamp)
4949 (exact-floor (* 1000 (current-inexact-milliseconds))))
5050
51+ (define *gc-logger* #f )
52+
5153(define (trace-start)
5254 (when (flag-set? 'dump 'trace )
55+ (set! *gc-logger* (make-log-receiver (current-logger) 'debug 'GC ))
5356 (call-with-output-file
5457 "dump-trace.json "
5558 #:exists 'truncate
5659 (λ (out)
5760 (fprintf out "{\"traceEvents\":[ " )
5861 (write-json (hash 'name "process_name " 'ph "M " 'ts 0 'pid 0 'tid 0 'args (hash 'name "herbie " ))
62+ out)
63+ (fprintf out ", " )
64+ (write-json (hash 'name
65+ "thread_name "
66+ 'ph
67+ "M "
68+ 'ts
69+ 0
70+ 'pid
71+ 0
72+ 'tid
73+ (equal-hash-code 'gc )
74+ 'args
75+ (hash 'name "GC " ))
5976 out)))))
6077
78+ (define (trace-sync)
79+ (when *gc-logger*
80+ (let drain ()
81+ (match (sync/timeout 0 *gc-logger*)
82+ [#f (void)]
83+ [(vector _lvl _msg (app struct->vector data) _topic)
84+ (define mode (~a (vector-ref data 1 )))
85+ (define start (exact-floor (* 1000 (vector-ref data 9 ))))
86+ (define end (exact-floor (* 1000 (vector-ref data 10 ))))
87+ (call-with-output-file "dump-trace.json "
88+ #:exists 'append
89+ (λ (out)
90+ (fprintf out ", " )
91+ (write-json (hash 'name
92+ mode
93+ 'ph
94+ "X "
95+ 'ts
96+ start
97+ 'dur
98+ (- end start)
99+ 'pid
100+ 0
101+ 'tid
102+ (equal-hash-code 'gc )
103+ 'args
104+ (hash))
105+ out)))
106+ (drain)]))))
107+
61108(define (trace name phase [args (hash)])
62109 (when (flag-set? 'dump 'trace )
110+ (trace-sync)
63111 (call-with-output-file "dump-trace.json "
64112 #:exists 'append
65113 (λ (out)
80128
81129(define (trace-end)
82130 (when (flag-set? 'dump 'trace )
131+ (trace-sync)
83132 (call-with-output-file "dump-trace.json " #:exists 'append (λ (out) (fprintf out "]}\n " )))))
84133
85134(define old-exit (exit-handler))
153202
154203(define (manager-ask msg . args)
155204 (log "Asking manager: ~a.\n " msg)
205+ (trace-sync)
156206 (match manager
157207 [(? place? x) (apply manager-ask-threaded x msg args)]
158208 ['basic (apply manager-ask-basic msg args)]))
You can’t perform that action at this time.
0 commit comments