resource-meter 0.2.0

A lightweight resource usage measurement library for Rust, providing scoped measurement of wall-clock time, user CPU time, and system CPU time.
Documentation
  • Coverage
  • 6.25%
    1 out of 16 items documented1 out of 12 items with examples
  • Size
  • Source code size: 12.35 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.54 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • oxnz

resource-meter

A lightweight resource usage measurement library for Rust, providing scoped measurement of wall-clock time, user CPU time, and system CPU time.

Features

  • Scoped measurement using a stack-based API
  • Hierarchical (tree) and flat reporting
  • Tracks wall time, user CPU time, and system CPU time
  • Simple API for integration
  • Platform support for Unix-like systems (uses libc::getrusage)

Example

use resource_meter::ResourceMeterStack;
use std::thread::sleep;
use std::time::Duration;

fn main() {
    // Create a stack to manage resource measurement scopes
    let mut stack = ResourceMeterStack::new();

    // Start a measurement scope named "outer"
    stack.push("outer");
    sleep(Duration::from_millis(100));

    // Start a nested measurement scope named "outer/inner"
    stack.push("outer/inner");
    sleep(Duration::from_millis(200));
    stack.pop(); // End "outer/inner"

    sleep(Duration::from_millis(50));
    stack.pop(); // End "outer"

    // Generate and print a hierarchical report
    let report = stack.finish();
    println!("{}", report);
}