Megatest

Check-in [0e9324f845]
Login
Overview
Comment:Bit of clean up on whodunit
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.65
Files: files | file ages | folders
SHA1: 0e9324f845275f8629bbace81e25f73bdc680823
User & Date: mrwellan on 2020-11-20 11:13:25
Other Links: branch diff | manifest | tags
Context
2020-11-20
13:10
Converted whodunit to chicken 5 check-in: 28b4ff78b6 user: jmoon18 tags: v1.65
11:13
Bit of clean up on whodunit check-in: 0e9324f845 user: mrwellan tags: v1.65
2020-11-06
15:33
Updated megatest version to 1.6578 check-in: 7c08813c70 user: mmgraham tags: v1.65, v1.6578
Changes

Modified utils/whodunit.scm from [dae56f8cd6] to [53b5450f55].

11
12
13
14
15
16
17






18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41














42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
;;     but WITHOUT ANY WARRANTY; without even the implied warranty of
;;     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;     GNU General Public License for more details.
;; 
;;     You should have received a copy of the GNU General Public License
;;     along with Megatest.  If not, see <http://www.gnu.org/licenses/>.
;;






(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)
   (let ((pid (car indat))
         (usr (cadr indat))
         (cpu (list-ref indat 8)))
     (hash-table-set! userhash usr (+ cpu (hash-table-ref/default userhash usr 0)))))
 data)

(for-each
 (lambda (usr)

   (print usr
          (if (< (string-length usr) 8) "\t\t" "\t")
          (inexact->exact (round (/ (hash-table-ref userhash usr) *numsamples*)))))
 (sort (hash-table-keys userhash)
       (lambda (a b)
         (> (hash-table-ref userhash a)
            (hash-table-ref userhash b)))))








>
>
>
>
>
>











|












>
>
>
>
>
>
>
>
>
>
>
>
>
>




>

<
<
<
<
<
<
<
<



>
|
|
<



|

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67








68
69
70
71
72
73

74
75
76
77
78
;;     but WITHOUT ANY WARRANTY; without even the implied warranty of
;;     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;     GNU General Public License for more details.
;; 
;;     You should have received a copy of the GNU General Public License
;;     along with Megatest.  If not, see <http://www.gnu.org/licenses/>.
;;

(module whodunit

 *

(import scheme chicken data-structures extras)
(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)
  (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)))))


;; sum up
(define (sum-up data ht)
  (for-each
   (lambda (indat)
     (let ((pid (car indat))
           (usr (cadr indat))
           (cpu (list-ref indat 8)))
       (hash-table-set! ht usr (+ cpu (hash-table-ref/default ht usr 0)))))
   data))

)
(import whodunit)

(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)))))