Whamcloud - gitweb
EX-8130 lipe: Add helper functions for stats
authorVitaliy Kuznetsov <vkuznetsov@ddn.com>
Tue, 5 Mar 2024 14:32:25 +0000 (15:32 +0100)
committerAndreas Dilger <adilger@whamcloud.com>
Sat, 9 Mar 2024 07:42:57 +0000 (07:42 +0000)
This patch adds several helper functions for working with
directory size statistics. Also add ls3_stats_rm_first_dir()
which remove the directory from the list to increase counters.

Test-Parameters: trivial
Signed-off-by: Vitaliy Kuznetsov <vkuznetsov@ddn.com>
Change-Id: I04807846b49d6fb0e476b8bf146ba337f80e3d5e
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53962
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alexandre Ioffe <aioffe@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lipe/src/lipe_scan3/ls3_dir_stats.c

index 9725b1a..4eb4c58 100644 (file)
@@ -177,6 +177,51 @@ static void ls3_stats_init_heap(void)
                        ls3_stats_create_heap(dir_stats->lsdg_top_rating_limit);
 }
 
+/* ls3_stats_get_dots - Generates dots to display
+ * depth in .out format reports.
+ */
+static char* ls3_stats_get_dots(int depth) {
+       int num_dots;
+       char *dots;
+       int i;
+
+       if (depth >= 0)
+               num_dots = depth * 4;
+       else
+               num_dots = 0;
+
+       dots = (char*) xcalloc(num_dots + 1, sizeof(char));
+       for (i = 0; i < num_dots; i++) {
+               if ((i + 1) % 4 == 0)
+                       dots[i] = '/';
+               else
+                       dots[i] = '.';
+       }
+
+       /* free(dots) will be call later after fprintf() */
+       return dots;
+}
+
+/* ls3_stats_fmt_size_units convert size in bytes to
+ * size in human readable output.
+ */
+static const char *ls3_stats_fmt_size_units(uint64_t bytes)
+{
+       const char *sizes[] = { "B", "KB", "MB", "GB", "TB", "Pb" };
+       int order = 0;
+       static char buffer[20];
+       double size = (double)bytes;
+
+       while (size >= 1024.0 && order < sizeof(sizes) / sizeof(*sizes) - 1) {
+               order++;
+               size /= 1024.0;
+       }
+
+       snprintf(buffer, sizeof(buffer), "%7.2f %2s", size, sizes[order]);
+
+       return buffer;
+}
+
 /* ls3_stats_dir_incr_counters - Increases directory size */
 static void ls3_stats_dir_incr_counters(struct ls3_object_attrs *loa_all,
                                        struct ls3_stats_dir_obj *dir_ptr)
@@ -444,6 +489,26 @@ static char** ls3_stats_dir_split_path(const char *path, int *count)
        return result;
 }
 
+/* ls3_stats_rm_first_dir - Removes the first directory from the array.
+ * Ex: ["dir1", "dir11", "dir111"] -> ["dir11", "dir111"]
+ */
+static void ls3_stats_rm_first_dir(char ***dirs, int *count)
+{
+       int i;
+
+       if ((*count) <= 0)
+               return;
+
+       free((*dirs)[0]);
+       for (i = 1; i < (*count); i++) {
+               (*dirs)[i - 1] = (*dirs)[i];
+       }
+
+       (*count)--;
+       /* free() for dirs will be later in ls3_stats_upd_dir_info() */
+       (*dirs)[(*count)] = NULL;
+}
+
 void ls3_stats_dir_init(void)
 {
        int rc;