Git Product home page Git Product logo

spork.rs's Introduction

Spork

CPU and memory usage for threads and processes.

Build Status Coverage Status MIT licensed

Documentation

Install

With Cargo Edit:

cargo add spork

Or add to your Cargo.toml

spork = "0.1"

Status

Currently POSIX compliant platforms are developed and tested, but Windows support remains a WIP.

Usage

extern crate spork;

use spork::{
  Spork,
  Error,
  ErrorKind,
  Platform,
  StatType,
  Stats
};

let spork = match Spork::new() {
  Ok(s) => s,
  Err(e) => panic!("Error creating spork client! {:?}", e)
};

println!("Using platform {:?}", spork.platform());
println!("CPU cores: {:?}x @ {:?} Hz", spork.num_cores(), spork.clock_speed());

// get process stats 
let p_stats = match spork.stats(StatType::Process) {
  Ok(s) => s,
  Err(e) => panic!("Error polling process stats! {:?}", e)
};
println!("Process stats: {:?}", p_stats);

// get thread stats 
let t_stats = match spork.stats(StatType::Thread) {
  Ok(s) => s,
  Err(e) => panic!("Error polling thread stats! {:?}", e)
};

println!("Thread CPU: {}%, Memory: {} bytes, Cores: {}, Type: {}, Polled at: {}", 
  t_stats.cpu, t_stats.memory, t_stats.cores, t_stats.kind, t_stats.polled);

// get process stats across all CPU cores
let p_stats = spork.stats_with_cpus(StatType::Process, None).unwrap();

// get process stats across only 2 cores
let p_stats = spork.stats_with_cpus(StatType::Process, Some(2)).unwrap();

// get stats for child threads of the calling thread across all CPU cores
let c_stats = spork.stats_with_cpus(StatType::Children, None).unwrap();

Unsupported Platforms

This module supports POSIX compliant platforms (Linux, OS X, etc) and Windows (soon). If you'd like to use this on an unsupported platform, or one on which you might expect compatibility issues, there are two options available for testing and usage. If you'd prefer to catch any compatibility issues at compile-time just download this library and try to build it. If it builds it shouldTM work, but it's still a good idea to run the test suite before trying it in production.

If you'd prefer to handle compatibility errors at runtime add the compile_unimplemented feature to your Cargo.toml for Spork. Instead of introducing compiler errors this will compile mock functions which always return Unimplemented errors in place of any missing platform-specific ones.

Tests

cargo test

spork.rs's People

Contributors

aembke avatar ronnychan-okta avatar stegmanh avatar colingabr avatar samuelxing-okta avatar virginiachiu-okta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.