1 | /* |
2 | * linear_hist.h |
3 | * |
4 | * Copyright (C) 2016 Aerospike, Inc. |
5 | * |
6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
7 | * license agreements. |
8 | * |
9 | * This program is free software: you can redistribute it and/or modify it under |
10 | * the terms of the GNU Affero General Public License as published by the Free |
11 | * Software Foundation, either version 3 of the License, or (at your option) any |
12 | * later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
17 | * details. |
18 | * |
19 | * You should have received a copy of the GNU Affero General Public License |
20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
21 | */ |
22 | |
23 | #pragma once |
24 | |
25 | //========================================================== |
26 | // Includes. |
27 | // |
28 | |
29 | #include <stdint.h> |
30 | |
31 | #include "dynbuf.h" |
32 | |
33 | |
34 | //========================================================== |
35 | // Typedefs & constants. |
36 | // |
37 | |
38 | typedef struct linear_hist_s linear_hist; |
39 | |
40 | typedef enum { |
41 | LINEAR_HIST_SECONDS, |
42 | LINEAR_HIST_SIZE, |
43 | LINEAR_HIST_SCALE_MAX_PLUS_1 |
44 | } linear_hist_scale; |
45 | |
46 | typedef struct linear_hist_threshold_s { |
47 | uint32_t value; |
48 | uint32_t bucket_index; |
49 | uint32_t bucket_width; |
50 | uint64_t bucket_count; |
51 | uint64_t target_count; |
52 | } linear_hist_threshold; |
53 | |
54 | |
55 | //========================================================== |
56 | // Public API. |
57 | // |
58 | |
59 | // These must all be called from the same thread! |
60 | |
61 | linear_hist *linear_hist_create(const char *name, linear_hist_scale scale, uint32_t start, uint32_t max_offset, uint32_t num_buckets); |
62 | void linear_hist_destroy(linear_hist *h); |
63 | void linear_hist_reset(linear_hist *h, uint32_t start, uint32_t max_offset, uint32_t num_buckets); |
64 | void linear_hist_clear(linear_hist *h, uint32_t start, uint32_t max_offset); |
65 | |
66 | uint64_t linear_hist_get_total(linear_hist *h); |
67 | void linear_hist_merge(linear_hist *h1, linear_hist *h2); |
68 | void linear_hist_insert_data_point(linear_hist *h, uint32_t point); |
69 | uint64_t linear_hist_get_threshold_for_fraction(linear_hist *h, uint32_t tenths_pct, linear_hist_threshold *p_threshold); |
70 | uint64_t linear_hist_get_threshold_for_subtotal(linear_hist *h, uint64_t subtotal, linear_hist_threshold *p_threshold); |
71 | |
72 | void linear_hist_dump(linear_hist *h); |
73 | void linear_hist_save_info(linear_hist *h); |
74 | |
75 | // This call is thread-safe. |
76 | void linear_hist_get_info(linear_hist *h, cf_dyn_buf *db); |
77 | |