1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
(use posix srfi-69)
(define *numsamples* (or (and (> (length (argv)) 1)
(string->number (cadr (argv))))
20))
(print "Using " *numsamples* " as number of samples.")
(define (topdata)
(with-input-from-pipe
(conc "top -b -n " *numsamples* " -d 0.2")
read-lines))
(define (cleanup-data topdat)list
(let loop ((hed (car topdat))
(tal (cdr topdat))
(res '()))
(let* ((line-list (string-split hed))
(nums (map (lambda (indat)(or (string->number indat) indat)) line-list))
(not-data (or (null? nums)
(not (number? (car nums)))))
(new-res (if not-data res (cons nums res))))
(if (null? tal)
new-res
(loop (car tal)(cdr tal) new-res)))))
(define data (cleanup-data (topdata)))
(define pidhash (make-hash-table))
(define userhash (make-hash-table))
;; sum up and normalize the
(for-each
(lambda (indat)
|
|
<
<
|
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
(use posix srfi-69)
(define *numsamples* (or (and (> (length (argv)) 1)
(string->number (cadr (argv))))
3))
(define (topdata)
(with-input-from-pipe
(conc "top -b -n " *numsamples* " -d 0.1")
read-lines))
(define (cleanup-data topdat)list
(let loop ((hed (car topdat))
(tal (cdr topdat))
(res '()))
(let* ((line-list (string-split hed))
(nums (map (lambda (indat)(or (string->number indat) indat)) line-list))
(not-data (or (null? nums)
(not (number? (car nums)))))
(new-res (if not-data res (cons nums res))))
(if (null? tal)
new-res
(loop (car tal)(cdr tal) new-res)))))
(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 and normalize the
(for-each
(lambda (indat)
|