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 : #ifndef TEST_QPS_REPORT_H
35 : #define TEST_QPS_REPORT_H
36 :
37 : #include <memory>
38 : #include <set>
39 : #include <vector>
40 :
41 : #include <grpc++/support/config.h>
42 :
43 : #include "test/cpp/qps/driver.h"
44 : #include "test/cpp/qps/qpstest.grpc.pb.h"
45 : #include "test/cpp/qps/perf_db_client.h"
46 :
47 : namespace grpc {
48 : namespace testing {
49 :
50 : /** Interface for all reporters. */
51 : class Reporter {
52 : public:
53 : /** Construct a reporter with the given \a name. */
54 12 : Reporter(const string& name) : name_(name) {}
55 :
56 12 : virtual ~Reporter() {}
57 :
58 : /** Returns this reporter's name.
59 : *
60 : * Names are constants, set at construction time. */
61 : string name() const { return name_; }
62 :
63 : /** Reports QPS for the given \a result. */
64 : virtual void ReportQPS(const ScenarioResult& result) = 0;
65 :
66 : /** Reports QPS per core as (YYY/server core). */
67 : virtual void ReportQPSPerCore(const ScenarioResult& result) = 0;
68 :
69 : /** Reports latencies for the 50, 90, 95, 99 and 99.9 percentiles, in ms. */
70 : virtual void ReportLatency(const ScenarioResult& result) = 0;
71 :
72 : /** Reports system and user time for client and server systems. */
73 : virtual void ReportTimes(const ScenarioResult& result) = 0;
74 :
75 : private:
76 : const string name_;
77 : };
78 :
79 : /** A composite for all reporters to be considered. */
80 12 : class CompositeReporter : public Reporter {
81 : public:
82 6 : CompositeReporter() : Reporter("CompositeReporter") {}
83 :
84 : /** Adds a \a reporter to the composite. */
85 : void add(std::unique_ptr<Reporter> reporter);
86 :
87 : void ReportQPS(const ScenarioResult& result) GRPC_OVERRIDE;
88 : void ReportQPSPerCore(const ScenarioResult& result) GRPC_OVERRIDE;
89 : void ReportLatency(const ScenarioResult& result) GRPC_OVERRIDE;
90 : void ReportTimes(const ScenarioResult& result) GRPC_OVERRIDE;
91 :
92 : private:
93 : std::vector<std::unique_ptr<Reporter> > reporters_;
94 : };
95 :
96 : /** Reporter to gpr_log(GPR_INFO). */
97 12 : class GprLogReporter : public Reporter {
98 : public:
99 6 : GprLogReporter(const string& name) : Reporter(name) {}
100 :
101 : private:
102 : void ReportQPS(const ScenarioResult& result) GRPC_OVERRIDE;
103 : void ReportQPSPerCore(const ScenarioResult& result) GRPC_OVERRIDE;
104 : void ReportLatency(const ScenarioResult& result) GRPC_OVERRIDE;
105 : void ReportTimes(const ScenarioResult& result) GRPC_OVERRIDE;
106 : };
107 :
108 : /** Reporter for performance database tool */
109 : class PerfDbReporter : public Reporter {
110 : public:
111 0 : PerfDbReporter(const string& name, const string& hashed_id,
112 : const string& test_name, const string& sys_info,
113 : const string& server_address, const string& tag)
114 : : Reporter(name),
115 : hashed_id_(hashed_id),
116 : test_name_(test_name),
117 : sys_info_(sys_info),
118 0 : tag_(tag) {
119 : perf_db_client_.init(
120 0 : grpc::CreateChannel(server_address, grpc::InsecureCredentials()));
121 0 : }
122 0 : ~PerfDbReporter() GRPC_OVERRIDE { SendData(); };
123 :
124 : private:
125 : PerfDbClient perf_db_client_;
126 : std::string hashed_id_;
127 : std::string test_name_;
128 : std::string sys_info_;
129 : std::string tag_;
130 : void ReportQPS(const ScenarioResult& result) GRPC_OVERRIDE;
131 : void ReportQPSPerCore(const ScenarioResult& result) GRPC_OVERRIDE;
132 : void ReportLatency(const ScenarioResult& result) GRPC_OVERRIDE;
133 : void ReportTimes(const ScenarioResult& result) GRPC_OVERRIDE;
134 : void SendData();
135 : };
136 :
137 : } // namespace testing
138 : } // namespace grpc
139 :
140 : #endif
|