From 98acd99c1537d00087ddfa488dd5fd8061f450b5 Mon Sep 17 00:00:00 2001 From: Vitaliy Kuznetsov Date: Tue, 5 Mar 2024 15:32:25 +0100 Subject: [PATCH] EX-8130 lipe: Add helper functions for stats 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 Change-Id: I04807846b49d6fb0e476b8bf146ba337f80e3d5e Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53962 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alexandre Ioffe Reviewed-by: Andreas Dilger --- lipe/src/lipe_scan3/ls3_dir_stats.c | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/lipe/src/lipe_scan3/ls3_dir_stats.c b/lipe/src/lipe_scan3/ls3_dir_stats.c index 9725b1af..4eb4c58 100644 --- a/lipe/src/lipe_scan3/ls3_dir_stats.c +++ b/lipe/src/lipe_scan3/ls3_dir_stats.c @@ -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; -- 1.8.3.1