#![warn(missing_docs)]
#![warn(missing_debug_implementations)]
extern crate libc;
extern crate num_cpus;
extern crate serde;
#[macro_use] extern crate quick_error;
#[macro_use] extern crate serde_derive;
use std::fs::File;
use std::time::{SystemTime, Instant, Duration};
use std::collections::{VecDeque, HashMap};
mod meter;
mod scan;
mod error;
mod report;
mod serialize;
mod debug;
pub use error::Error;
pub use report::ThreadReportIter;
pub type Pid = u32;
struct ThreadInfo {
user_time: u64,
system_time: u64,
child_user_time: u64,
child_system_time: u64,
}
struct Snapshot {
timestamp: SystemTime,
instant: Instant,
uptime: u64,
idle_time: u64,
process: ThreadInfo,
memory_rss: u64,
memory_virtual: u64,
memory_virtual_peak: u64,
memory_swap: u64,
read_bytes: u64,
write_bytes: u64,
read_ops: u64,
write_ops: u64,
read_disk_bytes: u64,
write_disk_bytes: u64,
write_cancelled_bytes: u64,
threads: HashMap<Pid, ThreadInfo>,
}
#[derive(Debug)]
pub struct ThreadUsage {
pub cpu_usage: f32,
pub cpu_usage_with_children: f32,
}
#[derive(Debug, Serialize)]
pub struct Report {
#[serde(serialize_with="serialize::serialize_timestamp")]
pub timestamp: SystemTime,
#[serde(serialize_with="serialize::serialize_duration")]
pub duration: Duration,
#[serde(serialize_with="serialize::serialize_timestamp")]
pub start_time: SystemTime,
#[serde(serialize_with="serialize::serialize_duration")]
pub system_uptime: Duration,
pub global_cpu_usage: f32,
pub process_cpu_usage: f32,
pub gross_cpu_usage: f32,
pub memory_rss: u64,
pub memory_virtual: u64,
pub memory_swap: u64,
pub memory_rss_peak: u64,
pub memory_virtual_peak: u64,
pub memory_swap_peak: u64,
pub disk_read: f32,
pub disk_write: f32,
pub disk_cancelled: f32,
pub io_read: f32,
pub io_write: f32,
pub io_read_ops: f32,
pub io_write_ops: f32,
}
#[derive(Debug, Serialize)]
pub struct ThreadReport {
pub cpu_usage: f32,
pub system_cpu: f32,
pub user_cpu: f32,
}
pub struct Meter {
#[allow(dead_code)]
scan_interval: Duration,
num_cpus: usize,
num_snapshots: usize,
start_time: SystemTime,
snapshots: VecDeque<Snapshot>,
thread_names: HashMap<Pid, String>,
text_buf: String,
path_buf: String,
#[cfg(target_os="linux")]
io_file: File,
memory_rss_peak: u64,
memory_swap_peak: u64,
}