1/*
2 * hist.h
3 *
4 * Copyright (C) 2009-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 <stdbool.h>
30#include <stdint.h>
31
32#include "cf_mutex.h"
33#include "dynbuf.h"
34
35
36//==========================================================
37// Typedefs & constants.
38//
39
40#define N_BUCKETS (1 + 64)
41#define HISTOGRAM_NAME_SIZE 512
42
43typedef enum {
44 HIST_MILLISECONDS,
45 HIST_MICROSECONDS,
46 HIST_SIZE,
47 HIST_COUNT,
48 HIST_SCALE_MAX_PLUS_1
49} histogram_scale;
50
51#define HIST_TAG_MILLISECONDS "msec"
52#define HIST_TAG_MICROSECONDS "usec"
53#define HIST_TAG_SIZE "bytes"
54#define HIST_TAG_COUNT "count"
55
56// DO NOT access this member data directly - use the API!
57// (Except for cf_hist_track, for which histogram is a base class.)
58typedef struct histogram_s {
59 char name[HISTOGRAM_NAME_SIZE];
60 const char* scale_tag;
61 uint32_t time_div;
62 cf_mutex info_lock;
63 char* info_snapshot;
64 uint64_t counts[N_BUCKETS];
65} histogram;
66
67
68//==========================================================
69// Public API.
70//
71
72histogram *histogram_create(const char *name, histogram_scale scale);
73void histogram_clear(histogram *h);
74void histogram_dump(histogram *h );
75
76uint64_t histogram_insert_data_point(histogram *h, uint64_t start_ns);
77void histogram_insert_raw(histogram *h, uint64_t value);
78void histogram_insert_raw_unsafe(histogram *h, uint64_t value);
79
80void histogram_save_info(histogram *h);
81void histogram_get_info(histogram *h, cf_dyn_buf *db);
82