3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 // Use the C histogram rather than C++ to avoid depending on proto
23 #include "test/core/util/histogram.h"
25 #include "test/core/util/test_config.h"
26 #include "test/cpp/qps/interarrival.h"
27 #include "test/cpp/util/test_config.h"
29 using grpc::testing::InterarrivalTimer;
30 using grpc::testing::RandomDistInterface;
32 static void RunTest(RandomDistInterface&& r, int threads,
33 const std::string& title) {
34 InterarrivalTimer timer;
35 timer.init(r, threads);
36 grpc_histogram* h(grpc_histogram_create(0.01, 60e9));
38 for (int i = 0; i < 10000000; i++) {
39 for (int j = 0; j < threads; j++) {
40 grpc_histogram_add(h, timer.next(j));
44 std::cout << title << " Distribution" << std::endl;
45 std::cout << "Value, Percentile" << std::endl;
46 for (double pct = 0.0; pct < 100.0; pct += 1.0) {
47 std::cout << grpc_histogram_percentile(h, pct) << "," << pct << std::endl;
50 grpc_histogram_destroy(h);
53 using grpc::testing::ExpDist;
55 int main(int argc, char** argv) {
56 grpc::testing::TestEnvironment env(argc, argv);
57 grpc::testing::InitTest(&argc, &argv, true);
59 RunTest(ExpDist(10.0), 5, std::string("Exponential(10)"));