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