Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:mirage/mirage-www
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
let (>>=) = Lwt.bind | ||
|
||
let delay = 60. *. 2. | ||
let history = 10_000 | ||
|
||
let html_of_stat t = | ||
let open Gc in | ||
let k f = | ||
let str = Printf.sprintf "%.0fk" (f /. 1000.) in | ||
Cow.Html.of_string str | ||
in | ||
<:html< | ||
<tr> | ||
<td>$k t.minor_words$</td> | ||
<td>$k t.major_words$</td> | ||
<td>$int:t.minor_collections$</td> | ||
<td>$int:t.major_collections$</td> | ||
</tr> | ||
>> | ||
|
||
let html_of_stats ts = | ||
<:html< | ||
<table> | ||
<tr> | ||
<th>Minor Words</th> | ||
<th>Major Words</th> | ||
<th>Minor Collections</th> | ||
<th>Major Collections</th> | ||
</tr> | ||
$list:List.map html_of_stat ts$ | ||
</table> | ||
>> | ||
|
||
let stats = Queue.create () | ||
|
||
let start ~sleep = | ||
let gather () = | ||
let stat = Gc.quick_stat () in | ||
if Queue.length stats >= history then ignore (Queue.pop stats); | ||
Queue.push stat stats | ||
in | ||
let rec loop () = | ||
gather (); | ||
sleep delay >>= fun () -> | ||
loop () | ||
in | ||
Lwt.async loop | ||
|
||
let page () = | ||
let stats = Queue.fold (fun acc s -> s :: acc) [] stats in | ||
html_of_stats stats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
val start: sleep:(float -> unit Lwt.t) -> unit | ||
val page: unit -> Cow.Html.t |