xref: /aosp_15_r20/external/grpc-grpc/test/cpp/qps/scenario_runner.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 // Copyright 2023 The gRPC Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "absl/flags/flag.h"
16 
17 #include <grpc/support/log.h>
18 
19 #include "src/core/lib/debug/stats.h"
20 #include "src/core/lib/debug/stats_data.h"
21 #include "src/core/lib/slice/slice_internal.h"
22 #include "src/proto/grpc/testing/control.pb.h"
23 #include "test/core/util/test_config.h"
24 #include "test/core/util/tls_utils.h"
25 #include "test/cpp/qps/benchmark_config.h"
26 #include "test/cpp/qps/driver.h"
27 #include "test/cpp/qps/parse_json.h"
28 #include "test/cpp/util/test_config.h"
29 #include "test/cpp/util/test_credentials_provider.h"
30 
31 ABSL_FLAG(std::string, loadtest_config, "",
32           "Path to a gRPC benchmark loadtest scenario JSON file. See "
33           "scenario_runner.py");
34 
35 namespace grpc {
36 namespace testing {
37 
RunScenario()38 static void RunScenario() {
39   std::string json_str =
40       grpc_core::testing::GetFileContents(absl::GetFlag(FLAGS_loadtest_config));
41   Scenarios scenarios;
42   ParseJson(json_str, "grpc.testing.Scenarios", &scenarios);
43   gpr_log(GPR_INFO, "Running %s", scenarios.scenarios(0).name().c_str());
44   const auto result =
45       RunScenario(scenarios.scenarios(0).client_config(), 1,
46                   scenarios.scenarios(0).server_config(), 1,
47                   scenarios.scenarios(0).warmup_seconds(),
48                   scenarios.scenarios(0).benchmark_seconds(), -2, "",
49                   kInsecureCredentialsType, {}, false, 0);
50   GetReporter()->ReportQPS(*result);
51   GetReporter()->ReportLatency(*result);
52   gpr_log(GPR_ERROR, "Global Stats:\n%s",
53           StatsAsJson(grpc_core::global_stats().Collect().get()).c_str());
54 }
55 
56 }  // namespace testing
57 }  // namespace grpc
58 
main(int argc,char ** argv)59 int main(int argc, char** argv) {
60   grpc::testing::TestEnvironment env(&argc, argv);
61   grpc::testing::InitTest(&argc, &argv, true);
62   grpc::testing::RunScenario();
63   return 0;
64 }
65