#include "ls3_scan.h"
#include "ls3_stats.h"
#include "ls3_dir_stats.h"
+#include "ls3_merge_stats.h"
#define LS3_MODULE_NAME "lipe"
#define LS3_SCAN "lipe-scan"
LS3_OPT_THREAD_COUNT,
LS3_OPT_SHOW_COUNTERS,
LS3_OPT_COLLECT_STATS,
+ LS3_OPT_MERGE_STATS,
LS3_OPT_HELP = 'h',
LS3_OPT_INTERACTIVE = 'i',
{ "print-json", optional_argument, NULL, LS3_OPT_PRINT_JSON },
{ LS3_SHOW_COUNTERS, no_argument, NULL, LS3_OPT_SHOW_COUNTERS},
{ LS3_COLLECT_STATS, optional_argument, NULL, LS3_OPT_COLLECT_STATS},
+ { "merge-reports", required_argument, NULL, LS3_OPT_MERGE_STATS},
{ "print-absolute-path", no_argument, NULL, LS3_OPT_PRINT_ABSOLUTE_PATH },
{ "print-relative-path", no_argument, NULL, LS3_OPT_PRINT_RELATIVE_PATH },
{ "all-paths", no_argument, NULL, LS3_OPT_ALL_PATHS },
if (optarg)
ls3_report_path = optarg;
break;
+ case LS3_OPT_MERGE_STATS:
+ if (optarg)
+ ls3_stats_merge_reports(optarg);
+ exit(EXIT_SUCCESS);
case LS3_OPT_PRINT_SELF_FID:
policy = LS3_PRINT_SELF_FID;
break;
--- /dev/null
+/*
+ * Copyright (c) 2024, DDN Storage Corporation.
+ *
+ * Author: Vitaliy Kuznetsov <vkuznetsov@ddn.com>
+ */
+
+#include "ls3_merge_stats.h"
+
+static void ls3_m_parsing_json(struct fstats_report *stats, FILE *fd,
+ const char *path)
+{
+
+}
+
+static FILE *ls3_m_open_json_file(const char *filename)
+{
+ FILE *file = fopen(filename, "r");
+
+ if (!file)
+ LS3_ERROR("error with read report [%s]: %s\n",
+ filename, strerror(errno));
+
+ return file;
+}
+
+static bool ls3_m_is_json_file(const char *filename)
+{
+ const char *extension;
+ int len = strlen(filename);
+
+ if (len < 5)
+ return false; /* ".json" format equal 5 char */
+
+ extension = &filename[len - 5];
+ if (strcmp(extension, ".json") == 0)
+ return true;
+
+ /* TODO: Add version check in report */
+ return false;
+}
+
+void ls3_m_read_reports(struct fstats_report *stats,
+ const char *dir_with_reports)
+{
+ struct dirent *entry;
+ DIR *dir;
+
+ /* TODO: Add support current dir by default */
+ dir = opendir(dir_with_reports);
+ if (!dir)
+ LS3_FATAL("error with read target dir: %s\n", dir_with_reports);
+
+ /* Read all reports in json format */
+ while ((entry = readdir(dir))) {
+ FILE *fd;
+ char full_path[4096];
+
+ if (strcmp(entry->d_name, ".") == 0 &&
+ strcmp(entry->d_name, "..") == 0)
+ continue; /* Skip it */
+
+ if (!ls3_m_is_json_file(entry->d_name))
+ continue; /* Skip if not JSON file */
+
+ sprintf(full_path, "%s/%s", dir_with_reports, entry->d_name);
+ fd = ls3_m_open_json_file(full_path);
+ ls3_m_parsing_json(stats, fd, full_path);
+ fclose(fd);
+ }
+}
+
+static struct fstats_report * ls3_m_report_init(void)
+{
+ struct fstats_report *stats;
+ int i;
+
+ stats = xcalloc(1, sizeof(struct fstats_report));
+ for (i = 0; i < LS3_STATS_TYPE_TOTAL_COUNT_REPORT; i++) {
+ stats->reports[i] = ls3_stats_get_new_report_ptr();
+ }
+
+ stats->max_count_users_in_report = LS3_STATS_ARRAY_SIZE_BY_DEFAULT;
+ stats->last_user_idx_in_array = 0;
+ stats->users_reports = (struct ls3_stats_user_report_template**)xcalloc(
+ stats->max_count_users_in_report,
+ sizeof(struct ls3_stats_user_report_template*));
+
+ pthread_mutex_init(&stats->user_rt_mutex, NULL);
+ return stats;
+}
+
+void ls3_stats_merge_reports(const char *dir_with_reports)
+{
+ struct fstats_report *main_report;
+
+ main_report = ls3_m_report_init();
+ main_report->merging = true;
+
+ ls3_m_read_reports(main_report, dir_with_reports);
+ ls3_stats_printf(main_report);
+ ls3_stats_destroy(main_report);
+}