Skip to content

Commit

Permalink
stopwatch: Fix qsort comparison function.
Browse files Browse the repository at this point in the history
Current version is broken because it converts first argument to
integer and after that substracts the duoble value. At the end
the result converted to integer again.
This does not cause unit test failures because qsort on linux
accidentially makes right order. On FreeBSD this leads to the
test failure:

  TEST '10-intervals-linear-growth'
  Assertion \
  '|(&stats)->pctl_95 - (&d->expected_stats)->pctl_95| < 1e-1' failed:
          |9 - 10| < 0.1

CC: Mark Michelson <mmichels@redhat.com>
Acked-by: Mark Michelson <mmichels@redhat.com>
Fixes: aed45be ("Add stopwatch timing API")
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
igsilya authored and blp committed Dec 18, 2018
1 parent fe07df8 commit ea2b622
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/stopwatch.c
Expand Up @@ -104,7 +104,7 @@ comp_samples(const void *left, const void *right)
const double *left_d = left;
const double *right_d = right;

return (int) *right_d - *left_d;
return *right_d > *left_d ? -1 : *right_d < *left_d;
}

/* Calculate the percentile using the P-square algorithm. For more
Expand Down

0 comments on commit ea2b622

Please sign in to comment.