6 let font = Glut.BITMAP_HELVETICA_12
7 let draw_string ?
(font=font) x y s
=
8 GlPix.raster_pos ~x ~y
();
9 String.iter
(fun c
-> Glut.bitmapCharacter ~
font ~c
:(Char.code c
)) s
44 ; softirq
= -.a
.softirq
54 ; iowait
= a
.iowait
*. s
56 ; softirq
= a
.softirq
*. s
61 { all
= a
.all
+. b
.all
62 ; user
= a
.user
+. b
.user
63 ; nice
= a
.nice
+. b
.nice
64 ; sys
= a
.sys
+. b
.sys
65 ; idle
= a
.idle
+. b
.idle
66 ; iowait
= a
.iowait
+. b
.iowait
67 ; intr
= a
.intr
+. b
.intr
68 ; softirq
= a
.softirq
+. b
.softirq
76 ; loads
: int64
* int64
* int64
94 external get_nprocs
: unit -> int = "ml_get_nprocs"
95 external idletimeofday
: Unix.file_descr
-> int -> float array
97 external sysinfo
: unit -> sysinfo
= "ml_sysinfo"
98 external waitalrm
: unit -> unit = "ml_waitalrm"
99 external get_hz
: unit -> int = "ml_get_hz"
100 external setnice
: int -> unit = "ml_nice"
101 external delay
: float -> unit = "ml_delay"
102 external os_type
: unit -> os
= "ml_os_type"
103 external solaris_kstat
: int -> float array
= "ml_solaris_kstat"
104 external macosx_host_processor_info
: int -> float array
=
105 "ml_macosx_host_processor_info"
106 external windows_processor_times
: int -> float array
=
107 "ml_windows_processor_times"
108 external fixwindow
: int -> unit = "ml_fixwindow"
109 external testpmc
: unit -> bool = "ml_testpmc"
111 let os_type = os_type ()
113 let winnt = os_type = Windows
114 let solaris = os_type = Solaris
115 let linux = os_type = Linux
116 let macosx = os_type = MacOSX
126 let hz = get_hz
() |> float
128 let parse_uptime () =
129 let ic = open_in
"/proc/uptime" in
130 let vals = Scanf.fscanf
ic "%f %f" (fun u i
-> (u
, i
)) in
135 let nprocs = get_nprocs
()
137 let rec parse_int_cont s pos
=
138 let jiffies_to_sec j
=
141 let slen = String.length s
in
149 if String.get s
pos = ' '
158 try String.index_from s
pos ' '
159 with Not_found
-> slen
161 let i = endpos - pos |> String.sub s
pos
168 `more
(i, fun () -> succ
endpos |> parse_int_cont s
)
172 let rec tolist accu
= function
173 | `last
i -> i :: accu
174 | `more
(i, f
) -> f
() |> tolist (i :: accu
)
176 let index = String.index s ' '
in
177 let cpuname = String.sub s
0 index in
178 let vals = parse_int_cont s
(succ
index) |> tolist [] in
179 let vals = List.rev
|<
180 if List.length
vals < 7
182 0.0 :: 0.0 :: 0.0 :: 0.0 :: vals
186 cpuname, Array.of_list
vals
193 let iukw = windows_processor_times
nprocs in
194 let rec create n ai ak au ad ar accu
=
197 ("cpu", [| au
; ad
; ak
; ai
; 0.0; ar
; 0.0 |]) :: List.rev accu
199 let hdr = "cpu" ^ string_of_int n
in
201 let i = Array.get
iukw (o + 0) in
202 let k = Array.get
iukw (o + 1) in
203 let u = Array.get
iukw (o + 2) in
204 let d = Array.get
iukw (o + 3) in
205 let r = Array.get
iukw (o + 4) in
211 let accu = (hdr, [| u; d; k; i; 0.0; r; 0.0 |]) :: accu in
212 create (succ n
) ai ak au ad ar accu
214 create 0 0.0 0.0 0.0 0.0 0.0 []
219 let ic = open_in
"/proc/stat" in
220 let rec loop i accu =
225 (input_line
ic |> parse_cpul) :: accu |> loop (pred
i)
227 let ret = loop nprocs [] in
234 let iukw = solaris_kstat
nprocs in
235 let rec create n
ai au ak aw
accu =
238 ("cpu", [| au; 0.0; ak; ai; aw
; 0.0; 0.0 |]) :: List.rev
accu
240 let hdr = "cpu" ^ string_of_int n
in
242 let i = Array.get
iukw (o + 0) /. hz in
243 let u = Array.get
iukw (o + 1) /. hz in
244 let k = Array.get
iukw (o + 2) /. hz in
245 let w = Array.get
iukw (o + 3) /. hz in
250 let accu = (hdr, [| u; 0.0; k; i; w; 0.0; 0.0 |]) :: accu in
251 create (succ n
) ai au ak aw accu
253 create 0 0.0 0.0 0.0 0.0 []
258 let iukn = macosx_host_processor_info
nprocs in
259 let rec create c
ai au ak an
accu =
262 ("cpu", [| au; an
; ak; ai; 0.0; 0.0; 0.0 |]) :: List.rev
accu
264 let hdr = "cpu" ^ string_of_int c
in
266 let i = Array.get
iukn (o + 0) /. hz in
267 let u = Array.get
iukn (o + 1) /. hz in
268 let k = Array.get
iukn (o + 2) /. hz in
269 let n = Array.get
iukn (o + 3) /. hz in
274 let accu = (hdr, [| u; n; k; i; 0.0; 0.0; 0.0 |]) :: accu in
275 create (succ c
) ai au ak an accu
277 create 0 0.0 0.0 0.0 0.0 []
283 Filename.dirname
|< Unix.readlink
"/proc/self/exe"
292 [ "Amazing Piece of Code by insanely gifted programmer, Version 1.01"
293 ; "Motivation by: gzh and afs"
295 ] |> String.concat
"\n"
298 let interval = ref 15.0
299 let devpath = NP.getselfdir () |> Filename.concat
|< "itc" |> ref
304 let verbose = ref false
306 let ksampler = ref true
307 let isampler = ref true
310 let sigway = ref (NP.os_type != NP.MacOSX
)
313 let scalebar = ref false
315 let debug = ref false
317 let uptime = ref false
319 let labels = ref true
320 let mgrid = ref false
321 let sepstat = ref true
322 let grid_green = ref 0.75
325 let l = String.length s
in
330 let d = String.make
n ' '
in
331 StringLabels.blit ~src
:s ~dst
:d
337 let sooo b
= if b
then "on" else "off"
338 let dA tos s
{contents
=v
} = s ^
" (" ^ tos v ^
")"
339 let dF = dA |< sprintf
"%4.2f"
342 let dI = dA string_of_int
343 let dS = dA (fun s
-> "`" ^
String.escaped s ^
"'")
346 "-" ^ opt
, Arg.Set_float
r, pad 9 "<float> " ^ doc
|> dF |< r
350 "-" ^ opt
, Arg.Set_int
r, pad 9 "<int> " ^ doc
|> dI |< r
354 "-" ^ opt
, Arg.Set
r, pad 9 "" ^ doc
|> dB |< r
358 "-" ^ opt
, Arg.Set_string
r, pad 9 "<string> " ^ doc
|> dS |< r
364 "-" ^ opt
, Arg.Clear
r, pad 9 "" ^ doc
|> dB |< r
366 "-" ^ opt
, Arg.Set
r, pad 9 "" ^ doc
|> dcB |< r
370 [ sF "f" freq "sampling frequency in seconds"
371 ; sF "D" delay "refresh delay in seconds"
372 ; sF "i" interval "history interval in seconds"
373 ; sI "p" pgrid "percent grid items"
374 ; sI "s" sgrid "history grid items"
377 ; sI "b" barw "bar width"
378 ; sI "B" bars "number of CPU bars"
379 ; sB "v" verbose "verbose"
380 ; fB "C" sepstat "separate sys/nice/intr/iowait values (kernel sampler)"
381 ; fB "c" scalebar "constant bar width"
382 ; fB "P" poly "filled area instead of lines"
383 ; fB "l" labels "labels"
384 ; fB "m" mgrid "moving grid"
390 sI "t" timer "timer frequency in herz"
391 :: fB "I" icon "icon (hack)"
392 :: sS "d" devpath "path to itc device"
393 :: (fB "k" ksampler |< "kernel sampler (`/proc/[stat|uptime]')")
394 :: (fB "M" isampler |< "idle sampler")
396 "`uptime' instead of `stat' as kernel sampler (UP only)")
397 :: sI "n" niceval "value to renice self on init"
398 :: fB "g" gzh "gzh way (does not quite work yet)"
399 :: fB "S" sigway "sigwait delay method"
402 let add_solaris opts
=
404 fB "I" icon "icon (hack)"
407 let add_windows opts
=
409 (fB "k" ksampler |< "kernel sampler (ZwQuerySystemInformation)")
410 :: (fB "M" isampler |< "idle sampler (PMC based)")
413 let add_macosx opts
=
415 fB "g" gzh "gzh way (does not quite work yet)"
418 match NP.os_type with
419 | NP.Linux
-> add_linux tail
420 | NP.Windows
-> add_windows tail
421 | NP.Solaris
-> add_solaris tail
422 | NP.MacOSX
-> add_macosx tail
426 let opts = add_opts commonopts in
430 ("Invocation error: Don't know what to do with " ^ s
));
434 let cp {contents
=v
} s
=
436 then (prerr_string s
; prerr_endline
" must be positive"; exit
1)
438 let cpf {contents
=v
} s
=
440 then (prerr_string s
; prerr_endline
" must be positive"; exit
1)
444 cp pgrid "Number of percent grid items";
445 cp sgrid "Number of history grid items";
446 cp bars "Number of CPU bars";
447 cp timer "Timer frequency";
448 cpf freq "Frequency";
450 cpf interval "Interval";
451 if not
(!isampler || !ksampler)
455 if NP.winnt && !isampler
457 isampler := NP.testpmc
()
468 let rec furious_cycle i =
469 if not
!stop && i > 0
471 pred
i |> furious_cycle
473 (i, Unix.gettimeofday
())
478 let it = { Unix.it_interval
= t; it_value
= t } in
486 let sign = Sys.sigalrm
in
487 let oldh = Sys.signal
sign |< Sys.Signal_handle
handler in
488 let oldi = Unix.setitimer
Unix.ITIMER_REAL
it in
489 let oldbp = Unix.sigprocmask
Unix.SIG_BLOCK
[sign] in
490 let () = NP.waitalrm
() in
491 let () = stop := false in
492 let oldup = Unix.sigprocmask
Unix.SIG_UNBLOCK
[sign] in
493 let t1 = Unix.gettimeofday
() in
494 let n, t2
= furious_cycle max_int
in
495 let () = refdt := t2
-. t1 in
496 let () = lim := tries * (max_int
- n) in
500 printf
"Completed %d iterations in %f seconds@." !lim !refdt
502 let _ = Unix.sigprocmask
Unix.SIG_UNBLOCK
oldup in
503 let _ = Unix.setitimer
Unix.ITIMER_REAL
oldi in
504 let _ = Unix.sigprocmask
Unix.SIG_BLOCK
oldbp in
505 let _ = Sys.signal
sign oldh in
515 let _, t2
= furious_cycle !lim in
518 if !Args.debug && !l > 10
521 printf
"Completed %d iterations in %f seconds load %f@."
522 !lim dt |< !refdt /. dt;
529 Unix.gettimeofday
() |> loop
531 let _ = Thread.create thf () in
537 let prev = ref 0.0 in
540 let b = Unix.gettimeofday
() in
551 let sighandler signr
= ()
553 let winfreq = ref 0.0
558 winfreq := 1.0 /. float freq
561 Sys.Signal_handle
sighandler |> Sys.set_signal
Sys.sigalrm
;
567 [Sys.sigprof
; Sys.sigvtalrm
]
571 Unix.sigprocmask
Unix.SIG_BLOCK
|< Sys.sigalrm
:: l |> ignore
;
574 let v = 1.0 /. float freq in
575 let t = { Unix.it_interval
= v; it_value
= v } in
576 let _ = Unix.setitimer
Unix.ITIMER_REAL
t in
591 try let _ = Unix.select
[] [] [] ~
-.1.0 in ()
592 with Unix.Unix_error
(Unix.EINTR
, _, _) -> ()
600 getyielder
: unit -> unit -> float option;
601 update
: float -> float -> unit;
605 module Sampler
(T
: sig val nsamples
: int val freq : float end) =
607 let nsamples = T.nsamples + 1
608 let samples = Array.create nsamples 0.0
614 let n = min
nsamples n in
627 Array.set
samples i v;
628 loop (succ
i) (pred j
)
630 let () = loop !head n in
631 let () = head := (!head + n) mod nsamples in
632 let () = active := min
(!active + n) nsamples in
638 let d = !head - !active in
645 let ry = ref (fun () -> assert false) in
652 ry := succ
i |> yield;
653 Some
((i + tail) mod nsamples |> Array.get
samples)
661 let isamples = dt /. T.freq |> truncate
in
662 let l = 1.0 -. (di
/. dt) in
668 module type ViewSampler
=
670 val getyielder : unit -> unit -> float option
671 val update : float -> float -> float -> float -> unit
684 val samplers
: sampler list
687 module View
(V
: sig val w : int val h : int end) =
693 let keyboard ~key ~x ~y
=
694 if key
= 27 || key
= Char.code 'q'
700 funcs := dri
:: !funcs
704 GlClear.clear
[`color
];
705 List.iter
(fun (display, _, _) -> display ()) !funcs;
712 List.iter
(fun (_, reshape, _) -> reshape w h) !funcs;
713 GlClear.clear
[`color
];
714 GlMat.mode `modelview
;
715 GlMat.load_identity
();
716 GlMat.mode `projection
;
717 GlMat.load_identity
();
718 GlMat.rotate ~y
:1.0 ~angle
:180.0 ();
719 GlMat.translate ~x
:~
-.1.0 ~y
:~
-.1.0 ();
720 GlMat.scale ~x
:2.0 ~y
:2.0 ();
721 Glut.postRedisplay
();
726 Glut.initDisplayMode ~double_buffer
:true ();
727 Glut.initWindowSize
V.w V.h
729 let winid = Glut.createWindow
"APC" in
730 Glut.displayFunc
display;
731 Glut.reshapeFunc
reshape;
732 Glut.keyboardFunc
keyboard;
733 GlDraw.color
(1.0, 1.0, 0.0);
737 let inc () = List.iter
(fun (_, _, inc) -> inc ()) !funcs
738 let update = Glut.postRedisplay
739 let func = Glut.idleFunc
740 let run = Glut.mainLoop
743 module type BarInfo
=
749 val getl
: stats
-> ((float * float * float) * float) list
752 module Bar
(I
: BarInfo
) =
755 let dontdraw = ref false
757 let xoffset = ref I.x
758 let xratio = float I.x
/. float !Args.w
759 let wratio = float I.w /. float !Args.w
760 let load = ref zero_stat
761 let nrcpuscale = 1.0 /. float NP.nprocs
763 let strw = Glut.bitmapLength ~
font ~str
:"55.55"
765 let base = GlList.gen_lists ~len
:1 in
766 GlList.nth
base ~
pos:0
772 GlDraw.viewport
!xoffset (I.y
+ 15) !w hh;
774 GlMat.load_identity
();
775 GlMat.translate ~x
:~
-.1.0 ~y
:~
-.1.0 ();
776 GlMat.scale ~y
:(2.0 /. (float hh)) ~x
:1.0 ();
779 let barh = float (hh - (!Args.bars - 1) * seph) /. float !Args.bars in
780 let barh = ceil
barh |> truncate
in
786 let yt = yb
+ seph in
787 let yn = yt + barh in
790 GlDraw.vertex2
(0.0, yb);
791 GlDraw.vertex2
(0.0, yt);
792 GlDraw.vertex2
(2.0, yt);
793 GlDraw.vertex2
(2.0, yb);
796 GlDraw.color
(0.0, 0.0, 0.0);
797 GlDraw.begins `quads
;
807 w := float w'
*. wratio |> truncate
;
808 xoffset := float w'
*. xratio |> truncate
;
817 GlList.begins
sepsl `compile
;
821 !h < 20 || !w < 20 || !xoffset < 0
826 let load = scale_stat !load nrcpuscale in
827 let load_all = min
(1.0 -. load.all
) 1.0 |> max
0.0 in
828 let () = GlMat.push
() in
830 GlDraw.viewport
!xoffset (I.y
+ 2) !w !h;
831 GlDraw.color
(1.0, 1.0, 1.0);
832 let load_all = 100.0 *. load_all in
833 let str = sprintf
"%5.2f" load_all in
835 GlMat.load_identity
();
839 Glut.bitmapLength ~
font ~
str:str
843 let x = -. (float strw /. float !w) in
844 GlMat.translate ~y
:~
-.1.0 ~
x ();
846 let () = draw_string 0.0 0.0 str in
849 GlDraw.viewport
!xoffset (I.y
+ 15) !w (!h - 26);
850 GlMat.load_identity
();
851 GlMat.translate ~
x:~
-.1. ~y
:~
-.1.();
853 GlDraw.begins `quads
;
854 GlDraw.vertex2
(0.0, yb);
855 GlDraw.vertex2
(0.0, yt);
856 GlDraw.vertex2
(2.0, yt);
857 GlDraw.vertex2
(2.0, yb);
860 let fold yb (color
, load) =
863 let () = GlDraw.color color
in
864 let yt = yb +. 2.0*.load in
865 let () = drawquad yb yt in
870 let cl = I.getl
load in
871 let yb = List.fold_left
fold 0.0 cl in
872 let () = GlDraw.color
(0.5, 0.5, 0.5) in
873 let () = drawquad yb 2.0 in
874 let () = GlList.call
sepsl in
888 let update delta'
load'
=
889 let delta = 1.0 /. delta'
in
890 load := scale_stat load'
delta;
894 module Graph
(V
: View
) =
896 let ox = if !Args.scalebar then 0 else !Args.barw
897 let sw = float V.w /. float (!Args.w - ox)
898 let sh = float V.h /. float !Args.h
899 let sx = float (V.x - ox) /. float V.w
900 let sy = float V.y
/. float V.h
905 let scale = V.freq /. V.interval
906 let gscale = 1.0 /. float V.sgrid
908 let dontdraw = ref false
913 3 * Glut.bitmapWidth
font (Char.code '
%'
), 20
919 let base = GlList.gen_lists ~len
:1 in
920 GlList.nth
base ~
pos:0
923 let getviewport typ
=
924 let ox = if !Args.scalebar then 0 else !Args.barw in
926 | `
labels -> (!vx + ox, !vy + 5, fw, !vh - fh)
927 | `graph
-> (!vx + fw + 5 + ox, !vy + 5, !vw - fw - 10, !vh - fh)
931 let x, y
, w, h = getviewport typ
in
932 GlDraw.viewport x y
w h;
938 let x = if i = 0 then 0.0009 else float i *. gscale in
939 GlDraw.vertex ~
x ~y
:0.0 ();
940 GlDraw.vertex ~
x ~y
:1.0 ();
946 GlDraw.line_width
1.0;
947 GlDraw.color
(0.0, !Args.grid_green, 0.0);
948 GlDraw.begins `lines
;
952 GlDraw.vertex2
(0.0009, 0.0);
953 GlDraw.vertex2
(0.0009, 1.0);
954 GlDraw.vertex2
(1.0000, 0.0);
955 GlDraw.vertex2
(1.0000, 1.0);
961 let lim = 100 / V.pgrid in
964 let y = (i * V.pgrid |> float) /. 100.0 in
965 let y = if i = lim then y -. 0.0009 else y in
966 GlDraw.vertex ~
x:0.0 ~
y ();
967 GlDraw.vertex ~
x:1.0 ~
y ();
970 let () = GlDraw.ends
() in
975 GlDraw.color
(1.0, 1.0, 1.0);
977 for i = 0 to 100 / V.pgrid
979 let p = i * V.pgrid in
980 let y = float p /. ohp in
981 let s = sprintf
"%3d%%" p in
988 let wxsw = float (w - ox) *. sw
989 and hxsh
= float h *. sh in
990 vw := wxsw |> truncate
;
991 vh := hxsh
|> truncate
;
992 vx := wxsw *. sx |> truncate
;
993 vy := hxsh
*. sy |> truncate
;
996 let x0, y0
, w0
, h0
= getviewport `
labels in
997 let x1, y1
, w1
, h1
= getviewport `graph
in
998 w0
< 20 || h0
< 20 || x0 < 0 || y0
< 0 ||
999 w1
< 20 || h1
< 20 || x1 < 0 || y1
< 0
1005 GlList.begins
gridlist `compile
;
1012 Glut.swapBuffers
|> oohz !Args.delay;
1015 let inc () = incr
nsamples
1018 GlDraw.line_width
1.0;
1019 GlDraw.color
(0.0, !Args.grid_green, 0.0);
1020 GlDraw.begins `lines
;
1022 ((pred
!nsamples |> float) *. scale /. gscale |> modf
|> fst
) *. gscale
1024 for i = 0 to pred
V.sgrid
1026 let x = offset +. float i *. gscale in
1027 GlDraw.vertex ~
x ~
y:0.0 ();
1028 GlDraw.vertex ~
x ~
y:1.0 ();
1033 let display_aux () =
1034 GlList.call
gridlist;
1036 if !Args.mgrid then mgrid ();
1037 GlDraw.line_width
2.0;
1038 let sample sampler
=
1039 GlDraw.color sampler
.color
;
1042 then GlDraw.begins `line_strip
1045 GlDraw.begins `polygon
;
1046 GlDraw.vertex2
(0.0, 0.0);
1049 let yield = sampler
.getyielder () in
1050 let rec loop last
i =
1053 let x = scale *. float i in
1054 GlDraw.vertex ~
x ~
y ();
1063 let x = scale *. float (pred
i) in
1064 GlDraw.vertex ~
x ~
y:0.0 ()
1069 List.iter
sample V.samplers
;
1081 let funcs = display, reshape, inc
1084 let getplacements w h n barw =
1085 let sr = float n |> sqrt
|> ceil
|> truncate
in
1087 let r = if n mod sr = 0 then 0 else 1 in
1095 let w'
= w - barw in
1099 let rec loop accu i =
1106 let xc = xc * vw + barw in
1108 (i, xc, yc) :: accu |> loop |< succ
i
1116 let freq = !Args.freq
1117 let nsamples = !Args.interval /. freq |> ceil
|> truncate
1120 let placements, vw, vh = getplacements w h NP.nprocs !Args.barw in
1123 if !Args.isampler then NP.idletimeofday fd
NP.nprocs else [||]
1128 let gks = NP.parse_stat () in
1129 gks () |> Array.of_list
1133 let crgraph (kaccu
, iaccu
, gaccu
) (i, x, y) =
1134 let module Si
= Sampler
(S
) in
1136 { getyielder = Si.getyielder
1137 ; color
= (1.0, 1.0, 0.0)
1138 ; update = Si.update
1141 let module Sk
= Sampler
(S
) in
1143 { getyielder = Sk.getyielder
1144 ; color
= (1.0, 0.0, 0.0)
1145 ; update = Sk.update
1148 let module V
= struct
1154 let interval = !Args.interval
1155 let pgrid = !Args.pgrid
1156 let sgrid = !Args.sgrid
1160 isampler :: (if !Args.ksampler then [ksampler] else [])
1162 if !Args.ksampler then [ksampler] else []
1165 let module Graph
= Graph
(V
) in
1173 let f d'
= d := d'
in
1174 let () = Gzh.gen f in
1178 all
= d; iowait = d; user = 1.0 -. d; idle = d }
1182 let (u1
, i1
) = NP.parse_uptime () in
1186 let (u2
, i2
) = NP.parse_uptime () in
1188 and di
= i2
-. !i1
in
1193 all
= d; iowait = d; user = 1.0 -. d; idle = d }
1195 let i'
= if i = NP.nprocs then 0 else succ
i in
1196 let g ks n = Array.get
ks i'
|> snd
|> Array.get
|< n in
1198 let user = g ks NP.user
1199 and nice = g ks NP.nice
1200 and sys = g ks NP.sys
1201 and idle = g ks NP.idle
1202 and iowait = g ks NP.idle
1203 and intr = g ks NP.intr
1204 and softirq = g ks NP.softirq in
1209 "user=%f nice=%f sys=%f iowait=%f intr=%f softirq=%f@."
1228 let i1 = ref (gall ks) in
1231 let diff = add_stat i2 (neg_stat !i1) in
1235 (i, calc, ksampler) :: kaccu
1243 let i1 = Array.get
is i |> ref in
1245 let i2 = Array.get
is i in
1246 if classify_float
i2 = FP_infinite
1248 { zero_stat with all
= t2
-. t1 }
1252 { zero_stat with all
= i2 -. i1'
}
1254 (i, calc, isampler) :: iaccu
1258 kaccu, iaccu, Graph.funcs :: gaccu
1260 let kl, il
, gl
= List.fold_left
crgraph ([], [], []) placements in
1261 ((if kl == [] then (fun () -> [||]) else kget), kl), (iget, il
), gl
1267 (* gross hack but we are not particularly picky today *)
1271 if (Unix.stat path
).Unix.st_kind
!= Unix.S_CHR
1274 eprintf
"File %S is not an ITC device@." path
;
1278 Unix.openfile path
[Unix.O_RDONLY
] 0
1280 | Unix.Unix_error
((Unix.ENODEV
| Unix.ENXIO
) as err
, s1
, s2
) ->
1281 eprintf
"Could not open ITC device %S:\n%s(%s): %s@."
1282 path s1 s2
|< Unix.error_message err
;
1283 eprintf
"(perhaps the module is not loaded?)@.";
1286 | Unix.Unix_error
(Unix.EALREADY
, s1
, s2
) ->
1287 eprintf
"Could not open ITC device %S:\n%s(%s): %s@."
1288 path s1 s2
|< Unix.error_message
Unix.EALREADY
;
1289 eprintf
"(perhaps modules is already in use?)@.";
1292 | Unix.Unix_error
(error
, s1
, s2
) ->
1293 eprintf
"Could not open ITC device %S:\n%s(%s): %s@."
1294 path s1 s2
|< Unix.error_message error
;
1298 eprintf
"Could not open ITC device %S:\n%s@."
1299 path
|< Printexc.to_string exn
;
1306 external seticon : string -> unit = "ml_seticon"
1310 let data = String.create |< 32*len + 2*4 in
1315 and a = Char.chr
a in
1316 let s = String.create len in
1323 x + 0 |> String.set
s |< b;
1324 x + 1 |> String.set
s |< g;
1325 x + 2 |> String.set
s |< r;
1326 x + 3 |> String.set
s |< a;
1332 let el = line 0x00 0x00 0x00 0xff
1333 and kl = line 0xff 0x00 0x00 0xff
1334 and il
= line 0xff 0xff 0x00 0xff in
1336 let src = l and dst
= data and src_pos
= 0 in
1337 let rec loop n dst_pos
=
1341 StringLabels.blit ~
src ~src_pos ~dst ~dst_pos ~
len;
1342 pred
n |> loop |< dst_pos
+ len
1345 (ey
- sy) |> loop |< (32 - ey
) * len + 4*2
1347 fun ~iload ~kload
->
1348 let iy = iload
*. 32.0 |> ceil
|> truncate
|> max
0 |> min
32
1349 and ky
= kload
*. 32.0 |> ceil
|> truncate
|> max
0 |> min
32 in
1353 (fill kl 0 ky
; fill il ky
iy; iy)
1361 let create_bars h kactive iactive
=
1365 let sum = kload
.user +. kload
.nice +. kload
.sys
1366 +. kload
.intr +. kload
.softirq
1368 [ (1.0, 1.0, 0.0), kload
.user
1369 ; (0.0, 0.0, 1.0), kload
.nice
1370 ; (1.0, 0.0, 0.0), kload
.sys
1371 ; (1.0, 1.0, 1.0), kload
.intr
1372 ; (0.75, 0.5, 0.5), (1.0 -. kload
.iowait) -. sum
1373 ; (0.0, 1.0, 0.0), kload
.all
-. kload
.iowait -. kload
.softirq
1376 [ (1.0, 0.0, 0.0), 1.0 -. kload
.idle ]
1379 [ (1.0, 1.0, 0.0), 1.0 -. iload
.all
]
1381 let barw = !Args.barw in
1383 (fun () -> ()), (fun _ _ -> ()), (fun _ _ -> ())
1392 let w = (if iactive
then barw / 2 else barw) - 3
1397 Bar.display, Bar.reshape, Bar.update
1406 let x = (if kactive
then barw / 2 else 0) + 3
1408 let w = (if kactive
then barw / 2 else barw) - 3
1413 Bar.display, Bar.reshape, Bar.update
1422 let d () = kd (); id () in
1423 let r w h = kr
w h; ir
w h in
1424 let u d k i = ku
d k; iu
d i in
1427 kd, kr
, (fun d k _ -> ku
d k)
1433 id, ir
, (fun d _ i -> iu
d i)
1435 (fun () -> ()), (fun _ _ -> ()), (fun _ _ _ -> ())
1440 let _ = Glut.init [|""|] in
1441 let () = Args.init () in
1445 "detected " ^ string_of_int
NP.nprocs ^
" CPUs" |> print_endline
1447 let () = if !Args.gzh then Gzh.init !Args.verbose else () in
1448 let () = Delay.init !Args.timer !Args.gzh in
1449 let () = if !Args.niceval != 0 then NP.setnice
!Args.niceval else () in
1452 let fd = opendev !Args.devpath in
1453 let module FullV
= View
(struct let w = w let h = h end) in
1454 let winid = FullV.init () in
1455 let () = NP.fixwindow
winid in
1456 let (kget, kfuncs
), (iget, ifuncs
), gl
= create fd w h in
1458 List.iter
FullV.add gl
;
1461 let (display, reshape, update) =
1462 create_bars h !Args.ksampler !Args.isampler
1464 FullV.add (display, reshape, fun _ -> ());
1469 let seticon = if !Args.icon then seticon () else fun ~iload ~kload
-> () in
1470 let rec loop t1 () =
1471 let t2 = Unix.gettimeofday
() in
1472 let dt = t2 -. t1 in
1477 let rec loop2 load sample = function
1479 | (nr
, calc, sampler
) :: rest
->
1480 let cpuload = calc sample t1 t2 in
1482 let thisload = 1.0 -. (cpuload.all
/. dt) in
1483 let thisload = max
0.0 thisload in
1486 ("cpu load(" ^ string_of_int nr ^
"): "
1487 ^
(thisload *. 100.0 |> string_of_float
)
1490 let load = add_stat load cpuload in
1491 sampler
.update dt cpuload.all
;
1492 loop2 load sample rest
1494 let iload = loop2 zero_stat is ifuncs
in
1495 let kload = loop2 zero_stat ks kfuncs
in
1499 iload.all
|> string_of_float
|> prerr_endline
;
1500 kload.all
|> string_of_float
|> prerr_endline
;
1503 seticon ~
iload:iload.all ~
kload:kload.all
;
1504 bar_update dt kload iload;
1507 FullV.func (Some
(loop t2))
1511 FullV.func (Some
(Unix.gettimeofday
() |> loop));
1519 | Unix.Unix_error
(e
, s1
, s2
) ->
1520 Unix.error_message e
|> eprintf
"main failure: %s(%s): %s@." s1 s2
1523 Printexc.to_string exn
|> eprintf
"main failure: %s@."