The rpc-port-benchmark package is added.
The tools are moved to the package.
The following servies of systemd are added for socket & dbus activation:
- rpc-port-benchmark-server-tidl.service
- rpc-port-benchmark-server-tidl.socket
- rpc-port-benchmark-server-dbus.service
- tizen.appfw.rpcport.benchmark.dbus.busname
- tizen.appfw.rpcport.benchmark.dbus.service
- rpc-port-benchmark-client-tidl.service
- rpc-port-benchmark-client-dbus.service
Change-Id: I3d39ef2c6c452069ff0656b967cfe5b70f11a450
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
<method name='Test'>
<arg type='s' name='data' direction='in'/>
<arg type='i' name='ret' direction='out'/>
- </method>
+ </method>
+ <method name='Start'>
+ <arg type='i' name='caller_pid' direction='in'/>
+ <arg type='i' name='ret' direction='out'/>
+ </method>
+ <method name='Stop'>
+ <arg type='i' name='caller_pid' direction='in'/>
+ <arg type='i' name='ret' direction='out'/>
+ </method>
</interface>
</node>
)__dbus";
GVariant* param = g_variant_new("(i)", ret);
g_dbus_method_invocation_return_value(invocation, param);
+ } else if (std::string_view(method_name) == "Stop") {
+ gint caller_pid = -1;
+ g_variant_get(parameters, "(i)", &caller_pid);
+ _D("Stop request received from caller(%d)", caller_pid);
+ auto* main_loop = static_cast<MainLoop*>(user_data);
+ int ret = main_loop->SetTermTimer();
+
+ GVariant* param = g_variant_new("(i)", ret);
+ g_dbus_method_invocation_return_value(invocation, param);
+ } else if (std::string_view(method_name) == "Start") {
+ gint caller_pid = -1;
+ g_variant_get(parameters, "(i)", &caller_pid);
+ _D("Start request received from caller(%d)", caller_pid);
+ auto* main_loop = static_cast<MainLoop*>(user_data);
+ int ret = main_loop->UnsetTermTimer();
+
+ GVariant* param = g_variant_new("(i)", ret);
+ g_dbus_method_invocation_return_value(invocation, param);
}
},
nullptr,
&interface_vtable,
this, nullptr, &error);
if (reg_id == 0) {
- _E("g_dbus_connection_register_object error(%s)", error ? error->message : "");
+ _E("g_dbus_connection_register_object error(%s)",
+ error ? error->message : "");
g_error_free(error);
}
}
g_main_loop_quit(loop_);
}
+ int SetTermTimer() {
+ if (timer_) return 0;
+
+ timer_ = g_timeout_add(
+ 5000, [](gpointer user_data) {
+ auto* main_loop = static_cast<MainLoop*>(user_data);
+ main_loop->Quit();
+ main_loop->timer_ = 0;
+ return G_SOURCE_REMOVE;
+ }, this);
+
+ return 0;
+ }
+
+ int UnsetTermTimer() {
+ if (timer_) {
+ g_source_remove(timer_);
+ timer_ = 0;
+ }
+
+ return 0;
+ }
+
private:
GMainLoop* loop_ = nullptr;
GDBusNodeInfo* introspection_data_ = nullptr;
+ guint timer_ = 0;
};
} // namespace
namespace bs = rpc_port::BenchmarkStub::stub;
+class MainLoop {
+ public:
+ MainLoop();
+ ~MainLoop();
+
+ void Run();
+ void Quit();
+ void SetTermTimer();
+ void RemoveTermTimer();
+
+ private:
+ GMainLoop* loop_;
+ bs::Benchmark stub_;
+ guint timer_ = 0;
+};
+
class TestService : public bs::Benchmark::ServiceBase {
public:
class Factory : public bs::Benchmark::ServiceBase::Factory {
public:
+ explicit Factory(MainLoop* loop) : loop_(loop) {}
+
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(std::move(sender), std::move(instance)));
+ new TestService(std::move(sender), std::move(instance), loop_));
}
+
+ private:
+ MainLoop* loop_ = nullptr;
};
- TestService(std::string sender, std::string instance) :
- bs::Benchmark::ServiceBase(std::move(sender), std::move(instance)) {}
+ TestService(std::string sender, std::string instance, MainLoop* loop)
+ : bs::Benchmark::ServiceBase(std::move(sender), std::move(instance)),
+ loop_(loop) {}
virtual ~TestService() = default;
void OnCreate() override {
+ loop_->RemoveTermTimer();
}
void OnTerminate() override {
+ loop_->SetTermTimer();
}
- int Test(std::string data) override {
- return 0;
- }
+ int Test(std::string data) override { return 0; }
+
+ private:
+ MainLoop* loop_ = nullptr;
};
-class MainLoop {
- public:
- MainLoop() {
- loop_ = g_main_loop_new(nullptr, FALSE);
+MainLoop::MainLoop() { loop_ = g_main_loop_new(nullptr, FALSE); }
+
+MainLoop::~MainLoop() {
+ RemoveTermTimer();
+ g_main_loop_unref(loop_);
+}
+
+void MainLoop::Run() {
+ std::string proc_name = std::string(SERVER_PROC_NAME);
+ if (getuid() >= 5000) proc_name = "u" + proc_name;
+
+ int ret = rpc_port_register_proc_info(proc_name.c_str(), nullptr);
+ if (ret != RPC_PORT_ERROR_NONE) {
+ _E("rpc_port_register_proc_info() failed (%d)", ret);
+ return;
}
- ~MainLoop() {
- g_main_loop_unref(loop_);
+ try {
+ stub_.Listen(std::shared_ptr<bs::Benchmark::ServiceBase::Factory>(
+ new TestService::Factory(this)));
+ } catch (const bs::Exception&) {
+ _E("stub listen is failed");
}
- void Run() {
- std::string proc_name = std::string(SERVER_PROC_NAME);
- if (getuid() >= 5000) proc_name = "u" + proc_name;
+ g_main_loop_run(loop_);
+}
- int ret = rpc_port_register_proc_info(proc_name.c_str(), nullptr);
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("rpc_port_register_proc_info() failed (%d)", ret);
- return;
- }
+void MainLoop::Quit() { g_main_loop_quit(loop_); }
- try {
- stub_.Listen(std::shared_ptr<bs::Benchmark::ServiceBase::Factory>(
- new TestService::Factory()));
- } catch (const bs::Exception&) {
- _E("stub listen is failed");
- }
+void MainLoop::SetTermTimer() {
+ if (timer_) return;
- g_main_loop_run(loop_);
- }
+ timer_ = g_timeout_add(
+ 5000,
+ [](gpointer data) -> gboolean {
+ auto* main_loop = static_cast<MainLoop*>(data);
+ main_loop->Quit();
+ main_loop->timer_ = 0;
+ return G_SOURCE_REMOVE;
+ },
+ this);
+}
- void Quit() {
- g_main_loop_quit(loop_);
+void MainLoop::RemoveTermTimer() {
+ if (timer_) {
+ g_source_remove(timer_);
+ timer_ = 0;
}
-
- private:
- GMainLoop* loop_;
- bs::Benchmark stub_;
-};
+}
} // namespace
}
}
-int DbusProxy::Test(std::string data) const {
- auto* msg = g_dbus_message_new_method_call(BUS_NAME,
- OBJECT_PATH, INTERFACE_NAME, "Test");
+int DbusProxy::Test(std::string data) {
+ return MethodCall("Test", g_variant_new("(s)", data.c_str()));
+}
+
+int DbusProxy::Start(pid_t caller_pid) {
+ return MethodCall("Start", g_variant_new("(i)", caller_pid));
+}
+
+int DbusProxy::Stop(pid_t caller_pid) {
+ return MethodCall("Stop", g_variant_new("(i)", caller_pid));
+}
+
+int DbusProxy::MethodCall(const std::string_view method_name,
+ GVariant* parameters) {
+ auto* msg = g_dbus_message_new_method_call(
+ BUS_NAME, OBJECT_PATH, INTERFACE_NAME, method_name.data());
if (msg == nullptr) {
_E("g_dbus_message_new_method_call() is failed");
return -1;
std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_auto(
msg, g_object_unref);
- g_dbus_message_set_body(msg, g_variant_new("(s)", data.c_str()));
+ g_dbus_message_set_body(msg, parameters);
GError* error = nullptr;
- auto* reply = g_dbus_connection_send_message_with_reply_sync(system_conn_, msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr, &error);
+ auto* reply = g_dbus_connection_send_message_with_reply_sync(
+ system_conn_, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr,
+ &error);
if (reply == nullptr || error != nullptr) {
_E("g_dbus_connection_send_message_with_reply_sync() is failed. error(%s)",
- error ? error->message : "Unknown");
+ error ? error->message : "Unknown");
g_clear_error(&error);
return -1;
}
#ifndef DBUS_PROXY_HH_
#define DBUS_PROXY_HH_
-#include <string>
-#include <memory>
-
#include <gio/gio.h>
#include <glib.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <memory>
+#include <string>
+#include <string_view>
namespace rpc_port {
namespace benchmark {
DbusProxy();
void Connect();
- int Test(std::string data) const;
+ int Test(std::string data);
+ int Start(pid_t caller_pid);
+ int Stop(pid_t caller_pid);
+
+ private:
+ int MethodCall(const std::string_view method_name,
+ GVariant* parameters);
private:
GDBusConnection* system_conn_ = nullptr;
#include <unistd.h>
#include <chrono>
+#include <ctime>
+#include <fstream>
#include <iostream>
+#include <sstream>
+#include <string>
-#include "log-private.hh"
-#include "options.hh"
#include "BenchmarkProxy.h"
#include "dbus-proxy.hh"
#include "grpc-proxy.hh"
+#include "log-private.hh"
+#include "options.hh"
namespace {
return;
}
+ if (options_->ShouldPrintTime()) PrintStartTime();
+
ExecuteServer();
if (options_->IsDbus()) {
dbus_proxy_.Connect();
bool is_dbus = options_->IsDbus();
bool is_grpc = options_->IsGrpc();
+ if (is_dbus) dbus_proxy_.Start(getpid());
+
StartTime();
for (int i = 0; i < iters; i++) {
if (is_func) {
}
}
EndTime(iters, size);
+
+ if (is_dbus) dbus_proxy_.Stop(getpid());
}
int FakeFunction(std::string str) {
void ExecuteServer() {
bool is_dbus = options_->IsDbus();
bool is_grpc = options_->IsGrpc();
+ if (!is_grpc) return;
server_pid_ = fork();
if (server_pid_ == 0) {
}
}
+ void PrintStartTime() {
+ std::ifstream stat_file("/proc/self/stat");
+ if (!stat_file) {
+ _E("Failed to open stat");
+ return;
+ }
+
+ std::string line;
+ getline(stat_file, line);
+ std::istringstream iss(line);
+
+ std::string value;
+ int pos = 21;
+ for (int i = 0; i < pos; ++i) iss >> value;
+
+ iss >> value;
+ stat_file.close();
+
+ long start_time = std::stol(value) / sysconf(_SC_CLK_TCK);
+ time_t start_time_seconds = start_time;
+ long start_time_microseconds = (start_time - start_time_seconds) * 1000000;
+
+ std::time_t start_time_utc = std::time(nullptr) - start_time_seconds;
+ std::tm* start_time_tm = std::localtime(&start_time_utc);
+
+ char buffer[26];
+ std::strftime(buffer, sizeof(buffer), "%Y-%m %H:%M:%S", start_time_tm);
+
+ std::string result = buffer;
+ result += ".";
+ result += std::to_string(start_time_microseconds);
+ result += " UTC";
+
+ std::cout << "Program start time: [" << value << "] " << result
+ << std::endl;
+ }
+
private:
std::unique_ptr<rpc_port::benchmark::Options> options_;
std::unique_ptr<bp::Benchmark> proxy_;
-h, --help Show help options
Additional Options:
- -f, --funcation Use function call instead of RPC
+ -f, --funct ion Use function call instead of RPC
-d, --dbus Use Dbus method instead of TIDL RPC
-g, --grpc Use gRPC over UDS instead of TIDL RPC
-a, --all Test pre-defined test-cases
-i, --interations=<Iterations> Iterations
-s, --size=<Data size> Data size (byte)
+ -t, --time Print starting time of this tool
Application Options:
-v, --version Show version information
{"dbus", no_argument, nullptr, 'd'},
{"grpc", no_argument, nullptr, 'g'},
{"all", no_argument, nullptr, 'a'},
+ {"time", no_argument, nullptr, 't'},
{0, 0, 0, 0}
};
while (true) {
- int c = getopt_long(argc, argv, "vhfdgai:s:", long_options,
+ int c = getopt_long(argc, argv, "vhfdgati:s:", long_options,
&option_index);
if (c == -1)
break;
options->is_all_ = true;
break;
+ case 't':
+ opt[OPT_TIME] = true,
+ options->should_print_time_ = true;
+ break;
+
default:
cmd[CMD_HELP] = true;
}
return is_grpc_;
}
+ bool ShouldPrintTime() const {
+ return should_print_time_;
+ }
+
private:
enum Cmd {
CMD_VERSION,
OPT_FUNCTION,
OPT_DBUS,
OPT_GRPC,
+ OPT_TIME,
OPT_MAX
};
bool is_all_ = false;
bool is_dbus_ = false;
bool is_grpc_ = false;
+ bool should_print_time_ = false;
};
} // namespace benchmark
--- /dev/null
+[Unit]
+Description=RPC-Port Benchmark Client (DBus)
+
+[Service]
+SmackProcessLabel=System
+ExecStart=/bin/sh -l -c '/usr/bin/rpc-port-benchmark-tool -d -a -t > /tmp/rpc-port-benchmark-tool-dbus.log'
+
+[Install]
+WantedBy=sysinit.target
--- /dev/null
+[Unit]
+Description=RPC-Port Benchmark Client (TIDL)
+After=rpc-port-benchmark-server-tidl.socket
+Requires=rpc-port-benchmark-server-tidl.socket
+
+[Service]
+SmackProcessLabel=System
+ExecStart=/bin/sh -l -c '/usr/bin/rpc-port-benchmark-tool -a -t > /tmp/rpc-port-benchmark-tool-tidl.log'
+
+[Install]
+WantedBy=sysinit.target
--- /dev/null
+[Unit]
+Description=RPC-Port Benchmark Server (DBus)
+
+[Service]
+BusName=tizen.appfw.rpcport.benchmark.dbus
+Type=dbus
+SmackProcessLabel=System
+ExecStart=/usr/bin/rpc-port-benchmark-server-dbus
+
+[Install]
+WantedBy=sysinit.target
\ No newline at end of file
--- /dev/null
+[Unit]
+Description=RPC-Port Benchmark Server (TIDL)
+After=rpc-port-benchmark-server-tidl.socket
+Requires=rpc-port-benchmark-server-tidl.socket
+
+[Service]
+User=app_fw
+Group=app_fw
+SmackProcessLabel=System
+ExecStart=/usr/bin/rpc-port-benchmark-server-tidl
+
+[Install]
+WantedBy=sysinit.target
\ No newline at end of file
--- /dev/null
+[Unit]
+Description=RPC Port Benchmark Server (TIDL)
+DefaultDependencies=no
+Before=sockets.target
+
+[Socket]
+ListenStream=/run/aul/rpcport/.d::org.tizen.appfw.rpc_port.benchmark::Benchmark
+SocketMode=0666
+SmackLabelIPIn=*
+SmackLabelIPOut=@
+
+[Install]
+WantedBy=sockets.target
\ No newline at end of file
Group: Application Framework/Libraries
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
-Source1001: %{name}.manifest
+Source1001: %{name}.manifest
+Source1002: rpc-port-benchmark-server-dbus.service
+Source1003: rpc-port-benchmark-server-tidl.service
+Source1004: rpc-port-benchmark-server-tidl.socket
+Source1005: tizen.appfw.rpcport.benchmark.dbus.busname
+Source1006: tizen.appfw.rpcport.benchmark.dbus.service
+Source1007: rpc-port-benchmark-client-dbus.service
+Source1008: rpc-port-benchmark-client-tidl.service
BuildRequires: cmake
BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(bundle)
RPC Port gcov objects
%endif
+%package benchmark
+Summary: Benchmark tool for rpc-port
+Group: Application Framework/Testing
+Requires: %{name}
+
+%description benchmark
+Benchmark tool for rpc-port
+
%prep
%setup -q
cp %{SOURCE1001} .
+cp %{SOURCE1002} .
+cp %{SOURCE1003} .
+cp %{SOURCE1004} .
+cp %{SOURCE1005} .
+cp %{SOURCE1006} .
+cp %{SOURCE1007} .
+cp %{SOURCE1008} .
%build
%if 0%{?gcov:1}
%make_install
+mkdir -p %{buildroot}%{_unitdir}
+install -m 0644 %{SOURCE1002} %{buildroot}%{_unitdir}/rpc-port-benchmark-server-dbus.service
+install -m 0644 %{SOURCE1003} %{buildroot}%{_unitdir}/rpc-port-benchmark-server-tidl.service
+
+mkdir -p %{buildroot}%{_unitdir}/sockets.target.wants
+install -m 0644 %{SOURCE1004} %{buildroot}%{_unitdir}/rpc-port-benchmark-server-tidl.socket
+ln -sf ../rpc-port-benchmark-server-tidl.socket %{buildroot}%{_unitdir}/sockets.target.wants/rpc-port-benchmark-server-tidl.socket
+
+mkdir -p %{buildroot}%{_unitdir}/busnames.target.wants
+install -m 0644 %{SOURCE1005} %{buildroot}%{_unitdir}/tizen.appfw.rpcport.benchmark.dbus.busname
+ln -sf ../tizen.appfw.rpcport.benchmark.dbus.busname %{buildroot}%{_unitdir}/busnames.target.wants/tizen.appfw.rpcport.benchmark.dbus.busname
+
+mkdir -p %{buildroot}%{_datadir}/dbus-1/system-services
+install -m 0644 %{SOURCE1006} %{buildroot}%{_datadir}/dbus-1/system-services/tizen.appfw.rpcport.benchmark.dbus.service
+
+mkdir -p %{buildroot}%{_unitdir}/sysinit.target.wants
+install -m 0644 %{SOURCE1007} %{buildroot}%{_unitdir}/rpc-port-benchmark-client-dbus.service
+ln -sf ../rpc-port-benchmark-client-dbus.service %{buildroot}%{_unitdir}/sysinit.target.wants/rpc-port-benchmark-client-dbus.service
+
+install -m 0644 %{SOURCE1008} %{buildroot}%{_unitdir}/rpc-port-benchmark-client-tidl.service
+ln -sf ../rpc-port-benchmark-client-tidl.service %{buildroot}%{_unitdir}/sysinit.target.wants/rpc-port-benchmark-client-tidl.service
+
%if 0%{?gcov:1}
builddir=$(basename $PWD)
gcno_obj_dir=%{buildroot}%{_datadir}/gcov/obj/%{name}/"$builddir"
%files
%manifest %{name}.manifest
-%config %{_sysconfdir}/dbus-1/system.d/rpc-port-benchmark.conf
%attr(0644,root,root) %{_libdir}/lib%{name}.so.*
%license LICENSE.APLv2
%{_bindir}/rpc-port-util
-%{_bindir}/rpc-port-benchmark-server-tidl
-%{_bindir}/rpc-port-benchmark-server-dbus
-%{_bindir}/rpc-port-benchmark-server-grpc
-%{_bindir}/rpc-port-benchmark-tool
%config %{_sysconfdir}/dbus-1/system.d/rpc-port.conf
%files devel
%files gcov
%{_datadir}/gcov/*
%endif
+
+%files benchmark
+%manifest %{name}.manifest
+%config %{_sysconfdir}/dbus-1/system.d/rpc-port-benchmark.conf
+%{_bindir}/rpc-port-benchmark-server-tidl
+%{_bindir}/rpc-port-benchmark-server-dbus
+%{_bindir}/rpc-port-benchmark-server-grpc
+%{_bindir}/rpc-port-benchmark-tool
+%attr(0644,root,root) %{_unitdir}/rpc-port-benchmark-server-tidl.service
+%attr(0644,root,root) %{_unitdir}/rpc-port-benchmark-server-tidl.socket
+%attr(0644,root,root) %{_unitdir}/sockets.target.wants/rpc-port-benchmark-server-tidl.socket
+%attr(0644,root,root) %{_unitdir}/rpc-port-benchmark-server-dbus.service
+%attr(0644,root,root) %{_unitdir}/tizen.appfw.rpcport.benchmark.dbus.busname
+%attr(0644,root,root) %{_unitdir}/busnames.target.wants/tizen.appfw.rpcport.benchmark.dbus.busname
+%attr(0644,root,root) %{_datadir}/dbus-1/system-services/tizen.appfw.rpcport.benchmark.dbus.service
+%attr(0644,root,root) %{_unitdir}/rpc-port-benchmark-client-tidl.service
+%attr(0644,root,root) %{_unitdir}/sysinit.target.wants/rpc-port-benchmark-client-tidl.service
+%attr(0644,root,root) %{_unitdir}/rpc-port-benchmark-client-dbus.service
+%attr(0644,root,root) %{_unitdir}/sysinit.target.wants/rpc-port-benchmark-client-dbus.service
--- /dev/null
+[Unit]
+Description=DBUS1:tizen.appfw.rpcport.benchmark.dbus
+Documentation=man:systemd
+DefaultDependencies=no
+
+[BusName]
+Name=tizen.appfw.rpcport.benchmark.dbus
+Service=rpc-port-benchmark-server-dbus.service
+AllowWorld=talk
\ No newline at end of file
--- /dev/null
+[D-BUS Service]
+Name=tizen.appfw.rpcport.benchmark.dbus
+Exec=/bin/false
+SystemdService=rpc-port-benchmark-server-dbus.service
\ No newline at end of file