Skip to content

Commit 1de0798

Browse files
authored
Merge pull request #1364 from herbie-fp/codex/move-profiling-to-server.rkt
Move profiling into server
2 parents 10dbd46 + f33596d commit 1de0798

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

src/api/sandbox.rkt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#lang racket
22

3-
(require profile
4-
racket/engine
3+
(require racket/engine
54
json)
65

76
(require "../syntax/read.rkt"
@@ -22,7 +21,6 @@
2221
"../core/programs.rkt"
2322
"../core/points.rkt"
2423
"../core/explain.rkt"
25-
"../utils/profile.rkt"
2624
"../utils/timeline.rkt"
2725
(submod "../utils/timeline.rkt" debug))
2826

@@ -143,14 +141,8 @@
143141
;; Public interface
144142
;;
145143

146-
(define (run-herbie command
147-
test
148-
#:seed [seed #f]
149-
#:pcontext [pcontext #f]
150-
#:profile? [profile? #f]
151-
#:timeline? [timeline? #f])
144+
(define (run-herbie command test #:seed [seed #f] #:pcontext [pcontext #f] #:timeline? [timeline? #f])
152145
(define timeline #f)
153-
(define profile #f)
154146

155147
(define (on-exception start-time e)
156148
(parameterize ([*timeline-disabled* (not timeline?)])
@@ -195,15 +187,7 @@
195187
(job-result command test 'success time (timeline-extract) #f (warning-log) result))))
196188

197189
(define (in-engine _)
198-
(cond
199-
[profile?
200-
(define result
201-
(profile-thunk compute-result
202-
#:order 'total
203-
#:delay 0.05
204-
#:render (λ (p order) (set! profile (profile->json p)))))
205-
(struct-copy job-result result [profile profile])]
206-
[else (compute-result)]))
190+
(compute-result))
207191

208192
;; Branch on whether or not we should run inside an engine
209193
(define eng (engine in-engine))

src/api/server.rkt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
(require (only-in xml write-xexpr))
55
(require json)
66
(require data/queue)
7+
(require profile)
78

89
(require "../syntax/read.rkt"
910
"../syntax/sugar.rkt"
@@ -23,6 +24,7 @@
2324
"../config.rkt"
2425
"datafile.rkt"
2526
"sandbox.rkt"
27+
"../utils/profile.rkt"
2628
(submod "../utils/timeline.rkt" debug))
2729

2830
(provide job-path
@@ -375,13 +377,17 @@
375377
(match-define (herbie-command command test seed pcontext profile? timeline?) h-command)
376378
(define metadata (hash 'job-id job-id 'command (~a command) 'name (test-name test)))
377379
(trace 'herbie 'B metadata)
380+
(define run (λ () (run-herbie command test #:seed seed #:pcontext pcontext #:timeline? timeline?)))
378381
(define herbie-result
379-
(run-herbie command
380-
test
381-
#:seed seed
382-
#:pcontext pcontext
383-
#:profile? profile?
384-
#:timeline? timeline?))
382+
(if profile?
383+
(let ([profile-data #f])
384+
(define result
385+
(profile-thunk run
386+
#:order 'total
387+
#:delay 0.05
388+
#:render (λ (p order) (set! profile-data (profile->json p)))))
389+
(struct-copy job-result result [profile profile-data]))
390+
(run)))
385391
(trace 'herbie 'E metadata)
386392
(trace 'to-json 'B metadata)
387393
(define basic-output ((get-json-converter command) herbie-result job-id))

0 commit comments

Comments
 (0)