Utils: Moving_average: use int64 for total

This commit is contained in:
Vincent Bernardoff 2017-02-17 18:49:46 +01:00 committed by Grégoire Henry
parent 92c339f732
commit 70491aea8c
4 changed files with 17 additions and 9 deletions

View File

@ -272,14 +272,15 @@ module Real = struct
P2p_connection_pool.write_all pool msg ;
Lwt.ignore_result (lwt_debug "message broadcasted")
let pool { pool } = pool
end
module Fake = struct
let id = Identity.generate (Crypto_box.make_target 0.)
let empty_stat = {
Stat.total_sent = 0 ;
total_recv = 0 ;
Stat.total_sent = 0L ;
total_recv = 0L ;
current_inflow = 0 ;
current_outflow = 0 ;
}

View File

@ -45,12 +45,19 @@ end
module Stat = struct
type t = {
total_sent : int ;
total_recv : int ;
total_sent : int64 ;
total_recv : int64 ;
current_inflow : int ;
current_outflow : int ;
}
let empty = {
total_sent = 0L ;
total_recv = 0L ;
current_inflow = 0 ;
current_outflow = 0 ;
}
let print_size ppf sz =
let ratio n = (float_of_int sz /. float_of_int (1 lsl n)) in
if sz < 1 lsl 10 then

View File

@ -18,7 +18,7 @@ module Inttbl = Hashtbl.Make(struct
type t = {
id: int;
alpha: int ;
mutable total: int ;
mutable total: int64 ;
mutable current: int ;
mutable average: int ;
}
@ -66,19 +66,19 @@ let create =
incr cpt ;
assert (0. < alpha && alpha <= 1.) ;
let alpha = int_of_float (1000. *. alpha) in
let c = { id ; alpha ; total = 0 ; current = 0 ; average = init } in
let c = { id ; alpha ; total = 0L ; current = 0 ; average = init } in
Inttbl.add counters id c ;
c
let add c x =
c.total <- c.total + x ;
c.total <- Int64.(add c.total (of_int x)) ;
c.current <- c.current + x
let destroy c =
Inttbl.remove counters c.id
type stat = {
total: int ;
total: int64 ;
average: int ;
}

View File

@ -18,7 +18,7 @@ val on_update: (unit -> unit) -> unit
val updated: unit Lwt_condition.t
type stat = {
total: int ;
total: int64 ;
average: int ;
}
val stat: t -> stat