cpu plugin: Fix ValuesPercentage to behave as documented.
authorFlorian Forster <octo@collectd.org>
Tue, 2 Dec 2014 10:09:32 +0000 (11:09 +0100)
committerFlorian Forster <octo@collectd.org>
Tue, 2 Dec 2014 10:09:32 +0000 (11:09 +0100)
The documentation claims that ValuesPercentage is only considered when
!ByState && !ByCpu. Fix the behavior to match this documented behavior.
This makes cpu_commit_without_aggregation much easier.

Bug: #820

src/cpu.c

index bee6f17..9d812c8 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -471,29 +471,15 @@ static void cpu_commit_without_aggregation (void) /* {{{ */
        for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
        {
                size_t cpu_num;
-               if (report_by_cpu) {
-                       for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
-                       {
-                               cpu_state_t *s = get_cpu_state (cpu_num, state);
 
-                               if (!s->has_value)
-                                       continue;
-
-                               submit_derive ((int) cpu_num, (int) state, s->conv.last_value.derive);
-                       }
-               } else {
-                       derive_t derive_total = 0;
-                       for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
-                               {
-                                       cpu_state_t *s = get_cpu_state (cpu_num, state);
-
-                                       if (!s->has_value)
-                                               continue;
+               for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+               {
+                       cpu_state_t *s = get_cpu_state (cpu_num, state);
 
-                                       derive_total += s->conv.last_value.derive;
+                       if (!s->has_value)
+                               continue;
 
-                               }
-                       submit_derive (-1, (int) state, derive_total);
+                       submit_derive ((int) cpu_num, (int) state, s->conv.last_value.derive);
                }
        }
 } /* }}} void cpu_commit_without_aggregation */
@@ -502,11 +488,11 @@ static void cpu_commit_without_aggregation (void) /* {{{ */
 static void cpu_commit (void) /* {{{ */
 {
        gauge_t global_rates[COLLECTD_CPU_STATE_MAX] = {
-               NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN
+               NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN /* Batman! */
        };
        size_t cpu_num;
 
-       if (report_by_state && !report_percent)
+       if (report_by_state && report_by_cpu && !report_percent)
        {
                cpu_commit_without_aggregation ();
                return;