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}
PKG_CHECK_MODULES(UUID_DEPS REQUIRED uuid)
ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(benchmark)
ADD_SUBDIRECTORY(utils)
ADD_SUBDIRECTORY(test)
--- /dev/null
+ADD_SUBDIRECTORY(tool)
+ADD_SUBDIRECTORY(server)
--- /dev/null
+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)
--- /dev/null
+/*
+ * 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_
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+#!/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/
--- /dev/null
+interface Benchmark {
+ int Test(string data);
+}
--- /dev/null
+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)
--- /dev/null
+/*
+ * 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_
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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_
BuildRequires: pkgconfig(pkgmgr)
BuildRequires: pkgconfig(pkgmgr-info)
BuildRequires: pkgconfig(uuid)
+BuildRequires: tidl
%if 0%{?gcov:1}
BuildRequires: lcov
%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"
%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