perf-series.scm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env guile
  2. !#
  3. (use-modules (charting) (charting csv) (ice-9 match)
  4. ((ice-9 rdelim) #:select (read-line))
  5. ((srfi srfi-1) #:select (filter-map append-map)))
  6. (define (parse-scenario data)
  7. (let lp ((in data) (out '()))
  8. (if (null? in)
  9. (filter-map string->number out)
  10. (lp (cdr in) (append (vector->list (car in)) out)))))
  11. (define numeric-chars char-set:digit)
  12. (define (scenario-name file)
  13. (let* ((end (or (string-index-right file numeric-chars)
  14. (error "not numeric" file)))
  15. (start (or (string-index-right file (char-set-complement numeric-chars) 0 end) -1)))
  16. (string->number (substring file (1+ start) (1+ end)))))
  17. (define (read-scenario file)
  18. (let ((rows (csv-port->row-list (open-input-file file) #\tab)))
  19. (or (= (vector-length (car rows)) 1)
  20. (error "expected only one row"))
  21. (cons (scenario-name file) (parse-scenario (cdr rows)))))
  22. (define (read-annotations file)
  23. (with-input-from-file file
  24. (lambda ()
  25. (let lp ((annotations '()))
  26. (let ((line (read-line)))
  27. (if (eof-object? line)
  28. (reverse annotations)
  29. (lp (cons (* (floor-remainder (string->number (substring line 0 (string-index line #\space))) 1.0) 1000)
  30. annotations))))))))
  31. (define (main args)
  32. (match args
  33. ((title output annotations file file* ...)
  34. (unless (string-suffix? ".png" output)
  35. ;; Otherwise we would have the possibility of overwriting data.
  36. ;; That would be bad!
  37. (format (current-error-port)
  38. "Error: output name does not end with .png: ~a\n" output)
  39. (exit 1))
  40. (make-performance-series title (map read-scenario (cons file file*))
  41. #:annotations (read-annotations annotations)
  42. #:write-to-png output))
  43. (_
  44. (format (current-error-port)
  45. "Usage: perf-series.scm title output annotations file1 file2 ...
  46. The files are expected to be in CSV format, with one row of headers,
  47. and one row per run. The different file names identify the different
  48. scenarios that you want to compare.
  49. ")
  50. (exit 1))))
  51. (main (cdr (command-line)))