Struct self_meter::Meter
source · pub struct Meter { /* private fields */ }Expand description
The main structure that makes mesurements and reports values
Create it with new() then add threads that you want to track in a thread
breakdown information with meter.track_thread() and
meter.untrack_thread().
Then add meter.scan() with a timer to scan the process info. It’s
recommended to call it on the interval of one second.
Method report() may be used to get structure with stats. report_json()
can return a rustc_serialize::Json and report_json_str() returns that
serialized.
Note that the structure returned with report() can be changed when we
bump major version of the library. And while report_json() and
report_json_str() will never break the type system, their format will
always reflect that of report() call.
We don’t track all the threads separately because thread ids are useless without names, and we can fine-tune performance in the case we have known number of threads. Obviously, process-wide info accounts all the threads.
Implementations§
source§impl Meter
impl Meter
sourcepub fn new(scan_interval: Duration) -> Result<Meter, Error>
pub fn new(scan_interval: Duration) -> Result<Meter, Error>
Create a new meter with scan_interval
Note: meter will not scan by itself, you are expected to call scan()
with interval.
You don’t have to guarantee the interval exactly, but it influences the accuracy of your measurements.
When creating a Meter object we are trying to discover the number
of processes on the system. If that fails, we return error.
sourcepub fn track_thread(&mut self, tid: Pid, name: &str)
pub fn track_thread(&mut self, tid: Pid, name: &str)
Start tracking specified thread
Note you must add main thread here manually
sourcepub fn untrack_thread(&mut self, tid: Pid)
pub fn untrack_thread(&mut self, tid: Pid)
Stop tracking specified thread (for example if it’s dead)
sourcepub fn track_current_thread(&mut self, name: &str) -> Pid
pub fn track_current_thread(&mut self, name: &str) -> Pid
Add current thread using track_thread, returns thread id