|
2 | 2 |
|
3 | 3 | (require openssl/sha1) |
4 | 4 | (require (only-in xml write-xexpr)) |
| 5 | +(require json) |
5 | 6 |
|
6 | 7 | (require "../syntax/read.rkt" |
7 | 8 | "../syntax/sugar.rkt" |
|
18 | 19 | "../reports/history.rkt" |
19 | 20 | "../reports/pages.rkt" |
20 | 21 | "../reports/plot.rkt" |
| 22 | + "../config.rkt" |
21 | 23 | "datafile.rkt" |
22 | 24 | "sandbox.rkt" |
23 | 25 | (submod "../utils/timeline.rkt" debug)) |
|
37 | 39 | (when false |
38 | 40 | (apply eprintf msg args))) |
39 | 41 |
|
| 42 | +;; Tracing support |
| 43 | + |
| 44 | +(define (current-thread-id) |
| 45 | + (equal-hash-code (current-thread))) |
| 46 | + |
| 47 | +(define (current-timestamp) |
| 48 | + (exact-floor (* 1000 (current-inexact-milliseconds)))) |
| 49 | + |
| 50 | +(define (trace-start) |
| 51 | + (when (flag-set? 'dump 'trace) |
| 52 | + (call-with-output-file |
| 53 | + "dump-trace.json" |
| 54 | + #:exists 'truncate |
| 55 | + (λ (out) |
| 56 | + (fprintf out "{\"traceEvents\":[") |
| 57 | + (write-json (hash 'name "process_name" 'ph "M" 'ts 0 'pid 0 'tid 0 'args (hash 'name "herbie")) |
| 58 | + out))))) |
| 59 | + |
| 60 | +(define (trace name phase [args (hash)]) |
| 61 | + (when (flag-set? 'dump 'trace) |
| 62 | + (call-with-output-file "dump-trace.json" |
| 63 | + #:exists 'append |
| 64 | + (λ (out) |
| 65 | + (fprintf out ",") |
| 66 | + (write-json (hash 'name |
| 67 | + (~a name) |
| 68 | + 'ph |
| 69 | + (~a phase) |
| 70 | + 'ts |
| 71 | + (current-timestamp) |
| 72 | + 'pid |
| 73 | + 0 |
| 74 | + 'tid |
| 75 | + (current-thread-id) |
| 76 | + 'args |
| 77 | + args) |
| 78 | + out))))) |
| 79 | + |
| 80 | +(define (trace-end) |
| 81 | + (when (flag-set? 'dump 'trace) |
| 82 | + (call-with-output-file "dump-trace.json" #:exists 'append (λ (out) (fprintf out "]}\n"))))) |
| 83 | + |
| 84 | +(define old-exit (exit-handler)) |
| 85 | +(exit-handler (λ (v) |
| 86 | + (trace-end) |
| 87 | + (old-exit v))) |
| 88 | + |
40 | 89 | ;; Job-specific public API |
41 | 90 | (define (job-path id) |
42 | 91 | (format "~a.~a" id *herbie-commit*)) |
|
71 | 120 | ;; Whole-server public methods |
72 | 121 |
|
73 | 122 | (define (server-start threads) |
| 123 | + (trace-start) |
74 | 124 | (cond |
75 | 125 | [threads |
76 | 126 | (eprintf "Starting Herbie ~a with ~a workers and seed ~a...\n" |
|
321 | 371 |
|
322 | 372 | (define (herbie-do-server-job h-command job-id) |
323 | 373 | (match-define (herbie-command command test seed pcontext profile? timeline?) h-command) |
324 | | - (log "Started ~a job (~a): ~a\n" command job-id (test-name test)) |
| 374 | + (define metadata (hash 'job-id job-id 'command (~a command) 'name (test-name test))) |
| 375 | + (trace 'herbie 'B metadata) |
325 | 376 | (define herbie-result |
326 | 377 | (run-herbie command |
327 | 378 | test |
328 | 379 | #:seed seed |
329 | 380 | #:pcontext pcontext |
330 | 381 | #:profile? profile? |
331 | 382 | #:timeline? timeline?)) |
332 | | - (log "Completed ~a job (~a), starting reporting\n" command job-id) |
| 383 | + (trace 'herbie 'E metadata) |
| 384 | + (trace 'to-json 'B metadata) |
333 | 385 | (define basic-output ((get-json-converter command) herbie-result job-id)) |
334 | | - (log "Completed reporting ~a job (~a)\n" command job-id) |
| 386 | + (trace 'to-json 'E metadata) |
335 | 387 | ;; Add default fields that all commands have |
336 | 388 | (hash-set* basic-output |
337 | 389 | 'job |
|
0 commit comments