Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,13 @@ keywords = ["performance", "instrumentation", "metric", "pcp", "mmv"]

[dependencies]
bitflags = "0.9.1"
byteorder = "1.0.0"
hdrsample = "4.0.0"
lazy_static = "0.2.8"
memmap = "0.5.2"
regex = "0.2"
time = "0.1"
memmap2 = "0.9"

[dev-dependencies]
rand = "0.3.15"
hyper = "0.11.2"
futures = "0.1.14"
curl = "0.4.8"
iron = "0.5.1"

[target.'cfg(unix)'.dependencies]
nix = "0.8.0"

[target.'cfg(windows)'.dependencies]
kernel32-sys = "0.2.2"
63 changes: 63 additions & 0 deletions src/byteio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//! Native-endian read/write helpers
//!
//! MMV files are a same-host IPC mechanism, written by an instrumented process
//! and read back via mmap by `pmdammv` running on that same machine, never
//! transferred across hosts. The mmv(5) spec and the reference `libpcp_mmv` C
//! implementation both write plain native integers with no conversion, so these
//! methods use the host's native byte order rather than a fixed one.

use std::io::{self, Read, Write};

pub trait ReadBytesExt: Read {
fn read_u8(&mut self) -> io::Result<u8> {
let mut buf = [0u8; 1];
self.read_exact(&mut buf)?;
Ok(buf[0])
}

fn read_i32(&mut self) -> io::Result<i32> {
let mut buf = [0u8; 4];
self.read_exact(&mut buf)?;
Ok(i32::from_ne_bytes(buf))
}

fn read_u32(&mut self) -> io::Result<u32> {
let mut buf = [0u8; 4];
self.read_exact(&mut buf)?;
Ok(u32::from_ne_bytes(buf))
}

fn read_i64(&mut self) -> io::Result<i64> {
let mut buf = [0u8; 8];
self.read_exact(&mut buf)?;
Ok(i64::from_ne_bytes(buf))
}

fn read_u64(&mut self) -> io::Result<u64> {
let mut buf = [0u8; 8];
self.read_exact(&mut buf)?;
Ok(u64::from_ne_bytes(buf))
}
}

impl<R: Read + ?Sized> ReadBytesExt for R {}

pub trait WriteBytesExt: Write {
fn write_i32(&mut self, n: i32) -> io::Result<()> {
self.write_all(&n.to_ne_bytes())
}

fn write_u32(&mut self, n: u32) -> io::Result<()> {
self.write_all(&n.to_ne_bytes())
}

fn write_i64(&mut self, n: i64) -> io::Result<()> {
self.write_all(&n.to_ne_bytes())
}

fn write_u64(&mut self, n: u64) -> io::Result<()> {
self.write_all(&n.to_ne_bytes())
}
}

impl<W: Write + ?Sized> WriteBytesExt for W {}
2 changes: 1 addition & 1 deletion src/client/metric/countvector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub fn test_multiple_initvals() {
assert_eq!(cv.val("b").unwrap(), 2);
assert_eq!(cv.val("c").unwrap(), 3);

Client::new("count_vector_test")
Client::new("count_vector_multiple_initvals_test")
.unwrap()
.export(&mut [&mut cv])
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/client/metric/gaugevector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn test() {
assert_eq!(gv.val("b").unwrap(), 1.5);
assert_eq!(gv.val("c").unwrap(), 1.5);

Client::new("count_vector_test")
Client::new("gauge_vector_test")
.unwrap()
.export(&mut [&mut gv])
.unwrap();
Expand Down
Loading