report.cc
Go to the documentation of this file.
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 
27 #include "src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.h"
28 #include "test/cpp/qps/driver.h"
30 #include "test/cpp/qps/stats.h"
31 
32 namespace grpc {
33 namespace testing {
34 
35 void CompositeReporter::add(std::unique_ptr<Reporter> reporter) {
36  reporters_.emplace_back(std::move(reporter));
37 }
38 
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 
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 
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 
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 
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 
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 
76  for (size_t i = 0; i < reporters_.size(); ++i) {
77  reporters_[i]->ReportQueriesPerCpuSec(result);
78  }
79 }
80 
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 
102  const grpc::core::Stats& stats) {
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,
113  &data, static_cast<grpc_stats_histograms>(i), 50),
115  &data, static_cast<grpc_stats_histograms>(i), 95),
117  &data, static_cast<grpc_stats_histograms>(i), 99));
118  }
119 }
120 
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 
126 void GprLogReporter::ReportLatency(const ScenarioResult& result) {
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 
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 
147 void GprLogReporter::ReportCpuUsage(const ScenarioResult& result) {
148  gpr_log(GPR_INFO, "Server CPU usage: %.2f%%",
149  result.summary().server_cpu_usage());
150 }
151 
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 
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 
166 void JsonReporter::ReportQPS(const ScenarioResult& result) {
167  std::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 
174 void JsonReporter::ReportQPSPerCore(const ScenarioResult& /*result*/) {
175  // NOP - all reporting is handled by ReportQPS.
176 }
177 
178 void JsonReporter::ReportLatency(const ScenarioResult& /*result*/) {
179  // NOP - all reporting is handled by ReportQPS.
180 }
181 
182 void JsonReporter::ReportTimes(const ScenarioResult& /*result*/) {
183  // NOP - all reporting is handled by ReportQPS.
184 }
185 
186 void JsonReporter::ReportCpuUsage(const ScenarioResult& /*result*/) {
187  // NOP - all reporting is handled by ReportQPS.
188 }
189 
190 void JsonReporter::ReportPollCount(const ScenarioResult& /*result*/) {
191  // NOP - all reporting is handled by ReportQPS.
192 }
193 
194 void JsonReporter::ReportQueriesPerCpuSec(const ScenarioResult& /*result*/) {
195  // NOP - all reporting is handled by ReportQPS.
196 }
197 
198 void RpcReporter::ReportQPS(const ScenarioResult& result) {
201  Void phony;
202 
203  gpr_log(GPR_INFO, "RPC reporter sending scenario result to server");
204  status = stub_->ReportScenario(&context, result, &phony);
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 
214 void RpcReporter::ReportQPSPerCore(const ScenarioResult& /*result*/) {
215  // NOP - all reporting is handled by ReportQPS.
216 }
217 
218 void RpcReporter::ReportLatency(const ScenarioResult& /*result*/) {
219  // NOP - all reporting is handled by ReportQPS.
220 }
221 
222 void RpcReporter::ReportTimes(const ScenarioResult& /*result*/) {
223  // NOP - all reporting is handled by ReportQPS.
224 }
225 
226 void RpcReporter::ReportCpuUsage(const ScenarioResult& /*result*/) {
227  // NOP - all reporting is handled by ReportQPS.
228 }
229 
230 void RpcReporter::ReportPollCount(const ScenarioResult& /*result*/) {
231  // NOP - all reporting is handled by ReportQPS.
232 }
233 
234 void RpcReporter::ReportQueriesPerCpuSec(const ScenarioResult& /*result*/) {
235  // NOP - all reporting is handled by ReportQPS.
236 }
237 
238 } // namespace testing
239 } // namespace grpc
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
GPR_INFO
#define GPR_INFO
Definition: include/grpc/impl/codegen/log.h:56
testing
Definition: aws_request_signer_test.cc:25
grpc::status
auto status
Definition: cpp/client/credentials_test.cc:200
grpc::testing::GprLogReporter::ReportCoreStats
void ReportCoreStats(const char *name, int idx, const grpc::core::Stats &stats)
Definition: report.cc:101
grpc::testing::GprLogReporter::ReportTimes
void ReportTimes(const ScenarioResult &result) override
Definition: report.cc:136
log.h
grpc::testing::GprLogReporter::ReportQPS
void ReportQPS(const ScenarioResult &result) override
Definition: report.cc:81
grpc::testing::RpcReporter::ReportQueriesPerCpuSec
void ReportQueriesPerCpuSec(const ScenarioResult &result) override
Definition: report.cc:234
grpc
Definition: grpcpp/alarm.h:33
driver.h
GRPC_STATS_HISTOGRAM_COUNT
@ GRPC_STATS_HISTOGRAM_COUNT
Definition: stats_data.h:142
grpc::testing::JsonReporter::ReportPollCount
void ReportPollCount(const ScenarioResult &result) override
Definition: report.cc:190
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::testing::RpcReporter::ReportQPS
void ReportQPS(const ScenarioResult &result) override
Definition: report.cc:198
setup.name
name
Definition: setup.py:542
grpc::testing::CompositeReporter::ReportLatency
void ReportLatency(const ScenarioResult &result) override
Definition: report.cc:51
grpc::ProtoToCoreStats
void ProtoToCoreStats(const grpc::core::Stats &proto, grpc_stats_data *core)
Definition: core_stats.cc:57
grpc::testing::GprLogReporter::ReportCpuUsage
void ReportCpuUsage(const ScenarioResult &result) override
Definition: report.cc:147
grpc_stats_counter_name
const char * grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT]
Definition: stats_data.cc:30
grpc::testing::JsonReporter::ReportQPS
void ReportQPS(const ScenarioResult &result) override
Definition: report.cc:166
grpc::testing::JsonReporter::ReportQueriesPerCpuSec
void ReportQueriesPerCpuSec(const ScenarioResult &result) override
Definition: report.cc:194
grpc::testing::SerializeJson
std::string SerializeJson(const GRPC_CUSTOM_MESSAGE &msg, const std::string &type)
Definition: parse_json.cc:46
core_stats.h
grpc::testing::JsonReporter::ReportTimes
void ReportTimes(const ScenarioResult &result) override
Definition: report.cc:182
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc::testing::RpcReporter::ReportPollCount
void ReportPollCount(const ScenarioResult &result) override
Definition: report.cc:230
grpc::testing::CompositeReporter::add
void add(std::unique_ptr< Reporter > reporter)
Definition: report.cc:35
grpc::testing::RpcReporter::ReportLatency
void ReportLatency(const ScenarioResult &result) override
Definition: report.cc:218
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
stats.h
gen_stats_data.stats
list stats
Definition: gen_stats_data.py:58
grpc::testing::GprLogReporter::ReportLatency
void ReportLatency(const ScenarioResult &result) override
Definition: report.cc:126
grpc::testing::GprLogReporter::ReportPollCount
void ReportPollCount(const ScenarioResult &result) override
Definition: report.cc:152
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
grpc::testing::RpcReporter::stub_
std::unique_ptr< ReportQpsScenarioService::Stub > stub_
Definition: report.h:143
GPR_ERROR
#define GPR_ERROR
Definition: include/grpc/impl/codegen/log.h:57
grpc::testing::CompositeReporter::ReportTimes
void ReportTimes(const ScenarioResult &result) override
Definition: report.cc:57
grpc_stats_histogram_name
const char * grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT]
Definition: stats_data.cc:254
setup.idx
idx
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:197
parse_json.h
grpc::testing::RpcReporter::ReportQPSPerCore
void ReportQPSPerCore(const ScenarioResult &result) override
Definition: report.cc:214
grpc::ClientContext
Definition: grpcpp/impl/codegen/client_context.h:195
report.h
grpc::testing::JsonReporter::report_file_
const string report_file_
Definition: report.h:126
client_context.h
grpc::testing::JsonReporter::ReportQPSPerCore
void ReportQPSPerCore(const ScenarioResult &result) override
Definition: report.cc:174
grpc::testing::CompositeReporter::reporters_
std::vector< std::unique_ptr< Reporter > > reporters_
Definition: report.h:90
grpc::testing::CompositeReporter::ReportPollCount
void ReportPollCount(const ScenarioResult &result) override
Definition: report.cc:69
grpc::testing::Reporter::name
string name() const
Definition: report.h:46
grpc::testing::CompositeReporter::ReportCpuUsage
void ReportCpuUsage(const ScenarioResult &result) override
Definition: report.cc:63
grpc_stats_data
Definition: src/core/lib/debug/stats.h:33
grpc::testing::CompositeReporter::ReportQPS
void ReportQPS(const ScenarioResult &result) override
Definition: report.cc:39
grpc::testing::JsonReporter::ReportLatency
void ReportLatency(const ScenarioResult &result) override
Definition: report.cc:178
grpc::Status
Definition: include/grpcpp/impl/codegen/status.h:35
grpc_stats_histograms
grpc_stats_histograms
Definition: stats_data.h:128
grpc_stats_histo_percentile
double grpc_stats_histo_percentile(const grpc_stats_data *stats, grpc_stats_histograms histogram, double percentile)
Definition: stats.cc:136
grpc::testing::CompositeReporter::ReportQueriesPerCpuSec
void ReportQueriesPerCpuSec(const ScenarioResult &result) override
Definition: report.cc:75
grpc::testing::RpcReporter::ReportTimes
void ReportTimes(const ScenarioResult &result) override
Definition: report.cc:222
GPR_DEBUG
#define GPR_DEBUG
Definition: include/grpc/impl/codegen/log.h:55
GRPC_STATS_COUNTER_COUNT
@ GRPC_STATS_COUNTER_COUNT
Definition: stats_data.h:124
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
grpc::testing::GprLogReporter::ReportQPSPerCore
void ReportQPSPerCore(const ScenarioResult &result) override
Definition: report.cc:121
grpc::testing::GprLogReporter::ReportQueriesPerCpuSec
void ReportQueriesPerCpuSec(const ScenarioResult &result) override
Definition: report.cc:159
grpc::testing::JsonReporter::ReportCpuUsage
void ReportCpuUsage(const ScenarioResult &result) override
Definition: report.cc:186
grpc::testing::CompositeReporter::ReportQPSPerCore
void ReportQPSPerCore(const ScenarioResult &result) override
Definition: report.cc:45
grpc::testing::RpcReporter::ReportCpuUsage
void ReportCpuUsage(const ScenarioResult &result) override
Definition: report.cc:226
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:04