+fill_taskprocinfo(task_t task, struct proc_taskinfo_internal * ptinfo)
+{
+ vm_map_t map;
+ task_absolutetime_info_data_t tinfo;
+ thread_t thread;
+ uint32_t cswitch = 0, numrunning = 0;
+ uint32_t syscalls_unix = 0;
+ uint32_t syscalls_mach = 0;
+
+ task_lock(task);
+
+ map = (task == kernel_task)? kernel_map: task->map;
+
+ ptinfo->pti_virtual_size = map->size;
+ ptinfo->pti_resident_size =
+ (mach_vm_size_t)(pmap_resident_count(map->pmap))
+ * PAGE_SIZE_64;
+
+ ptinfo->pti_policy = ((task != kernel_task)?
+ POLICY_TIMESHARE: POLICY_RR);
+
+ tinfo.threads_user = tinfo.threads_system = 0;
+ tinfo.total_user = task->total_user_time;
+ tinfo.total_system = task->total_system_time;
+
+ queue_iterate(&task->threads, thread, thread_t, task_threads) {
+ uint64_t tval;
+ spl_t x;
+
+ if (thread->options & TH_OPT_IDLE_THREAD)
+ continue;
+
+ x = splsched();
+ thread_lock(thread);
+
+ if ((thread->state & TH_RUN) == TH_RUN)
+ numrunning++;
+ cswitch += thread->c_switch;
+ tval = timer_grab(&thread->user_timer);
+ tinfo.threads_user += tval;
+ tinfo.total_user += tval;
+
+ tval = timer_grab(&thread->system_timer);
+
+ if (thread->precise_user_kernel_time) {
+ tinfo.threads_system += tval;
+ tinfo.total_system += tval;
+ } else {
+ /* system_timer may represent either sys or user */
+ tinfo.threads_user += tval;
+ tinfo.total_user += tval;
+ }
+
+ syscalls_unix += thread->syscalls_unix;
+ syscalls_mach += thread->syscalls_mach;
+
+ thread_unlock(thread);
+ splx(x);
+ }
+
+ ptinfo->pti_total_system = tinfo.total_system;
+ ptinfo->pti_total_user = tinfo.total_user;
+ ptinfo->pti_threads_system = tinfo.threads_system;
+ ptinfo->pti_threads_user = tinfo.threads_user;
+
+ ptinfo->pti_faults = task->faults;
+ ptinfo->pti_pageins = task->pageins;
+ ptinfo->pti_cow_faults = task->cow_faults;
+ ptinfo->pti_messages_sent = task->messages_sent;
+ ptinfo->pti_messages_received = task->messages_received;
+ ptinfo->pti_syscalls_mach = task->syscalls_mach + syscalls_mach;
+ ptinfo->pti_syscalls_unix = task->syscalls_unix + syscalls_unix;
+ ptinfo->pti_csw = task->c_switch + cswitch;
+ ptinfo->pti_threadnum = task->thread_count;
+ ptinfo->pti_numrunning = numrunning;
+ ptinfo->pti_priority = task->priority;
+
+ task_unlock(task);
+}
+
+int
+fill_taskthreadinfo(task_t task, uint64_t thaddr, int thuniqueid, struct proc_threadinfo_internal * ptinfo, void * vpp, int *vidp)