cpp/qps/histogram.h
Go to the documentation of this file.
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_HISTOGRAM_H
20 #define TEST_QPS_HISTOGRAM_H
21 
22 #include "src/proto/grpc/testing/stats.pb.h"
24 
25 namespace grpc {
26 namespace testing {
27 
28 class Histogram {
29  public:
30  // TODO(unknown): look into making histogram params not hardcoded for C++
36  }
37  void Reset() {
40  }
41 
42  Histogram(Histogram&& other) noexcept : impl_(other.impl_) {
43  other.impl_ = nullptr;
44  }
45 
46  void Merge(const Histogram& h) { grpc_histogram_merge(impl_, h.impl_); }
47  void Add(double value) { grpc_histogram_add(impl_, value); }
48  double Percentile(double pctile) const {
49  return grpc_histogram_percentile(impl_, pctile);
50  }
51  double Count() const { return grpc_histogram_count(impl_); }
52  void Swap(Histogram* other) { std::swap(impl_, other->impl_); }
53  void FillProto(HistogramData* p) {
54  size_t n;
55  const auto* data = grpc_histogram_get_contents(impl_, &n);
56  for (size_t i = 0; i < n; i++) {
57  p->add_bucket(data[i]);
58  }
59  p->set_min_seen(grpc_histogram_minimum(impl_));
60  p->set_max_seen(grpc_histogram_maximum(impl_));
61  p->set_sum(grpc_histogram_sum(impl_));
62  p->set_sum_of_squares(grpc_histogram_sum_of_squares(impl_));
63  p->set_count(grpc_histogram_count(impl_));
64  }
65  void MergeProto(const HistogramData& p) {
66  grpc_histogram_merge_contents(impl_, &*p.bucket().begin(), p.bucket_size(),
67  p.min_seen(), p.max_seen(), p.sum(),
68  p.sum_of_squares(), p.count());
69  }
70 
71  static double default_resolution() { return 0.01; }
72  static double default_max_possible() { return 60e9; }
73 
74  private:
75  Histogram(const Histogram&);
76  Histogram& operator=(const Histogram&);
77 
79 };
80 } // namespace testing
81 } // namespace grpc
82 
83 #endif /* TEST_QPS_HISTOGRAM_H */
grpc::testing::Histogram::Merge
void Merge(const Histogram &h)
Definition: cpp/qps/histogram.h:46
testing
Definition: aws_request_signer_test.cc:25
grpc_histogram_merge_contents
void grpc_histogram_merge_contents(grpc_histogram *histogram, const uint32_t *data, size_t data_count, double min_seen, double max_seen, double sum, double sum_of_squares, double count)
Definition: histogram.cc:129
grpc
Definition: grpcpp/alarm.h:33
grpc::testing::Histogram::Histogram
Histogram(Histogram &&other) noexcept
Definition: cpp/qps/histogram.h:42
grpc::testing::Histogram::Percentile
double Percentile(double pctile) const
Definition: cpp/qps/histogram.h:48
grpc::testing::Histogram::Count
double Count() const
Definition: cpp/qps/histogram.h:51
grpc::testing::Histogram::impl_
grpc_histogram * impl_
Definition: cpp/qps/histogram.h:78
grpc::testing::Histogram::FillProto
void FillProto(HistogramData *p)
Definition: cpp/qps/histogram.h:53
grpc::testing::Histogram::operator=
Histogram & operator=(const Histogram &)
grpc::testing::Histogram::~Histogram
~Histogram()
Definition: cpp/qps/histogram.h:34
grpc::testing::Histogram::default_resolution
static double default_resolution()
Definition: cpp/qps/histogram.h:71
grpc_histogram_minimum
double grpc_histogram_minimum(grpc_histogram *h)
Definition: histogram.cc:219
grpc::testing::Histogram::Swap
void Swap(Histogram *other)
Definition: cpp/qps/histogram.h:52
grpc_histogram_count
double grpc_histogram_count(grpc_histogram *h)
Definition: histogram.cc:221
grpc_histogram_destroy
void grpc_histogram_destroy(grpc_histogram *h)
Definition: histogram.cc:99
grpc_histogram
Definition: histogram.cc:37
std::swap
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:1226
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
grpc_histogram_percentile
double grpc_histogram_percentile(grpc_histogram *h, double percentile)
Definition: histogram.cc:198
grpc::testing::Histogram::Histogram
Histogram()
Definition: cpp/qps/histogram.h:31
histogram.h
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
grpc_histogram_create
grpc_histogram * grpc_histogram_create(double resolution, double max_bucket_start)
Definition: histogram.cc:77
value
const char * value
Definition: hpack_parser_table.cc:165
grpc::testing::Histogram::Reset
void Reset()
Definition: cpp/qps/histogram.h:37
grpc_histogram_maximum
double grpc_histogram_maximum(grpc_histogram *h)
Definition: histogram.cc:217
grpc::testing::Histogram::Add
void Add(double value)
Definition: cpp/qps/histogram.h:47
grpc_histogram_sum
double grpc_histogram_sum(grpc_histogram *h)
Definition: histogram.cc:223
grpc_histogram_sum_of_squares
double grpc_histogram_sum_of_squares(grpc_histogram *h)
Definition: histogram.cc:225
grpc::testing::Histogram
Definition: cpp/qps/histogram.h:28
grpc_histogram_add
void grpc_histogram_add(grpc_histogram *h, double x)
Definition: histogram.cc:104
grpc_histogram_get_contents
const uint32_t * grpc_histogram_get_contents(grpc_histogram *histogram, size_t *count)
Definition: histogram.cc:229
grpc::testing::Histogram::MergeProto
void MergeProto(const HistogramData &p)
Definition: cpp/qps/histogram.h:65
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
grpc::testing::Histogram::default_max_possible
static double default_max_possible()
Definition: cpp/qps/histogram.h:72
grpc_histogram_merge
int grpc_histogram_merge(grpc_histogram *dst, const grpc_histogram *src)
Definition: histogram.cc:117


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:12