Tor 0.4.9.0-alpha-dev
metrics_store_entry.h
Go to the documentation of this file.
1/* Copyright (c) 2020-2021, The Tor Project, Inc. */
2/* See LICENSE for licensing information */
3
4/**
5 * @file metrics_store_entry.h
6 * @brief Header for lib/metrics/metrics_store_entry.c
7 **/
8
9#ifndef TOR_LIB_METRICS_METRICS_STORE_ENTRY_H
10#define TOR_LIB_METRICS_METRICS_STORE_ENTRY_H
11
12#include "lib/cc/torint.h"
13
16
17#ifdef METRICS_STORE_ENTRY_PRIVATE
18
19/** Metrics store entry. They reside in a metrics_store_t object and are
20 * opaque to the outside world. */
21struct metrics_store_entry_t {
22 /** Type of entry. */
23 metrics_type_t type;
24
25 /** Name. */
26 char *name;
27
28 /** Help comment string. */
29 char *help;
30
31 /** Labels attached to that entry. If NULL, no labels.
32 *
33 * Labels are used to add extra context to a metrics. For example, a label
34 * could be an onion address so the metrics can be differentiate. */
35 smartlist_t *labels;
36
37 /* Actual data. */
38 union {
39 metrics_counter_t counter;
40 metrics_gauge_t gauge;
41 metrics_histogram_t histogram;
42 } u;
43};
44
45#endif /* defined(METRICS_STORE_ENTRY_PRIVATE) */
46
47typedef struct metrics_store_entry_t metrics_store_entry_t;
48
49/* Allocators. */
50metrics_store_entry_t *metrics_store_entry_new(const metrics_type_t type,
51 const char *name,
52 const char *help,
53 size_t bucket_count,
54 const int64_t *buckets);
55
56void metrics_store_entry_free_(metrics_store_entry_t *entry);
57#define metrics_store_entry_free(entry) \
58 FREE_AND_NULL(metrics_store_entry_t, metrics_store_entry_free_, (entry));
59
60/* Accessors. */
61int64_t metrics_store_entry_get_value(const metrics_store_entry_t *entry);
62uint64_t metrics_store_hist_entry_get_value(const metrics_store_entry_t *entry,
63 const int64_t bucket);
64bool metrics_store_entry_has_label(const metrics_store_entry_t *entry,
65 const char *label);
66metrics_store_entry_t *metrics_store_find_entry_with_label(
67 const smartlist_t *entries, const char *label);
68bool metrics_store_entry_is_histogram(const metrics_store_entry_t *entry);
70 const metrics_store_entry_t *entry);
71int64_t metrics_store_hist_entry_get_sum(const metrics_store_entry_t *entry);
72
73/* Modifiers. */
74void metrics_store_entry_add_label(metrics_store_entry_t *entry,
75 const char *label);
76void metrics_store_entry_reset(metrics_store_entry_t *entry);
77void metrics_store_entry_update(metrics_store_entry_t *entry,
78 const int64_t value);
79void metrics_store_hist_entry_update(metrics_store_entry_t *entry,
80 const int64_t value, const int64_t obs);
81
82#endif /* !defined(TOR_LIB_METRICS_METRICS_STORE_ENTRY_H) */
const char * name
Definition: config.c:2462
Header for lib/metrics/metrics_common.c.
metrics_type_t
uint64_t metrics_store_hist_entry_get_count(const metrics_store_entry_t *entry)
void metrics_store_entry_update(metrics_store_entry_t *entry, const int64_t value)
bool metrics_store_entry_is_histogram(const metrics_store_entry_t *entry)
uint64_t metrics_store_hist_entry_get_value(const metrics_store_entry_t *entry, const int64_t bucket)
void metrics_store_entry_add_label(metrics_store_entry_t *entry, const char *label)
int64_t metrics_store_hist_entry_get_sum(const metrics_store_entry_t *entry)
metrics_store_entry_t * metrics_store_entry_new(const metrics_type_t type, const char *name, const char *help, size_t bucket_count, const int64_t *buckets)
metrics_store_entry_t * metrics_store_find_entry_with_label(const smartlist_t *entries, const char *label)
void metrics_store_entry_free_(metrics_store_entry_t *entry)
void metrics_store_hist_entry_update(metrics_store_entry_t *entry, const int64_t value, const int64_t obs)
int64_t metrics_store_entry_get_value(const metrics_store_entry_t *entry)
void metrics_store_entry_reset(metrics_store_entry_t *entry)
bool metrics_store_entry_has_label(const metrics_store_entry_t *entry, const char *label)
Header for smartlist.c.
Integer definitions used throughout Tor.