X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcpu.c;h=9c432d1791d0090191842aa364c48d761b5da72e;hb=95dcf60c822e4ab92c0dd1a7ff6cba73bc55bcd1;hp=c9462506dca025a633ccf3f591de8c23f2671c1a;hpb=b286b677bb54a3192a4121c2aa0857a133fd0603;p=collectd.git diff --git a/src/cpu.c b/src/cpu.c index c9462506..9c432d17 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -536,11 +536,12 @@ static void cpu_commit (void) /* {{{ */ /* Adds a derive value to the internal state. This should be used by each read * function for each state. At the end of the iteration, the read function * should call cpu_commit(). */ -static int cpu_stage (size_t cpu_num, size_t state, derive_t value, cdtime_t now) /* {{{ */ +static int cpu_stage (size_t cpu_num, size_t state, derive_t d, cdtime_t now) /* {{{ */ { int status; cpu_state_t *s; - value_t v; + gauge_t rate = NAN; + value_t val = {.derive = d}; if (state >= COLLECTD_CPU_STATE_ACTIVE) return (EINVAL); @@ -554,12 +555,11 @@ static int cpu_stage (size_t cpu_num, size_t state, derive_t value, cdtime_t now s = get_cpu_state (cpu_num, state); - v.gauge = NAN; - status = value_to_rate (&v, value, &s->conv, DS_TYPE_DERIVE, now); + status = value_to_rate (&rate, val, DS_TYPE_DERIVE, now, &s->conv); if (status != 0) return (status); - s->rate = v.gauge; + s->rate = rate; s->has_value = 1; return (0); } /* }}} int cpu_stage */ @@ -814,8 +814,7 @@ static int cpu_read (void) if (pnumcpu != numcpu || perfcpu == NULL) { - if (perfcpu != NULL) - free(perfcpu); + free(perfcpu); perfcpu = malloc(numcpu * sizeof(perfstat_cpu_t)); } pnumcpu = numcpu;