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 GRPC_TEST_CORE_UTIL_HISTOGRAM_H 20 #define GRPC_TEST_CORE_UTIL_HISTOGRAM_H 21 22 #include <stddef.h> 23 #include <stdint.h> 24 25 #include <grpc/support/port_platform.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 typedef struct grpc_histogram grpc_histogram; 32 33 grpc_histogram* grpc_histogram_create(double resolution, 34 double max_bucket_start); 35 void grpc_histogram_destroy(grpc_histogram* h); 36 void grpc_histogram_add(grpc_histogram* h, double x); 37 38 /// The following merges the second histogram into the first. It only works 39 /// if they have the same buckets and resolution. Returns 0 on failure, 1 40 /// on success 41 int grpc_histogram_merge(grpc_histogram* dst, const grpc_histogram* src); 42 43 double grpc_histogram_percentile(grpc_histogram* histogram, double percentile); 44 double grpc_histogram_mean(grpc_histogram* histogram); 45 double grpc_histogram_stddev(grpc_histogram* histogram); 46 double grpc_histogram_variance(grpc_histogram* histogram); 47 double grpc_histogram_maximum(grpc_histogram* histogram); 48 double grpc_histogram_minimum(grpc_histogram* histogram); 49 double grpc_histogram_count(grpc_histogram* histogram); 50 double grpc_histogram_sum(grpc_histogram* histogram); 51 double grpc_histogram_sum_of_squares(grpc_histogram* histogram); 52 53 const uint32_t* grpc_histogram_get_contents(grpc_histogram* histogram, 54 size_t* count); 55 void grpc_histogram_merge_contents(grpc_histogram* histogram, 56 const uint32_t* data, size_t data_count, 57 double min_seen, double max_seen, double sum, 58 double sum_of_squares, double count); 59 60 #ifdef __cplusplus 61 } 62 #endif 63 64 #endif // GRPC_TEST_CORE_UTIL_HISTOGRAM_H 65