diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-06 16:11:30 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-06 16:11:30 +0000 |
commit | aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7 (patch) | |
tree | 941cbdd387b41c1a81587c20a6df9f0e5e0ff7ab /libnetdata/worker_utilization | |
parent | Adding upstream version 1.37.1. (diff) | |
download | netdata-aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7.tar.xz netdata-aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7.zip |
Adding upstream version 1.38.0.upstream/1.38.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/worker_utilization')
-rw-r--r-- | libnetdata/worker_utilization/worker_utilization.c | 25 | ||||
-rw-r--r-- | libnetdata/worker_utilization/worker_utilization.h | 1 |
2 files changed, 20 insertions, 6 deletions
diff --git a/libnetdata/worker_utilization/worker_utilization.c b/libnetdata/worker_utilization/worker_utilization.c index afaff209..8028e3a2 100644 --- a/libnetdata/worker_utilization/worker_utilization.c +++ b/libnetdata/worker_utilization/worker_utilization.c @@ -52,6 +52,7 @@ struct workers_workname { // this is what we add to Ju static struct workers_globals { SPINLOCK spinlock; Pvoid_t worknames_JudyHS; + size_t memory; } workers_globals = { // workers globals, the base of all worknames .spinlock = NETDATA_SPINLOCK_INITIALIZER, // a lock for the worknames index @@ -60,6 +61,14 @@ static struct workers_globals { static __thread struct worker *worker = NULL; // the current thread worker +size_t workers_allocated_memory(void) { + netdata_spinlock_lock(&workers_globals.spinlock); + size_t memory = workers_globals.memory; + netdata_spinlock_unlock(&workers_globals.spinlock); + + return memory; +} + void worker_register(const char *name) { if(unlikely(worker)) return; @@ -76,20 +85,22 @@ void worker_register(const char *name) { size_t name_size = strlen(name) + 1; netdata_spinlock_lock(&workers_globals.spinlock); - Pvoid_t *PValue = JudyHSGet(workers_globals.worknames_JudyHS, (void *)name, name_size); - if(!PValue) - PValue = JudyHSIns(&workers_globals.worknames_JudyHS, (void *)name, name_size, PJE0); + workers_globals.memory += sizeof(struct worker) + strlen(worker->tag) + 1 + strlen(worker->workname) + 1; + + Pvoid_t *PValue = JudyHSIns(&workers_globals.worknames_JudyHS, (void *)name, name_size, PJE0); struct workers_workname *workname = *PValue; if(!workname) { workname = mallocz(sizeof(struct workers_workname)); - workname->spinlock = NETDATA_SPINLOCK_INITIALIZER; + netdata_spinlock_init(&workname->spinlock); workname->base = NULL; *PValue = workname; + + workers_globals.memory += sizeof(struct workers_workname) + JUDYHS_INDEX_SIZE_ESTIMATE(name_size); } netdata_spinlock_lock(&workname->spinlock); - DOUBLE_LINKED_LIST_APPEND_UNSAFE(workname->base, worker, prev, next); + DOUBLE_LINKED_LIST_APPEND_ITEM_UNSAFE(workname->base, worker, prev, next); netdata_spinlock_unlock(&workname->spinlock); netdata_spinlock_unlock(&workers_globals.spinlock); @@ -130,14 +141,16 @@ void worker_unregister(void) { if(PValue) { struct workers_workname *workname = *PValue; netdata_spinlock_lock(&workname->spinlock); - DOUBLE_LINKED_LIST_REMOVE_UNSAFE(workname->base, worker, prev, next); + DOUBLE_LINKED_LIST_REMOVE_ITEM_UNSAFE(workname->base, worker, prev, next); netdata_spinlock_unlock(&workname->spinlock); if(!workname->base) { JudyHSDel(&workers_globals.worknames_JudyHS, (void *) worker->workname, workname_size, PJE0); freez(workname); + workers_globals.memory -= sizeof(struct workers_workname) + JUDYHS_INDEX_SIZE_ESTIMATE(workname_size); } } + workers_globals.memory -= sizeof(struct worker) + strlen(worker->tag) + 1 + strlen(worker->workname) + 1; netdata_spinlock_unlock(&workers_globals.spinlock); for(int i = 0; i < WORKER_UTILIZATION_MAX_JOB_TYPES ;i++) { diff --git a/libnetdata/worker_utilization/worker_utilization.h b/libnetdata/worker_utilization/worker_utilization.h index f1412e6b..6745a010 100644 --- a/libnetdata/worker_utilization/worker_utilization.h +++ b/libnetdata/worker_utilization/worker_utilization.h @@ -15,6 +15,7 @@ typedef enum { WORKER_METRIC_INCREMENTAL_TOTAL = 4, } WORKER_METRIC_TYPE; +size_t workers_allocated_memory(void); void worker_register(const char *name); void worker_register_job_name(size_t job_id, const char *name); void worker_register_job_custom_metric(size_t job_id, const char *name, const char *units, WORKER_METRIC_TYPE type); |