2003-01-19 11:57:27 -05:00
|
|
|
(define-structure surflet surflet-interface
|
2002-12-08 10:49:27 -05:00
|
|
|
(open scheme-with-scsh
|
2003-01-19 11:57:27 -05:00
|
|
|
surflets
|
2003-03-13 06:36:49 -05:00
|
|
|
surflets/error
|
2002-10-01 13:44:58 -04:00
|
|
|
profiling
|
|
|
|
handle-fatal-error
|
2002-10-02 19:45:35 -04:00
|
|
|
(subset srfi-1 (iota))
|
2002-10-21 04:34:12 -04:00
|
|
|
define-record-types
|
2002-10-02 21:25:47 -04:00
|
|
|
locks
|
2002-10-01 13:44:58 -04:00
|
|
|
let-opt
|
2003-01-16 06:10:38 -05:00
|
|
|
receiving
|
2003-03-13 06:36:49 -05:00
|
|
|
(subset primitives (add-finalizer!))
|
2002-10-01 13:44:58 -04:00
|
|
|
)
|
|
|
|
(begin
|
|
|
|
|
2002-10-02 19:45:35 -04:00
|
|
|
;; This uses the filesystem heavily to not influence the
|
|
|
|
;; profiling. Note to get the resulting picture, gnuplot must be
|
|
|
|
;; installed.
|
|
|
|
|
2002-10-21 04:34:12 -04:00
|
|
|
(define-record-type state :state
|
|
|
|
(make-state file-name file-names-to-delete counter)
|
|
|
|
state?
|
2003-01-17 12:47:31 -05:00
|
|
|
(file-name state:file-name set-state:file-name!)
|
|
|
|
(file-names-to-delete state:file-names-to-delete set-state:file-names-to-delete!)
|
|
|
|
(counter state:counter set-state:counter!))
|
2002-10-02 21:25:47 -04:00
|
|
|
|
|
|
|
(define (state-file-name)
|
2003-03-09 13:03:15 -05:00
|
|
|
(state:file-name (get-session-data)))
|
2002-10-02 21:25:47 -04:00
|
|
|
(define (state-file-names-to-delete)
|
2003-03-09 13:03:15 -05:00
|
|
|
(state:file-names-to-delete (get-session-data)))
|
2002-10-02 21:25:47 -04:00
|
|
|
(define (state-counter)
|
2003-03-09 13:03:15 -05:00
|
|
|
(state:counter (get-session-data)))
|
2003-01-17 12:47:31 -05:00
|
|
|
|
2003-01-16 06:10:38 -05:00
|
|
|
;; Leave this global. Servers are running on a single system.
|
|
|
|
(define gnuplot #f) ;; Set in main.
|
2003-02-19 13:26:10 -05:00
|
|
|
(define convert #f)
|
|
|
|
(define use-convert? #f)
|
2002-10-02 21:25:47 -04:00
|
|
|
(define lock (make-lock))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
|
|
|
(define (profile req . maybe-update-text)
|
|
|
|
(let* ((update-text (:optional maybe-update-text ""))
|
2003-07-08 17:22:06 -04:00
|
|
|
(gnuplot-input-field (make-text-field gnuplot '(@ (size 20))))
|
2003-02-19 13:26:10 -05:00
|
|
|
(gnuplot-change-button (make-submit-button "Change"))
|
2003-07-08 17:22:06 -04:00
|
|
|
(convert-check-box (make-checkbox use-convert?))
|
|
|
|
(convert-input-field (make-text-field convert '(@ (size 20))))
|
2003-02-19 13:26:10 -05:00
|
|
|
(convert-change-button (make-submit-button "Change"))
|
2002-10-02 16:15:54 -04:00
|
|
|
(new-profile-address (make-address))
|
|
|
|
(result-address (make-address))
|
|
|
|
(reset-address (make-address))
|
|
|
|
(return-address (make-address))
|
|
|
|
(reset-return-address (make-address))
|
2002-10-01 13:44:58 -04:00
|
|
|
(req
|
|
|
|
(send-html/suspend
|
|
|
|
(lambda (new-url)
|
|
|
|
`(html
|
2003-01-19 11:57:27 -05:00
|
|
|
(title "SUrflet Administration -- Profiling")
|
|
|
|
(body (h1 "SUrflet Administration")
|
2002-10-01 13:44:58 -04:00
|
|
|
(h2 "Profiling")
|
2003-01-15 09:42:32 -05:00
|
|
|
(p "Note: The operations performable via this interface take a while depending on the speed of the machine the server is running. Please be patient.")
|
2003-02-19 13:26:10 -05:00
|
|
|
,(emph update-text)
|
2002-10-02 21:25:47 -04:00
|
|
|
(p "Currently, there are " ,(state-counter) " profiles saved.")
|
2002-10-01 13:44:58 -04:00
|
|
|
(ul
|
2003-03-10 04:23:41 -05:00
|
|
|
(li (url ,(new-profile-address new-url)
|
2003-01-15 09:42:32 -05:00
|
|
|
"Create new profile"))
|
2003-03-10 04:23:41 -05:00
|
|
|
(li (url ,(result-address new-url)
|
2002-10-02 15:13:14 -04:00
|
|
|
"Show profile results")
|
2002-10-01 13:44:58 -04:00
|
|
|
(br)
|
2003-01-19 11:57:27 -05:00
|
|
|
(surflet-form
|
2002-10-01 13:44:58 -04:00
|
|
|
,new-url
|
2002-10-09 11:14:54 -04:00
|
|
|
POST
|
2003-02-19 13:26:10 -05:00
|
|
|
(table
|
|
|
|
(@ (border 0))
|
|
|
|
(thead)
|
|
|
|
(tfoot)
|
|
|
|
(tbody
|
|
|
|
(@ (valign "top"))
|
|
|
|
(tr
|
|
|
|
(td)
|
|
|
|
(td "This uses " (var "gnuplot") " that is searched at ")
|
|
|
|
(td ,(executable-input gnuplot-input-field
|
|
|
|
gnuplot
|
|
|
|
gnuplot-change-button)))
|
|
|
|
(tr
|
|
|
|
(td ,convert-check-box)
|
|
|
|
(td "This uses " (var "convert") " that is searched at ")
|
|
|
|
(td ,(executable-input convert-input-field
|
|
|
|
convert
|
|
|
|
convert-change-button)))
|
|
|
|
))))
|
2003-03-10 04:23:41 -05:00
|
|
|
(li (url ,(reset-address new-url)
|
2003-01-15 09:42:32 -05:00
|
|
|
"Delete files and reset profile state.")))
|
2002-10-02 15:13:14 -04:00
|
|
|
(hr)
|
2003-03-10 04:23:41 -05:00
|
|
|
(url ,(return-address new-url)
|
2002-10-21 04:38:46 -04:00
|
|
|
"Return to administration menu leaving files and state untouched.")
|
2002-10-02 15:13:14 -04:00
|
|
|
(br)
|
2003-03-10 04:23:41 -05:00
|
|
|
(url ,(reset-return-address new-url)
|
2002-10-21 04:38:46 -04:00
|
|
|
"Return to administration menu removing files and reseting state.")
|
|
|
|
(br)
|
2003-03-10 04:23:41 -05:00
|
|
|
(url "/" "Return to main menu."))))))
|
2002-10-01 13:44:58 -04:00
|
|
|
(bindings (get-bindings req)))
|
2002-10-02 15:13:14 -04:00
|
|
|
(cond
|
2002-10-02 16:15:54 -04:00
|
|
|
((returned-via? new-profile-address bindings)
|
2002-10-02 15:13:14 -04:00
|
|
|
(new-profile req))
|
2002-10-02 16:15:54 -04:00
|
|
|
((returned-via? result-address bindings)
|
2002-10-02 21:25:47 -04:00
|
|
|
(if (zero? (state-counter))
|
2002-10-02 19:45:35 -04:00
|
|
|
(profile req "Now profiles created, currently. Select 'Create new profile' to create one.")
|
|
|
|
(result req)))
|
2002-10-02 16:15:54 -04:00
|
|
|
((returned-via? reset-address bindings)
|
2002-10-02 15:13:14 -04:00
|
|
|
(reset req))
|
2002-10-02 16:15:54 -04:00
|
|
|
((returned-via? return-address bindings)
|
|
|
|
(return-to-main-page req))
|
|
|
|
((returned-via? reset-return-address bindings)
|
2002-10-02 15:13:14 -04:00
|
|
|
(reset-and-return-to-main-page req))
|
2003-02-19 13:34:48 -05:00
|
|
|
((returned-via? gnuplot-change-button bindings)
|
2003-02-19 13:26:10 -05:00
|
|
|
(let ((new-gnuplot-location (input-field-value gnuplot-input-field bindings)))
|
|
|
|
(if (executable? new-gnuplot-location)
|
2002-10-02 15:13:14 -04:00
|
|
|
(begin
|
|
|
|
(set! gnuplot new-gnuplot-location)
|
|
|
|
(profile req (format #f "Gnuplot is now searched at ~a." gnuplot)))
|
2003-02-19 13:26:10 -05:00
|
|
|
(profile req "Please enter a file name of an existing executable."))))
|
2003-02-19 13:34:48 -05:00
|
|
|
((returned-via? convert-change-button bindings)
|
2003-02-19 13:26:10 -05:00
|
|
|
(let ((new-use-convert? (input-field-value convert-check-box bindings))
|
|
|
|
(new-convert-location (input-field-value convert-input-field bindings)))
|
|
|
|
(if (equal? use-convert? new-use-convert?)
|
|
|
|
(if (executable? new-convert-location)
|
|
|
|
(begin
|
|
|
|
(set! convert new-convert-location)
|
|
|
|
(profile req (format #f "Convert is now searched at ~a." convert)))
|
|
|
|
(profile req "Please enter a file name of an existing executable."))
|
|
|
|
(if (equal? new-convert-location convert)
|
|
|
|
(begin
|
|
|
|
(set! use-convert? new-use-convert?)
|
|
|
|
(profile req (format #f "Convert is ~a used now."
|
|
|
|
(if use-convert? "" "not"))))
|
|
|
|
(begin
|
|
|
|
(if (executable? new-convert-location)
|
|
|
|
(begin
|
|
|
|
(set! use-convert? new-use-convert?)
|
|
|
|
(set! convert new-convert-location)
|
|
|
|
(profile req (format #f "Convert (at ~a) is ~a used now."
|
|
|
|
convert
|
|
|
|
(if use-convert? "" "not"))))
|
|
|
|
(profile req (format #f "Please enter a file name of an existing executable."))))))))
|
|
|
|
(else
|
|
|
|
(error "Unexpected choice.")))))
|
2003-01-16 06:10:38 -05:00
|
|
|
|
2003-02-19 13:26:10 -05:00
|
|
|
(define (executable? file-name)
|
|
|
|
(and file-name
|
|
|
|
(file-executable? file-name)))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
|
|
|
(define (new-profile req)
|
2003-03-09 13:03:15 -05:00
|
|
|
(let ((state (get-session-data)))
|
2002-10-02 21:25:47 -04:00
|
|
|
(format #t "profiling...~%")
|
|
|
|
(obtain-lock lock)
|
|
|
|
(profile-space (state:file-name state))
|
|
|
|
(release-lock lock)
|
|
|
|
(format #t "profile recorded in ~s~%" (state:file-name state))
|
2003-01-17 12:47:31 -05:00
|
|
|
(set-state:counter! state (+ 1 (state:counter state)))
|
2002-10-02 21:25:47 -04:00
|
|
|
(profile req (format #f "Profile #~a generated" (state:counter state)))))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
|
|
|
(define (result req)
|
2002-10-02 21:25:47 -04:00
|
|
|
(let ((results (profile-results (state-file-name)))
|
2003-01-19 11:57:27 -05:00
|
|
|
(gnuplot-data-file-name (create-temp-file "surflet-profiling.data"))
|
2003-02-19 13:26:10 -05:00
|
|
|
(gnuplot-picture-name (create-empty-picture-file
|
2003-01-19 11:57:27 -05:00
|
|
|
"../img/surflet-profiling.picture"
|
2003-01-15 09:42:32 -05:00
|
|
|
".pbm"))
|
2003-02-19 13:26:10 -05:00
|
|
|
(convert-picture-name (create-empty-picture-file
|
|
|
|
"../img/surflet-profiling.picture"
|
|
|
|
".png"))
|
2002-10-02 19:45:35 -04:00
|
|
|
(get-total-bytes (lambda (space-info)
|
2002-10-02 21:25:47 -04:00
|
|
|
(total-bytes (space-info-total space-info))))
|
|
|
|
(return-address (make-address))
|
|
|
|
(reset-return-address (make-address)))
|
2002-10-01 13:44:58 -04:00
|
|
|
(write-gnuplot-data-file gnuplot-data-file-name
|
2002-10-02 19:45:35 -04:00
|
|
|
get-total-bytes
|
2002-10-01 13:44:58 -04:00
|
|
|
results)
|
2003-02-19 13:26:10 -05:00
|
|
|
(let* ((gnuplot-status
|
|
|
|
(run (,gnuplot -)
|
2002-10-22 11:34:59 -04:00
|
|
|
(<< ,(format #f "set terminal pbm color
|
2002-10-01 13:44:58 -04:00
|
|
|
set output '~a'
|
2002-10-22 12:05:18 -04:00
|
|
|
set size 0.7,0.7
|
2003-01-19 11:57:27 -05:00
|
|
|
plot '~a' title 'SUrflet Profiling ~a' with lines"
|
2003-02-19 13:26:10 -05:00
|
|
|
gnuplot-picture-name
|
2002-10-01 13:44:58 -04:00
|
|
|
gnuplot-data-file-name
|
|
|
|
(format-date "~c" (date))
|
2003-02-19 13:26:10 -05:00
|
|
|
))))
|
|
|
|
(convert-status (and use-convert?
|
|
|
|
(zero? gnuplot-status)
|
|
|
|
(run (,convert ,gnuplot-picture-name
|
|
|
|
,convert-picture-name)))))
|
2002-10-01 13:44:58 -04:00
|
|
|
(delete-file gnuplot-data-file-name)
|
2003-02-19 13:26:10 -05:00
|
|
|
(add-file-name-to-delete! gnuplot-picture-name)
|
|
|
|
(if (and use-convert?
|
|
|
|
(not (zero? convert-status)))
|
|
|
|
(add-file-name-to-delete! convert-picture-name))
|
|
|
|
(let* ((req (show-results gnuplot-status gnuplot-picture-name
|
|
|
|
convert-status convert-picture-name
|
|
|
|
get-total-bytes results
|
2002-10-02 21:25:47 -04:00
|
|
|
return-address reset-return-address))
|
|
|
|
(bindings (get-bindings req)))
|
|
|
|
(cond
|
|
|
|
((returned-via? return-address bindings)
|
|
|
|
(profile req "You may continue to make profiles."))
|
|
|
|
((returned-via? reset-return-address bindings)
|
|
|
|
(reset-and-return-to-main-page req))
|
|
|
|
(else
|
|
|
|
(error "unexpected return address")))))))
|
2003-01-15 09:42:32 -05:00
|
|
|
|
|
|
|
(define create-empty-picture-file
|
|
|
|
(let ((lock (make-lock)))
|
|
|
|
(lambda (file-prefix file-suffix)
|
|
|
|
(obtain-lock lock)
|
|
|
|
(let* ((tmp-file-name (create-temp-file file-prefix))
|
|
|
|
(picture-file-name (string-append tmp-file-name file-suffix)))
|
|
|
|
(rename-file tmp-file-name picture-file-name)
|
|
|
|
(release-lock lock)
|
|
|
|
picture-file-name))))
|
2002-10-02 21:25:47 -04:00
|
|
|
|
2003-02-19 13:26:10 -05:00
|
|
|
(define (show-results gnuplot-status gnuplot-picture-name
|
|
|
|
convert-status convert-picture-name
|
|
|
|
get-total-bytes results
|
2002-10-02 21:25:47 -04:00
|
|
|
return-address reset-return-address)
|
|
|
|
(send-html/suspend
|
|
|
|
(lambda (new-url)
|
|
|
|
`(html
|
2003-01-19 11:57:27 -05:00
|
|
|
(title "SUrflet Administration -- Profiling Results")
|
2002-10-02 21:25:47 -04:00
|
|
|
(body
|
2003-01-19 11:57:27 -05:00
|
|
|
(h1 "SUrflet-Administration")
|
2002-10-02 21:25:47 -04:00
|
|
|
(h2 "Profiling Results")
|
|
|
|
(h3 "Picture")
|
2003-02-19 13:26:10 -05:00
|
|
|
,(if (zero? gnuplot-status)
|
|
|
|
(if use-convert?
|
|
|
|
(if (zero? convert-status)
|
|
|
|
`(image (@ (src ,convert-picture-name)))
|
2005-04-14 04:53:44 -04:00
|
|
|
`(p "An error occurred while generating the profiling results"
|
2003-02-19 13:26:10 -05:00
|
|
|
" chart with convert (" ,convert ")."
|
|
|
|
" Anyway, you can download the "
|
2003-03-10 04:23:41 -05:00
|
|
|
(url ,gnuplot-picture-name "raw profiling chart") "."))
|
|
|
|
`(url ,gnuplot-picture-name "Profiling chart."))
|
2005-04-14 04:53:44 -04:00
|
|
|
`(p "An error occurred while generating the profiling results picture."
|
2002-10-02 21:25:47 -04:00
|
|
|
(br)
|
|
|
|
"Are you sure, you have " (q "gnuplot")
|
|
|
|
" installed at " (q ,gnuplot) "?"))
|
|
|
|
(hr)
|
|
|
|
(h3 "Data")
|
|
|
|
(table
|
|
|
|
(tr (th "#") (th "Total bytes occupied"))
|
|
|
|
,@(map (lambda (num space-info)
|
|
|
|
`(tr (td ,(+ 1 num))
|
|
|
|
(td ,(get-total-bytes space-info))))
|
|
|
|
(iota (length results))
|
|
|
|
results))
|
|
|
|
(hr)
|
2003-03-10 04:23:41 -05:00
|
|
|
(p (url ,(return-address new-url) "Return to previous page") (br)
|
|
|
|
(url ,(reset-return-address new-url)
|
2002-10-22 12:05:18 -04:00
|
|
|
"Delete files, reset state and return to main menu.")))))))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
|
|
|
(define (reset req)
|
|
|
|
(reset-profiling-state!)
|
2002-10-02 15:13:14 -04:00
|
|
|
(profile req "Profiling state reseted."))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
2002-10-02 21:25:47 -04:00
|
|
|
(define (add-file-name-to-delete! file-name)
|
2003-03-09 13:03:15 -05:00
|
|
|
(let ((state (get-session-data)))
|
2003-01-17 12:47:31 -05:00
|
|
|
(set-state:file-names-to-delete!
|
2002-10-02 21:25:47 -04:00
|
|
|
state
|
|
|
|
(cons file-name
|
|
|
|
(state:file-names-to-delete state)))))
|
|
|
|
|
|
|
|
(define (delete-files state)
|
|
|
|
(let ((file-names-to-delete (state:file-names-to-delete state)))
|
|
|
|
(if file-names-to-delete
|
|
|
|
(for-each delete-filesys-object file-names-to-delete))))
|
2002-10-02 19:45:35 -04:00
|
|
|
|
2002-10-02 15:13:14 -04:00
|
|
|
(define (reset-profiling-state!)
|
2003-03-09 13:03:15 -05:00
|
|
|
(let ((state (get-session-data)))
|
2003-01-17 12:47:31 -05:00
|
|
|
(set-state:counter! state 0)
|
2002-10-02 21:25:47 -04:00
|
|
|
(delete-files state)
|
2003-01-17 12:47:31 -05:00
|
|
|
(set-state:file-name! state
|
2003-01-19 11:57:27 -05:00
|
|
|
(absolute-file-name (create-temp-file "surflet-profiling")))
|
2003-01-17 12:47:31 -05:00
|
|
|
(set-state:file-names-to-delete! state
|
|
|
|
(list (state:file-name state)))))
|
2002-10-02 21:25:47 -04:00
|
|
|
|
2002-10-01 13:44:58 -04:00
|
|
|
(define (reset-and-return-to-main-page req)
|
2002-10-02 21:25:47 -04:00
|
|
|
;; Overhead included :-|
|
2002-10-01 13:44:58 -04:00
|
|
|
(reset-profiling-state!)
|
2003-03-09 13:03:15 -05:00
|
|
|
(delete-files (get-session-data))
|
2002-10-02 19:45:35 -04:00
|
|
|
(return-to-main-page req))
|
2002-10-02 15:13:14 -04:00
|
|
|
|
|
|
|
(define (return-to-main-page req)
|
2003-01-25 08:42:50 -05:00
|
|
|
(send-error (status-code moved-perm) req
|
|
|
|
"admin.scm" "admin.scm"))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
|
|
|
(define (main req)
|
2002-10-02 21:25:47 -04:00
|
|
|
;; We'll fill this out soon.
|
2003-02-19 13:26:10 -05:00
|
|
|
(set! gnuplot (search-executable "gnuplot"))
|
|
|
|
(if (string=? gnuplot "")
|
|
|
|
(begin
|
|
|
|
(set! use-convert? #f)
|
|
|
|
(set! convert ""))
|
|
|
|
(begin
|
|
|
|
(set! convert (search-executable "convert"))
|
|
|
|
(if (string=? convert "")
|
|
|
|
(set! use-convert? #f)
|
|
|
|
(set! use-convert? #t))))
|
2003-03-09 13:03:15 -05:00
|
|
|
(set-session-data! (make-state #f #f 0))
|
2002-10-02 19:45:35 -04:00
|
|
|
(reset-profiling-state!)
|
2003-01-18 10:02:22 -05:00
|
|
|
;; Remove state files if user did not do it.
|
2003-03-09 13:03:15 -05:00
|
|
|
(add-finalizer! (get-session-data) delete-files)
|
2002-10-01 13:44:58 -04:00
|
|
|
(profile req))
|
|
|
|
|
2003-02-19 13:26:10 -05:00
|
|
|
(define (search-executable exec-name)
|
2003-02-19 13:45:57 -05:00
|
|
|
(with-fatal-error-handler
|
|
|
|
;; If `which' is unavailable, return nothing.
|
|
|
|
(lambda (condition decline) "")
|
|
|
|
(receive (status ports) (run/collecting (1) (which ,exec-name))
|
|
|
|
(if (zero? status)
|
|
|
|
(read-line ports)
|
|
|
|
""))))
|
2003-02-19 13:26:10 -05:00
|
|
|
|
|
|
|
(define (emph text)
|
|
|
|
`(font (@ (color "red")) ,text))
|
|
|
|
|
|
|
|
(define (executable-input input-field exec-name change-button)
|
|
|
|
`(table
|
|
|
|
(@ (border 0))
|
|
|
|
(tr (td ,input-field) (td ,change-button))
|
|
|
|
,(if (executable? exec-name)
|
|
|
|
#f
|
|
|
|
`(tr (td (@ (colspan 2))
|
|
|
|
,(emph "Note: There is no executable."))))))
|
|
|
|
|
2002-10-01 13:44:58 -04:00
|
|
|
))
|