Overview
Comment: | Tweaks to loadwatch |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | v1.60 |
Files: | files | file ages | folders |
SHA1: |
d0797d3ec2c6778a8b684530e5591a25 |
User & Date: | mrwellan on 2015-06-18 18:00:13 |
Other Links: | branch diff | manifest | tags |
Context
2015-06-18
| ||
23:12 | Added queuefeeder check-in: a095ada3d1 user: matt tags: v1.60 | |
18:00 | Tweaks to loadwatch check-in: d0797d3ec2 user: mrwellan tags: v1.60 | |
06:00 | Added loadwatch check-in: 610dd685d1 user: matt tags: v1.60 | |
Changes
Modified loadwatch/loadwatch.scm from [ac08451f48] to [d281425009].
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 | (use regex srfi-69) (define-record processdat %cpu virt res %mem count ) (define (snagload) (let ((dat (make-hash-table)) ;; user => hash-of-processdat (hdr (regexp "^\\s+PID")) (rx (regexp "\\s+")) (wht (regexp "^\\s+")) ) (with-input-from-pipe "top -n 1 -b" (lambda () (let loop ((inl (read-line)) (inbod #f)) (if (eof-object? inl) dat (if (not inbod) (if (string-search hdr inl) (loop (read-line) #t) (loop (read-line) #f)) (let* ((lparts (map (lambda (x) | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | > | | | | | | | | | | | | | | | | | | | | | | > | | | 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 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 79 80 81 82 83 84 85 86 | (use regex srfi-69) (define-record processdat %cpu virt res %mem count ) (define (pp-processdat dat) (print "(processdat" " %cpu=" (processdat-%cpu dat) " virt=" (processdat-virt dat) " res=" (processdat-res dat) " %mem=" (processdat-%mem dat) " count=" (processdat-count dat))) (define nrex (regexp "^(\\d+[\\d\\.]*)([mkgMKG])$")) (define (get-number numstr) (let ((n (string->number numstr))) (if n n (let ((nmatch (string-match nrex numstr))) (if nmatch (* (string->number (cadr nmatch)) (case (string->symbol (caddr nmatch)) ((k) 1024) ((m) 1048576) ((g) 1073741824) (else (print "ERROR: Unrecognised unit: " (caddr nmatch) ", extracted for " numstr) 1))) #f))))) (define (snagload) (let ((dat (make-hash-table)) ;; user => hash-of-processdat (hdr (regexp "^\\s+PID")) (rx (regexp "\\s+")) (wht (regexp "^\\s+")) ) (with-input-from-pipe "top -n 1 -b" (lambda () (let loop ((inl (read-line)) (inbod #f)) (if (eof-object? inl) dat (if (not inbod) (if (string-search hdr inl) (loop (read-line) #t) (loop (read-line) #f)) (let* ((lparts (map (lambda (x) (let ((num (get-number x))) (if num num x))) (string-split-fields rx (string-substitute wht "" inl) #:infix)))) (if (> (length lparts) 10) (let* ((user (list-ref lparts 1)) (virt (list-ref lparts 4)) (res (list-ref lparts 5)) (%cpu (list-ref lparts 8)) (%mem (list-ref lparts 9)) (time (list-ref lparts 10)) (pname (list-ref lparts 11)) (udat (or (hash-table-ref/default dat user #f) (let ((u (make-hash-table))) (hash-table-set! dat user u) u))) (pdat (or (hash-table-ref/default udat pname #f) (let ((p (make-processdat 0 0 0 0 0))) (hash-table-set! udat pname p) p)))) (print "User: " user ", pname: " pname ", virt: " virt ", res: " res ", %cpu: " %cpu ", %mem: " %mem) (processdat-%cpu-set! pdat (+ (processdat-%cpu pdat) %cpu)) (processdat-%mem-set! pdat (+ (processdat-%mem pdat) %mem)) (processdat-virt-set! pdat (+ (processdat-virt pdat) virt)) (processdat-res-set! pdat (+ (processdat-res pdat) res)) (processdat-count-set! pdat (+ (processdat-count pdat) 1)) (loop (read-line) inbod)) dat))))))))) (define x (snagload)) ;; (processdat-%cpu (hash-table-ref (hash-table-ref x "matt") "evolution-calen")) |