3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "test/cpp/qps/benchmark_config.h"
20 #include <gflags/gflags.h>
21 #include <grpc/support/log.h>
22 #include <grpcpp/create_channel.h>
23 #include <grpcpp/security/credentials.h>
25 #include "test/cpp/util/test_credentials_provider.h"
27 DEFINE_bool(enable_log_reporter, true,
28 "Enable reporting of benchmark results through GprLog");
30 DEFINE_string(scenario_result_file, "",
31 "Write JSON benchmark report to the file specified.");
33 DEFINE_string(hashed_id, "", "Hash of the user id");
35 DEFINE_string(test_name, "", "Name of the test being executed");
37 DEFINE_string(sys_info, "", "System information");
39 DEFINE_string(server_address, "localhost:50052",
40 "Address of the performance database server");
42 DEFINE_string(tag, "", "Optional tag for the test");
44 DEFINE_string(rpc_reporter_server_address, "",
45 "Server address for rpc reporter to send results to");
47 DEFINE_bool(enable_rpc_reporter, false, "Enable use of RPC reporter");
50 rpc_reporter_credential_type, grpc::testing::kInsecureCredentialsType,
51 "Credential type for communication to the QPS benchmark report server");
53 // In some distros, gflags is in the namespace google, and in some others,
54 // in gflags. This hack is enabling us to find both.
57 using namespace google;
58 using namespace gflags;
63 static std::shared_ptr<Reporter> InitBenchmarkReporters() {
64 auto* composite_reporter = new CompositeReporter;
65 if (FLAGS_enable_log_reporter) {
66 composite_reporter->add(
67 std::unique_ptr<Reporter>(new GprLogReporter("LogReporter")));
69 if (!FLAGS_scenario_result_file.empty()) {
70 composite_reporter->add(std::unique_ptr<Reporter>(
71 new JsonReporter("JsonReporter", FLAGS_scenario_result_file)));
73 if (FLAGS_enable_rpc_reporter) {
74 ChannelArguments channel_args;
75 std::shared_ptr<ChannelCredentials> channel_creds =
76 testing::GetCredentialsProvider()->GetChannelCredentials(
77 FLAGS_rpc_reporter_credential_type, &channel_args);
78 GPR_ASSERT(!FLAGS_rpc_reporter_server_address.empty());
79 composite_reporter->add(std::unique_ptr<Reporter>(new RpcReporter(
80 "RpcReporter", grpc::CreateChannel(FLAGS_rpc_reporter_server_address,
84 return std::shared_ptr<Reporter>(composite_reporter);
87 std::shared_ptr<Reporter> GetReporter() {
88 static std::shared_ptr<Reporter> reporter(InitBenchmarkReporters());
92 } // namespace testing