Debian Codegraph @

test/cpp/qps/report.h

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 #ifndef TEST_QPS_REPORT_H
20 #define TEST_QPS_REPORT_H
21
22 #include <memory>
23 #include <set>
24 #include <vector>
25
26 #include <grpcpp/channel.h>
27 #include <grpcpp/support/config.h>
28
29 #include "src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.h"
30 #include "test/cpp/qps/driver.h"
31
32 namespace grpc {
33 namespace testing {
34
35 /** Interface for all reporters. */
36 class Reporter {
37 public:
38 /** Construct a reporter with the given \a name. */
39 explicit Reporter(const string& name) : name_(name) {}
40
41 virtual ~Reporter() {}
42
43 /** Returns this reporter's name.
44 *
45 * Names are constants, set at construction time. */
46 string name() const { return name_; }
47
48 /** Reports QPS for the given \a result. */
49 virtual void ReportQPS(const ScenarioResult& result) = 0;
50
51 /** Reports QPS per core as (YYY/server core). */
52 virtual void ReportQPSPerCore(const ScenarioResult& result) = 0;
53
54 /** Reports latencies for the 50, 90, 95, 99 and 99.9 percentiles, in ms. */
55 virtual void ReportLatency(const ScenarioResult& result) = 0;
56
57 /** Reports system and user time for client and server systems. */
58 virtual void ReportTimes(const ScenarioResult& result) = 0;
59
60 /** Reports server cpu usage. */
61 virtual void ReportCpuUsage(const ScenarioResult& result) = 0;
62
63 /** Reports client and server poll usage inside completion queue. */
64 virtual void ReportPollCount(const ScenarioResult& result) = 0;
65
66 /** Reports queries per cpu-sec. */
67 virtual void ReportQueriesPerCpuSec(const ScenarioResult& result) = 0;
68
69 private:
70 const string name_;
71 };
72
73 /** A composite for all reporters to be considered. */
74 class CompositeReporter : public Reporter {
75 public:
76 CompositeReporter() : Reporter("CompositeReporter") {}
77
78 /** Adds a \a reporter to the composite. */
79 void add(std::unique_ptr<Reporter> reporter);
80
81 void ReportQPS(const ScenarioResult& result) override;
82 void ReportQPSPerCore(const ScenarioResult& result) override;
83 void ReportLatency(const ScenarioResult& result) override;
84 void ReportTimes(const ScenarioResult& result) override;
85 void ReportCpuUsage(const ScenarioResult& result) override;
86 void ReportPollCount(const ScenarioResult& result) override;
87 void ReportQueriesPerCpuSec(const ScenarioResult& result) override;
88
89 private:
90 std::vector<std::unique_ptr<Reporter> > reporters_;
91 };
92
93 /** Reporter to gpr_log(GPR_INFO). */
94 class GprLogReporter : public Reporter {
95 public:
96 explicit GprLogReporter(const string& name) : Reporter(name) {}
97
98 private:
99 void ReportQPS(const ScenarioResult& result) override;
100 void ReportQPSPerCore(const ScenarioResult& result) override;
101 void ReportLatency(const ScenarioResult& result) override;
102 void ReportTimes(const ScenarioResult& result) override;
103 void ReportCpuUsage(const ScenarioResult& result) override;
104 void ReportPollCount(const ScenarioResult& result) override;
105 void ReportQueriesPerCpuSec(const ScenarioResult& result) override;
106 };
107
108 /** Dumps the report to a JSON file. */
109 class JsonReporter : public Reporter {
110 public:
111 JsonReporter(const string& name, const string& report_file)
112 : Reporter(name), report_file_(report_file) {}
113
114 private:
115 void ReportQPS(const ScenarioResult& result) override;
116 void ReportQPSPerCore(const ScenarioResult& result) override;
117 void ReportLatency(const ScenarioResult& result) override;
118 void ReportTimes(const ScenarioResult& result) override;
119 void ReportCpuUsage(const ScenarioResult& result) override;
120 void ReportPollCount(const ScenarioResult& result) override;
121 void ReportQueriesPerCpuSec(const ScenarioResult& result) override;
122
123 const string report_file_;
124 };
125
126 class RpcReporter : public Reporter {
127 public:
128 RpcReporter(const string& name, const std::shared_ptr<grpc::Channel>& channel)
129 : Reporter(name), stub_(ReportQpsScenarioService::NewStub(channel)) {}
130
131 private:
132 void ReportQPS(const ScenarioResult& result) override;
133 void ReportQPSPerCore(const ScenarioResult& result) override;
134 void ReportLatency(const ScenarioResult& result) override;
135 void ReportTimes(const ScenarioResult& result) override;
136 void ReportCpuUsage(const ScenarioResult& result) override;
137 void ReportPollCount(const ScenarioResult& result) override;
138 void ReportQueriesPerCpuSec(const ScenarioResult& result) override;
139
140 std::unique_ptr<ReportQpsScenarioService::Stub> stub_;
141 };
142
143 } // namespace testing
144 } // namespace grpc
145
146 #endif