diff options
Diffstat (limited to 'test/cpp/util/metrics_server.h')
-rw-r--r-- | test/cpp/util/metrics_server.h | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/test/cpp/util/metrics_server.h b/test/cpp/util/metrics_server.h index ce05e0be64..aa9bfed23d 100644 --- a/test/cpp/util/metrics_server.h +++ b/test/cpp/util/metrics_server.h @@ -48,10 +48,13 @@ * Example: * MetricsServiceImpl metricsImpl; * .. - * // Create Gauge(s). Note: Gauges can be created even after calling + * // Create QpsGauge(s). Note: QpsGauges can be created even after calling * // 'StartServer'. - * Gauge gauge1 = metricsImpl.CreateGauge("foo",is_present); - * // gauge1 can now be used anywhere in the program to set values. + * QpsGauge qps_gauge1 = metricsImpl.CreateQpsGauge("foo", is_present); + * // qps_gauge1 can now be used anywhere in the program by first making a + * // one-time call qps_gauge1.Reset() and then calling qps_gauge1.Incr() + * // every time to increment a query counter + * * ... * // Create the metrics server * std::unique_ptr<grpc::Server> server = metricsImpl.StartServer(port); @@ -60,17 +63,24 @@ namespace grpc { namespace testing { -// TODO(sreek): Add support for other types of Gauges like Double, String in -// future -class Gauge { +class QpsGauge { public: - Gauge(long initial_val); - void Set(long new_val); + QpsGauge(); + + // Initialize the internal timer and reset the query count to 0 + void Reset(); + + // Increment the query count by 1 + void Incr(); + + // Return the current qps (i.e query count divided by the time since this + // QpsGauge object created (or Reset() was called)) long Get(); private: - long val_; - std::mutex val_mu_; + gpr_timespec start_time_; + long num_queries_; + std::mutex num_queries_mu_; }; class MetricsServiceImpl GRPC_FINAL : public MetricsService::Service { @@ -81,17 +91,17 @@ class MetricsServiceImpl GRPC_FINAL : public MetricsService::Service { grpc::Status GetGauge(ServerContext* context, const GaugeRequest* request, GaugeResponse* response) GRPC_OVERRIDE; - // Create a Gauge with name 'name'. is_present is set to true if the Gauge + // Create a QpsGauge with name 'name'. is_present is set to true if the Gauge // is already present in the map. - // NOTE: CreateGauge can be called anytime (i.e before or after calling + // NOTE: CreateQpsGauge can be called anytime (i.e before or after calling // StartServer). - std::shared_ptr<Gauge> CreateGauge(const grpc::string& name, - bool* already_present); + std::shared_ptr<QpsGauge> CreateQpsGauge(const grpc::string& name, + bool* already_present); std::unique_ptr<grpc::Server> StartServer(int port); private: - std::map<string, std::shared_ptr<Gauge>> gauges_; + std::map<string, std::shared_ptr<QpsGauge>> qps_gauges_; std::mutex mu_; }; |