2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include "log-private.hh"
25 #include "BenchmarkProxy.h"
29 constexpr const char SERVER_PROC_NAME[] = "org.tizen.appfw.rpc_port.benchmark";
31 namespace bp = rpc_port::BenchmarkProxy::proxy;
33 class ConnectionListener : public bp::Benchmark::IEventListener {
35 void OnConnected() override {
38 void OnDisconnected() override {
41 void OnRejected() override {
53 void Run(int argc, char** argv) {
54 options_ = rpc_port::benchmark::Options::Parse(argc, argv);
56 _E("options is nullptr");
60 proxy_.reset(new bp::Benchmark(&listener_, SERVER_PROC_NAME));
63 proxy_->Connect(true);
64 } catch (const bp::Exception& e) {
65 _E("Connect() failed");
74 int iters = options_->GetIters();
75 int size = options_->GetSize();
78 for (int i = 0; i < iters; i++) {
79 int ret = proxy_->Test(std::string(size, 'a'));
89 start_ = std::chrono::system_clock::now();
93 std::chrono::duration<double> sec = std::chrono::system_clock::now() - start_;
94 std::cout << "Iterations: " << std::to_string(options_->GetIters()) << std::endl;
95 std::cout << "Data size: " << std::to_string(options_->GetSize()) << "Byte" << std::endl;
96 std::cout << "Duration: " << sec.count() << "s" << std::endl;
97 double t = options_->GetSize() * options_->GetIters() / sec.count() / 1024 / 1024;
98 std::cout << "Throughput: " << std::to_string(t * 8) << "Mb/s" << std::endl;
99 double l = sec.count() * 1000 / options_->GetIters();
100 std::cout << "Latency: " << std::to_string(l) << "ms" << std::endl;
104 std::unique_ptr<rpc_port::benchmark::Options> options_;
105 std::unique_ptr<bp::Benchmark> proxy_;
106 ConnectionListener listener_;
107 std::chrono::system_clock::time_point start_;
112 int main(int argc, char** argv) {
114 tester.Run(argc, argv);