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"
109 let os_type = os_type ()
111 let winnt = os_type = Windows
112 let solaris = os_type = Solaris
113 let linux = os_type = Linux
114 let macosx = os_type = MacOSX
124 let hz = get_hz
() |> float
126 let parse_uptime () =
127 let ic = open_in
"/proc/uptime" in
128 let vals = Scanf.fscanf
ic "%f %f" (fun u i
-> (u
, i
)) in
133 let nprocs = get_nprocs
()
135 let rec parse_int_cont s pos
=
136 let jiffies_to_sec j
=
139 let slen = String.length s
in
147 if String.get s
pos = ' '
156 try String.index_from s
pos ' '
157 with Not_found
-> slen
159 let i = endpos - pos |> String.sub s
pos
166 `more
(i, fun () -> succ
endpos |> parse_int_cont s
)
170 let rec tolist accu
= function
171 | `last
i -> i :: accu
172 | `more
(i, f
) -> f
() |> tolist (i :: accu
)
174 let index = String.index s ' '
in
175 let cpuname = String.sub s
0 index in
176 let vals = parse_int_cont s
(succ
index) |> tolist [] in
177 let vals = List.rev
|<
178 if List.length
vals < 7
180 0.0 :: 0.0 :: 0.0 :: 0.0 :: vals
184 cpuname, Array.of_list
vals
191 let iukw = windows_processor_times
nprocs in
192 let rec create n ai ak au ad ar accu
=
195 ("cpu", [| au
; ad
; ak
; ai
; 0.0; ar
; 0.0 |]) :: List.rev accu
197 let hdr = "cpu" ^ string_of_int n
in
199 let i = Array.get
iukw (o + 0) in
200 let k = Array.get
iukw (o + 1) in
201 let u = Array.get
iukw (o + 2) in
202 let d = Array.get
iukw (o + 3) in
203 let r = Array.get
iukw (o + 4) in
209 let accu = (hdr, [| u; d; k; i; 0.0; r; 0.0 |]) :: accu in
210 create (succ n
) ai ak au ad ar accu
212 create 0 0.0 0.0 0.0 0.0 0.0 []
217 let ic = open_in
"/proc/stat" in
218 let rec loop i accu =
223 (input_line
ic |> parse_cpul) :: accu |> loop (pred
i)
225 let ret = loop nprocs [] in
232 let iukw = solaris_kstat
nprocs in
233 let rec create n
ai au ak aw
accu =
236 ("cpu", [| au; 0.0; ak; ai; aw
; 0.0; 0.0 |]) :: List.rev
accu
238 let hdr = "cpu" ^ string_of_int n
in
240 let i = Array.get
iukw (o + 0) /. hz in
241 let u = Array.get
iukw (o + 1) /. hz in
242 let k = Array.get
iukw (o + 2) /. hz in
243 let w = Array.get
iukw (o + 3) /. hz in
248 let accu = (hdr, [| u; 0.0; k; i; w; 0.0; 0.0 |]) :: accu in
249 create (succ n
) ai au ak aw accu
251 create 0 0.0 0.0 0.0 0.0 []
256 let iukn = macosx_host_processor_info
nprocs in
257 let rec create c
ai au ak an
accu =
260 ("cpu", [| au; an
; ak; ai; 0.0; 0.0; 0.0 |]) :: List.rev
accu
262 let hdr = "cpu" ^ string_of_int c
in
264 let i = Array.get
iukn (o + 0) /. hz in
265 let u = Array.get
iukn (o + 1) /. hz in
266 let k = Array.get
iukn (o + 2) /. hz in
267 let n = Array.get
iukn (o + 3) /. hz in
272 let accu = (hdr, [| u; n; k; i; 0.0; 0.0; 0.0 |]) :: accu in
273 create (succ c
) ai au ak an accu
275 create 0 0.0 0.0 0.0 0.0 []
281 Filename.dirname
|< Unix.readlink
"/proc/self/exe"
290 [ "Amazing Piece of Code by insanely gifted programmer, Version 0.99"
291 ; "Motivation by: gzh and afs"
293 ] |> String.concat
"\n"
296 let interval = ref 15.0
297 let devpath = NP.getselfdir () |> Filename.concat
|< "itc" |> ref
302 let verbose = ref false
304 let ksampler = ref true
305 let isampler = ref true
308 let sigway = ref (NP.os_type != NP.MacOSX
)
311 let scalebar = ref false
313 let debug = ref false
315 let uptime = ref false
317 let labels = ref true
318 let mgrid = ref false
319 let sepstat = ref true
322 let l = String.length s
in
327 let d = String.make
n ' '
in
328 StringLabels.blit ~src
:s ~dst
:d
334 let sooo b
= if b
then "on" else "off"
335 let dA tos s
{contents
=v
} = s ^
" (" ^ tos v ^
")"
336 let dF = dA |< sprintf
"%4.2f"
339 let dI = dA string_of_int
340 let dS = dA (fun s
-> "`" ^
String.escaped s ^
"'")
343 "-" ^ opt
, Arg.Set_float
r, pad 9 "<float> " ^ doc
|> dF |< r
347 "-" ^ opt
, Arg.Set_int
r, pad 9 "<int> " ^ doc
|> dI |< r
351 "-" ^ opt
, Arg.Set
r, pad 9 "" ^ doc
|> dB |< r
355 "-" ^ opt
, Arg.Set_string
r, pad 9 "<string> " ^ doc
|> dS |< r
361 "-" ^ opt
, Arg.Clear
r, pad 9 "" ^ doc
|> dB |< r
363 "-" ^ opt
, Arg.Set
r, pad 9 "" ^ doc
|> dcB |< r
367 [ sF "f" freq "sampling frequency in seconds"
368 ; sF "D" delay "refresh delay in seconds"
369 ; sF "i" interval "history interval in seconds"
370 ; sI "p" pgrid "percent grid items"
371 ; sI "s" sgrid "history grid items"
374 ; sI "b" barw "bar width"
375 ; sI "B" bars "number of CPU bars"
376 ; sB "v" verbose "verbose"
377 ; fB "C" sepstat "separate sys/nice/intr/iowait values (kernel sampler)"
378 ; fB "c" scalebar "constant bar width"
379 ; fB "P" poly "filled area instead of lines"
380 ; fB "l" labels "labels"
381 ; fB "m" mgrid "moving grid"
387 sI "t" timer "timer frequency in herz"
388 :: fB "I" icon "icon (hack)"
389 :: sS "d" devpath "path to itc device"
390 :: (fB "k" ksampler |< "kernel sampler (`/proc/[stat|uptime]')")
391 :: (fB "M" isampler |< "idle sampler")
393 "`uptime' instead of `stat' as kernel sampler (UP only)")
394 :: sI "n" niceval "value to renice self on init"
395 :: fB "g" gzh "gzh way (does not quite work yet)"
396 :: fB "S" sigway "sigwait delay method"
399 let add_solaris opts
=
401 fB "I" icon "icon (hack)"
404 let add_windows opts
=
408 let add_macosx opts
=
410 fB "g" gzh "gzh way (does not quite work yet)"
413 match NP.os_type with
414 | NP.Linux
-> add_linux tail
415 | NP.Windows
-> add_windows tail
416 | NP.Solaris
-> add_solaris tail
417 | NP.MacOSX
-> add_macosx tail
421 let opts = add_opts commonopts in
425 ("Invocation error: Don't know what to do with " ^ s
));
429 let cp {contents
=v
} s
=
431 then (prerr_string s
; prerr_endline
" must be positive"; exit
1)
433 let cpf {contents
=v
} s
=
435 then (prerr_string s
; prerr_endline
" must be pisitive"; exit
1)
439 cp pgrid "Number of percent grid items";
440 cp sgrid "Number of history grid items";
441 cp bars "Number of CPU bars";
442 cp timer "Timer frequency";
443 cpf freq "Frequency";
445 cpf interval "Interval";
446 if not
(!isampler || !ksampler)
459 let rec furious_cycle i =
460 if not
!stop && i > 0
462 pred
i |> furious_cycle
464 (i, Unix.gettimeofday
())
469 let it = { Unix.it_interval
= t; it_value
= t } in
477 let sign = Sys.sigalrm
in
478 let oldh = Sys.signal
sign |< Sys.Signal_handle
handler in
479 let oldi = Unix.setitimer
Unix.ITIMER_REAL
it in
480 let oldbp = Unix.sigprocmask
Unix.SIG_BLOCK
[sign] in
481 let () = NP.waitalrm
() in
482 let () = stop := false in
483 let oldup = Unix.sigprocmask
Unix.SIG_UNBLOCK
[sign] in
484 let t1 = Unix.gettimeofday
() in
485 let n, t2
= furious_cycle max_int
in
486 let () = refdt := t2
-. t1 in
487 let () = lim := tries * (max_int
- n) in
491 printf
"Completed %d iterations in %f seconds@." !lim !refdt
493 let _ = Unix.sigprocmask
Unix.SIG_UNBLOCK
oldup in
494 let _ = Unix.setitimer
Unix.ITIMER_REAL
oldi in
495 let _ = Unix.sigprocmask
Unix.SIG_BLOCK
oldbp in
496 let _ = Sys.signal
sign oldh in
506 let _, t2
= furious_cycle !lim in
509 if !Args.debug && !l > 10
512 printf
"Completed %d iterations in %f seconds load %f@."
513 !lim dt |< !refdt /. dt;
520 Unix.gettimeofday
() |> loop
522 let _ = Thread.create thf () in
528 let prev = ref 0.0 in
531 let b = Unix.gettimeofday
() in
542 let sighandler signr
= ()
544 let winfreq = ref 0.0
549 winfreq := 1.0 /. float freq
552 Sys.Signal_handle
sighandler |> Sys.set_signal
Sys.sigalrm
;
558 [Sys.sigprof
; Sys.sigvtalrm
]
562 Unix.sigprocmask
Unix.SIG_BLOCK
|< Sys.sigalrm
:: l |> ignore
;
565 let v = 1.0 /. float freq in
566 let t = { Unix.it_interval
= v; it_value
= v } in
567 let _ = Unix.setitimer
Unix.ITIMER_REAL
t in
582 try let _ = Unix.select
[] [] [] ~
-.1.0 in ()
583 with Unix.Unix_error
(Unix.EINTR
, _, _) -> ()
591 getyielder
: unit -> unit -> float option;
592 update
: float -> float -> unit;
596 module Sampler
(T
: sig val nsamples
: int val freq : float end) =
598 let nsamples = T.nsamples + 1
599 let samples = Array.create nsamples 0.0
605 let n = min
nsamples n in
618 Array.set
samples i v;
619 loop (succ
i) (pred j
)
621 let () = loop !head n in
622 let () = head := (!head + n) mod nsamples in
623 let () = active := min
(!active + n) nsamples in
629 let d = !head - !active in
636 let ry = ref (fun () -> assert false) in
643 ry := succ
i |> yield;
644 Some
((i + tail) mod nsamples |> Array.get
samples)
652 let isamples = dt /. T.freq |> truncate
in
653 let l = 1.0 -. (di
/. dt) in
659 module type ViewSampler
=
661 val getyielder : unit -> unit -> float option
662 val update : float -> float -> float -> float -> unit
675 val samplers
: sampler list
678 module View
(V
: sig val w : int val h : int end) =
684 let keyboard ~key ~x ~y
=
685 if key
= 27 || key
= Char.code 'q'
691 funcs := dri
:: !funcs
695 GlClear.clear
[`color
];
696 List.iter
(fun (display, _, _) -> display ()) !funcs;
703 List.iter
(fun (_, reshape, _) -> reshape w h) !funcs;
704 GlClear.clear
[`color
];
705 GlMat.mode `modelview
;
706 GlMat.load_identity
();
707 GlMat.mode `projection
;
708 GlMat.load_identity
();
709 GlMat.rotate ~y
:1.0 ~angle
:180.0 ();
710 GlMat.translate ~x
:~
-.1.0 ~y
:~
-.1.0 ();
711 GlMat.scale ~x
:2.0 ~y
:2.0 ();
712 Glut.postRedisplay
();
717 Glut.initDisplayMode ~double_buffer
:true ();
718 Glut.initWindowSize
V.w V.h
720 let winid = Glut.createWindow
"APC" in
721 Glut.displayFunc
display;
722 Glut.reshapeFunc
reshape;
723 Glut.keyboardFunc
keyboard;
724 GlDraw.color
(1.0, 1.0, 0.0);
728 let inc () = List.iter
(fun (_, _, inc) -> inc ()) !funcs
729 let update = Glut.postRedisplay
730 let func = Glut.idleFunc
731 let run = Glut.mainLoop
734 module type BarInfo
=
740 val getl
: stats
-> ((float * float * float) * float) list
743 module Bar
(I
: BarInfo
) =
747 let wratio = float I.w /. float !Args.w
748 let load = ref zero_stat
749 let nrcpuscale = 1.0 /. float NP.nprocs
751 let strw = Glut.bitmapLength ~
font ~str
:"55.55"
753 let base = GlList.gen_lists ~len
:1 in
754 GlList.nth
base ~
pos:0
760 GlDraw.viewport
I.x
(I.y
+ 15) !w hh;
762 GlMat.load_identity
();
763 GlMat.translate ~x
:~
-.1.0 ~y
:~
-.1.0 ();
764 GlMat.scale ~y
:(2.0 /. (float hh)) ~x
:1.0 ();
767 let barh = float (hh - (!Args.bars - 1) * seph) /. float !Args.bars in
768 let barh = ceil
barh |> truncate
in
774 let yt = yb
+ seph in
775 let yn = yt + barh in
778 GlDraw.vertex2
(0.0, yb);
779 GlDraw.vertex2
(0.0, yt);
780 GlDraw.vertex2
(2.0, yt);
781 GlDraw.vertex2
(2.0, yb);
784 GlDraw.color
(0.0, 0.0, 0.0);
785 GlDraw.begins `quads
;
795 (float w'
*. wratio |> truncate
)
800 GlList.begins
sepsl `compile
;
806 let load = scale_stat !load nrcpuscale in
807 let load_all = min
(1.0 -. load.all
) 1.0 |> max
0.0 in
808 let () = GlMat.push
() in
810 GlDraw.viewport
I.x
(I.y
+ 2) !w !h;
811 GlDraw.color
(1.0, 1.0, 1.0);
812 let load_all = 100.0 *. load_all in
813 let str = sprintf
"%5.2f" load_all in
815 GlMat.load_identity
();
819 Glut.bitmapLength ~
font ~
str:str
823 let x = -. (float strw /. float !w) in
824 GlMat.translate ~y
:~
-.1.0 ~
x ();
826 let () = draw_string 0.0 0.0 str in
829 GlDraw.viewport
I.x (I.y
+ 15) !w (!h - 26);
830 GlMat.load_identity
();
831 GlMat.translate ~
x:~
-.1. ~y
:~
-.1.();
833 GlDraw.begins `quads
;
834 GlDraw.vertex2
(0.0, yb);
835 GlDraw.vertex2
(0.0, yt);
836 GlDraw.vertex2
(2.0, yt);
837 GlDraw.vertex2
(2.0, yb);
840 let fold yb (color
, load) =
843 let () = GlDraw.color color
in
844 let yt = yb +. 2.0*.load in
845 let () = drawquad yb yt in
850 let cl = I.getl
load in
851 let yb = List.fold_left
fold 0.0 cl in
852 let () = GlDraw.color
(0.5, 0.5, 0.5) in
853 let () = drawquad yb 2.0 in
854 let () = GlList.call
sepsl in
859 let update delta'
load'
=
860 let delta = 1.0 /. delta'
in
861 load := scale_stat load'
delta;
865 module Graph
(V
: View
) =
867 let ox = if !Args.scalebar then 0 else !Args.barw
868 let sw = float V.w /. float (!Args.w - ox)
869 let sh = float V.h /. float !Args.h
870 let sx = float (V.x - ox) /. float V.w
871 let sy = float V.y
/. float V.h
876 let scale = V.freq /. V.interval
877 let gscale = 1.0 /. float V.sgrid
883 3 * Glut.bitmapWidth
font (Char.code '
%'
), 20
889 let base = GlList.gen_lists ~len
:1 in
890 GlList.nth
base ~
pos:0
893 let ox = if !Args.scalebar then 0 else !Args.barw in
896 | `
labels -> (!vx + ox, !vy + 5, fw, !vh - fh)
897 | `graph
-> (!vx + fw + 5 + ox, !vy + 5, !vw - fw - 10, !vh - fh)
899 GlDraw.viewport x y
w h;
905 let x = if i = 0 then 0.0009 else float i *. gscale in
906 GlDraw.vertex ~
x ~y
:0.0 ();
907 GlDraw.vertex ~
x ~y
:1.0 ();
913 GlDraw.line_width
1.0;
914 GlDraw.color
(0.0, 1.0, 0.0);
915 GlDraw.begins `lines
;
919 GlDraw.vertex2
(0.0009, 0.0);
920 GlDraw.vertex2
(0.0009, 1.0);
921 GlDraw.vertex2
(1.0000, 0.0);
922 GlDraw.vertex2
(1.0000, 1.0);
928 let lim = 100 / V.pgrid in
931 let y = (i * V.pgrid |> float) /. 100.0 in
932 let y = if i = lim then y -. 0.0009 else y in
933 GlDraw.vertex ~
x:0.0 ~
y ();
934 GlDraw.vertex ~
x:1.0 ~
y ();
937 let () = GlDraw.ends
() in
942 GlDraw.color
(1.0, 1.0, 1.0);
944 for i = 0 to 100 / V.pgrid
946 let p = i * V.pgrid in
947 let y = float p /. ohp in
948 let s = Printf.sprintf
"%3d%%" p in
955 let wxsw = float (w - ox) *. sw
956 and hxsh
= float h *. sh in
957 vw := wxsw |> truncate
;
958 vh := hxsh
|> truncate
;
959 vx := wxsw *. sx |> truncate
;
960 vy := hxsh
*. sy |> truncate
;
961 GlList.begins
gridlist `compile
;
967 Glut.swapBuffers
|> oohz !Args.delay;
970 let inc () = incr
nsamples
973 GlDraw.line_width
1.0;
974 GlDraw.color
(0.0, 1.0, 0.0);
975 GlDraw.begins `lines
;
977 ((pred
!nsamples |> float) *. scale /. gscale |> modf
|> fst
) *. gscale
979 for i = 0 to pred
V.sgrid
981 let x = offset +. float i *. gscale in
982 GlDraw.vertex ~
x ~
y:0.0 ();
983 GlDraw.vertex ~
x ~
y:1.0 ();
989 GlList.call
gridlist;
991 if !Args.mgrid then mgrid ();
992 GlDraw.line_width
2.0;
994 GlDraw.color sampler
.color
;
997 then GlDraw.begins `line_strip
1000 GlDraw.begins `polygon
;
1001 GlDraw.vertex2
(0.0, 0.0);
1004 let yield = sampler
.getyielder () in
1005 let rec loop last
i =
1008 let x = scale *. float i in
1009 GlDraw.vertex ~
x ~
y ();
1018 let x = scale *. float (pred
i) in
1019 GlDraw.vertex ~
x ~
y:0.0 ()
1024 List.iter
sample V.samplers
;
1027 let funcs = display, reshape, inc
1030 let getplacements w h n barw =
1031 let sr = float n |> sqrt
|> ceil
|> truncate
in
1033 let r = if n mod sr = 0 then 0 else 1 in
1041 let w'
= w - barw in
1045 let rec loop accu i =
1052 let xc = xc * vw + barw in
1054 (i, xc, yc) :: accu |> loop |< succ
i
1062 let freq = !Args.freq
1063 let nsamples = !Args.interval /. freq |> ceil
|> truncate
1066 let placements, vw, vh = getplacements w h NP.nprocs !Args.barw in
1069 if !Args.isampler then NP.idletimeofday fd
NP.nprocs else [||]
1074 let gks = NP.parse_stat () in
1075 gks () |> Array.of_list
1079 let crgraph (kaccu
, iaccu
, gaccu
) (i, x, y) =
1080 let module Si
= Sampler
(S
) in
1082 { getyielder = Si.getyielder
1083 ; color
= (1.0, 1.0, 0.0)
1084 ; update = Si.update
1087 let module Sk
= Sampler
(S
) in
1089 { getyielder = Sk.getyielder
1090 ; color
= (1.0, 0.0, 0.0)
1091 ; update = Sk.update
1094 let module V
= struct
1100 let interval = !Args.interval
1101 let pgrid = !Args.pgrid
1102 let sgrid = !Args.sgrid
1106 isampler :: (if !Args.ksampler then [ksampler] else [])
1108 if !Args.ksampler then [ksampler] else []
1111 let module Graph
= Graph
(V
) in
1119 let f d'
= d := d'
in
1120 let () = Gzh.gen f in
1124 all
= d; iowait = d; user = 1.0 -. d; idle = d }
1128 let (u1
, i1
) = NP.parse_uptime () in
1132 let (u2
, i2
) = NP.parse_uptime () in
1134 and di
= i2
-. !i1
in
1139 all
= d; iowait = d; user = 1.0 -. d; idle = d }
1141 let i'
= if i = NP.nprocs then 0 else succ
i in
1142 let g ks n = Array.get
ks i'
|> snd
|> Array.get
|< n in
1144 let user = g ks NP.user
1145 and nice = g ks NP.nice
1146 and sys = g ks NP.sys
1147 and idle = g ks NP.idle
1148 and iowait = g ks NP.idle
1149 and intr = g ks NP.intr
1150 and softirq = g ks NP.softirq in
1155 "user=%f nice=%f sys=%f iowait=%f intr=%f softirq=%f@."
1174 let i1 = ref (gall ks) in
1177 let diff = add_stat i2 (neg_stat !i1) in
1181 (i, calc, ksampler) :: kaccu
1189 let i1 = Array.get
is i |> ref in
1191 let i2 = Array.get
is i in
1192 if classify_float
i2 = FP_infinite
1194 { zero_stat with all
= t2
-. t1 }
1198 { zero_stat with all
= i2 -. i1'
}
1200 (i, calc, isampler) :: iaccu
1204 kaccu, iaccu, Graph.funcs :: gaccu
1206 let kl, il
, gl
= List.fold_left
crgraph ([], [], []) placements in
1207 ((if kl == [] then (fun () -> [||]) else kget), kl), (iget, il
), gl
1213 (* gross hack but we are not particularly picky today *)
1217 if (Unix.stat path
).Unix.st_kind
!= Unix.S_CHR
1220 eprintf
"File %S is not an ITC device@." path
;
1224 Unix.openfile path
[Unix.O_RDONLY
] 0
1226 | Unix.Unix_error
((Unix.ENODEV
| Unix.ENXIO
) as err
, s1
, s2
) ->
1227 eprintf
"Could not open ITC device %S:\n%s(%s): %s@."
1228 path s1 s2
|< Unix.error_message err
;
1229 eprintf
"(perhaps the module is not loaded?)@.";
1232 | Unix.Unix_error
(Unix.EALREADY
, s1
, s2
) ->
1233 eprintf
"Could not open ITC device %S:\n%s(%s): %s@."
1234 path s1 s2
|< Unix.error_message
Unix.EALREADY
;
1235 eprintf
"(perhaps modules is already in use?)@.";
1238 | Unix.Unix_error
(error
, s1
, s2
) ->
1239 eprintf
"Could not open ITC device %S:\n%s(%s): %s@."
1240 path s1 s2
|< Unix.error_message error
;
1244 eprintf
"Could not open ITC device %S:\n%s@."
1245 path
|< Printexc.to_string exn
;
1252 external seticon : string -> unit = "ml_seticon"
1256 let data = String.create |< 32*len + 2*4 in
1261 and a = Char.chr
a in
1262 let s = String.create len in
1269 x + 0 |> String.set
s |< b;
1270 x + 1 |> String.set
s |< g;
1271 x + 2 |> String.set
s |< r;
1272 x + 3 |> String.set
s |< a;
1278 let el = line 0x00 0x00 0x00 0xff
1279 and kl = line 0xff 0x00 0x00 0xff
1280 and il
= line 0xff 0xff 0x00 0xff in
1282 let src = l and dst
= data and src_pos
= 0 in
1283 let rec loop n dst_pos
=
1287 StringLabels.blit ~
src ~src_pos ~dst ~dst_pos ~
len;
1288 pred
n |> loop |< dst_pos
+ len
1291 (ey
- sy) |> loop |< (32 - ey
) * len + 4*2
1293 fun ~iload ~kload
->
1294 let iy = iload
*. 32.0 |> ceil
|> truncate
|> max
0 |> min
32
1295 and ky
= kload
*. 32.0 |> ceil
|> truncate
|> max
0 |> min
32 in
1299 (fill kl 0 ky
; fill il ky
iy; iy)
1307 let create_bars h kactive iactive
=
1311 let sum = kload
.user +. kload
.nice +. kload
.sys
1312 +. kload
.intr +. kload
.softirq
1314 [ (1.0, 1.0, 0.0), kload
.user
1315 ; (0.0, 0.0, 1.0), kload
.nice
1316 ; (1.0, 0.0, 0.0), kload
.sys
1317 ; (1.0, 1.0, 1.0), kload
.intr
1318 ; (0.75, 0.5, 0.5), (1.0 -. kload
.iowait) -. sum
1319 ; (0.0, 1.0, 0.0), kload
.all
-. kload
.iowait -. kload
.softirq
1322 [ (1.0, 0.0, 0.0), 1.0 -. kload
.idle ]
1325 [ (1.0, 1.0, 0.0), 1.0 -. iload
.all
]
1327 let barw = !Args.barw in
1329 (fun () -> ()), (fun _ _ -> ()), (fun _ _ -> ())
1338 let w = (if iactive
then barw / 2 else barw) - 3
1343 Bar.display, Bar.reshape, Bar.update
1352 let x = (if kactive
then barw / 2 else 0) + 3
1354 let w = (if kactive
then barw / 2 else barw) - 3
1359 Bar.display, Bar.reshape, Bar.update
1368 let d () = kd (); id () in
1369 let r w h = kr
w h; ir
w h in
1370 let u d k i = ku
d k; iu
d i in
1373 kd, kr
, (fun d k _ -> ku
d k)
1379 id, ir
, (fun d _ i -> iu
d i)
1381 (fun () -> ()), (fun _ _ -> ()), (fun _ _ _ -> ())
1386 let _ = Glut.init [|""|] in
1387 let () = Args.init () in
1391 "detected " ^ string_of_int
NP.nprocs ^
" CPUs" |> print_endline
1393 let () = if !Args.gzh then Gzh.init !Args.verbose else () in
1394 let () = Delay.init !Args.timer !Args.gzh in
1395 let () = if !Args.niceval != 0 then NP.setnice
!Args.niceval else () in
1398 let fd = opendev !Args.devpath in
1399 let module FullV
= View
(struct let w = w let h = h end) in
1400 let _winid = FullV.init () in
1401 let (kget, kfuncs
), (iget, ifuncs
), gl
= create fd w h in
1403 List.iter
FullV.add gl
;
1406 let (display, reshape, update) =
1407 create_bars h !Args.ksampler !Args.isampler
1409 FullV.add (display, reshape, fun _ -> ());
1414 let seticon = if !Args.icon then seticon () else fun ~iload ~kload
-> () in
1415 let rec loop t1 () =
1416 let t2 = Unix.gettimeofday
() in
1417 let dt = t2 -. t1 in
1422 let rec loop2 load sample = function
1424 | (nr
, calc, sampler
) :: rest
->
1425 let cpuload = calc sample t1 t2 in
1427 let thisload = 1.0 -. (cpuload.all
/. dt) in
1428 let thisload = max
0.0 thisload in
1431 ("cpu load(" ^ string_of_int nr ^
"): "
1432 ^
(thisload *. 100.0 |> string_of_float
)
1435 let load = add_stat load cpuload in
1436 sampler
.update dt cpuload.all
;
1437 loop2 load sample rest
1439 let iload = loop2 zero_stat is ifuncs
in
1440 let kload = loop2 zero_stat ks kfuncs
in
1444 iload.all
|> string_of_float
|> prerr_endline
;
1445 kload.all
|> string_of_float
|> prerr_endline
;
1448 seticon ~
iload:iload.all ~
kload:kload.all
;
1449 bar_update dt kload iload;
1452 FullV.func (Some
(loop t2))
1456 FullV.func (Some
(Unix.gettimeofday
() |> loop));
1464 | Unix.Unix_error
(e
, s1
, s2
) ->
1465 Unix.error_message e
|> eprintf
"main failure: %s(%s): %s@." s1 s2
1468 Printexc.to_string exn
|> eprintf
"main failure: %s@."