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.
29 help_ = R"__option_cb(
31 rpc-port-benchmark-tool [OPTION...]
34 -h, --help Show help options
37 -f, --funct ion Use function call instead of RPC
38 -d, --dbus Use Dbus method instead of TIDL RPC
39 -g, --grpc Use gRPC over UDS instead of TIDL RPC
40 -a, --all Test pre-defined test-cases
41 -i, --interations=<Iterations> Iterations
42 -s, --size=<Data size> Data size (byte)
43 -t, --time Print starting time of this tool
46 -v, --version Show version information
50 void Options::PrintUsage() {
51 std::cerr << help_ << std::endl;
54 void Options::PrintVersion() {
55 std::cerr << "rpc-port-benchmark-tool " << FULLVER << std::endl;
58 void Options::PrintSample() {
59 std::cerr << "rpc-port-benchmark-tool -i 1000 -s 10000" << std::endl;
62 std::unique_ptr<Options> Options::Parse(int argc, char** argv) {
63 bool cmd[CMD_MAX] = { false, };
64 bool opt[OPT_MAX] = { false, };
65 auto options = std::unique_ptr<Options>(new Options());
68 struct option long_options[] = {
69 {"version", no_argument, nullptr, 'v'},
70 {"help", no_argument, nullptr, 'h'},
71 {"iterations", required_argument, nullptr, 'i'},
72 {"size", required_argument, nullptr, 's'},
73 {"function", no_argument, nullptr, 'f'},
74 {"dbus", no_argument, nullptr, 'd'},
75 {"grpc", no_argument, nullptr, 'g'},
76 {"all", no_argument, nullptr, 'a'},
77 {"time", no_argument, nullptr, 't'},
82 int c = getopt_long(argc, argv, "vhfdgati:s:", long_options,
92 cmd[CMD_VERSION] = true;
100 opt[OPT_ITER] = true;
101 options->iters_ = std::stoi(optarg);
105 opt[OPT_SIZE] = true;
106 options->size_ = std::stoi(optarg);
110 opt[OPT_FUNCTION] = true;
111 options->is_function_ = true;
115 opt[OPT_DBUS] = true;
116 options->is_dbus_ = true;
120 opt[OPT_GRPC] = true;
121 options->is_grpc_ = true;
126 options->is_all_ = true;
130 opt[OPT_TIME] = true,
131 options->should_print_time_ = true;
135 cmd[CMD_HELP] = true;
139 if (cmd[CMD_VERSION]) {
140 options->PrintVersion();
141 return std::unique_ptr<Options>(nullptr);
145 options->PrintUsage();
146 return std::unique_ptr<Options>(nullptr);
147 } else if (opt[OPT_ALL]) {
149 } else if (!opt[OPT_ITER] || !opt[OPT_SIZE]) {
150 options->PrintSample();
151 return std::unique_ptr<Options>(nullptr);
157 } // namespace benchmark
158 } // namespace rpc_port