processes plugin generates spikes on (re)start. That is caused by
wrong counter logic: When collectd (re)started, monitored processes,
which was started before collectd, have non-zero values in
cpu_user/cpu_system/vmem_minflt/vmem_majflt, so `want_init` is false.
What produces spike.
At other hand, processes which are started between read cycles, should
be fully accounted without initialization. So, we must skip only first
cycle for these counters.
static procstat_t *list_head_g = NULL;
static procstat_t *list_head_g = NULL;
+static _Bool want_init = 1;
static _Bool report_ctx_switch = 0;
#if HAVE_THREAD_INFO
static _Bool report_ctx_switch = 0;
#if HAVE_THREAD_INFO
return (0);
} /* int ps_list_match */
return (0);
} /* int ps_list_match */
-static void ps_update_counter (_Bool init, derive_t *group_counter,
+static void ps_update_counter (derive_t *group_counter,
derive_t *curr_counter, derive_t new_counter)
{
unsigned long curr_value;
derive_t *curr_counter, derive_t new_counter)
{
unsigned long curr_value;
+ if (want_init)
+ {
+ *curr_counter = new_counter;
if (new_counter < *curr_counter)
curr_value = new_counter + (ULONG_MAX - *curr_counter);
if (new_counter < *curr_counter)
curr_value = new_counter + (ULONG_MAX - *curr_counter);
for (procstat_t *ps = list_head_g; ps != NULL; ps = ps->next)
{
for (procstat_t *ps = list_head_g; ps != NULL; ps = ps->next)
{
if ((ps_list_match (name, cmdline, ps)) == 0)
continue;
if ((ps_list_match (name, cmdline, ps)) == 0)
continue;
ps->cswitch_vol += ((pse->cswitch_vol == -1)?0:pse->cswitch_vol);
ps->cswitch_invol += ((pse->cswitch_invol == -1)?0:pse->cswitch_invol);
ps->cswitch_vol += ((pse->cswitch_vol == -1)?0:pse->cswitch_vol);
ps->cswitch_invol += ((pse->cswitch_invol == -1)?0:pse->cswitch_invol);
- want_init = (entry->vmem_minflt_counter == 0)
- && (entry->vmem_majflt_counter == 0);
- ps_update_counter (want_init,
&ps->vmem_minflt_counter,
&pse->vmem_minflt_counter,
entry->vmem_minflt_counter);
&ps->vmem_minflt_counter,
&pse->vmem_minflt_counter,
entry->vmem_minflt_counter);
- ps_update_counter (want_init,
&ps->vmem_majflt_counter,
&pse->vmem_majflt_counter,
entry->vmem_majflt_counter);
&ps->vmem_majflt_counter,
&pse->vmem_majflt_counter,
entry->vmem_majflt_counter);
- want_init = (entry->cpu_user_counter == 0)
- && (entry->cpu_system_counter == 0);
- ps_update_counter (want_init,
&ps->cpu_user_counter,
&pse->cpu_user_counter,
entry->cpu_user_counter);
&ps->cpu_user_counter,
&pse->cpu_user_counter,
entry->cpu_user_counter);
- ps_update_counter (want_init,
&ps->cpu_system_counter,
&pse->cpu_system_counter,
entry->cpu_system_counter);
&ps->cpu_system_counter,
&pse->cpu_system_counter,
entry->cpu_system_counter);
read_fork_rate();
#endif /* KERNEL_SOLARIS */
read_fork_rate();
#endif /* KERNEL_SOLARIS */
return (0);
} /* int ps_read */
return (0);
} /* int ps_read */