Add benchmark tool 29/279529/5
authorjh9216.park <jh9216.park@samsung.com>
Thu, 11 Aug 2022 03:46:55 +0000 (23:46 -0400)
committerjh9216.park <jh9216.park@samsung.com>
Thu, 11 Aug 2022 07:25:19 +0000 (03:25 -0400)
Change-Id: I8360367d6a62e00f4c2a3525a409aa9e8079ab87
Signed-off-by: jh9216.park <jh9216.park@samsung.com>
13 files changed:
CMakeLists.txt
benchmark/CMakeLists.txt [new file with mode: 0644]
benchmark/server/CMakeLists.txt [new file with mode: 0644]
benchmark/server/log-private.hh [new file with mode: 0644]
benchmark/server/main.cc [new file with mode: 0644]
benchmark/tidl/prebuild.sh [new file with mode: 0755]
benchmark/tidl/test.tidl [new file with mode: 0644]
benchmark/tool/CMakeLists.txt [new file with mode: 0644]
benchmark/tool/log-private.hh [new file with mode: 0644]
benchmark/tool/main.cc [new file with mode: 0644]
benchmark/tool/options.cc [new file with mode: 0644]
benchmark/tool/options.hh [new file with mode: 0644]
packaging/rpc-port.spec

index c7f5b49..4a5a157 100644 (file)
@@ -28,6 +28,8 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
 SET(TARGET_RPC_PORT "rpc-port")
 SET(TARGET_RPC_PORT_UNITTESTS "rpc-port_unittests")
 SET(TARGET_RPC_PORT_UTIL "rpc-port-util")
+SET(TARGET_BENCHMARK_SERVER "rpc-port-benchmark-server")
+SET(TARGET_BENCHMARK_TOOL "rpc-port-benchmark-tool")
 
 ENABLE_TESTING()
 ADD_TEST(NAME ${TARGET_RPC_PORT_UNITTESTS}
@@ -53,6 +55,7 @@ PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
 PKG_CHECK_MODULES(UUID_DEPS REQUIRED uuid)
 
 ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(benchmark)
 ADD_SUBDIRECTORY(utils)
 ADD_SUBDIRECTORY(test)
 
diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b96ba8c
--- /dev/null
@@ -0,0 +1,2 @@
+ADD_SUBDIRECTORY(tool)
+ADD_SUBDIRECTORY(server)
diff --git a/benchmark/server/CMakeLists.txt b/benchmark/server/CMakeLists.txt
new file mode 100644 (file)
index 0000000..cff54c1
--- /dev/null
@@ -0,0 +1,22 @@
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} BENCHMARK_SERVER_SRCS)
+
+ADD_EXECUTABLE(${TARGET_BENCHMARK_SERVER} ${BENCHMARK_SERVER_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_BENCHMARK_SERVER} PUBLIC
+  ${CMAKE_CURRENT_SOURCE_DIR}
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../include/)
+
+APPLY_PKG_CONFIG(${TARGET_BENCHMARK_SERVER} PUBLIC
+  AUL_DEPS
+  DLOG_DEPS
+  GLIB_DEPS
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_BENCHMARK_SERVER} PUBLIC
+  ${TARGET_RPC_PORT} "-lpthread")
+SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_SERVER} PROPERTIES
+  COMPILE_FLAGS "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_SERVER} PROPERTIES
+  LINK_FLAGS "-pie")
+
+INSTALL(TARGETS ${TARGET_BENCHMARK_SERVER} DESTINATION bin)
diff --git a/benchmark/server/log-private.hh b/benchmark/server/log-private.hh
new file mode 100644 (file)
index 0000000..2f507b4
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LOG_PRIVATE_HH_
+#define LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "RPC_PORT_BENCHMARK_SERVER"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif  // LOG_PRIVATE_HH_
diff --git a/benchmark/server/main.cc b/benchmark/server/main.cc
new file mode 100644 (file)
index 0000000..b44fb96
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+
+#include <aul_proc.h>
+
+#include "BenchmarkStub.h"
+#include "log-private.hh"
+
+namespace {
+constexpr const char SERVER_PROC_NAME[] = "org.tizen.appfw.rpc_port.benchmark";
+
+namespace bs = rpc_port::BenchmarkStub::stub;
+
+class TestService : public bs::Benchmark::ServiceBase {
+ public:
+  class Factory : public bs::Benchmark::ServiceBase::Factory {
+     public:
+      virtual ~Factory() = default;
+
+      std::unique_ptr<bs::Benchmark::ServiceBase>
+          CreateService(std::string sender, std::string instance) {
+        return std::unique_ptr<bs::Benchmark::ServiceBase>(
+            new TestService(sender, instance));
+      }
+  };
+
+  TestService(std::string sender, std::string instance) :
+      bs::Benchmark::ServiceBase(sender, instance) {}
+
+  virtual ~TestService() = default;
+
+  void OnCreate() override {
+  }
+
+  void OnTerminate() override {
+  }
+
+  int Test(std::string data) override {
+    return 0;
+  }
+};
+
+class MainLoop {
+ public:
+  MainLoop() {
+    loop_ = g_main_loop_new(nullptr, FALSE);
+  }
+
+  ~MainLoop() {
+    g_main_loop_unref(loop_);
+  }
+
+  void Run() {
+    int ret = aul_proc_register(SERVER_PROC_NAME, nullptr);
+    if (ret != AUL_R_OK) {
+      _E("aul_proc_register() failed (%d)", ret);
+      return;
+    }
+
+    stub_.Listen(std::shared_ptr<
+        bs::Benchmark::ServiceBase::Factory>(
+        new TestService::Factory()));
+    g_main_loop_run(loop_);
+  }
+
+  void Quit() {
+    g_main_loop_quit(loop_);
+  }
+
+ private:
+  GMainLoop* loop_;
+  bs::Benchmark stub_;
+};
+
+}  // namespace
+
+int main(int argc, char** argv) {
+  MainLoop loop;
+  loop.Run();
+  return 0;
+}
diff --git a/benchmark/tidl/prebuild.sh b/benchmark/tidl/prebuild.sh
new file mode 100755 (executable)
index 0000000..7160187
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+tidlc -p -l C++ -i test.tidl -o BenchmarkProxy
+mv ./BenchmarkProxy.* ../tool/
+tidlc -s -l C++ -i test.tidl -o BenchmarkStub
+mv ./BenchmarkStub.* ../server/
diff --git a/benchmark/tidl/test.tidl b/benchmark/tidl/test.tidl
new file mode 100644 (file)
index 0000000..d14eed5
--- /dev/null
@@ -0,0 +1,3 @@
+interface Benchmark {
+  int Test(string data);
+}
diff --git a/benchmark/tool/CMakeLists.txt b/benchmark/tool/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b5481d8
--- /dev/null
@@ -0,0 +1,23 @@
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} BENCHMARK_SRCS)
+
+ADD_EXECUTABLE(${TARGET_BENCHMARK_TOOL} ${BENCHMARK_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_BENCHMARK_TOOL} PUBLIC
+  ${CMAKE_CURRENT_SOURCE_DIR}
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../include/)
+
+APPLY_PKG_CONFIG(${TARGET_BENCHMARK_TOOL} PUBLIC
+  AUL_DEPS
+  BUNDLE_DEPS
+  DLOG_DEPS
+  GLIB_DEPS
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_BENCHMARK_TOOL} PUBLIC
+  ${TARGET_RPC_PORT} "-lpthread")
+SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_TOOL} PROPERTIES
+  COMPILE_FLAGS "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_TOOL} PROPERTIES
+  LINK_FLAGS "-pie")
+
+INSTALL(TARGETS ${TARGET_BENCHMARK_TOOL} DESTINATION bin)
diff --git a/benchmark/tool/log-private.hh b/benchmark/tool/log-private.hh
new file mode 100644 (file)
index 0000000..824116b
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LOG_PRIVATE_HH_
+#define LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "RPC_PORT_BENCHMARK_TOOL"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif  // LOG_PRIVATE_HH_
diff --git a/benchmark/tool/main.cc b/benchmark/tool/main.cc
new file mode 100644 (file)
index 0000000..d7f632a
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <glib.h>
+
+#include <chrono>
+#include <iostream>
+
+#include "log-private.hh"
+#include "options.hh"
+#include "BenchmarkProxy.h"
+
+namespace {
+
+constexpr const char SERVER_PROC_NAME[] = "org.tizen.appfw.rpc_port.benchmark";
+
+namespace bp = rpc_port::BenchmarkProxy::proxy;
+
+class ConnectionListener : public bp::Benchmark::IEventListener {
+ public:
+  void OnConnected() override {
+  }
+
+  void OnDisconnected() override {
+  }
+
+  void OnRejected() override {
+  }
+};
+
+class Tester {
+ public:
+  Tester() {
+  }
+
+  ~Tester() {
+  }
+
+  void Run(int argc, char** argv) {
+    options_ = rpc_port::benchmark::Options::Parse(argc, argv);
+    if (!options_) {
+      _E("options is nullptr");
+      exit(1);
+    }
+
+    proxy_.reset(new bp::Benchmark(&listener_, SERVER_PROC_NAME));
+
+    try {
+      proxy_->Connect(true);
+    } catch (const bp::Exception& e) {
+      _E("Connect() failed");
+      exit(1);
+    }
+
+    DoTest();
+  }
+
+ private:
+  void DoTest() {
+    int iters = options_->GetIters();
+    int size = options_->GetSize();
+
+    StartTime();
+    for (int i = 0; i < iters; i++) {
+      int ret = proxy_->Test(std::string(size, 'a'));
+      if (ret != 0) {
+        _E("Invalid return");
+        break;
+      }
+    }
+    EndTime();
+  }
+
+  void StartTime() {
+    start_ = std::chrono::system_clock::now();
+  }
+
+  void EndTime() {
+    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;
+  }
+
+ private:
+  std::unique_ptr<rpc_port::benchmark::Options> options_;
+  std::unique_ptr<bp::Benchmark> proxy_;
+  ConnectionListener listener_;
+  std::chrono::system_clock::time_point start_;
+};
+
+}  // namespace
+
+int main(int argc, char** argv) {
+  Tester tester;
+  tester.Run(argc, argv);
+  return 0;
+}
diff --git a/benchmark/tool/options.cc b/benchmark/tool/options.cc
new file mode 100644 (file)
index 0000000..e3dd721
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <getopt.h>
+
+#include <iostream>
+#include <cstring>
+#include <memory>
+
+#include "options.hh"
+
+namespace rpc_port {
+namespace benchmark {
+
+Options::Options() {
+  help_ = R"__option_cb(
+Usage:
+  rpc-port-benchmark-tool [OPTION...]
+
+Help Options:
+  -h, --help                  Show help options
+
+Additional Options:
+  -i, --interations=<Iterations>      Iterations
+  -s, --size=<Data size>              Data size (byte)
+
+Application Options:
+  -v, --version               Show version information
+)__option_cb";
+}
+
+void Options::PrintUsage() {
+  std::cerr << help_ << std::endl;
+}
+
+void Options::PrintVersion() {
+  std::cerr << "rpc-port-benchmark-tool " << FULLVER << std::endl;
+}
+
+void Options::PrintSample() {
+  std::cerr << "rpc-port-benchmark-tool -i 1000 -s 10000" << std::endl;
+}
+
+std::unique_ptr<Options> Options::Parse(int argc, char** argv) {
+  int cmd[CMD_MAX] = { 0, };
+  int opt[OPT_MAX] = { 0, };
+  auto options = std::unique_ptr<Options>(new Options());
+  int option_index = 0;
+
+  struct option long_options[] = {
+    {"version", no_argument, nullptr, 'v'},
+    {"help", no_argument, nullptr, 'h'},
+    {"iterations", required_argument, nullptr, 'i'},
+    {"size", required_argument, nullptr, 's'},
+    {0, 0, 0, 0}
+  };
+
+  while (true) {
+    int c = getopt_long(argc, argv, "vhi:s:", long_options,
+        &option_index);
+    if (c == -1)
+      break;
+
+    switch (c) {
+      case 0:
+        break;
+
+      case 'v':
+        cmd[CMD_VERSION] = 1;
+        break;
+
+      case 'h':
+        cmd[CMD_HELP] = 1;
+        break;
+
+      case 'i':
+        opt[OPT_ITER] = 1;
+        options->iters_ = std::stoi(optarg);
+        break;
+
+      case 's':
+        opt[OPT_SIZE] = 1;
+        options->size_ = std::stoi(optarg);
+        break;
+
+      default:
+        cmd[CMD_HELP] = 1;
+    }
+  }
+
+  if (cmd[CMD_VERSION]) {
+    options->PrintVersion();
+    return std::unique_ptr<Options>(nullptr);
+  }
+
+  if (cmd[CMD_HELP]) {
+    options->PrintUsage();
+    return std::unique_ptr<Options>(nullptr);
+  } else if (!opt[OPT_ITER] || !opt[OPT_SIZE]) {
+    options->PrintSample();
+    return std::unique_ptr<Options>(nullptr);
+  }
+
+  return options;
+}
+
+}  // namespace benchmark
+}  // namespace rpc_port
diff --git a/benchmark/tool/options.hh b/benchmark/tool/options.hh
new file mode 100644 (file)
index 0000000..98573f2
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OPTIONS_HH_
+#define OPTIONS_HH_
+
+#include <string>
+#include <memory>
+
+namespace rpc_port {
+namespace benchmark {
+
+class Options {
+ public:
+  Options();
+  ~Options() = default;
+
+  static std::unique_ptr<Options> Parse(int argc, char** argv);
+
+  int GetIters() const {
+    return iters_;
+  }
+
+  int GetSize() const {
+    return size_;
+  }
+
+ private:
+  enum Cmd {
+    CMD_VERSION,
+    CMD_HELP,
+    CMD_MAX
+  };
+
+  enum Opt {
+    OPT_ITER,
+    OPT_SIZE,
+    OPT_MAX
+  };
+
+  void PrintUsage();
+  void PrintVersion();
+  void PrintSample();
+
+ private:
+  int iters_ = 0;
+  int size_ = 0;
+  std::string help_;
+};
+
+}  // namespace benchmark
+}  // namespace rpc_port
+
+#endif  // OPTIONS_HH_
index 7d958fb..1399426 100644 (file)
@@ -19,6 +19,7 @@ BuildRequires:  pkgconfig(parcel)
 BuildRequires:  pkgconfig(pkgmgr)
 BuildRequires:  pkgconfig(pkgmgr-info)
 BuildRequires:  pkgconfig(uuid)
+BuildRequires:  tidl
 
 %if 0%{?gcov:1}
 BuildRequires:  lcov
@@ -69,6 +70,11 @@ RPC Port gcov objects
 %setup -q
 cp %{SOURCE1001} .
 
+tidlc -p -l C++ -i ./benchmark/tidl/test.tidl -o BenchmarkProxy
+mv ./BenchmarkProxy.* ./benchmark/tool/
+tidlc -s -l C++ -i ./benchmark/tidl/test.tidl -o BenchmarkStub
+mv ./BenchmarkStub.* ./benchmark/server/
+
 %build
 %if 0%{?gcov:1}
 export CFLAGS+=" -fprofile-arcs -ftest-coverage"
@@ -153,6 +159,8 @@ install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name}/
 %attr(0644,root,root) %{_libdir}/lib%{name}.so.*
 %license LICENSE.APLv2
 %{_bindir}/rpc-port-util
+%{_bindir}/rpc-port-benchmark-server
+%{_bindir}/rpc-port-benchmark-tool
 %config %{_sysconfdir}/dbus-1/system.d/rpc-port.conf
 
 %files devel