]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Fix signed/unsigned warning and add parameter range checking. 61164/head
authorJesse F. Williamson <1643380+chardan@users.noreply.github.com>
Wed, 18 Dec 2024 14:38:56 +0000 (06:38 -0800)
committerJesse F. Williamson <jfw@ibm.com>
Wed, 8 Jan 2025 19:32:34 +0000 (11:32 -0800)
Signed-off-by: Jesse F. Williamson <1643380+chardan@users.noreply.github.com>
src/test/objectstore/allocsim/ops_replayer.cc

index fd947f5c4547a6a3ac6d825a482a87d21f4d18bf..c5908d9f57603dd68b95305a7bdf89f5c8852203 100644 (file)
@@ -1,4 +1,5 @@
 #include <algorithm>
+#include <functional>
 #include <boost/program_options/value_semantic.hpp>
 #include <cassert>
 #include <cctype>
 #include <fstream>
 #include <filesystem>
 #include <mutex>
-#include "include/rados/buffer_fwd.h"
-#include "include/rados/librados.hpp"
 #include <atomic>
-#include <fmt/format.h>
 #include <map>
 #include <memory>
 #include <random>
 #include <string>
 #include <iostream>
 #include <vector>
+#include <format>
+
+#include <fmt/format.h>
 
 #include <boost/program_options/variables_map.hpp>
 #include <boost/program_options/parsers.hpp>
 
+#include "include/rados/buffer_fwd.h"
+#include "include/rados/librados.hpp"
+
 namespace po = boost::program_options;
 
 
 using namespace std;
 using namespace ceph;
 
+namespace settings {
+
+// Returns a function which restricts a value to a specified range by throwing if it is not in range:
+// (Note: std::clamp() does not throw.)
+auto clamp_or_throw(auto min, auto max)
+{
+ return [=](auto& x) { 
+               if(std::less<>{}(x, min) or std::greater<>{}(x, max)) {
+                throw std::out_of_range(fmt::format("value expected between {} and {}, but got {}", min, max, x));
+               }
+
+               return x;       
+       };
+}
+
+} // namespace settings
+
 // compare shared_ptr<string>
 struct StringPtrCompare
 {
@@ -338,8 +359,8 @@ int main(int argc, char** argv) {
 
   // options
   uint64_t io_depth = 8;
-  uint64_t nparser_threads = 16;
-  uint64_t nworker_threads = 16;
+  int nparser_threads = 16;
+  int nworker_threads = 16;
   string file("input.txt");
   string ceph_conf_path("./ceph.conf");
   string pool("test_pool");
@@ -351,8 +372,8 @@ int main(int argc, char** argv) {
     ("input-files,i", po::value<vector<string>>()->multitoken(), "List of input files (output of op_scraper.py). Multiple files will be merged and sorted by time order")
     ("ceph-conf", po::value<string>(&ceph_conf_path)->default_value("ceph.conf"), "Path to ceph conf")
     ("io-depth", po::value<uint64_t>(&io_depth)->default_value(64), "I/O depth")
-    ("parser-threads", po::value<uint64_t>(&nparser_threads)->default_value(16), "Number of parser threads")
-    ("worker-threads", po::value<uint64_t>(&nworker_threads)->default_value(16), "Number of I/O worker threads")
+    ("parser-threads", po::value<int>(&nparser_threads)->default_value(16)->notifier(settings::clamp_or_throw(1, 256)), "Number of parser threads")
+    ("worker-threads", po::value<int>(&nworker_threads)->default_value(16)->notifier(settings::clamp_or_throw(1, 256)), "Number of I/O worker threads")
     ("pool", po::value<string>(&pool)->default_value("test_pool"), "Pool to use for I/O")
     ("skip-do-ops", po::bool_switch(&skip_do_ops)->default_value(false), "Skip doing operations")
     ;