summaryrefslogtreecommitdiff
path: root/libps/procstat.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-05-29 15:44:32 +0000
committerMiles Bader <miles@gnu.org>1996-05-29 15:44:32 +0000
commitdfc53b9ed4742c62b563bf9e94a5c3f34f363544 (patch)
tree1cf0dae3f927d02ae67085e9f2e96f69e746eda6 /libps/procstat.c
parent0bd1f0b162a549e828398391f308f54e77dfa539 (diff)
(merge_procinfo): Don't die if WAITS == 0.
(summarize_thread_waits): Correctly advance NEXT_WAIT. Skip threads marked `itimer'. (proc_stat_set_flags): Consider processes with less than 4 threads to be candidates for a meaningful process wait status.
Diffstat (limited to 'libps/procstat.c')
-rw-r--r--libps/procstat.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/libps/procstat.c b/libps/procstat.c
index 4167e130..2ed3f1af 100644
--- a/libps/procstat.c
+++ b/libps/procstat.c
@@ -182,8 +182,15 @@ merge_procinfo (process_t server, pid_t pid,
*pi = new_pi;
*pi_size = new_pi_size;
- *waits = new_waits;
- *waits_len = new_waits_len;
+
+ if (waits && waits_len)
+ {
+ *waits = new_waits;
+ *waits_len = new_waits_len;
+ }
+ else if (new_waits_len)
+ /* Caller doesn't want wait info, so free it. */
+ vm_deallocate (mach_task_self (), (vm_address_t)new_waits, new_waits_len);
return 0;
}
@@ -420,20 +427,28 @@ summarize_thread_waits (struct procinfo *pi, char *waits, size_t waits_len,
if (! pi->threadinfos[i].died)
if (next_wait > waits + waits_len)
break;
- else if (strncmp (next_wait, "msgport", waits + waits_len - next_wait)
- == 0)
- next_wait++; /* signal thread. */
- else if (*wait)
- /* There are multiple user threads. Punt. */
- {
- *wait = "*";
- *rpc = 0;
- break;
- }
else
{
- *wait = next_wait;
- *rpc = pi->threadinfos[i].rpc_block;
+ int left = waits + waits_len - next_wait;
+
+ if (strncmp (next_wait, "msgport", left) == 0
+ || strncmp (next_wait, "itimer", left) == 0)
+ ; /* libc internal threads; ignore. */
+ else if (*wait)
+ /* There are multiple user threads. Punt. */
+ {
+ *wait = "*";
+ *rpc = 0;
+ break;
+ }
+ else
+ {
+ *wait = next_wait;
+ *rpc = pi->threadinfos[i].rpc_block;
+ }
+
+ /* Advance NEXT_WAIT to the next wait string. */
+ next_wait += strnlen (next_wait, left);
}
}
@@ -599,8 +614,9 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags)
if (! err)
need &= ~PSTAT_NUM_THREADS;
}
- if ((have & PSTAT_NUM_THREADS) && ps->num_threads == 2)
- /* Only one user thread -- thread-wait info is meaningful! */
+ if ((have & PSTAT_NUM_THREADS) && ps->num_threads <= 3)
+ /* Perhaps only 1 user thread -- thread-wait info may be
+ meaningful! */
need |= PSTAT_THREAD_WAITS;
}