Debian Codegraph @

test/cpp/qps/report.cc

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