Skip to content

Commit

Permalink
support csv output format in form performance report
Browse files Browse the repository at this point in the history
  • Loading branch information
countvajhula committed Jan 7, 2023
1 parent 4f4df31 commit 678fff9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions qi-sdk/info.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"math-lib"
"collections-lib"
"relation-lib"
"csv-writing"
"cover"
"cover-coveralls"))
(define build-deps '())
Expand Down
26 changes: 25 additions & 1 deletion qi-sdk/profile/report.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
relation
qi
json
csv-writing
(only-in "util.rkt"
only-if
for/call))
Expand Down Expand Up @@ -149,6 +150,22 @@
(usage (~a "Report on the performance of all of the forms "
"of the language, in JSON format.")))

(flag (output-format #:param [output-format "json"] fmt)
("-f" "--format" "Output format to use, either 'json' or 'csv'")
(output-format fmt))

(define (write-csv data)
(~> (data)
(>< (~> (-< (hash-ref 'name)
(hash-ref 'unit)
(hash-ref 'value))
▽))
(-< '(name unit value)
_)
display-table))

(program (main)
;; TODO: could use try-order? with hash-keys if support is dropped for Racket 8.3
(define fs (~>> (env) hash-keys (sort <)))
Expand All @@ -158,6 +175,13 @@
(define require-data (list (hash 'name "(require qi)"
'unit "ms"
'value (time-module-ms "qi"))))
(write-json (append forms-data require-data)))
(let ([output (append forms-data require-data)])
;; Note: this is a case where declaring "constraints" on the CLI args
;; would be useful, instead of using the ad hoc fallback `else` check here
;; https://github.com/countvajhula/cli/issues/6
(cond
[(equal? (output-format) "json") (write-json output)]
[(equal? (output-format) "csv") (write-csv output)]
[else (error "Unrecognized format!")])))

(run main)

0 comments on commit 678fff9

Please sign in to comment.