Add raco profile.
This commit is contained in:
parent
70c723e3ae
commit
a834da0a86
|
@ -8,6 +8,16 @@
|
||||||
|
|
||||||
@title{Toplevel Interface}
|
@title{Toplevel Interface}
|
||||||
|
|
||||||
|
@index["raco profile"]{
|
||||||
|
The profiler can be invoked directly from the command-line using the
|
||||||
|
@exec{raco profile} command, which takes a file name as argument, and runs the
|
||||||
|
profiler on the @racket[main] submodule of that file (if it exists), or on the
|
||||||
|
module itself (if there is no @racket[main] submodule).
|
||||||
|
|
||||||
|
To allow control over its behavior, @exec{raco profile} accepts flags that
|
||||||
|
correspond to those of @racket[profile-thunk] below.
|
||||||
|
}
|
||||||
|
|
||||||
@defmodule[profile]
|
@defmodule[profile]
|
||||||
|
|
||||||
This module provides one procedure and one macro that are convenient
|
This module provides one procedure and one macro that are convenient
|
||||||
|
|
|
@ -8,3 +8,9 @@
|
||||||
(define pkg-desc "implementation (no documentation) part of \"profile\"")
|
(define pkg-desc "implementation (no documentation) part of \"profile\"")
|
||||||
|
|
||||||
(define pkg-authors '(eli stamourv))
|
(define pkg-authors '(eli stamourv))
|
||||||
|
|
||||||
|
(define raco-commands
|
||||||
|
'(("profile"
|
||||||
|
profile/raco
|
||||||
|
"profile execution time"
|
||||||
|
#f)))
|
||||||
|
|
12
profile-lib/raco-utils.rkt
Normal file
12
profile-lib/raco-utils.rkt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
(provide module-to-profile)
|
||||||
|
|
||||||
|
(define (module-to-profile file)
|
||||||
|
;; check if there's a main submodule
|
||||||
|
(define file-path `(file ,file))
|
||||||
|
(define main-path `(submod ,file-path main))
|
||||||
|
(dynamic-require file-path (void)) ; visit the module, but don't run it
|
||||||
|
(if (module-declared? main-path #f)
|
||||||
|
main-path
|
||||||
|
file-path))
|
63
profile-lib/raco.rkt
Normal file
63
profile-lib/raco.rkt
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
(require racket/cmdline
|
||||||
|
raco/command-name
|
||||||
|
errortrace/errortrace-lib
|
||||||
|
"main.rkt" "raco-utils.rkt")
|
||||||
|
|
||||||
|
;; raco profile
|
||||||
|
;; profile the main submodule (if there is one), or the top-level module
|
||||||
|
|
||||||
|
(define delay #f)
|
||||||
|
(define iterations #f)
|
||||||
|
(define threads? #f)
|
||||||
|
(define use-errortrace? #f)
|
||||||
|
(define file
|
||||||
|
(command-line #:program (short-program+command-name)
|
||||||
|
#:once-each
|
||||||
|
[("--delay") n
|
||||||
|
"Sampling rate (seconds)"
|
||||||
|
(let ([n* (string->number n)])
|
||||||
|
(unless (real? n)
|
||||||
|
(raise-argument-error 'raco-profile "real?" n*))
|
||||||
|
(set! delay n*))]
|
||||||
|
[("--repeat") n
|
||||||
|
"Number of iterations"
|
||||||
|
(let ([n* (string->number n)])
|
||||||
|
(unless (integer?)
|
||||||
|
(raise-argument-error 'raco-profile "integer?" n*))
|
||||||
|
(set! iterations n*))]
|
||||||
|
[("--all-threads")
|
||||||
|
"Profile all threads"
|
||||||
|
(set! threads? #t)]
|
||||||
|
[("--use-errortrace")
|
||||||
|
"Use errortrace mode"
|
||||||
|
(set! use-errortrace? #t)]
|
||||||
|
#:args (filename)
|
||||||
|
filename))
|
||||||
|
|
||||||
|
(parameterize ([current-compile
|
||||||
|
(if use-errortrace?
|
||||||
|
(make-errortrace-compile-handler)
|
||||||
|
(current-compile))])
|
||||||
|
(define (t) (dynamic-require (module-to-profile file) #f))
|
||||||
|
(cond [(and delay iterations)
|
||||||
|
(profile-thunk t
|
||||||
|
#:delay delay
|
||||||
|
#:repeat iterations
|
||||||
|
#:threads threads?
|
||||||
|
#:use-errortrace? use-errortrace?)]
|
||||||
|
[delay
|
||||||
|
(profile-thunk t
|
||||||
|
#:delay delay
|
||||||
|
#:threads threads?
|
||||||
|
#:use-errortrace? use-errortrace?)]
|
||||||
|
[iterations
|
||||||
|
(profile-thunk t
|
||||||
|
#:repeat iterations
|
||||||
|
#:threads threads?
|
||||||
|
#:use-errortrace? use-errortrace?)]
|
||||||
|
[else
|
||||||
|
(profile-thunk t
|
||||||
|
#:threads threads?
|
||||||
|
#:use-errortrace? use-errortrace?)]))
|
Loading…
Reference in New Issue
Block a user