X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fprocesses.c;h=f83913afb9ca77cd97d3063127768a2a0c2e0da1;hp=cfc5790099cf957aef9ae6ec7d182d005694fd32;hb=0e73c26f5670b2f11eecfdadaf545bcc7f260658;hpb=b9b5e5d573d0011c4f3276e9b84b73ba4dd2e870 diff --git a/src/processes.c b/src/processes.c index cfc57900..f83913af 100644 --- a/src/processes.c +++ b/src/processes.c @@ -38,12 +38,12 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" +#include "utils/common/common.h" #if HAVE_LIBTASKSTATS +#include "utils/taskstats/taskstats.h" #include "utils_complain.h" -#include "utils_taskstats.h" #endif /* Include header files for the mach system, if they exist.. */ @@ -216,7 +216,7 @@ typedef struct process_entry_s { typedef struct procstat_entry_s { unsigned long id; - unsigned long age; + unsigned char age; derive_t vmem_minflt_counter; derive_t vmem_majflt_counter; @@ -587,7 +587,8 @@ static void ps_list_add(const char *name, const char *cmdline, entry->cpu_system_counter); #if HAVE_LIBTASKSTATS - ps_update_delay(ps, pse, entry); + if (entry->has_delay) + ps_update_delay(ps, pse, entry); #endif } } @@ -616,7 +617,7 @@ static void ps_list_reset(void) { pse_prev = NULL; pse = ps->instances; while (pse != NULL) { - if (pse->age > 10) { + if (pse->age > 0) { DEBUG("Removing this procstat entry cause it's too old: " "id = %lu; name = %s;", pse->id, ps->name); @@ -631,7 +632,7 @@ static void ps_list_reset(void) { pse = pse_prev->next; } } else { - pse->age++; + pse->age = 1; pse_prev = pse; pse = pse->next; } @@ -756,7 +757,7 @@ static int ps_init(void) { pset_list_len = 0; return -1; } -/* #endif HAVE_THREAD_INFO */ + /* #endif HAVE_THREAD_INFO */ #elif KERNEL_LINUX pagesize_g = sysconf(_SC_PAGESIZE); @@ -770,13 +771,13 @@ static int ps_init(void) { } } #endif -/* #endif KERNEL_LINUX */ + /* #endif KERNEL_LINUX */ #elif HAVE_LIBKVM_GETPROCS && \ (HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD) pagesize = getpagesize(); -/* #endif HAVE_LIBKVM_GETPROCS && (HAVE_STRUCT_KINFO_PROC_FREEBSD || - * HAVE_STRUCT_KINFO_PROC_OPENBSD) */ + /* #endif HAVE_LIBKVM_GETPROCS && (HAVE_STRUCT_KINFO_PROC_FREEBSD || + * HAVE_STRUCT_KINFO_PROC_OPENBSD) */ #elif HAVE_PROCINFO_H pagesize = getpagesize(); @@ -909,7 +910,7 @@ static void ps_submit_proc_list(procstat_t *ps) { gauge_t const delay_factor = 1000000000.0; struct { - char *type_instance; + const char *type_instance; gauge_t rate_ns; } delay_metrics[] = { {"delay-cpu", ps->delay_cpu}, @@ -924,7 +925,7 @@ static void ps_submit_proc_list(procstat_t *ps) { sstrncpy(vl.type, "delay_rate", sizeof(vl.type)); sstrncpy(vl.type_instance, delay_metrics[i].type_instance, sizeof(vl.type_instance)); - vl.values[0].gauge = delay_metrics[i].rate_ns * delay_factor; + vl.values[0].gauge = delay_metrics[i].rate_ns / delay_factor; vl.values_len = 1; plugin_dispatch_values(&vl); } @@ -995,8 +996,9 @@ static int ps_read_tasks_status(process_entry_t *ps) { tpid = ent->d_name; - if (snprintf(filename, sizeof(filename), "/proc/%li/task/%s/status", ps->id, - tpid) >= sizeof(filename)) { + int r = snprintf(filename, sizeof(filename), "/proc/%li/task/%s/status", + ps->id, tpid); + if ((size_t)r >= sizeof(filename)) { DEBUG("Filename too long: `%s'", filename); continue; } @@ -1576,7 +1578,6 @@ static char *ps_get_cmdline(long pid, return NULL; } - info.pr_psargs[sizeof(info.pr_psargs) - 1] = 0; sstrncpy(buffer, info.pr_psargs, buffer_size); return buffer; @@ -1680,7 +1681,7 @@ static int ps_read_process(long pid, process_entry_t *ps, char *state) { /* * TODO: context switch counters for Solaris -*/ + */ ps->cswitch_vol = -1; ps->cswitch_invol = -1; @@ -2012,7 +2013,7 @@ static int ps_read(void) { for (ps = list_head_g; ps != NULL; ps = ps->next) ps_submit_proc_list(ps); -/* #endif HAVE_THREAD_INFO */ + /* #endif HAVE_THREAD_INFO */ #elif KERNEL_LINUX int running = 0; @@ -2094,7 +2095,7 @@ static int ps_read(void) { ps_submit_proc_list(ps_ptr); read_fork_rate(); -/* #endif KERNEL_LINUX */ + /* #endif KERNEL_LINUX */ #elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD int running = 0; @@ -2249,7 +2250,7 @@ static int ps_read(void) { for (procstat_t *ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) ps_submit_proc_list(ps_ptr); -/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */ + /* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */ #elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_OPENBSD int running = 0; @@ -2393,7 +2394,7 @@ static int ps_read(void) { for (procstat_t *ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) ps_submit_proc_list(ps_ptr); -/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_OPENBSD */ + /* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_OPENBSD */ #elif HAVE_PROCINFO_H /* AIX */ @@ -2532,7 +2533,7 @@ static int ps_read(void) { for (procstat_t *ps = list_head_g; ps != NULL; ps = ps->next) ps_submit_proc_list(ps); -/* #endif HAVE_PROCINFO_H */ + /* #endif HAVE_PROCINFO_H */ #elif KERNEL_SOLARIS /*