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/report.h"
20
21 #include <fstream>
22
23 #include <grpc/support/log.h>
24 #include <grpcpp/client_context.h>
25
26 #include "src/core/lib/gprpp/crash.h"
27 #include "src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.h"
28 #include "test/cpp/qps/driver.h"
29 #include "test/cpp/qps/parse_json.h"
30 #include "test/cpp/qps/stats.h"
31
32 namespace grpc {
33 namespace testing {
34
add(std::unique_ptr<Reporter> reporter)35 void CompositeReporter::add(std::unique_ptr<Reporter> reporter) {
36 reporters_.emplace_back(std::move(reporter));
37 }
38
ReportQPS(const ScenarioResult & result)39 void CompositeReporter::ReportQPS(const ScenarioResult& result) {
40 for (size_t i = 0; i < reporters_.size(); ++i) {
41 reporters_[i]->ReportQPS(result);
42 }
43 }
44
ReportQPSPerCore(const ScenarioResult & result)45 void CompositeReporter::ReportQPSPerCore(const ScenarioResult& result) {
46 for (size_t i = 0; i < reporters_.size(); ++i) {
47 reporters_[i]->ReportQPSPerCore(result);
48 }
49 }
50
ReportLatency(const ScenarioResult & result)51 void CompositeReporter::ReportLatency(const ScenarioResult& result) {
52 for (size_t i = 0; i < reporters_.size(); ++i) {
53 reporters_[i]->ReportLatency(result);
54 }
55 }
56
ReportTimes(const ScenarioResult & result)57 void CompositeReporter::ReportTimes(const ScenarioResult& result) {
58 for (size_t i = 0; i < reporters_.size(); ++i) {
59 reporters_[i]->ReportTimes(result);
60 }
61 }
62
ReportCpuUsage(const ScenarioResult & result)63 void CompositeReporter::ReportCpuUsage(const ScenarioResult& result) {
64 for (size_t i = 0; i < reporters_.size(); ++i) {
65 reporters_[i]->ReportCpuUsage(result);
66 }
67 }
68
ReportPollCount(const ScenarioResult & result)69 void CompositeReporter::ReportPollCount(const ScenarioResult& result) {
70 for (size_t i = 0; i < reporters_.size(); ++i) {
71 reporters_[i]->ReportPollCount(result);
72 }
73 }
74
ReportQueriesPerCpuSec(const ScenarioResult & result)75 void CompositeReporter::ReportQueriesPerCpuSec(const ScenarioResult& result) {
76 for (size_t i = 0; i < reporters_.size(); ++i) {
77 reporters_[i]->ReportQueriesPerCpuSec(result);
78 }
79 }
80
ReportQPS(const ScenarioResult & result)81 void GprLogReporter::ReportQPS(const ScenarioResult& result) {
82 gpr_log(GPR_INFO, "QPS: %.1f", result.summary().qps());
83 if (result.summary().failed_requests_per_second() > 0) {
84 gpr_log(GPR_INFO, "failed requests/second: %.1f",
85 result.summary().failed_requests_per_second());
86 gpr_log(GPR_INFO, "successful requests/second: %.1f",
87 result.summary().successful_requests_per_second());
88 }
89 }
90
ReportQPSPerCore(const ScenarioResult & result)91 void GprLogReporter::ReportQPSPerCore(const ScenarioResult& result) {
92 gpr_log(GPR_INFO, "QPS: %.1f (%.1f/server core)", result.summary().qps(),
93 result.summary().qps_per_server_core());
94 }
95
ReportLatency(const ScenarioResult & result)96 void GprLogReporter::ReportLatency(const ScenarioResult& result) {
97 gpr_log(GPR_INFO,
98 "Latencies (50/90/95/99/99.9%%-ile): %.1f/%.1f/%.1f/%.1f/%.1f us",
99 result.summary().latency_50() / 1000,
100 result.summary().latency_90() / 1000,
101 result.summary().latency_95() / 1000,
102 result.summary().latency_99() / 1000,
103 result.summary().latency_999() / 1000);
104 }
105
ReportTimes(const ScenarioResult & result)106 void GprLogReporter::ReportTimes(const ScenarioResult& result) {
107 gpr_log(GPR_INFO, "Server system time: %.2f%%",
108 result.summary().server_system_time());
109 gpr_log(GPR_INFO, "Server user time: %.2f%%",
110 result.summary().server_user_time());
111 gpr_log(GPR_INFO, "Client system time: %.2f%%",
112 result.summary().client_system_time());
113 gpr_log(GPR_INFO, "Client user time: %.2f%%",
114 result.summary().client_user_time());
115 }
116
ReportCpuUsage(const ScenarioResult & result)117 void GprLogReporter::ReportCpuUsage(const ScenarioResult& result) {
118 gpr_log(GPR_INFO, "Server CPU usage: %.2f%%",
119 result.summary().server_cpu_usage());
120 }
121
ReportPollCount(const ScenarioResult & result)122 void GprLogReporter::ReportPollCount(const ScenarioResult& result) {
123 gpr_log(GPR_INFO, "Client Polls per Request: %.2f",
124 result.summary().client_polls_per_request());
125 gpr_log(GPR_INFO, "Server Polls per Request: %.2f",
126 result.summary().server_polls_per_request());
127 }
128
ReportQueriesPerCpuSec(const ScenarioResult & result)129 void GprLogReporter::ReportQueriesPerCpuSec(const ScenarioResult& result) {
130 gpr_log(GPR_INFO, "Server Queries/CPU-sec: %.2f",
131 result.summary().server_queries_per_cpu_sec());
132 gpr_log(GPR_INFO, "Client Queries/CPU-sec: %.2f",
133 result.summary().client_queries_per_cpu_sec());
134 }
135
ReportQPS(const ScenarioResult & result)136 void JsonReporter::ReportQPS(const ScenarioResult& result) {
137 std::string json_string =
138 SerializeJson(result, "type.googleapis.com/grpc.testing.ScenarioResult");
139 std::ofstream output_file(report_file_);
140 output_file << json_string;
141 output_file.close();
142 }
143
ReportQPSPerCore(const ScenarioResult &)144 void JsonReporter::ReportQPSPerCore(const ScenarioResult& /*result*/) {
145 // NOP - all reporting is handled by ReportQPS.
146 }
147
ReportLatency(const ScenarioResult &)148 void JsonReporter::ReportLatency(const ScenarioResult& /*result*/) {
149 // NOP - all reporting is handled by ReportQPS.
150 }
151
ReportTimes(const ScenarioResult &)152 void JsonReporter::ReportTimes(const ScenarioResult& /*result*/) {
153 // NOP - all reporting is handled by ReportQPS.
154 }
155
ReportCpuUsage(const ScenarioResult &)156 void JsonReporter::ReportCpuUsage(const ScenarioResult& /*result*/) {
157 // NOP - all reporting is handled by ReportQPS.
158 }
159
ReportPollCount(const ScenarioResult &)160 void JsonReporter::ReportPollCount(const ScenarioResult& /*result*/) {
161 // NOP - all reporting is handled by ReportQPS.
162 }
163
ReportQueriesPerCpuSec(const ScenarioResult &)164 void JsonReporter::ReportQueriesPerCpuSec(const ScenarioResult& /*result*/) {
165 // NOP - all reporting is handled by ReportQPS.
166 }
167
ReportQPS(const ScenarioResult & result)168 void RpcReporter::ReportQPS(const ScenarioResult& result) {
169 grpc::ClientContext context;
170 grpc::Status status;
171 Void phony;
172
173 gpr_log(GPR_INFO, "RPC reporter sending scenario result to server");
174 status = stub_->ReportScenario(&context, result, &phony);
175
176 if (status.ok()) {
177 gpr_log(GPR_INFO, "RpcReporter report RPC success!");
178 } else {
179 gpr_log(GPR_ERROR, "RpcReporter report RPC: code: %d. message: %s",
180 status.error_code(), status.error_message().c_str());
181 }
182 }
183
ReportQPSPerCore(const ScenarioResult &)184 void RpcReporter::ReportQPSPerCore(const ScenarioResult& /*result*/) {
185 // NOP - all reporting is handled by ReportQPS.
186 }
187
ReportLatency(const ScenarioResult &)188 void RpcReporter::ReportLatency(const ScenarioResult& /*result*/) {
189 // NOP - all reporting is handled by ReportQPS.
190 }
191
ReportTimes(const ScenarioResult &)192 void RpcReporter::ReportTimes(const ScenarioResult& /*result*/) {
193 // NOP - all reporting is handled by ReportQPS.
194 }
195
ReportCpuUsage(const ScenarioResult &)196 void RpcReporter::ReportCpuUsage(const ScenarioResult& /*result*/) {
197 // NOP - all reporting is handled by ReportQPS.
198 }
199
ReportPollCount(const ScenarioResult &)200 void RpcReporter::ReportPollCount(const ScenarioResult& /*result*/) {
201 // NOP - all reporting is handled by ReportQPS.
202 }
203
ReportQueriesPerCpuSec(const ScenarioResult &)204 void RpcReporter::ReportQueriesPerCpuSec(const ScenarioResult& /*result*/) {
205 // NOP - all reporting is handled by ReportQPS.
206 }
207
208 } // namespace testing
209 } // namespace grpc
210