From 8363a26c15beeaa473d5a5e3fb79e4b3194e1c49 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 28 Oct 2021 14:14:49 +0900 Subject: [PATCH 01/16] Separate locking mutex Currently, the rpc_port_parcel_create_from_port() function and the rpc_port_parcel_send() function use the mutex of the Port to locking the mutex. After this patch is applied, a new mutex is added to the Port to avoid problems that cannot be written. And, the maximum queue size of the delayed messages is increased to 10MB. Change-Id: I048adec69643b6cd975f7b2c3345e4babfb4a222 Signed-off-by: Hwankyu Jhun --- src/port-internal.cc | 43 +++++++++++++++++++++++-------------------- src/port-internal.hh | 1 + 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/port-internal.cc b/src/port-internal.cc index aaccee8..aba4772 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -35,7 +35,7 @@ namespace rpc_port { namespace internal { namespace { -constexpr const int QUEUE_SIZE_MAX = 1024 * 1024; +constexpr const int QUEUE_SIZE_MAX = 1024 * 1024 * 10; constexpr const int MAX_RETRY_CNT = 10; constexpr const int MAX_TIMEOUT = 1000; constexpr const int MIN_TIMEOUT = 50; @@ -77,6 +77,7 @@ Port::Port(int fd, std::string id, std::string instance) : fd_(fd), id_(std::move(id)), instance_(std::move(instance)), seq_(0) {} Port::~Port() { + std::lock_guard lock(mutex_); ClearQueue(); Disconnect(); } @@ -84,7 +85,7 @@ Port::~Port() { void Port::Disconnect() { IgnoreIOEvent(); - std::lock_guard lock(mutex_); + std::lock_guard lock(rw_mutex_); if (fd_ > 0) { _W("Close fd(%d)", fd_); close(fd_); @@ -123,18 +124,22 @@ int Port::Read(void* buf, unsigned int size) { int timeout = MIN_TIMEOUT; int fd; - mutex_.lock(); - fd = fd_; - mutex_.unlock(); + { + std::lock_guard lock(rw_mutex_); + fd = fd_; + } + if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) { _E("Invalid fd(%d)", fd); return RPC_PORT_ERROR_IO_ERROR; } while (left) { - mutex_.lock(); - nb = read(fd_, buffer, left); - mutex_.unlock(); + { + std::lock_guard lock(rw_mutex_); + nb = read(fd_, buffer, left); + } + if (nb == 0) { _E("read_socket: ...read EOF, socket closed %d: nb %zd\n", fd, nb); return RPC_PORT_ERROR_IO_ERROR; @@ -143,9 +148,7 @@ int Port::Read(void* buf, unsigned int size) { bool can_read = false; while (!can_read && max_timeout > 0) { auto start = std::chrono::steady_clock::now(); - mutex_.lock(); can_read = CanRead(timeout); - mutex_.unlock(); auto end = std::chrono::steady_clock::now(); auto elapsed_time = std::chrono::duration_cast( @@ -212,7 +215,7 @@ bool Port::CanWrite() { int Port::Write(const void* buf, unsigned int size) { int sent_bytes = 0; int ret; - std::lock_guard lock(mutex_); + std::lock_guard lock(rw_mutex_); if (queue_.empty()) { ret = Write(buf, size, &sent_bytes); @@ -296,7 +299,7 @@ gboolean Port::OnEventReceived(GIOChannel* io, GIOCondition condition, return G_SOURCE_CONTINUE; } - std::lock_guard lock(port->mutex_); + std::lock_guard lock(port->rw_mutex_); if (port->queue_.empty()) { port->IgnoreIOEvent(); return G_SOURCE_CONTINUE; @@ -313,7 +316,7 @@ gboolean Port::OnEventReceived(GIOChannel* io, GIOCondition condition, } void Port::ClearQueue() { - std::lock_guard lock(mutex_); + std::lock_guard lock(rw_mutex_); while (queue_.empty() == false) queue_.pop(); @@ -323,7 +326,7 @@ void Port::ClearQueue() { } void Port::IgnoreIOEvent() { - std::lock_guard lock(mutex_); + std::lock_guard lock(rw_mutex_); if (source_ != nullptr && !g_source_is_destroyed(source_)) g_source_destroy(source_); @@ -336,7 +339,7 @@ void Port::IgnoreIOEvent() { } int Port::ListenIOEvent() { - std::lock_guard lock(mutex_); + std::lock_guard lock(rw_mutex_); channel_ = g_io_channel_unix_new(fd_); if (channel_ == nullptr) { _E("Failed to create GIOChannel"); @@ -365,7 +368,7 @@ int Port::ListenIOEvent() { int Port::PopDelayedMessage() { int sent_bytes = 0; - std::lock_guard lock(mutex_); + std::lock_guard lock(rw_mutex_); auto dm = queue_.front(); int ret = Write(dm->GetMessage(), dm->GetSize(), &sent_bytes); @@ -378,13 +381,13 @@ int Port::PopDelayedMessage() { queue_.pop(); } - _W("cache : count(%zu), delayed_message_size (%d), ret(%d)", - queue_.size(), delayed_message_size_, ret); + _W("cache : count(%zu), delayed_message_size(%d), ret(%d), sent_bytes(%d)", + queue_.size(), delayed_message_size_, ret, sent_bytes); return ret; } int Port::PushDelayedMessage(std::shared_ptr dm) { - std::lock_guard lock(mutex_); + std::lock_guard lock(rw_mutex_); if (queue_.empty()) { int ret = ListenIOEvent(); if (ret != RPC_PORT_ERROR_NONE) @@ -394,7 +397,7 @@ int Port::PushDelayedMessage(std::shared_ptr dm) { delayed_message_size_ += dm->GetOriginalSize(); queue_.push(dm); - _W("cache : count(%zu), delayed_message_size (%d)", + _W("cache : count(%zu), delayed_message_size(%d)", queue_.size(), delayed_message_size_); return RPC_PORT_ERROR_NONE; } diff --git a/src/port-internal.hh b/src/port-internal.hh index 853b27f..8924a8a 100644 --- a/src/port-internal.hh +++ b/src/port-internal.hh @@ -104,6 +104,7 @@ class Port : public std::enable_shared_from_this { std::string instance_; std::atomic seq_; mutable std::recursive_mutex mutex_; + mutable std::recursive_mutex rw_mutex_; std::queue> queue_; int delayed_message_size_ = 0; GIOChannel* channel_ = nullptr; -- 2.7.4 From 2e7f3fab41c069eed5acfa630632a43a3bf56d55 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 28 Oct 2021 14:38:19 +0900 Subject: [PATCH 02/16] Release version 1.12.7 Changes: - Revert "Fix Write() method of Port" - Separate locking mutex Change-Id: I4bb6117a01b18445e7feb8233f99e09cecd4b2ff Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index c486de5..b398cdc 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.12.6 +Version: 1.12.7 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From a17cec6d9ae784d7df84462ccc40bce345f7dddb Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 20 Jan 2022 14:44:38 +0900 Subject: [PATCH 03/16] Fix installation path of gcov result Change-Id: Ic6638bd0c1fd8c86e28f27f9e8dcf341c679237d Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index b398cdc..0187bfd 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -103,8 +103,8 @@ rm -rf %{buildroot} %make_install %if 0%{?gcov:1} -mkdir -p %{buildroot}%{_datadir}/gcov/obj -install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj +mkdir -p %{buildroot}%{_datadir}/gcov/obj/%{name} +install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name} %endif %post -p /sbin/ldconfig -- 2.7.4 From b39392ea6a48a0a7b1c11b6dba908cd6f4e357b3 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 20 Jan 2022 15:22:13 +0900 Subject: [PATCH 04/16] Release version 1.12.8 Changes: - Fix installation path of gcov result Change-Id: Ied2f20a9c2f7e8b5ba493b430c17e7b59773a600 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 0187bfd..81874de 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.12.7 +Version: 1.12.8 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From ba5621bd991eb43989c5b65e0cd4b90ffd129218 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 24 Feb 2022 11:56:32 +0900 Subject: [PATCH 05/16] Fix a bug about callback invocation The connection request will not be successful until the stub is the idle state. After sending the connection request to the stub, the proxy cannot get the rejected event or the disconnected event until the stub is the idle state. Because, when the port is appeared, the proxy removes the connection timer. This patch adjusts a position of the UnsetConnTimer() call to remove the connection timer properly. Change-Id: I4d0fb651fd30c77df9088580b38b171f1a98ca5d Signed-off-by: Hwankyu Jhun --- src/proxy-internal.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 098f742..faaa062 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -395,11 +395,11 @@ void Proxy::OnPortAppeared(const char* app_id, const char* port_name, int pid, return; } - proxy->UnsetConnTimer(); proxy->Cancel(); int ret = proxy->Connect(false); if (ret != RPC_PORT_ERROR_NONE) { + proxy->UnsetConnTimer(); proxy->listener_ = nullptr; if (ret == RPC_PORT_ERROR_PERMISSION_DENIED) listener->OnRejected(proxy->target_appid_, ret); @@ -673,6 +673,7 @@ gboolean Proxy::Client::OnSocketDisconnected(GIOChannel* channel, GIOCondition cond, gpointer user_data) { auto* proxy = static_cast(user_data); std::lock_guard lock(proxy->GetMutex()); + proxy->UnsetConnTimer(); auto* listener = proxy->listener_; if (listener == nullptr) { _E("Invalid context"); @@ -700,6 +701,7 @@ gboolean Proxy::Client::OnResponseReceived(GIOChannel* channel, GIOCondition cond, gpointer user_data) { auto* proxy = static_cast(user_data); std::lock_guard lock(proxy->GetMutex()); + proxy->UnsetConnTimer(); auto* listener = proxy->listener_; if (listener == nullptr) { _E("Invalid context"); -- 2.7.4 From e52c78ef2fbbd2d2fa8d2a460241b664f06c2c08 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 24 Feb 2022 15:05:35 +0900 Subject: [PATCH 06/16] Release version 1.12.9 Changes: - Fix a bug about callback invocation Change-Id: I5a13ebfd08fbe181384c8ae461aa795caf82797c Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 81874de..b63021e 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.12.8 +Version: 1.12.9 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From ccfeb7899f47c60d18d7412ded3cd352d052fd34 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 26 May 2022 10:34:32 +0900 Subject: [PATCH 07/16] Fix spec file for coverage measurement To measure code coverages automatically, a run-unittest.sh is needed. Change-Id: I298bc4d70010af80024374f49e8d5a8682b480e5 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 57 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index b63021e..73d5c75 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -45,12 +45,12 @@ RPC Port library (Development) package. ################################################# # rpc-port-unittests ################################################# -%package -n rpc-port-unittests +%package unittests Summary: GTest for rpc-port Group: Development/Libraries Requires: %{name} -%description -n rpc-port-unittests +%description unittests GTest for rpc-port ################################################# @@ -82,19 +82,13 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` # Call make instruction with smp support %__make %{?jobs:-j%jobs} -%if 0%{?gcov:1} -mkdir -p gcov-obj -find . -name '*.gcno' -exec cp '{}' gcov-obj ';' -%endif - %check export LD_LIBRARY_PATH="../../src" ctest -V %{?_smp_mflags} + %if 0%{?gcov:1} -lcov -c --ignore-errors graph --no-external -q -d . -o rpc-port.info -genhtml rpc-port.info -o rpc-port.out -zip -r rpc-port.zip rpc-port.out rpc-port.info -install -m 0644 rpc-port.zip %{buildroot}%{_datadir}/gcov/ +lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info +genhtml %{name}.info -o out --legend --show-details %endif %install @@ -103,19 +97,43 @@ rm -rf %{buildroot} %make_install %if 0%{?gcov:1} -mkdir -p %{buildroot}%{_datadir}/gcov/obj/%{name} -install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name} +builddir=$(basename $PWD) +gcno_obj_dir=%{buildroot}%{_datadir}/gcov/obj/%{name}/"$builddir" +mkdir -p "$gcno_obj_dir" +find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';' %endif +cat << EOF > run-unittest.sh +#!/bin/sh +setup() { + echo "setup start" +} + +test_main() { + echo "test_main start" + /usr/bin/rpc-port_unittests +} + +teardown() { + echo "teardown start" +} + +main() { + setup + test_main + teardown +} + +main "\$*" +EOF + +mkdir -p %{buildroot}%{_bindir}/tizen-unittests/%{name} +install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name}/ + %post -p /sbin/ldconfig %postun -p /sbin/ldconfig -%post -n rpc-port-unittests -%if 0%{?gcov:1} -%{_bindir}/rpc-port_unittests -%endif - %files %manifest %{name}.manifest %attr(0644,root,root) %{_libdir}/lib%{name}.so.* @@ -131,8 +149,9 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name} ################################################# # rpc-port-unittests ################################################# -%files -n rpc-port-unittests +%files unittests %{_bindir}/rpc-port_unittests +%{_bindir}/tizen-unittests/%{name}/run-unittest.sh ################################################# # rpc-port-gcov -- 2.7.4 From 6b6e3e7276fe2b2804c8d813e181c65343abb8b0 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 26 May 2022 10:45:04 +0900 Subject: [PATCH 08/16] Release version 1.12.10 Changes: - Fix spec file for coverage measurement Change-Id: I3f2ad32077205536e3ac4d403471b6c0a9771494 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 73d5c75..691e47a 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.12.9 +Version: 1.12.10 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 64edab5b01f61cd97bed9104f3de8cd03ec84f61 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 2 Jun 2022 12:15:10 +0900 Subject: [PATCH 09/16] Use source ID instead of GSource To find the GSource properly from the GMainContext, the port object uses the source_id instead of the GSource. And, if creating shared_ptr is failed, the OnEventReceived callback function should return G_SOURCE_REMOVE to prevent recalling the function. Change-Id: I26604a7671f73f1d48476434e180ec4d542c05f2 Signed-off-by: Hwankyu Jhun --- src/port-internal.cc | 35 ++++++++++++++++++++--------------- src/port-internal.hh | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/port-internal.cc b/src/port-internal.cc index aba4772..b895d88 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -296,17 +296,16 @@ gboolean Port::OnEventReceived(GIOChannel* io, GIOCondition condition, auto port = ptr->lock(); if (port == nullptr) { _E("port is destructed"); - return G_SOURCE_CONTINUE; + return G_SOURCE_REMOVE; } std::lock_guard lock(port->rw_mutex_); - if (port->queue_.empty()) { - port->IgnoreIOEvent(); - return G_SOURCE_CONTINUE; + if (port->source_id_ == 0) { + _E("GSource is destroyed"); + return G_SOURCE_REMOVE; } - if (port->source_ == nullptr || g_source_is_destroyed(port->source_)) { - _E("GSource(%p) is destroyed", port->source_); + if (port->queue_.empty()) { port->IgnoreIOEvent(); return G_SOURCE_CONTINUE; } @@ -327,10 +326,14 @@ void Port::ClearQueue() { void Port::IgnoreIOEvent() { std::lock_guard lock(rw_mutex_); - if (source_ != nullptr && !g_source_is_destroyed(source_)) - g_source_destroy(source_); + if (source_id_ != 0) { + GSource* source = g_main_context_find_source_by_id( + MessageSendingThread::GetInst().GetContext(), source_id_); + if (source != nullptr && !g_source_is_destroyed(source)) + g_source_destroy(source); - source_ = nullptr; + source_id_ = 0; + } if (channel_ != nullptr) { g_io_channel_unref(channel_); @@ -346,22 +349,24 @@ int Port::ListenIOEvent() { return RPC_PORT_ERROR_OUT_OF_MEMORY; } - source_ = g_io_create_watch(channel_, static_cast(G_IO_OUT)); - if (source_ == nullptr) { + GSource* source = g_io_create_watch(channel_, + static_cast(G_IO_OUT)); + if (source == nullptr) { _E("Failed to create GSource"); IgnoreIOEvent(); return RPC_PORT_ERROR_OUT_OF_MEMORY; } auto* ptr = new (std::nothrow) std::weak_ptr(shared_from_this()); - g_source_set_callback(source_, reinterpret_cast(OnEventReceived), + g_source_set_callback(source, reinterpret_cast(OnEventReceived), static_cast(ptr), [](gpointer ptr) { auto* port = static_cast*>(ptr); delete port; }); - g_source_set_priority(source_, G_PRIORITY_DEFAULT); - g_source_attach(source_, MessageSendingThread::GetInst().GetContext()); - g_source_unref(source_); + g_source_set_priority(source, G_PRIORITY_DEFAULT); + source_id_ = g_source_attach(source, + MessageSendingThread::GetInst().GetContext()); + g_source_unref(source); return RPC_PORT_ERROR_NONE; } diff --git a/src/port-internal.hh b/src/port-internal.hh index 8924a8a..f9aba93 100644 --- a/src/port-internal.hh +++ b/src/port-internal.hh @@ -108,7 +108,7 @@ class Port : public std::enable_shared_from_this { std::queue> queue_; int delayed_message_size_ = 0; GIOChannel* channel_ = nullptr; - GSource* source_ = nullptr; + guint source_id_ = 0; }; } // namespace internal -- 2.7.4 From bcd24fd0343d0e713286fd8c8a41eacd95229ac7 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 2 Jun 2022 13:02:48 +0900 Subject: [PATCH 10/16] Release version 1.12.11 Changes: - Use source ID instead of GSource Change-Id: I01c1634f39f83a5e6986491a9290e847d03f34c7 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 691e47a..5b9bf4b 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.12.10 +Version: 1.12.11 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 0905bb297b09b9929befd4bcf6d984eab2ed9845 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 8 Jun 2022 16:33:22 +0900 Subject: [PATCH 11/16] Fix memory leak When the handle is destroying, the session information of the DebugPort has to be removed. Change-Id: I6c931b889261d4d5374ac89775c2b50a1c6ad483 Signed-off-by: Hwankyu Jhun --- src/proxy-internal.cc | 3 +++ src/stub-internal.cc | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index faaa062..2eb538b 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -105,6 +105,9 @@ Proxy::Proxy() { Proxy::~Proxy() { std::lock_guard lock(GetMutex()); _D("Proxy::~Proxy()"); + if (main_port_.get() != nullptr) + DebugPort::GetInst()->RemoveSession(main_port_->GetFd()); + listener_ = nullptr; UnsetIdler(); UnsetConnTimer(); diff --git a/src/stub-internal.cc b/src/stub-internal.cc index f16035c..1ffc2e8 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -95,6 +95,11 @@ Stub::Stub(std::string port_name) : port_name_(std::move(port_name)) { Stub::~Stub() { std::lock_guard lock(GetMutex()); _D("Stub::~Stub"); + for (auto& p : ports_) { + if (!p->IsDelegate()) + DebugPort::GetInst()->RemoveSession(p->GetFd()); + } + listener_ = nullptr; server_.reset(); } -- 2.7.4 From e7f6e8e19ba60b330c33d8ad52b93eef1dfc9cc9 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 9 Jun 2022 07:47:33 +0900 Subject: [PATCH 12/16] Release version 1.12.12 Changes: - Fix memory leak Change-Id: Icecb3fb8c38746afa1ae833c3c6354cba732da2a Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 5b9bf4b..e2a6bac 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.12.11 +Version: 1.12.12 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 5e6e219e91f24979e4d2ffe391b16479038e2a78 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 14 Jul 2022 14:51:24 +0900 Subject: [PATCH 13/16] Fix run-unittest.sh script For code coverage measurement, the permission of directories and files should be changed for applications. The script sets the smack label as "System::Run" to files. Change-Id: I7c405e0fc8e6548298e3addffcdaeaa2b6a460a0 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index e2a6bac..399cc91 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -105,17 +105,31 @@ find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';' cat << EOF > run-unittest.sh #!/bin/sh +GCOV_PATH="/tmp/home/abuild/rpmbuild/BUILD" +PAKCAGE="%{name}-%{version}" + +set_perm() { + ## Sets the permission for applications + /usr/bin/find /tmp/home/ -print | /usr/bin/xargs -n1 /usr/bin/chsmack -a "System::Run" &> /dev/null + /usr/bin/find /tmp/home/ -print | /usr/bin/xargs -n1 /usr/bin/chsmack -a "System::Run" -t &> /dev/null + /usr/bin/chmod -R 777 /tmp/home/ +} + setup() { echo "setup start" + /usr/bin/mkdir -p "${GCOV_PATH}/${PACKAGE}" + set_perm } test_main() { echo "test_main start" + export "GCOV_PREFIX=/tmp" /usr/bin/rpc-port_unittests } teardown() { echo "teardown start" + set_perm } main() { -- 2.7.4 From d7a1dacae4e6509302bd085fd4ecbd160bcfac59 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 14 Jul 2022 15:40:32 +0900 Subject: [PATCH 14/16] Release version 1.12.13 Changes: - Fix run-unittest.sh script Change-Id: I5009ec01aad2c5efeb05238b517a05b61f683504 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 399cc91..7d958fb 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.12.12 +Version: 1.12.13 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 0c24a79e918d10944c4c669b62fc517cec9fad28 Mon Sep 17 00:00:00 2001 From: "jh9216.park" Date: Wed, 10 Aug 2022 23:46:55 -0400 Subject: [PATCH 15/16] Add benchmark tool Change-Id: I8360367d6a62e00f4c2a3525a409aa9e8079ab87 Signed-off-by: jh9216.park --- CMakeLists.txt | 3 + benchmark/CMakeLists.txt | 2 + benchmark/server/CMakeLists.txt | 22 ++++++++ benchmark/server/log-private.hh | 37 ++++++++++++ benchmark/server/main.cc | 96 +++++++++++++++++++++++++++++++ benchmark/tidl/prebuild.sh | 5 ++ benchmark/tidl/test.tidl | 3 + benchmark/tool/CMakeLists.txt | 23 ++++++++ benchmark/tool/log-private.hh | 37 ++++++++++++ benchmark/tool/main.cc | 116 ++++++++++++++++++++++++++++++++++++++ benchmark/tool/options.cc | 121 ++++++++++++++++++++++++++++++++++++++++ benchmark/tool/options.hh | 67 ++++++++++++++++++++++ packaging/rpc-port.spec | 8 +++ 13 files changed, 540 insertions(+) create mode 100644 benchmark/CMakeLists.txt create mode 100644 benchmark/server/CMakeLists.txt create mode 100644 benchmark/server/log-private.hh create mode 100644 benchmark/server/main.cc create mode 100755 benchmark/tidl/prebuild.sh create mode 100644 benchmark/tidl/test.tidl create mode 100644 benchmark/tool/CMakeLists.txt create mode 100644 benchmark/tool/log-private.hh create mode 100644 benchmark/tool/main.cc create mode 100644 benchmark/tool/options.cc create mode 100644 benchmark/tool/options.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index c7f5b49..4a5a157 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 0000000..b96ba8c --- /dev/null +++ b/benchmark/CMakeLists.txt @@ -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 index 0000000..cff54c1 --- /dev/null +++ b/benchmark/server/CMakeLists.txt @@ -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 index 0000000..2f507b4 --- /dev/null +++ b/benchmark/server/log-private.hh @@ -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 + +#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 index 0000000..b44fb96 --- /dev/null +++ b/benchmark/server/main.cc @@ -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 + +#include + +#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 + CreateService(std::string sender, std::string instance) { + return std::unique_ptr( + 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 index 0000000..7160187 --- /dev/null +++ b/benchmark/tidl/prebuild.sh @@ -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 index 0000000..d14eed5 --- /dev/null +++ b/benchmark/tidl/test.tidl @@ -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 index 0000000..b5481d8 --- /dev/null +++ b/benchmark/tool/CMakeLists.txt @@ -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 index 0000000..824116b --- /dev/null +++ b/benchmark/tool/log-private.hh @@ -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 + +#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 index 0000000..d7f632a --- /dev/null +++ b/benchmark/tool/main.cc @@ -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 + +#include +#include + +#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 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 options_; + std::unique_ptr 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 index 0000000..e3dd721 --- /dev/null +++ b/benchmark/tool/options.cc @@ -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 + +#include +#include +#include + +#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 + -s, --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::Parse(int argc, char** argv) { + int cmd[CMD_MAX] = { 0, }; + int opt[OPT_MAX] = { 0, }; + auto options = std::unique_ptr(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(nullptr); + } + + if (cmd[CMD_HELP]) { + options->PrintUsage(); + return std::unique_ptr(nullptr); + } else if (!opt[OPT_ITER] || !opt[OPT_SIZE]) { + options->PrintSample(); + return std::unique_ptr(nullptr); + } + + return options; +} + +} // namespace benchmark +} // namespace rpc_port diff --git a/benchmark/tool/options.hh b/benchmark/tool/options.hh new file mode 100644 index 0000000..98573f2 --- /dev/null +++ b/benchmark/tool/options.hh @@ -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 +#include + +namespace rpc_port { +namespace benchmark { + +class Options { + public: + Options(); + ~Options() = default; + + static std::unique_ptr 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_ diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 7d958fb..1399426 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -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 -- 2.7.4 From 75ad4b38dcf490f893adaf3f4e52457a49f39d17 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 11 Aug 2022 16:42:00 +0900 Subject: [PATCH 16/16] Execute benchmark server as child process To test the performance easily, the benchmark-server will be executed using fork() & execv() by the tool. Change-Id: I394131d6294a78c869adfcb6f6565397feb9b77b Signed-off-by: Hwankyu Jhun --- benchmark/tool/main.cc | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/benchmark/tool/main.cc b/benchmark/tool/main.cc index d7f632a..a92c8ea 100644 --- a/benchmark/tool/main.cc +++ b/benchmark/tool/main.cc @@ -14,8 +14,11 @@ * limitations under the License. */ - #include +#include +#include +#include +#include #include #include @@ -27,6 +30,7 @@ namespace { constexpr const char SERVER_PROC_NAME[] = "org.tizen.appfw.rpc_port.benchmark"; +constexpr const char SERVER_BIN[] = "/usr/bin/rpc-port-benchmark-server"; namespace bp = rpc_port::BenchmarkProxy::proxy; @@ -48,6 +52,14 @@ class Tester { } ~Tester() { + if (server_pid_ > 0) { + if (kill(server_pid_, SIGTERM) != 0) { + std::cerr << "kill() is failed. errno: " << errno << std::endl; + } else { + int status; + waitpid(server_pid_, &status, 0); + } + } } void Run(int argc, char** argv) { @@ -57,6 +69,7 @@ class Tester { exit(1); } + ExecuteServer(); proxy_.reset(new bp::Benchmark(&listener_, SERVER_PROC_NAME)); try { @@ -100,11 +113,32 @@ class Tester { std::cout << "Latency: " << std::to_string(l) << "ms" << std::endl; } + void ExecuteServer() { + server_pid_ = fork(); + if (server_pid_ == 0) { + setsid(); + + char* argv[] = { strdup(SERVER_BIN), nullptr, nullptr }; + int ret = execv(argv[0], argv); + if (ret < 0) { + std::cerr << "execv() is failed. errno: " << errno << std::endl; + exit(-1); + } + } else if (server_pid_ == -1) { + std::cerr << "fork() is failed. errno: " << errno << std::endl; + exit(-1); + } else { + _W("benchmark server is running. pid: %d", server_pid_); + usleep(100 * 1000); + } + } + private: std::unique_ptr options_; std::unique_ptr proxy_; ConnectionListener listener_; std::chrono::system_clock::time_point start_; + pid_t server_pid_ = -1; }; } // namespace -- 2.7.4