4ec07e9fde08499bd32a781723f4ef2e8ceadecd
[platform/upstream/grpc.git] / test / cpp / qps / benchmark_config.cc
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 #include "test/cpp/qps/benchmark_config.h"
20
21 #include <grpc/support/log.h>
22 #include <grpcpp/create_channel.h>
23 #include <grpcpp/security/credentials.h>
24
25 #include "absl/flags/flag.h"
26 #include "test/cpp/util/test_credentials_provider.h"
27
28 ABSL_FLAG(bool, enable_log_reporter, true,
29           "Enable reporting of benchmark results through GprLog");
30
31 ABSL_FLAG(std::string, scenario_result_file, "",
32           "Write JSON benchmark report to the file specified.");
33
34 ABSL_FLAG(std::string, hashed_id, "", "Hash of the user id");
35
36 ABSL_FLAG(std::string, test_name, "", "Name of the test being executed");
37
38 ABSL_FLAG(std::string, sys_info, "", "System information");
39
40 ABSL_FLAG(std::string, server_address, "localhost:50052",
41           "Address of the performance database server");
42
43 ABSL_FLAG(std::string, tag, "", "Optional tag for the test");
44
45 ABSL_FLAG(std::string, rpc_reporter_server_address, "",
46           "Server address for rpc reporter to send results to");
47
48 ABSL_FLAG(bool, enable_rpc_reporter, false, "Enable use of RPC reporter");
49
50 ABSL_FLAG(
51     std::string, rpc_reporter_credential_type,
52     grpc::testing::kInsecureCredentialsType,
53     "Credential type for communication to the QPS benchmark report server");
54
55 namespace grpc {
56 namespace testing {
57
58 static std::shared_ptr<Reporter> InitBenchmarkReporters() {
59   auto* composite_reporter = new CompositeReporter;
60   if (absl::GetFlag(FLAGS_enable_log_reporter)) {
61     composite_reporter->add(
62         std::unique_ptr<Reporter>(new GprLogReporter("LogReporter")));
63   }
64   if (!absl::GetFlag(FLAGS_scenario_result_file).empty()) {
65     composite_reporter->add(std::unique_ptr<Reporter>(new JsonReporter(
66         "JsonReporter", absl::GetFlag(FLAGS_scenario_result_file))));
67   }
68   if (absl::GetFlag(FLAGS_enable_rpc_reporter)) {
69     ChannelArguments channel_args;
70     std::shared_ptr<ChannelCredentials> channel_creds =
71         testing::GetCredentialsProvider()->GetChannelCredentials(
72             absl::GetFlag(FLAGS_rpc_reporter_credential_type), &channel_args);
73     GPR_ASSERT(!absl::GetFlag(FLAGS_rpc_reporter_server_address).empty());
74     composite_reporter->add(std::unique_ptr<Reporter>(new RpcReporter(
75         "RpcReporter",
76         grpc::CreateChannel(absl::GetFlag(FLAGS_rpc_reporter_server_address),
77                             channel_creds))));
78   }
79
80   return std::shared_ptr<Reporter>(composite_reporter);
81 }
82
83 std::shared_ptr<Reporter> GetReporter() {
84   static std::shared_ptr<Reporter> reporter(InitBenchmarkReporters());
85   return reporter;
86 }
87
88 }  // namespace testing
89 }  // namespace grpc