Skip to content

Commit 4a88348

Browse files
Merge pull request #70 from andrewdavidmackenzie/improve_task_info
Add tests and comments to pidinfo()
2 parents a825bec + b2c30b6 commit 4a88348

File tree

3 files changed

+67
-11
lines changed

3 files changed

+67
-11
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ jobs:
4141
components: clippy
4242

4343
- name: Clippy
44-
run: cargo clippy --all --all-targets --all-features -- -D warnings
44+
run: cargo clippy --all --tests --all-targets --all-features -- -D warnings
4545

4646
- name: ConfigureCoverage
4747
if: matrix.rust == 'nightly'
4848
run: |
4949
cargo install grcov
5050
rustup component add llvm-tools-preview
5151
echo RUSTFLAGS="-Zinstrument-coverage" >> "$GITHUB_ENV"
52-
echo LLVM_PROFILE_FILE="flow-%p-%m.profraw" >> "$GITHUB_ENV"
52+
echo LLVM_PROFILE_FILE="libproc-%p-%m.profraw" >> "$GITHUB_ENV"
5353
5454
- name: Run Tests
5555
if: matrix.os != 'macos-11'

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libproc"
3-
version = "0.10.0"
3+
version = "0.10.1"
44
description = "A library to get information about running processes - for Mac OS X and Linux"
55
authors = ["Andrew Mackenzie <[email protected]>"]
66
repository = "https://github.com/andrewdavidmackenzie/libproc-rs"

src/libproc/proc_pid.rs

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,12 @@ pub fn listpidspath(proc_types: ProcType, path: &str) -> Result<Vec<u32>, String
275275
}
276276
}
277277

278-
/// Get info about a process
279-
///
280-
/// arg - is "heavily not documented" and need to look at code for each flavour
281-
/// [here](http://opensource.apple.com/source/xnu/xnu-1504.7.4/bsd/kern/proc_info.c)
282-
/// to figure out what it's doing.
283-
///
284-
/// Pull-Requests welcome!
278+
/// Get info about a process, task, thread or work queue by specifying the appropriate type for `T`:
279+
/// - `BSDInfo`
280+
/// - `TaskInfo`
281+
/// - `TaskAllInfo`
282+
/// - `ThreadInfo`
283+
/// - `WorkQueueInfo`
285284
///
286285
/// # Examples
287286
///
@@ -293,6 +292,7 @@ pub fn listpidspath(proc_types: ProcType, path: &str) -> Result<Vec<u32>, String
293292
///
294293
/// let pid = process::id() as i32;
295294
///
295+
/// // Get the `BSDInfo` for Process of pid 0
296296
/// match pidinfo::<BSDInfo>(pid, 0) {
297297
/// Ok(info) => assert_eq!(info.pbi_pid as i32, pid),
298298
/// Err(err) => assert!(false, "Error retrieving process info: {}", err)
@@ -685,6 +685,12 @@ mod test {
685685
use super::am_root;
686686
#[cfg(target_os = "linux")]
687687
use crate::libproc::helpers;
688+
#[cfg(target_os = "macos")]
689+
use crate::libproc::task_info::TaskInfo;
690+
#[cfg(target_os = "macos")]
691+
use crate::libproc::thread_info::ThreadInfo;
692+
#[cfg(target_os = "macos")]
693+
use crate::libproc::work_queue_info::WorkQueueInfo;
688694

689695
#[cfg(target_os = "macos")]
690696
#[test]
@@ -694,7 +700,57 @@ mod test {
694700

695701
match pidinfo::<BSDInfo>(pid, 0) {
696702
Ok(info) => assert_eq!(info.pbi_pid as i32, pid),
697-
Err(_) => panic!("Error retrieving process info")
703+
Err(e) => panic!("Error retrieving BSDInfo: {}", e)
704+
};
705+
}
706+
707+
#[cfg(target_os = "macos")]
708+
#[test]
709+
fn taskinfo_test() {
710+
use std::process;
711+
let pid = process::id() as i32;
712+
713+
match pidinfo::<TaskInfo>(pid, 0) {
714+
Ok(info) => assert!(info.pti_virtual_size > 0),
715+
Err(e) => panic!("Error retrieving TaskInfo: {}", e)
716+
};
717+
}
718+
719+
#[cfg(target_os = "macos")]
720+
#[test]
721+
fn taskallinfo_test() {
722+
use std::process;
723+
let pid = process::id() as i32;
724+
725+
match pidinfo::<TaskAllInfo>(pid, 0) {
726+
Ok(info) => assert!(info.ptinfo.pti_virtual_size > 0),
727+
Err(e) => panic!("Error retrieving TaskAllInfo: {}", e)
728+
};
729+
}
730+
731+
#[ignore]
732+
#[cfg(target_os = "macos")]
733+
#[test]
734+
fn threadinfo_test() {
735+
use std::process;
736+
let pid = process::id() as i32;
737+
738+
match pidinfo::<ThreadInfo>(pid, 0) {
739+
Ok(info) => assert!(info.pth_user_time > 0),
740+
Err(e) => panic!("Error retrieving ThreadInfo: {}", e)
741+
};
742+
}
743+
744+
#[ignore]
745+
#[cfg(target_os = "macos")]
746+
#[test]
747+
fn workqueueinfo_test() {
748+
use std::process;
749+
let pid = process::id() as i32;
750+
751+
match pidinfo::<WorkQueueInfo>(pid, 0) {
752+
Ok(info) => assert!(info.pwq_nthreads > 0),
753+
Err(_) => panic!("Error retrieving WorkQueueInfo")
698754
};
699755
}
700756

0 commit comments

Comments
 (0)