Add options 73/279573/1
authorjh9216.park <jh9216.park@samsung.com>
Fri, 12 Aug 2022 00:47:33 +0000 (20:47 -0400)
committerjh9216.park <jh9216.park@samsung.com>
Fri, 12 Aug 2022 00:47:33 +0000 (20:47 -0400)
- Added options
  -f, --funcation  Use function call instead of RPC
  -a, --all        Test pre-defined test-cases

Change-Id: I993432e219bb16a0bd3d9a80a24daae60e781f41
Signed-off-by: jh9216.park <jh9216.park@samsung.com>
benchmark/tool/main.cc
benchmark/tool/options.cc
benchmark/tool/options.hh

index a92c8ea..7883b32 100644 (file)
@@ -79,38 +79,67 @@ class Tester {
       exit(1);
     }
 
-    DoTest();
+    printf("%15s\t%15s\t%15s\t\t%15s\t\t%15s\n", "Iterations", "Data size",
+        "Time", "Throughput", "Latency");
+    if (options_->IsAll()) {
+      DoTest(4000, 10);
+      DoTest(4000, 20);
+      DoTest(4000, 100);
+      DoTest(4000, 200);
+      DoTest(2000, 1000);
+      DoTest(2000, 2000);
+      DoTest(1000, 10000);
+      DoTest(1000, 20000);
+      DoTest(1000, 30000);
+      DoTest(1000, 40000);
+      DoTest(1000, 50000);
+      DoTest(1000, 60000);
+      DoTest(500, 100000);
+    } else {
+      DoTest(options_->GetIters(), options_->GetSize());
+    }
   }
 
  private:
-  void DoTest() {
-    int iters = options_->GetIters();
-    int size = options_->GetSize();
+  void DoTest(int iters, int size) {
+    bool is_func = options_->IsFunction();
 
     StartTime();
     for (int i = 0; i < iters; i++) {
+      if (is_func) {
+        int ret = FakeFunction(std::string(size, 'a'));
+        if (ret != 0) {
+          _E("Invalid return");
+          break;
+        }
+
+        continue;
+      }
+
       int ret = proxy_->Test(std::string(size, 'a'));
       if (ret != 0) {
         _E("Invalid return");
         break;
       }
     }
-    EndTime();
+    EndTime(iters, size);
+  }
+
+  int FakeFunction(std::string str) {
+    return 0;
   }
 
   void StartTime() {
     start_ = std::chrono::system_clock::now();
   }
 
-  void EndTime() {
+  void EndTime(int iters, int size) {
     std::chrono::duration<double> sec = std::chrono::system_clock::now() - start_;
-    std::cout << "Iterations: " << std::to_string(options_->GetIters()) << std::endl;
-    std::cout << "Data size: " << std::to_string(options_->GetSize()) << "Byte" << std::endl;
-    std::cout << "Duration: " << sec.count() << "s" << std::endl;
-    double t = options_->GetSize() * options_->GetIters() / sec.count() / 1024 / 1024;
-    std::cout << "Throughput: " << std::to_string(t * 8) << "Mb/s" << std::endl;
-    double l = sec.count() * 1000 / options_->GetIters();
-    std::cout << "Latency: " << std::to_string(l) << "ms" << std::endl;
+    double t = size * iters * 8 / sec.count() / 1024 / 1024;
+    double l = sec.count() * 1000 / iters;
+
+    printf("%10d\t%10dByte\t%15.4fs\t%15.4fMb/s\t%15.4fms\n", iters, size,
+        sec.count(), t, l);
   }
 
   void ExecuteServer() {
index e3dd721..38d9166 100644 (file)
@@ -34,6 +34,8 @@ Help Options:
   -h, --help                  Show help options
 
 Additional Options:
+  -f, --funcation                     Use function call instead of RPC
+  -a, --all                           Test pre-defined test-cases
   -i, --interations=<Iterations>      Iterations
   -s, --size=<Data size>              Data size (byte)
 
@@ -55,8 +57,8 @@ void Options::PrintSample() {
 }
 
 std::unique_ptr<Options> Options::Parse(int argc, char** argv) {
-  int cmd[CMD_MAX] = { 0, };
-  int opt[OPT_MAX] = { 0, };
+  bool cmd[CMD_MAX] = { false, };
+  bool opt[OPT_MAX] = { false, };
   auto options = std::unique_ptr<Options>(new Options());
   int option_index = 0;
 
@@ -65,11 +67,13 @@ std::unique_ptr<Options> Options::Parse(int argc, char** argv) {
     {"help", no_argument, nullptr, 'h'},
     {"iterations", required_argument, nullptr, 'i'},
     {"size", required_argument, nullptr, 's'},
+    {"function", no_argument, nullptr, 'f'},
+    {"all", no_argument, nullptr, 'a'},
     {0, 0, 0, 0}
   };
 
   while (true) {
-    int c = getopt_long(argc, argv, "vhi:s:", long_options,
+    int c = getopt_long(argc, argv, "vhfai:s:", long_options,
         &option_index);
     if (c == -1)
       break;
@@ -79,25 +83,35 @@ std::unique_ptr<Options> Options::Parse(int argc, char** argv) {
         break;
 
       case 'v':
-        cmd[CMD_VERSION] = 1;
+        cmd[CMD_VERSION] = true;
         break;
 
       case 'h':
-        cmd[CMD_HELP] = 1;
+        cmd[CMD_HELP] = true;
         break;
 
       case 'i':
-        opt[OPT_ITER] = 1;
+        opt[OPT_ITER] = true;
         options->iters_ = std::stoi(optarg);
         break;
 
       case 's':
-        opt[OPT_SIZE] = 1;
+        opt[OPT_SIZE] = true;
         options->size_ = std::stoi(optarg);
         break;
 
+      case 'f':
+        opt[OPT_FUNCTION] = true;
+        options->is_function_ = true;
+        break;
+
+      case 'a':
+        opt[OPT_ALL] = true;
+        options->is_all_ = true;
+        break;
+
       default:
-        cmd[CMD_HELP] = 1;
+        cmd[CMD_HELP] = true;
     }
   }
 
@@ -109,6 +123,8 @@ std::unique_ptr<Options> Options::Parse(int argc, char** argv) {
   if (cmd[CMD_HELP]) {
     options->PrintUsage();
     return std::unique_ptr<Options>(nullptr);
+  } else if (opt[OPT_ALL]) {
+    return options;
   } else if (!opt[OPT_ITER] || !opt[OPT_SIZE]) {
     options->PrintSample();
     return std::unique_ptr<Options>(nullptr);
index 98573f2..3b8fd4c 100644 (file)
@@ -38,6 +38,14 @@ class Options {
     return size_;
   }
 
+  bool IsFunction() const {
+    return is_function_;
+  }
+
+  bool IsAll() const {
+    return is_all_;
+  }
+
  private:
   enum Cmd {
     CMD_VERSION,
@@ -48,6 +56,8 @@ class Options {
   enum Opt {
     OPT_ITER,
     OPT_SIZE,
+    OPT_ALL,
+    OPT_FUNCTION,
     OPT_MAX
   };
 
@@ -59,6 +69,8 @@ class Options {
   int iters_ = 0;
   int size_ = 0;
   std::string help_;
+  bool is_function_ = false;
+  bool is_all_ = false;
 };
 
 }  // namespace benchmark