Index: utils/Makefile.whodunit ================================================================== --- utils/Makefile.whodunit +++ utils/Makefile.whodunit @@ -3,7 +3,7 @@ all : whodunit clean : rm whodunit -whodunit : +whodunit : whodunit.scm csc -static -L -static -L -lm -L -ldl -L -lpthread -L -lssl -L -lcrypto -L -lz whodunit.scm -o whodunit Index: utils/whodunit.scm ================================================================== --- utils/whodunit.scm +++ utils/whodunit.scm @@ -22,10 +22,11 @@ (import (chicken process-context) (chicken process) (chicken string) + (chicken base) (chicken sort) (chicken io) srfi-69 scheme ) @@ -61,25 +62,26 @@ (usr (cadr indat)) (cpu (list-ref indat 8))) (hash-table-set! ht usr (+ cpu (hash-table-ref/default ht usr 0))))) data)) +(define (print-results userhash) + (for-each + (lambda (usr) + (let* ((usage (inexact->exact (round (/ (hash-table-ref userhash usr) *numsamples*))))) + (if (> usage 0) + (print usr (if (< (string-length usr) 8) "\t\t" "\t") usage)))) + (sort (hash-table-keys userhash) + (lambda (a b) + (> (hash-table-ref userhash a) + (hash-table-ref userhash b)))))) + ) (import whodunit srfi-69 (chicken sort)) (print "Getting " *numsamples* " samples of cpu usage data.") (define data (cleanup-data (topdata))) (define pidhash (make-hash-table)) (define userhash (make-hash-table)) (sum-up data userhash) - -(for-each - (lambda (usr) - (let* ((usage (inexact->exact (round (/ (hash-table-ref userhash usr) *numsamples*))))) - (if (> usage 0) - (print usr (if (< (string-length usr) 8) "\t\t" "\t") usage)))) - (sort (hash-table-keys userhash) - (lambda (a b) - (> (hash-table-ref userhash a) - (hash-table-ref userhash b))))) - +(print-results userhash)