• 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/report.h"
20 
21 #include <fstream>
22 
23 #include <grpc/support/log.h>
24 #include "test/cpp/qps/driver.h"
25 #include "test/cpp/qps/parse_json.h"
26 #include "test/cpp/qps/stats.h"
27 
28 #include <grpcpp/client_context.h>
29 #include "src/cpp/util/core_stats.h"
30 #include "src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.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   for (int i = 0; i < result.client_stats_size(); i++) {
90     if (result.client_stats(i).has_core_stats()) {
91       ReportCoreStats("CLIENT", i, result.client_stats(i).core_stats());
92     }
93   }
94   for (int i = 0; i < result.server_stats_size(); i++) {
95     if (result.server_stats(i).has_core_stats()) {
96       ReportCoreStats("SERVER", i, result.server_stats(i).core_stats());
97     }
98   }
99 }
100 
ReportCoreStats(const char * name,int idx,const grpc::core::Stats & stats)101 void GprLogReporter::ReportCoreStats(const char* name, int idx,
102                                      const grpc::core::Stats& stats) {
103   grpc_stats_data data;
104   ProtoToCoreStats(stats, &data);
105   for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) {
106     gpr_log(GPR_DEBUG, "%s[%d].%s = %" PRIdPTR, name, idx,
107             grpc_stats_counter_name[i], data.counters[i]);
108   }
109   for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) {
110     gpr_log(GPR_DEBUG, "%s[%d].%s = %.1lf/%.1lf/%.1lf (50/95/99%%-ile)", name,
111             idx, grpc_stats_histogram_name[i],
112             grpc_stats_histo_percentile(
113                 &data, static_cast<grpc_stats_histograms>(i), 50),
114             grpc_stats_histo_percentile(
115                 &data, static_cast<grpc_stats_histograms>(i), 95),
116             grpc_stats_histo_percentile(
117                 &data, static_cast<grpc_stats_histograms>(i), 99));
118   }
119 }
120 
ReportQPSPerCore(const ScenarioResult & result)121 void GprLogReporter::ReportQPSPerCore(const ScenarioResult& result) {
122   gpr_log(GPR_INFO, "QPS: %.1f (%.1f/server core)", result.summary().qps(),
123           result.summary().qps_per_server_core());
124 }
125 
ReportLatency(const ScenarioResult & result)126 void GprLogReporter::ReportLatency(const ScenarioResult& result) {
127   gpr_log(GPR_INFO,
128           "Latencies (50/90/95/99/99.9%%-ile): %.1f/%.1f/%.1f/%.1f/%.1f us",
129           result.summary().latency_50() / 1000,
130           result.summary().latency_90() / 1000,
131           result.summary().latency_95() / 1000,
132           result.summary().latency_99() / 1000,
133           result.summary().latency_999() / 1000);
134 }
135 
ReportTimes(const ScenarioResult & result)136 void GprLogReporter::ReportTimes(const ScenarioResult& result) {
137   gpr_log(GPR_INFO, "Server system time: %.2f%%",
138           result.summary().server_system_time());
139   gpr_log(GPR_INFO, "Server user time:   %.2f%%",
140           result.summary().server_user_time());
141   gpr_log(GPR_INFO, "Client system time: %.2f%%",
142           result.summary().client_system_time());
143   gpr_log(GPR_INFO, "Client user time:   %.2f%%",
144           result.summary().client_user_time());
145 }
146 
ReportCpuUsage(const ScenarioResult & result)147 void GprLogReporter::ReportCpuUsage(const ScenarioResult& result) {
148   gpr_log(GPR_INFO, "Server CPU usage: %.2f%%",
149           result.summary().server_cpu_usage());
150 }
151 
ReportPollCount(const ScenarioResult & result)152 void GprLogReporter::ReportPollCount(const ScenarioResult& result) {
153   gpr_log(GPR_INFO, "Client Polls per Request: %.2f",
154           result.summary().client_polls_per_request());
155   gpr_log(GPR_INFO, "Server Polls per Request: %.2f",
156           result.summary().server_polls_per_request());
157 }
158 
ReportQueriesPerCpuSec(const ScenarioResult & result)159 void GprLogReporter::ReportQueriesPerCpuSec(const ScenarioResult& result) {
160   gpr_log(GPR_INFO, "Server Queries/CPU-sec: %.2f",
161           result.summary().server_queries_per_cpu_sec());
162   gpr_log(GPR_INFO, "Client Queries/CPU-sec: %.2f",
163           result.summary().client_queries_per_cpu_sec());
164 }
165 
ReportQPS(const ScenarioResult & result)166 void JsonReporter::ReportQPS(const ScenarioResult& result) {
167   grpc::string json_string =
168       SerializeJson(result, "type.googleapis.com/grpc.testing.ScenarioResult");
169   std::ofstream output_file(report_file_);
170   output_file << json_string;
171   output_file.close();
172 }
173 
ReportQPSPerCore(const ScenarioResult & result)174 void JsonReporter::ReportQPSPerCore(const ScenarioResult& result) {
175   // NOP - all reporting is handled by ReportQPS.
176 }
177 
ReportLatency(const ScenarioResult & result)178 void JsonReporter::ReportLatency(const ScenarioResult& result) {
179   // NOP - all reporting is handled by ReportQPS.
180 }
181 
ReportTimes(const ScenarioResult & result)182 void JsonReporter::ReportTimes(const ScenarioResult& result) {
183   // NOP - all reporting is handled by ReportQPS.
184 }
185 
ReportCpuUsage(const ScenarioResult & result)186 void JsonReporter::ReportCpuUsage(const ScenarioResult& result) {
187   // NOP - all reporting is handled by ReportQPS.
188 }
189 
ReportPollCount(const ScenarioResult & result)190 void JsonReporter::ReportPollCount(const ScenarioResult& result) {
191   // NOP - all reporting is handled by ReportQPS.
192 }
193 
ReportQueriesPerCpuSec(const ScenarioResult & result)194 void JsonReporter::ReportQueriesPerCpuSec(const ScenarioResult& result) {
195   // NOP - all reporting is handled by ReportQPS.
196 }
197 
ReportQPS(const ScenarioResult & result)198 void RpcReporter::ReportQPS(const ScenarioResult& result) {
199   grpc::ClientContext context;
200   grpc::Status status;
201   Void dummy;
202 
203   gpr_log(GPR_INFO, "RPC reporter sending scenario result to server");
204   status = stub_->ReportScenario(&context, result, &dummy);
205 
206   if (status.ok()) {
207     gpr_log(GPR_INFO, "RpcReporter report RPC success!");
208   } else {
209     gpr_log(GPR_ERROR, "RpcReporter report RPC: code: %d. message: %s",
210             status.error_code(), status.error_message().c_str());
211   }
212 }
213 
ReportQPSPerCore(const ScenarioResult & result)214 void RpcReporter::ReportQPSPerCore(const ScenarioResult& result) {
215   // NOP - all reporting is handled by ReportQPS.
216 }
217 
ReportLatency(const ScenarioResult & result)218 void RpcReporter::ReportLatency(const ScenarioResult& result) {
219   // NOP - all reporting is handled by ReportQPS.
220 }
221 
ReportTimes(const ScenarioResult & result)222 void RpcReporter::ReportTimes(const ScenarioResult& result) {
223   // NOP - all reporting is handled by ReportQPS.
224 }
225 
ReportCpuUsage(const ScenarioResult & result)226 void RpcReporter::ReportCpuUsage(const ScenarioResult& result) {
227   // NOP - all reporting is handled by ReportQPS.
228 }
229 
ReportPollCount(const ScenarioResult & result)230 void RpcReporter::ReportPollCount(const ScenarioResult& result) {
231   // NOP - all reporting is handled by ReportQPS.
232 }
233 
ReportQueriesPerCpuSec(const ScenarioResult & result)234 void RpcReporter::ReportQueriesPerCpuSec(const ScenarioResult& result) {
235   // NOP - all reporting is handled by ReportQPS.
236 }
237 
238 }  // namespace testing
239 }  // namespace grpc
240