gfio: fix problem with graph finding data range.
authorStephen M. Cameron <stephenmcameron@gmail.com>
Wed, 7 Mar 2012 18:37:57 +0000 (19:37 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 Mar 2012 18:37:57 +0000 (19:37 +0100)
In finding minimum value, it used zero as an initializer
but if the graph had no data below say, 1000, it would still
find zero as the minimum, which was incorrect.

Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
graph.c

diff --git a/graph.c b/graph.c
index d3fcb8dbbcdd02d11373508878e3eaf341c98500..40c5256be5dafb7028c85a67312cb323bdf8db9e 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -383,13 +383,18 @@ static double gety(struct graph_value *v)
 
 static double find_xy_value(struct graph *g, xy_value_extractor getvalue, double_comparator cmp)
 {
 
 static double find_xy_value(struct graph *g, xy_value_extractor getvalue, double_comparator cmp)
 {
-       double tmp, answer = 0.0;
+       double tmp, answer;
        struct graph_label *i;
        struct graph_value *j;
        struct graph_label *i;
        struct graph_value *j;
+       int first = 1;
 
        for (i = g->labels; i; i = i->next)
                for (j = i->values; j; j = j->next) {
                        tmp = getvalue(j);
 
        for (i = g->labels; i; i = i->next)
                for (j = i->values; j; j = j->next) {
                        tmp = getvalue(j);
+                       if (first) {
+                               first = 0;
+                               answer = tmp;
+                       }
                        answer = cmp(tmp, answer);      
                }
        return answer;
                        answer = cmp(tmp, answer);      
                }
        return answer;