stat: clean up calc_clat_percentiles
authorVincent Fu <vincent.fu@wdc.com>
Thu, 7 Feb 2019 15:51:06 +0000 (10:51 -0500)
committerJens Axboe <axboe@kernel.dk>
Thu, 7 Feb 2019 16:48:44 +0000 (09:48 -0700)
We already know the size of the buffer needed. So there
is no need to do anything fancy when allocating it.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
stat.c

diff --git a/stat.c b/stat.c
index 351c49cc4f720024a7b500b525e9a32657e65299..7c843e6b1423497ba3b0bf6b44227285d9c1e6c7 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -139,7 +139,6 @@ unsigned int calc_clat_percentiles(uint64_t *io_u_plat, unsigned long long nr,
 {
        unsigned long long sum = 0;
        unsigned int len, i, j = 0;
 {
        unsigned long long sum = 0;
        unsigned int len, i, j = 0;
-       unsigned int oval_len = 0;
        unsigned long long *ovals = NULL;
        bool is_last;
 
        unsigned long long *ovals = NULL;
        bool is_last;
 
@@ -161,6 +160,10 @@ unsigned int calc_clat_percentiles(uint64_t *io_u_plat, unsigned long long nr,
        if (len > 1)
                qsort((void *)plist, len, sizeof(plist[0]), double_cmp);
 
        if (len > 1)
                qsort((void *)plist, len, sizeof(plist[0]), double_cmp);
 
+       ovals = malloc(len * sizeof(*ovals));
+       if (!ovals)
+               return 0;
+
        /*
         * Calculate bucket values, note down max and min values
         */
        /*
         * Calculate bucket values, note down max and min values
         */
@@ -170,11 +173,6 @@ unsigned int calc_clat_percentiles(uint64_t *io_u_plat, unsigned long long nr,
                while (sum >= (plist[j].u.f / 100.0 * nr)) {
                        assert(plist[j].u.f <= 100.0);
 
                while (sum >= (plist[j].u.f / 100.0 * nr)) {
                        assert(plist[j].u.f <= 100.0);
 
-                       if (j == oval_len) {
-                               oval_len += 100;
-                               ovals = realloc(ovals, oval_len * sizeof(*ovals));
-                       }
-
                        ovals[j] = plat_idx_to_val(i);
                        if (ovals[j] < *minv)
                                *minv = ovals[j];
                        ovals[j] = plat_idx_to_val(i);
                        if (ovals[j] < *minv)
                                *minv = ovals[j];