Skip to content

Commit 1d72433

Browse files
committed
use Mirage_net.Stats helpers (reset / create / rx / tx)
1 parent db2219a commit 1d72433

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/netif.ml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ let connect devname =
5959
Log.debug (fun m -> m "plugging into %s with mac %a and mtu %d"
6060
devname Macaddr.pp mac mtu);
6161
let active = true in
62-
let t = {
63-
id=devname; dev; active; mac; mtu;
64-
stats= { rx_bytes=0L;rx_pkts=0l; tx_bytes=0L; tx_pkts=0l } }
65-
in
62+
let stats = Mirage_net.Stats.create () in
63+
let t = { id=devname; dev; active; mac; mtu; stats } in
6664
Log.info (fun m -> m "connect %s with mac %a" devname Macaddr.pp mac);
6765
Lwt.return t
6866
with
@@ -85,8 +83,7 @@ let rec read t buf =
8583
| (-1) -> Error `Continue (* EAGAIN or EWOULDBLOCK *)
8684
| 0 -> Error `Disconnected (* EOF *)
8785
| len ->
88-
t.stats.rx_pkts <- Int32.succ t.stats.rx_pkts;
89-
t.stats.rx_bytes <- Int64.add t.stats.rx_bytes (Int64.of_int len);
86+
Mirage_net.Stats.rx t.stats (Int64.of_int len);
9087
let buf = Cstruct.sub buf 0 len in
9188
Ok buf)
9289
(function
@@ -144,8 +141,7 @@ let write t ~size fillf =
144141
else
145142
Lwt.catch (fun () ->
146143
Lwt_bytes.write t.dev buf.Cstruct.buffer 0 len >|= fun len' ->
147-
t.stats.tx_pkts <- Int32.succ t.stats.tx_pkts;
148-
t.stats.tx_bytes <- Int64.add t.stats.tx_bytes (Int64.of_int len);
144+
Mirage_net.Stats.tx t.stats (Int64.of_int len);
149145
if len' <> len then Error (`Partial (t.id, len', buf))
150146
else Ok ())
151147
(fun exn -> Lwt.return (Error (`Exn exn)))
@@ -156,8 +152,4 @@ let mtu t = t.mtu
156152

157153
let get_stats_counters t = t.stats
158154

159-
let reset_stats_counters t =
160-
t.stats.rx_bytes <- 0L;
161-
t.stats.rx_pkts <- 0l;
162-
t.stats.tx_bytes <- 0L;
163-
t.stats.tx_pkts <- 0l
155+
let reset_stats_counters t = Mirage_net.Stats.reset t.stats

0 commit comments

Comments
 (0)