mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
vm-virtio: net: Expose network counters through VirtioDevice
Through the counters() function on the trait expose the accumulated counters. TEST=Observe that the counters from the VM match those from the tap on the host (RX-TX inverted) and inside the guest (non inverted.) Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
dd54883a07
commit
6713a3c859
@ -20,6 +20,7 @@ use libc::EAGAIN;
|
||||
use libc::EFD_NONBLOCK;
|
||||
use net_util::{MacAddr, Tap};
|
||||
use std::cmp;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::io::{self, Write};
|
||||
@ -739,6 +740,29 @@ impl VirtioDevice for Net {
|
||||
self.queue_evts.take().unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
fn counters(&self) -> Option<HashMap<&'static str, Wrapping<u64>>> {
|
||||
let mut counters = HashMap::new();
|
||||
|
||||
counters.insert(
|
||||
"rx_bytes",
|
||||
Wrapping(self.counters.rx_bytes.load(Ordering::Acquire)),
|
||||
);
|
||||
counters.insert(
|
||||
"rx_frames",
|
||||
Wrapping(self.counters.rx_frames.load(Ordering::Acquire)),
|
||||
);
|
||||
counters.insert(
|
||||
"tx_bytes",
|
||||
Wrapping(self.counters.tx_bytes.load(Ordering::Acquire)),
|
||||
);
|
||||
counters.insert(
|
||||
"tx_frames",
|
||||
Wrapping(self.counters.tx_frames.load(Ordering::Acquire)),
|
||||
);
|
||||
|
||||
Some(counters)
|
||||
}
|
||||
}
|
||||
|
||||
virtio_ctrl_q_pausable!(Net);
|
||||
|
Loading…
Reference in New Issue
Block a user