@@ -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