Deleted Added
full compact
procstat_threads.c (225736) procstat_threads.c (250871)
1/*-
2 * Copyright (c) 2007 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2007 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: stable/9/usr.bin/procstat/procstat_threads.c 224199 2011-07-18 20:06:15Z bz $
26 * $FreeBSD: stable/9/usr.bin/procstat/procstat_threads.c 250871 2013-05-21 19:05:27Z trociny $
27 */
28
29#include <sys/param.h>
30#include <sys/sysctl.h>
31#include <sys/user.h>
32
33#include <err.h>
34#include <errno.h>
35#include <libprocstat.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39
40#include "procstat.h"
41
42void
27 */
28
29#include <sys/param.h>
30#include <sys/sysctl.h>
31#include <sys/user.h>
32
33#include <err.h>
34#include <errno.h>
35#include <libprocstat.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39
40#include "procstat.h"
41
42void
43procstat_threads(struct kinfo_proc *kipp)
43procstat_threads(struct procstat *procstat, struct kinfo_proc *kipp)
44{
45 struct kinfo_proc *kip;
44{
45 struct kinfo_proc *kip;
46 int error, name[4];
47 unsigned int i;
46 unsigned int count, i;
48 const char *str;
47 const char *str;
49 size_t len;
50
51 if (!hflag)
52 printf("%5s %6s %-16s %-16s %2s %4s %-7s %-9s\n", "PID",
53 "TID", "COMM", "TDNAME", "CPU", "PRI", "STATE", "WCHAN");
54
48
49 if (!hflag)
50 printf("%5s %6s %-16s %-16s %2s %4s %-7s %-9s\n", "PID",
51 "TID", "COMM", "TDNAME", "CPU", "PRI", "STATE", "WCHAN");
52
55 /*
56 * We need to re-query for thread information, so don't use *kipp.
57 */
58 name[0] = CTL_KERN;
59 name[1] = KERN_PROC;
60 name[2] = KERN_PROC_PID | KERN_PROC_INC_THREAD;
61 name[3] = kipp->ki_pid;
62
63 len = 0;
64 error = sysctl(name, 4, NULL, &len, NULL, 0);
65 if (error < 0 && errno != ESRCH) {
66 warn("sysctl: kern.proc.pid: %d", kipp->ki_pid);
67 return;
68 }
69 if (error < 0)
70 return;
71
72 kip = malloc(len);
53 kip = procstat_getprocs(procstat, KERN_PROC_PID | KERN_PROC_INC_THREAD,
54 kipp->ki_pid, &count);
73 if (kip == NULL)
55 if (kip == NULL)
74 err(-1, "malloc");
75
76 if (sysctl(name, 4, kip, &len, NULL, 0) < 0) {
77 warn("sysctl: kern.proc.pid: %d", kipp->ki_pid);
78 free(kip);
79 return;
56 return;
80 }
81
82 kinfo_proc_sort(kip, len / sizeof(*kipp));
83 for (i = 0; i < len / sizeof(*kipp); i++) {
57 kinfo_proc_sort(kip, count);
58 for (i = 0; i < count; i++) {
84 kipp = &kip[i];
85 printf("%5d ", kipp->ki_pid);
86 printf("%6d ", kipp->ki_tid);
87 printf("%-16s ", strlen(kipp->ki_comm) ?
88 kipp->ki_comm : "-");
89 printf("%-16s ", (strlen(kipp->ki_tdname) &&
90 (strcmp(kipp->ki_comm, kipp->ki_tdname) != 0)) ?
91 kipp->ki_tdname : "-");

--- 42 unchanged lines hidden (view full) ---

134 printf("*%-8s ", strlen(kipp->ki_lockname) ?
135 kipp->ki_lockname : "-");
136 } else {
137 printf("%-9s ", strlen(kipp->ki_wmesg) ?
138 kipp->ki_wmesg : "-");
139 }
140 printf("\n");
141 }
59 kipp = &kip[i];
60 printf("%5d ", kipp->ki_pid);
61 printf("%6d ", kipp->ki_tid);
62 printf("%-16s ", strlen(kipp->ki_comm) ?
63 kipp->ki_comm : "-");
64 printf("%-16s ", (strlen(kipp->ki_tdname) &&
65 (strcmp(kipp->ki_comm, kipp->ki_tdname) != 0)) ?
66 kipp->ki_tdname : "-");

--- 42 unchanged lines hidden (view full) ---

109 printf("*%-8s ", strlen(kipp->ki_lockname) ?
110 kipp->ki_lockname : "-");
111 } else {
112 printf("%-9s ", strlen(kipp->ki_wmesg) ?
113 kipp->ki_wmesg : "-");
114 }
115 printf("\n");
116 }
142 free(kip);
117 procstat_freeprocs(procstat, kip);
143}
118}