Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
- name: Run tests (only default features)
run: cargo test
- name: Run tests (all tests enabled)
- name: Run tests
run: cargo test
build:
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Changelog

## Unversioned

- Major: Replaced async api with synchronous API. (#20, #22, #24)
- macOS: apply timebase information to CPU times. (#21, #25)
- Bugfix: macOS: apply timebase information to CPU times. (#21, #25)
- Dev: Dependency updates (#26).

## v1.0.0

Expand Down
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ description = "Get memory usage and CPU time on Linux and Windows"
license = "MIT"
version = "1.0.0"
keywords = ["process", "cpu", "memory"]
categories = ["api-bindings", "asynchronous", "os"]
categories = ["api-bindings", "os"]
repository = "https://github.com/robotty/simple-process-stats"
readme = "README.md"
authors = ["Ruben Anders <ruben.anders@robotty.de>"]
edition = "2018"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
thiserror = "1.0.20"
thiserror = "2"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3.9", features = ["psapi", "processthreadsapi"] }
winapi = { version = "0.3", features = ["psapi", "processthreadsapi"] }

[target.'cfg(target_os = "linux")'.dependencies]
procfs = "0.9.0"
libc = "0.2.72"
procfs = "0.18"
libc = "0.2"

[target.'cfg(target_os = "macos")'.dependencies]
darwin-libproc = "0.2.0"
libc = "0.2.72"
darwin-libproc = "0.2"
libc = "0.2"
10 changes: 5 additions & 5 deletions src/linux.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use crate::{Error, ProcessStats};
use procfs::FromRead;
use procfs::process::Stat;
use std::io::Cursor;
use std::path::Path;
use std::time::Duration;

pub fn get_info() -> Result<ProcessStats, Error> {
let bytes_per_page = procfs::page_size().map_err(Error::SystemCall)?;
let ticks_per_second = procfs::ticks_per_second().map_err(Error::SystemCall)?;
let bytes_per_page = procfs::page_size();
let ticks_per_second = procfs::ticks_per_second();

let path = Path::new("/proc/self/stat");
let file_contents = std::fs::read(path).map_err(|e| Error::FileRead(path.to_path_buf(), e))?;

let readable_string = Cursor::new(file_contents);
let stat_file =
Stat::from_reader(readable_string).map_err(|_e| Error::FileContentsMalformed)?;
let stat_file = Stat::from_read(readable_string).map_err(|_e| Error::FileContentsMalformed)?;

let memory_usage_bytes = (stat_file.rss as u64) * (bytes_per_page as u64);
let user_mode_seconds = (stat_file.utime as f64) / (ticks_per_second as f64);
Expand All @@ -32,7 +32,7 @@ pub mod tests {

#[test]
pub fn test_no_error() {
#[no_mangle]
#[unsafe(no_mangle)]
fn spin_for_a_bit() {
let mut _a = 0;
for _i in 0..9999999 {
Expand Down
4 changes: 2 additions & 2 deletions src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct mach_timebase_info {

impl mach_timebase_info {
pub fn get() -> Self {
extern "C" {
unsafe extern "C" {
fn mach_timebase_info(info: *mut mach_timebase_info) -> libc::c_int;
}
let mut info = mach_timebase_info { numer: 0, denom: 0 };
Expand All @@ -43,7 +43,7 @@ pub mod tests {

#[test]
pub fn test_no_error() {
#[no_mangle]
#[unsafe(no_mangle)]
fn spin_for_a_bit() {
let mut _a = 0;
for _i in 0..9999999 {
Expand Down
3 changes: 2 additions & 1 deletion src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ mod tests {

#[test]
fn test_no_error() {
#[no_mangle]
#[unsafe(no_mangle)]
fn spin_for_a_bit() {
let mut _a = 0;
#[allow(clippy::explicit_counter_loop)]
for _i in 0..9999999 {
_a += 1;
}
Expand Down
Loading