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 #include <chrono>
20 #include <iostream>
21
22 // Use the C histogram rather than C++ to avoid depending on proto
23 #include "test/core/util/histogram.h"
24 #include "test/core/util/test_config.h"
25 #include "test/cpp/qps/interarrival.h"
26 #include "test/cpp/util/test_config.h"
27
28 using grpc::testing::InterarrivalTimer;
29 using grpc::testing::RandomDistInterface;
30
RunTest(RandomDistInterface && r,int threads,const std::string & title)31 static void RunTest(RandomDistInterface&& r, int threads,
32 const std::string& title) {
33 InterarrivalTimer timer;
34 timer.init(r, threads);
35 grpc_histogram* h(grpc_histogram_create(0.01, 60e9));
36
37 for (int i = 0; i < 10000000; i++) {
38 for (int j = 0; j < threads; j++) {
39 grpc_histogram_add(h, timer.next(j));
40 }
41 }
42
43 std::cout << title << " Distribution" << std::endl;
44 std::cout << "Value, Percentile" << std::endl;
45 for (double pct = 0.0; pct < 100.0; pct += 1.0) {
46 std::cout << grpc_histogram_percentile(h, pct) << "," << pct << std::endl;
47 }
48
49 grpc_histogram_destroy(h);
50 }
51
52 using grpc::testing::ExpDist;
53
main(int argc,char ** argv)54 int main(int argc, char** argv) {
55 grpc::testing::TestEnvironment env(&argc, argv);
56 grpc::testing::InitTest(&argc, &argv, true);
57
58 RunTest(ExpDist(10.0), 5, std::string("Exponential(10)"));
59 return 0;
60 }
61