summaryrefslogtreecommitdiff
path: root/src/libvmon/vmon.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2025-04-12 11:23:53 -0700
committerVito Caputo <vcaputo@pengaru.com>2025-04-12 11:23:53 -0700
commitb0eba82135bae9a28d7a916c4f54fd43a86f7159 (patch)
tree7f2f50366c17b2a29dda3f4fc930f44d0d3ad7d2 /src/libvmon/vmon.c
parent77a5a77216e8c174e1df516d660c79643576c43c (diff)
libvmon: track active threads count per process
This introduces vmon_proc_t.n_current_threads, a counter reflecting the currently non-stale number of threads in an is_threaded process. You could get this by walking the threads linked list and filtering out the is_stale entries, but in preparation of showing this count in the charts hierarchy I'm caching the incrementally maintained count so the list doesn't need to be walked repeatedly. Note it's important to suppress the is_stale nodes from the count, so the count isn't being decremented when stale nodes get finally removed from the list - instead when nodes transition to being stale. The count shown in charts should reflect the number of thread rows seen at the same time (when --no-threads isn't in use)
Diffstat (limited to 'src/libvmon/vmon.c')
-rw-r--r--src/libvmon/vmon.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libvmon/vmon.c b/src/libvmon/vmon.c
index e8a8d23..b4c008c 100644
--- a/src/libvmon/vmon.c
+++ b/src/libvmon/vmon.c
@@ -442,6 +442,7 @@ static vmon_proc_t * proc_monitor(vmon_t *vmon, vmon_proc_t *parent, int pid, vm
list_add_tail(&proc->threads, &parent->threads);
parent->threads_changed = 1;
parent->is_threaded = 1;
+ parent->n_current_threads++;
} else {
list_add_tail(&proc->siblings, &parent->children);
parent->children_changed = 1;
@@ -643,6 +644,8 @@ static int proc_follow_threads(vmon_t *vmon, vmon_proc_t *proc, vmon_proc_follow
list_for_each_entry(tmp, &proc->threads, threads)
tmp->is_stale = 1;
+ proc->n_current_threads = 0;
+
/* FIXME: the changes count seems to be unused here, so this currently always returns SAMPLE_UNCHANGED, and
* it's unclear to me if that was intentional or just never finished.
*/
@@ -679,8 +682,11 @@ static int proc_follow_threads(vmon_t *vmon, vmon_proc_t *proc, vmon_proc_follow
list_for_each_entry_safe(tmp, _tmp, &proc->threads, threads) {
/* set children not found to stale status so the caller can respond and on our next sample invocation we will unmonitor them */
- if (tmp->generation != vmon->generation)
+ if (tmp->generation != vmon->generation) {
tmp->is_stale = 1;
+ assert(proc->n_current_threads);
+ proc->n_current_threads--;
+ }
}
return changes ? SAMPLE_CHANGED : SAMPLE_UNCHANGED;
© All Rights Reserved