]> git.hungrycats.org Git - bees/commitdiff
throttle: add --throttle-factor option to control throttling factor
authorZygo Blaxell <bees@furryterror.org>
Tue, 17 Dec 2024 03:23:56 +0000 (22:23 -0500)
committerZygo Blaxell <bees@furryterror.org>
Sat, 4 Jan 2025 04:13:51 +0000 (23:13 -0500)
Also change the initializer syntax for the option list to use C99
compound literals.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees-usage.txt
src/bees.cc

index 1fd47e1f09b3c010715d704c8179cbb72492d196..b402bb035d12d7bb4b380463719040ea728ea50e 100644 (file)
@@ -12,6 +12,7 @@ Load management options:
     -C, --thread-factor   Worker thread factor (default 1)
     -G, --thread-min      Minimum worker thread count (default 0)
     -g, --loadavg-target  Target load average for worker threads (default none)
+        --throttle-factor Idle time between operations (default 1.0)
 
 Filesystem tree traversal options:
     -m, --scan-mode       Scanning mode (0..4, default 4)
index 635ec3f2742b745ed9c8cd26884fb822a4a4c8b8..6c34584f2e1cab6d5cea165ba54baf0ba46e52cd 100644 (file)
@@ -716,20 +716,25 @@ bees_main(int argc, char *argv[])
        BeesRoots::ScanMode root_scan_mode = BeesRoots::SCAN_MODE_EXTENT;
 
        // Configure getopt_long
+       // Options with no short form
+       enum {
+               BEES_OPT_THROTTLE_FACTOR = 256,
+       };
        static const struct option long_options[] = {
-               { "thread-factor",         required_argument, NULL, 'C' },
-               { "thread-min",            required_argument, NULL, 'G' },
-               { "strip-paths",           no_argument,       NULL, 'P' },
-               { "no-timestamps",         no_argument,       NULL, 'T' },
-               { "workaround-btrfs-send", no_argument,       NULL, 'a' },
-               { "thread-count",          required_argument, NULL, 'c' },
-               { "loadavg-target",        required_argument, NULL, 'g' },
-               { "help",                  no_argument,       NULL, 'h' },
-               { "scan-mode",             required_argument, NULL, 'm' },
-               { "absolute-paths",        no_argument,       NULL, 'p' },
-               { "timestamps",            no_argument,       NULL, 't' },
-               { "verbose",               required_argument, NULL, 'v' },
-               { 0, 0, 0, 0 },
+               { .name = "thread-factor",         .has_arg = required_argument, .val = 'C' },
+               { .name = "throttle-factor",       .has_arg = required_argument, .val = BEES_OPT_THROTTLE_FACTOR },
+               { .name = "thread-min",            .has_arg = required_argument, .val = 'G' },
+               { .name = "strip-paths",           .has_arg = no_argument,       .val = 'P' },
+               { .name = "no-timestamps",         .has_arg = no_argument,       .val = 'T' },
+               { .name = "workaround-btrfs-send", .has_arg = no_argument,       .val = 'a' },
+               { .name = "thread-count",          .has_arg = required_argument, .val = 'c' },
+               { .name = "loadavg-target",        .has_arg = required_argument, .val = 'g' },
+               { .name = "help",                  .has_arg = no_argument,       .val = 'h' },
+               { .name = "scan-mode",             .has_arg = required_argument, .val = 'm' },
+               { .name = "absolute-paths",        .has_arg = no_argument,       .val = 'p' },
+               { .name = "timestamps",            .has_arg = no_argument,       .val = 't' },
+               { .name = "verbose",               .has_arg = required_argument, .val = 'v' },
+               { 0 },
        };
 
        // Build getopt_long's short option list from the long_options table.
@@ -766,6 +771,9 @@ bees_main(int argc, char *argv[])
                        case 'C':
                                thread_factor = stod(optarg);
                                break;
+                       case BEES_OPT_THROTTLE_FACTOR:
+                               bees_throttle_factor = stod(optarg);
+                               break;
                        case 'G':
                                thread_min = stoul(optarg);
                                break;
@@ -851,6 +859,8 @@ bees_main(int argc, char *argv[])
        BEESLOGNOTICE("setting worker thread pool maximum size to " << thread_count);
        TaskMaster::set_thread_count(thread_count);
 
+       BEESLOGNOTICE("setting throttle factor to " << bees_throttle_factor);
+
        // Set root path
        string root_path = argv[optind++];
        BEESLOGNOTICE("setting root path to '" << root_path << "'");