report.h 5.0 KB

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