From 4e1a6d0e6744fbd594114870804c3a5062815280 Mon Sep 17 00:00:00 2001 From: jhb Date: Mon, 18 Jul 2011 17:33:08 +0000 Subject: - Export each thread's individual resource usage in in struct kinfo_proc's ki_rusage member when KERN_PROC_INC_THREAD is passed to one of the process sysctls. - Correctly account for the current thread's cputime in the thread when doing the runtime fixup in calcru(). - Use TIDs as the key to lookup the previous thread to compute IO stat deltas in IO mode in top when thread display is enabled. Reviewed by: kib Approved by: re (kib) --- usr.bin/top/machine.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'usr.bin/top') diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 02dc847..1f8a002 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -235,6 +235,7 @@ static int *pcpu_cpu_states; static int compare_jid(const void *a, const void *b); static int compare_pid(const void *a, const void *b); +static int compare_tid(const void *a, const void *b); static const char *format_nice(const struct kinfo_proc *pp); static void getsysctl(const char *name, void *ptr, size_t len); static int swapmode(int *retavail, int *retfree); @@ -557,7 +558,7 @@ get_old_proc(struct kinfo_proc *pp) * cache it. */ oldpp = bsearch(&pp, previous_pref, previous_proc_count, - sizeof(*previous_pref), compare_pid); + sizeof(*previous_pref), ps.thread ? compare_tid : compare_pid); if (oldpp == NULL) { pp->ki_udata = NOPROC; return (NULL); @@ -652,7 +653,7 @@ get_process_info(struct system_info *si, struct process_select *sel, previous_pref[i] = &previous_procs[i]; bcopy(pbase, previous_procs, nproc * sizeof(*previous_procs)); qsort(previous_pref, nproc, sizeof(*previous_pref), - compare_pid); + ps.thread ? compare_tid : compare_pid); } previous_proc_count = nproc; @@ -1059,6 +1060,18 @@ compare_pid(const void *p1, const void *p2) return ((*pp1)->ki_pid - (*pp2)->ki_pid); } +static int +compare_tid(const void *p1, const void *p2) +{ + const struct kinfo_proc * const *pp1 = p1; + const struct kinfo_proc * const *pp2 = p2; + + if ((*pp2)->ki_tid < 0 || (*pp1)->ki_tid < 0) + abort(); + + return ((*pp1)->ki_tid - (*pp2)->ki_tid); +} + /* * proc_compare - comparison function for "qsort" * Compares the resource consumption of two processes using five -- cgit v1.1