diff --git a/ChangeLog b/ChangeLog index 0ab3d993..ba0f860b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-03-24 Doug MacEachern + + * Implement proc_state_t.threads on OS X + 2007-03-11 Doug MacEachern * Implement native sigar_proc_cpu_get function diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index c10b2781..2ef2bbf1 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -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';