• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gflags/gflags.h>
21 #include <grpc/support/log.h>
22 #include <grpcpp/create_channel.h>
23 #include <grpcpp/security/credentials.h>
24 
25 #include "test/cpp/util/test_credentials_provider.h"
26 
27 DEFINE_bool(enable_log_reporter, true,
28             "Enable reporting of benchmark results through GprLog");
29 
30 DEFINE_string(scenario_result_file, "",
31               "Write JSON benchmark report to the file specified.");
32 
33 DEFINE_string(hashed_id, "", "Hash of the user id");
34 
35 DEFINE_string(test_name, "", "Name of the test being executed");
36 
37 DEFINE_string(sys_info, "", "System information");
38 
39 DEFINE_string(server_address, "localhost:50052",
40               "Address of the performance database server");
41 
42 DEFINE_string(tag, "", "Optional tag for the test");
43 
44 DEFINE_string(rpc_reporter_server_address, "",
45               "Server address for rpc reporter to send results to");
46 
47 DEFINE_bool(enable_rpc_reporter, false, "Enable use of RPC reporter");
48 
49 DEFINE_string(
50     rpc_reporter_credential_type, grpc::testing::kInsecureCredentialsType,
51     "Credential type for communication to the QPS benchmark report server");
52 
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.
55 namespace google {}
56 namespace gflags {}
57 using namespace google;
58 using namespace gflags;
59 
60 namespace grpc {
61 namespace testing {
62 
InitBenchmarkReporters()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")));
68   }
69   if (FLAGS_scenario_result_file != "") {
70     composite_reporter->add(std::unique_ptr<Reporter>(
71         new JsonReporter("JsonReporter", FLAGS_scenario_result_file)));
72   }
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,
81                                            channel_creds))));
82   }
83 
84   return std::shared_ptr<Reporter>(composite_reporter);
85 }
86 
GetReporter()87 std::shared_ptr<Reporter> GetReporter() {
88   static std::shared_ptr<Reporter> reporter(InitBenchmarkReporters());
89   return reporter;
90 }
91 
92 }  // namespace testing
93 }  // namespace grpc
94