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]

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.

Start tracking specified thread

Note you must add main thread here manually

Stop tracking specified thread (for example if it's dead)

Add current thread using track_thread, returns thread id

Remove current thread using untrack_thread

Returns interval value configured in constructor

impl Meter
[src]

Scan system for metrics

This method must be called regularly at intervals specified in constructor.

impl Meter
[src]

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.

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.

Trait Implementations

impl Debug for Meter
[src]

Formats the value using the given formatter.