Whamcloud - gitweb
EX-5258 lipe: add hidden option -show_counters
authorVitaliy Kuznetsov <vkuznetsov@ddn.com>
Fri, 3 Nov 2023 15:39:14 +0000 (16:39 +0100)
committerAndreas Dilger <adilger@whamcloud.com>
Sun, 5 Nov 2023 10:40:56 +0000 (10:40 +0000)
This patch adds a hidden output policy option
to lipe_find3 that shows how many total inodes
were scanned and the number of inodes
that matched the filters.

Usage example:
lipe_find3 /dev/nvme1n1 -path dir-1/* -show-counters
Output:
scanned: 1460
matched: 200

Test-Parameters: trivial
Signed-off-by: Vitaliy Kuznetsov <vkuznetsov@ddn.com>
Change-Id: Ibcd22a94e01ea6322cd38fd414e6058314aac8ef
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52937
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lipe/src/lipe_find3/lf3_lexer.l
lipe/src/lipe_scan3/ls3_main.c
lipe/src/lipe_scan3/ls3_scan.c
lipe/src/lipe_scan3/ls3_scan.h

index afe8faa..93fabf3 100644 (file)
@@ -45,7 +45,7 @@ static int expr_arg_type;
 
 %% /* rules */
 
--(delete|print|print0|print-file-fid|print-self-fid|print-absolute-path|print-relative-path|quit)\0 {
+-(delete|print|print0|print-file-fid|print-self-fid|print-absolute-path|print-relative-path|show-counters|quit)\0 {
        LF3_DEBUG("nullary '%s'\n", yytext);
        yylval.u_range[0] = lf3_arg_index;
        yylval.u_range[1] = lf3_arg_index + 1;
index a304630..8524c42 100644 (file)
@@ -38,6 +38,7 @@
 #define LS3_PRINT_ABSOLUTE_PATH "print-absolute-path"
 #define LS3_PRINT_RELATIVE_PATH "print-relative-path"
 #define LS3_COLLECT_STATS "collect-fsize-stats"
+#define LS3_SHOW_COUNTERS "show-counters"
 
 #define LS3_GETOPT_DEVICE_PATH "lipe-getopt-device-path"
 #define LS3_GETOPT_CLIENT_MOUNT_PATH "lipe-getopt-client-mount-path"
@@ -55,6 +56,7 @@ SCM ls3_scm_policy_exception_handler;
 
 bool ls3_debug;
 bool save_fsize_stats;
+bool show_counters;
 bool ls3_warn_get_attr;
 const char *ls3_progname_;
 __thread int ls3_tid; /* gettid() thread id for debug messages. */
@@ -1015,6 +1017,21 @@ SCM_DEFINE(ls3_scm_print_self_fid, LS3_PRINT_SELF_FID, 0, 0, 0,
        return SCM_UNSPECIFIED;
 }
 
+static void ls3_counters_print(void)
+{
+       printf("scanned: %ju\n", ls3_scanned_inodes_counter);
+       printf("matched: %ju\n", ls3_matched_inodes_counter);
+}
+
+SCM_DEFINE(ls3_scm_show_counters, LS3_SHOW_COUNTERS, 0, 0, 0,
+          (), "increase match counter")
+{
+       if (!show_counters)
+               show_counters = true;
+
+       return SCM_UNSPECIFIED;
+}
+
 SCM_DEFINE(ls3_scm_collect_fsize_stats, LS3_COLLECT_STATS, 0, 1, 0,
                (SCM string), "collect file size info of current file")
 {
@@ -1282,6 +1299,7 @@ enum {
        LS3_OPT_PRINT_RELATIVE_PATH,
        LS3_OPT_REQUIRED_ATTRS,
        LS3_OPT_THREAD_COUNT,
+       LS3_OPT_SHOW_COUNTERS,
        LS3_OPT_COLLECT_STATS,
 
        LS3_OPT_HELP = 'h',
@@ -1303,6 +1321,7 @@ static struct option options[] = {
        { LS3_PRINT_FILE_FID, no_argument, NULL, LS3_OPT_PRINT_FILE_FID },
        { LS3_PRINT_SELF_FID, no_argument, NULL, LS3_OPT_PRINT_SELF_FID },
        { "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},
        { "print-absolute-path", no_argument, NULL, LS3_OPT_PRINT_ABSOLUTE_PATH },
        { "print-relative-path", no_argument, NULL, LS3_OPT_PRINT_RELATIVE_PATH },
@@ -1439,6 +1458,7 @@ static void ls3_module_init(void *unused)
        "print-self-fid",
        "print-absolute-path",
        "print-relative-path",
+       "show-counters",
        "collect-fsize-stats",
        NULL);
 }
@@ -1617,6 +1637,9 @@ static void ls3_main_scm(void *data, int argc, char *argv[])
        if (save_fsize_stats)
                ls3_stats_printf();
 
+       if (show_counters)
+               ls3_counters_print();
+
        ls3_stats_destroy();
        LS3_DEBUG_D(exit_status);
        exit(exit_status);
index fe08362..2ca6d0d 100644 (file)
@@ -53,6 +53,8 @@ struct ls3_scan_control {
        uintmax_t sc_read_attr_error_count[LS3_OBJECT_ATTR_BIT_MAX];
        uintmax_t sc_read_attr_error_count_total;
        uintmax_t sc_other_error_count;
+       uintmax_t sc_scanned_inodes_counter;
+       uintmax_t sc_matched_inodes_counter;
 };
 
 struct ls3_thread_info {
@@ -69,10 +71,14 @@ struct ls3_thread_info {
        uintmax_t ti_other_error_count;
        int ti_started;
        int ti_should_stop; /* Use __ATOMIC_RELAXED. */
+       uintmax_t ti_scanned_inodes_counter;
+       uintmax_t ti_matched_inodes_counter;
 };
 
 const char LS3_CSTR_AUTO[] = "AUTO";
 const char LS3_CSTR_NONE[] = "NONE";
+uintmax_t ls3_scanned_inodes_counter = 0;
+uintmax_t ls3_matched_inodes_counter = 0;
 
 #ifndef EXT4_SNAPFILE_FL
 # define EXT4_SNAPFILE_FL 0x01000000 /* Inode is a snapshot */
@@ -732,7 +738,8 @@ static void ls3_copy_inode_attrs(struct ls3_object_attrs *loa,
 static void ls3_scan_inode(struct ls3_instance *li,
                           ext2_filsys fs,
                           ext2_ino_t ino,
-                          struct ext2_inode_large *inode)
+                          struct ext2_inode_large *inode,
+                          struct ls3_thread_info *ti)
 {
        struct lipe_object lo = {
                .u.lo_ldiskfs.lol_fs = fs,
@@ -741,6 +748,7 @@ static void ls3_scan_inode(struct ls3_instance *li,
        };
        struct ls3_object_attrs loa;
        int rc;
+       SCM matched;
 
        lipe_object_attrs_init(&loa);
        ls3_copy_inode_attrs(&loa, fs, ino, inode);
@@ -775,7 +783,12 @@ static void ls3_scan_inode(struct ls3_instance *li,
        LS3_CURRENT.lc_object = &lo;
        LS3_CURRENT.lc_attrs = &loa;
 
-       scm_catch(SCM_BOOL_T, li->li_scm_policy_thunk, ls3_scm_policy_exception_handler);
+       matched = scm_catch(SCM_BOOL_T, li->li_scm_policy_thunk,
+                           ls3_scm_policy_exception_handler);
+       if (!scm_is_bool(matched))
+               /* If we don't have a match we get false,
+                * but if we do have a match we don't get a bool */
+               ti->ti_matched_inodes_counter++;
 
        LS3_CURRENT.lc_object = NULL;
        LS3_CURRENT.lc_attrs = NULL;
@@ -833,7 +846,8 @@ static int ldiskfs_scan_groups(ext2_inode_scan scan,
                        continue;
                }
 
-               ls3_scan_inode(li, fs, ino, inode);
+               ls3_scan_inode(li, fs, ino, inode, ti);
+               ti->ti_scanned_inodes_counter++;
        }
 
        rc = 0;
@@ -981,6 +995,8 @@ static int ls3_scan_control_start(struct ls3_scan_control *sc, struct ls3_instan
                ti->ti_instance = li;
                ti->ti_scan_control = sc;
                ti->ti_thread_index = i;
+               ti->ti_scanned_inodes_counter = 0;
+               ti->ti_matched_inodes_counter = 0;
 
                rc = pthread_create(&ti->ti_thread_id, pattr, &ls3_scan_thread_start, ti);
                if (rc != 0) {
@@ -1047,7 +1063,8 @@ static int ls3_scan_control_join(struct ls3_scan_control *sc)
                        sc->sc_read_attr_error_count_total +=
                                ti->ti_read_attr_error_count[j];
                }
-
+               sc->sc_scanned_inodes_counter += ti->ti_scanned_inodes_counter;
+               sc->sc_matched_inodes_counter += ti->ti_matched_inodes_counter;
                sc->sc_other_error_count += ti->ti_other_error_count;
        }
 
@@ -1063,6 +1080,8 @@ static intmax_t ls3_scan_fs(struct ls3_instance *li, ext2_filsys fs, size_t thre
        unsigned long group_desc_per_batch;
        struct ls3_scan_control sc = {
                .sc_thread_count = 0,
+               .sc_scanned_inodes_counter = 0,
+               .sc_matched_inodes_counter = 0,
                .sc_break_rc = INTMAX_MIN,
                .sc_group_desc_count = fs->group_desc_count,
        };
@@ -1115,6 +1134,9 @@ static intmax_t ls3_scan_fs(struct ls3_instance *li, ext2_filsys fs, size_t thre
                LS3_WARNING("device '%s': other error count %"PRIuMAX"\n",
                            li->li_device_path, sc.sc_other_error_count);
 
+       ls3_scanned_inodes_counter = sc.sc_scanned_inodes_counter;
+       ls3_matched_inodes_counter = sc.sc_matched_inodes_counter;
+
        /* If (lipe-scan-break rc) was called then return rc
         * regardless of other errors. */
        if (sc.sc_break_rc != INTMAX_MIN)
index cc7cc38..5309e7f 100644 (file)
@@ -61,6 +61,8 @@ struct ls3_context {
 };
 
 extern int ls3_direct_io;
+extern uintmax_t ls3_scanned_inodes_counter;
+extern uintmax_t ls3_matched_inodes_counter;
 extern const char *ls3_io_options;
 extern const char LS3_CSTR_AUTO[];
 extern const char LS3_CSTR_NONE[];