Line data Source code
1 : /*
2 : *
3 : * Copyright 2015, Google Inc.
4 : * All rights reserved.
5 : *
6 : * Redistribution and use in source and binary forms, with or without
7 : * modification, are permitted provided that the following conditions are
8 : * met:
9 : *
10 : * * Redistributions of source code must retain the above copyright
11 : * notice, this list of conditions and the following disclaimer.
12 : * * Redistributions in binary form must reproduce the above
13 : * copyright notice, this list of conditions and the following disclaimer
14 : * in the documentation and/or other materials provided with the
15 : * distribution.
16 : * * Neither the name of Google Inc. nor the names of its
17 : * contributors may be used to endorse or promote products derived from
18 : * this software without specific prior written permission.
19 : *
20 : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 : * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 : * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 : * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 : * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 : *
32 : */
33 :
34 : #include "test/cpp/qps/report.h"
35 :
36 : #include <grpc/support/log.h>
37 : #include "test/cpp/qps/driver.h"
38 : #include "test/cpp/qps/stats.h"
39 :
40 : namespace grpc {
41 : namespace testing {
42 :
43 6 : static double WallTime(ResourceUsage u) { return u.wall_time(); }
44 0 : static double UserTime(ResourceUsage u) { return u.user_time(); }
45 0 : static double SystemTime(ResourceUsage u) { return u.system_time(); }
46 :
47 6 : void CompositeReporter::add(std::unique_ptr<Reporter> reporter) {
48 6 : reporters_.emplace_back(std::move(reporter));
49 6 : }
50 :
51 4 : void CompositeReporter::ReportQPS(const ScenarioResult& result) {
52 8 : for (size_t i = 0; i < reporters_.size(); ++i) {
53 4 : reporters_[i]->ReportQPS(result);
54 : }
55 4 : }
56 :
57 2 : void CompositeReporter::ReportQPSPerCore(const ScenarioResult& result) {
58 4 : for (size_t i = 0; i < reporters_.size(); ++i) {
59 2 : reporters_[i]->ReportQPSPerCore(result);
60 : }
61 2 : }
62 :
63 6 : void CompositeReporter::ReportLatency(const ScenarioResult& result) {
64 12 : for (size_t i = 0; i < reporters_.size(); ++i) {
65 6 : reporters_[i]->ReportLatency(result);
66 : }
67 6 : }
68 :
69 0 : void CompositeReporter::ReportTimes(const ScenarioResult& result) {
70 0 : for (size_t i = 0; i < reporters_.size(); ++i) {
71 0 : reporters_[i]->ReportTimes(result);
72 : }
73 0 : }
74 :
75 4 : void GprLogReporter::ReportQPS(const ScenarioResult& result) {
76 : gpr_log(
77 : GPR_INFO, "QPS: %.1f",
78 4 : result.latencies.Count() / average(result.client_resources, WallTime));
79 4 : }
80 :
81 2 : void GprLogReporter::ReportQPSPerCore(const ScenarioResult& result) {
82 : auto qps =
83 2 : result.latencies.Count() / average(result.client_resources, WallTime);
84 :
85 : gpr_log(GPR_INFO, "QPS: %.1f (%.1f/server core)", qps,
86 2 : qps / result.server_config.threads());
87 2 : }
88 :
89 6 : void GprLogReporter::ReportLatency(const ScenarioResult& result) {
90 : gpr_log(GPR_INFO,
91 : "Latencies (50/90/95/99/99.9%%-ile): %.1f/%.1f/%.1f/%.1f/%.1f us",
92 6 : result.latencies.Percentile(50) / 1000,
93 6 : result.latencies.Percentile(90) / 1000,
94 6 : result.latencies.Percentile(95) / 1000,
95 6 : result.latencies.Percentile(99) / 1000,
96 30 : result.latencies.Percentile(99.9) / 1000);
97 6 : }
98 :
99 0 : void GprLogReporter::ReportTimes(const ScenarioResult& result) {
100 : gpr_log(GPR_INFO, "Server system time: %.2f%%",
101 0 : 100.0 * sum(result.server_resources, SystemTime) /
102 0 : sum(result.server_resources, WallTime));
103 : gpr_log(GPR_INFO, "Server user time: %.2f%%",
104 0 : 100.0 * sum(result.server_resources, UserTime) /
105 0 : sum(result.server_resources, WallTime));
106 : gpr_log(GPR_INFO, "Client system time: %.2f%%",
107 0 : 100.0 * sum(result.client_resources, SystemTime) /
108 0 : sum(result.client_resources, WallTime));
109 : gpr_log(GPR_INFO, "Client user time: %.2f%%",
110 0 : 100.0 * sum(result.client_resources, UserTime) /
111 0 : sum(result.client_resources, WallTime));
112 0 : }
113 :
114 0 : void PerfDbReporter::ReportQPS(const ScenarioResult& result) {
115 : auto qps =
116 0 : result.latencies.Count() / average(result.client_resources, WallTime);
117 :
118 0 : perf_db_client_.setQps(qps);
119 0 : perf_db_client_.setConfigs(result.client_config, result.server_config);
120 0 : }
121 :
122 0 : void PerfDbReporter::ReportQPSPerCore(const ScenarioResult& result) {
123 : auto qps =
124 0 : result.latencies.Count() / average(result.client_resources, WallTime);
125 :
126 0 : auto qpsPerCore = qps / result.server_config.threads();
127 :
128 0 : perf_db_client_.setQps(qps);
129 0 : perf_db_client_.setQpsPerCore(qpsPerCore);
130 0 : perf_db_client_.setConfigs(result.client_config, result.server_config);
131 0 : }
132 :
133 0 : void PerfDbReporter::ReportLatency(const ScenarioResult& result) {
134 0 : perf_db_client_.setLatencies(result.latencies.Percentile(50) / 1000,
135 0 : result.latencies.Percentile(90) / 1000,
136 0 : result.latencies.Percentile(95) / 1000,
137 0 : result.latencies.Percentile(99) / 1000,
138 0 : result.latencies.Percentile(99.9) / 1000);
139 0 : perf_db_client_.setConfigs(result.client_config, result.server_config);
140 0 : }
141 :
142 0 : void PerfDbReporter::ReportTimes(const ScenarioResult& result) {
143 0 : const double server_system_time = 100.0 *
144 0 : sum(result.server_resources, SystemTime) /
145 0 : sum(result.server_resources, WallTime);
146 0 : const double server_user_time = 100.0 *
147 0 : sum(result.server_resources, UserTime) /
148 0 : sum(result.server_resources, WallTime);
149 0 : const double client_system_time = 100.0 *
150 0 : sum(result.client_resources, SystemTime) /
151 0 : sum(result.client_resources, WallTime);
152 0 : const double client_user_time = 100.0 *
153 0 : sum(result.client_resources, UserTime) /
154 0 : sum(result.client_resources, WallTime);
155 :
156 : perf_db_client_.setTimes(server_system_time, server_user_time,
157 0 : client_system_time, client_user_time);
158 0 : perf_db_client_.setConfigs(result.client_config, result.server_config);
159 0 : }
160 :
161 0 : void PerfDbReporter::SendData() {
162 : // send data to performance database
163 : bool data_state =
164 0 : perf_db_client_.sendData(hashed_id_, test_name_, sys_info_, tag_);
165 :
166 : // check state of data sending
167 0 : if (data_state) {
168 0 : gpr_log(GPR_INFO, "Data sent to performance database successfully");
169 : } else {
170 0 : gpr_log(GPR_INFO, "Data could not be sent to performance database");
171 : }
172 0 : }
173 :
174 : } // namespace testing
175 18 : } // namespace grpc
|