+} /* }}} void cpu_commit_without_aggregation */
+
+/* Aggregates the internal state and dispatches the metrics. */
+static void cpu_commit (void) /* {{{ */
+{
+ gauge_t global_rates[COLLECTD_CPU_STATE_MAX] = {
+ NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN /* Batman! */
+ };
+ size_t cpu_num;
+
+ if (report_by_state && report_by_cpu && !report_percent)
+ {
+ cpu_commit_without_aggregation ();
+ return;
+ }
+
+ aggregate (global_rates);
+
+ if (!report_by_cpu)
+ {
+ cpu_commit_one (-1, global_rates);
+ return;
+ }
+
+ for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+ {
+ cpu_state_t *this_cpu_states = get_cpu_state (cpu_num, 0);
+ gauge_t local_rates[COLLECTD_CPU_STATE_MAX] = {
+ NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN
+ };
+ size_t state;
+
+ for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
+ if (this_cpu_states[state].has_value)
+ local_rates[state] = this_cpu_states[state].rate;
+
+ cpu_commit_one ((int) cpu_num, local_rates);
+ }
+} /* }}} void cpu_commit */
+
+/* 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) /* {{{ */
+{
+ int status;
+ cpu_state_t *s;
+ value_t v;
+
+ if (state >= COLLECTD_CPU_STATE_ACTIVE)
+ return (EINVAL);
+
+ status = cpu_states_alloc (cpu_num);
+ if (status != 0)
+ return (status);
+
+ if (global_cpu_num <= cpu_num)
+ global_cpu_num = cpu_num + 1;
+
+ s = get_cpu_state (cpu_num, state);
+
+ v.gauge = NAN;
+ status = value_to_rate (&v, value, &s->conv, DS_TYPE_DERIVE, now);
+ if (status != 0)
+ return (status);
+
+ s->rate = v.gauge;
+ s->has_value = 1;
+ return (0);
+} /* }}} int cpu_stage */