File tree Expand file tree Collapse file tree 4 files changed +54
-24
lines changed
Expand file tree Collapse file tree 4 files changed +54
-24
lines changed Original file line number Diff line number Diff line change 1313(define-json-union 1)
1414(call-with-read-lock 1)
1515(call-with-write-lock 1)
16+ (define-syntax-parse-rule 1)
Original file line number Diff line number Diff line change 1+ #lang racket/base
2+ (require racket/file
3+ racket/runtime-path
4+ racket/match
5+ racket/string
6+ racket/format)
7+
8+ (provide
9+ maybe-debug-log
10+ maybe-debug-file
11+ D
12+ T)
13+
14+ (define debug? #f )
15+
16+ (define-runtime-path df "debug.out.rkt " )
17+ (define (maybe-debug-file t)
18+ (when debug?
19+ (display-to-file t df #:exists 'replace )))
20+
21+ (define-runtime-path dp "debug.log " )
22+ (define (maybe-debug-log m)
23+ (when debug?
24+ (with-output-to-file dp
25+ #:exists 'append
26+ (lambda ()
27+ (writeln m)))))
28+
29+ (define (err-log tag name msg)
30+ (eprintf "[~a] ~a:\n~a\n " tag name msg))
31+
32+ ;; DEBUG macro: evaluates the expression, logs the result, and returns the result.
33+ (define-syntax-rule (D expr)
34+ (call-with-values
35+ (lambda () expr)
36+ (lambda results
37+ (err-log 'DEBUG (quote expr)
38+ (match results
39+ [(list) (format "void " )]
40+ [(list x) (~v x)]
41+ [_ (string-join (map ~v results) "\n " )]))
42+ (apply values results))))
43+
44+ ;; TIME macro: evaluates the expression, logs the time taken, and returns the result.
45+ (define-syntax-rule (T expr)
46+ (let-values ([(results cpu-time real-time gc-time)
47+ (time-apply (lambda () expr) '() )])
48+ (err-log 'TIME (quote expr)
49+ (format "cpu time: ~a real time: ~a gc time: ~a "
50+ cpu-time real-time gc-time))
51+ (apply values results)))
52+
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 88 racket/class
99 racket/async-channel
1010 "common/interfaces.rkt "
11- "lsp /debug.rkt "
11+ "common /debug.rkt "
1212 "lsp/methods.rkt "
1313 "lsp/msg-io.rkt "
1414 "lsp/responses.rkt " )
You can’t perform that action at this time.
0 commit comments