From c6c6744b22e2b041f93f5ec4df7b804909f0ce8f Mon Sep 17 00:00:00 2001 From: Nikolay Puzanov Date: Sun, 4 Dec 2022 10:20:53 +0300 Subject: [PATCH] Show execution time of compilation and simulation --- _web_server/server/playground-server.scm | 44 ++++++++++++++++-------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/_web_server/server/playground-server.scm b/_web_server/server/playground-server.scm index 4d59e1e..ee47771 100755 --- a/_web_server/server/playground-server.scm +++ b/_web_server/server/playground-server.scm @@ -205,6 +205,22 @@ (out (get-string-all p))) (values (close-pipe p) out))) +;;; +;;; Same as system-to-string but returns execution time (in ms) also +;;; +(define* (system-to-string-with-time cmd #:key (pwd #f)) + (let ((start-time (gettimeofday))) + (let-values + (((status out) + (system-to-string cmd #:pwd pwd))) + (let ((stop-time (gettimeofday))) + (values status out + (exact->inexact + (- (+ (* (car stop-time) 1000) + (/ (cdr stop-time) 1000)) + (+ (* (car start-time) 1000) + (/ (cdr start-time) 1000))))))))) + ;;; ;;; Execute system command and capture stdout and stderr to string list ;;; @@ -218,10 +234,10 @@ ;;; ;;; Make pretty log from executable output ;;; -(define (exe-log-pretty cmdline status out) +(define (exe-log-pretty cmdline status out time) (string-append (format "$ ~a\n" cmdline) - (format "Return code: ~a\n" status) + (format "Return code: ~a, Exec time: ~a ms\n" status time) (if (string-null? out) "\n" (format "--\n~a\n" out)))) @@ -339,19 +355,19 @@ (let ((cmdline (format "~a -g2012 -s __~a__ -o ~a -c~a" (wrap-exe IVERILOG-EXE iverilog-wrap) top exe-file command-file))) - (let-values (((status out) - (system-to-string cmdline))) + (let-values (((status out time) + (system-to-string-with-time cmdline))) (let ((compile-log - (exe-log-pretty cmdline status out))) + (exe-log-pretty cmdline status out time))) (if (not (zero? status)) (values status compile-log) ;; Execute (let ((cmdline (format "~a -N ~a" (wrap-exe VVP-EXE vvp-wrap) exe-file))) - (let-values (((status out) - (system-to-string cmdline))) + (let-values (((status out time) + (system-to-string-with-time cmdline))) (let ((execution-log - (exe-log-pretty cmdline status out))) + (exe-log-pretty cmdline status out time))) (values status (string-append compile-log execution-log))))))))))) ;;; @@ -364,20 +380,20 @@ (cmdline (format "~a -f ~a" (wrap-exe VERILATR-EXE verilator-wrap) command-file))) - (let-values (((status out) - (system-to-string cmdline))) + (let-values (((status out time) + (system-to-string-with-time cmdline))) (let ((compile-log - (exe-log-pretty cmdline status out))) + (exe-log-pretty cmdline status out time))) (if (not (zero? status)) (values status compile-log) ;; Execute (let ((cmdline (wrap-exe (path+ work-dir (format "~a/~a" top top)) verilator-sim-wrap))) - (let-values (((status out) - (system-to-string cmdline))) + (let-values (((status out time) + (system-to-string-with-time cmdline))) (let ((execution-log - (exe-log-pretty cmdline status out))) + (exe-log-pretty cmdline status out time))) (values status (string-append compile-log execution-log)))))))))) ;;;