summaryrefslogtreecommitdiffstats
path: root/libnetdata/worker_utilization
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:20:02 +0000
commit58daab21cd043e1dc37024a7f99b396788372918 (patch)
tree96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /libnetdata/worker_utilization
parentReleasing debian version 1.43.2-1. (diff)
downloadnetdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz
netdata-58daab21cd043e1dc37024a7f99b396788372918.zip
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--libnetdata/worker_utilization/worker_utilization.c21
-rw-r--r--libnetdata/worker_utilization/worker_utilization.h1
2 files changed, 19 insertions, 3 deletions
diff --git a/libnetdata/worker_utilization/worker_utilization.c b/libnetdata/worker_utilization/worker_utilization.c
index ad45dbc7f..f39cea8a0 100644
--- a/libnetdata/worker_utilization/worker_utilization.c
+++ b/libnetdata/worker_utilization/worker_utilization.c
@@ -50,13 +50,16 @@ struct workers_workname { // this is what we add to Ju
};
static struct workers_globals {
+ bool enabled;
+
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
- .worknames_JudyHS = NULL, // the worknames index
+ .enabled = false,
+ .spinlock = NETDATA_SPINLOCK_INITIALIZER, // a lock for the worknames index
+ .worknames_JudyHS = NULL, // the worknames index
};
static __thread struct worker *worker = NULL; // the current thread worker
@@ -69,7 +72,14 @@ static inline usec_t worker_now_monotonic_usec(void) {
#endif
}
+void workers_utilization_enable(void) {
+ workers_globals.enabled = true;
+}
+
size_t workers_allocated_memory(void) {
+ if(!workers_globals.enabled)
+ return 0;
+
spinlock_lock(&workers_globals.spinlock);
size_t memory = workers_globals.memory;
spinlock_unlock(&workers_globals.spinlock);
@@ -78,7 +88,8 @@ size_t workers_allocated_memory(void) {
}
void worker_register(const char *name) {
- if(unlikely(worker)) return;
+ if(unlikely(worker || !workers_globals.enabled))
+ return;
worker = callocz(1, sizeof(struct worker));
worker->pid = gettid();
@@ -213,6 +224,7 @@ void worker_is_busy(size_t job_id) {
void worker_set_metric(size_t job_id, NETDATA_DOUBLE value) {
if(unlikely(!worker)) return;
+
if(unlikely(job_id >= WORKER_UTILIZATION_MAX_JOB_TYPES))
return;
@@ -247,6 +259,9 @@ void workers_foreach(const char *name, void (*callback)(
, NETDATA_DOUBLE *job_custom_values
)
, void *data) {
+ if(!workers_globals.enabled)
+ return;
+
spinlock_lock(&workers_globals.spinlock);
usec_t busy_time, delta;
size_t i, jobs_started, jobs_running;
diff --git a/libnetdata/worker_utilization/worker_utilization.h b/libnetdata/worker_utilization/worker_utilization.h
index cc3f82688..e2f46c5a6 100644
--- a/libnetdata/worker_utilization/worker_utilization.h
+++ b/libnetdata/worker_utilization/worker_utilization.h
@@ -15,6 +15,7 @@ typedef enum __attribute__((packed)) {
WORKER_METRIC_INCREMENTAL_TOTAL = 4,
} WORKER_METRIC_TYPE;
+void workers_utilization_enable(void);
size_t workers_allocated_memory(void);
void worker_register(const char *name);
void worker_register_job_name(size_t job_id, const char *name);