Implement proc_state_t.threads on OS X

This commit is contained in:
Doug MacEachern 2007-03-24 23:07:42 +00:00
parent da7ea6cb29
commit b1a19f4e72
2 changed files with 35 additions and 0 deletions

View File

@ -1,3 +1,7 @@
2007-03-24 Doug MacEachern <dougm@hyperic.com>
* Implement proc_state_t.threads on OS X
2007-03-11 Doug MacEachern <dougm@hyperic.com>
* Implement native sigar_proc_cpu_get function

View File

@ -891,6 +891,33 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
return SIGAR_OK;
}
#ifdef DARWIN
static int sigar_proc_threads_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_state_t *procstate)
{
mach_port_t task, self = mach_task_self();
kern_return_t status;
thread_array_t threads;
mach_msg_type_number_t count;
status = task_for_pid(self, pid, &task);
if (status != KERN_SUCCESS) {
return errno;
}
status = task_threads(task, &threads, &count);
if (status != KERN_SUCCESS) {
return errno;
}
procstate->threads = count;
vm_deallocate(self, (vm_address_t)threads, sizeof(thread_t) * count);
return SIGAR_OK;
}
#endif
int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_state_t *procstate)
{
@ -909,6 +936,10 @@ int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
procstate->threads = SIGAR_FIELD_NOTIMPL;
procstate->processor = SIGAR_FIELD_NOTIMPL;
#ifdef DARWIN
sigar_proc_threads_get(sigar, pid, procstate);
#endif
switch (pinfo->KI_STAT) {
case SIDL:
procstate->state = 'D';