Struct self_meter::Meter
[−]
[src]
pub struct Meter { /* fields omitted */ }
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.
Methods
impl Meter
[src]
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.
fn track_thread(&mut self, tid: Pid, name: &str)
Start tracking specified thread
Note you must add main thread here manually
fn untrack_thread(&mut self, tid: Pid)
Stop tracking specified thread (for example if it's dead)
fn track_current_thread(&mut self, _name: &str) -> Pid
Add current thread using track_thread
, returns thread id
Non-linux is not supported yet (no-op)
fn untrack_current_thread(&mut self)
Remove current thread using untrack_thread
Non-linux is not supported yet (no-op)
fn get_scan_interval(&self) -> Duration
Returns interval value configured in constructor
impl Meter
[src]
fn scan(&mut self) -> Result<(), Error>
Scan system for metrics
This method must be called regularly at intervals specified in constructor.
impl Meter
[src]
fn report(&self) -> Option<Report>
Get report of the last scan interval
We need at least two scans to measure CPU usage, so this method returns None if less than two scans were done ever in the past.
fn thread_report(&self) -> Option<ThreadReportIter>
Returns iterator over reports for threads
Note: each thread must be registered with Meter::track_thread
or
Meter::track_current_thread
to be tracked here.
We need at least two scans to measure CPU usage, so this method returns None if less than two scans were done ever in the past.