summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/libnetdata.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnetdata/libnetdata.h')
-rw-r--r--src/libnetdata/libnetdata.h327
1 files changed, 3 insertions, 324 deletions
diff --git a/src/libnetdata/libnetdata.h b/src/libnetdata/libnetdata.h
index 4bade9b5bb..effb4f8e28 100644
--- a/src/libnetdata/libnetdata.h
+++ b/src/libnetdata/libnetdata.h
@@ -246,256 +246,8 @@ size_t judy_aral_structures(void);
#define GUID_LEN 36
-// ---------------------------------------------------------------------------------------------
-// double linked list management
-// inspired by https://github.com/troydhanson/uthash/blob/master/src/utlist.h
-
-#define DOUBLE_LINKED_LIST_PREPEND_ITEM_UNSAFE(head, item, prev, next) \
- do { \
- (item)->next = (head); \
- \
- if(likely(head)) { \
- (item)->prev = (head)->prev; \
- (head)->prev = (item); \
- } \
- else \
- (item)->prev = (item); \
- \
- (head) = (item); \
- } while (0)
-
-#define DOUBLE_LINKED_LIST_APPEND_ITEM_UNSAFE(head, item, prev, next) \
- do { \
- \
- (item)->next = NULL; \
- \
- if(likely(head)) { \
- (item)->prev = (head)->prev; \
- (head)->prev->next = (item); \
- (head)->prev = (item); \
- } \
- else { \
- (item)->prev = (item); \
- (head) = (item); \
- } \
- \
- } while (0)
-
-#define DOUBLE_LINKED_LIST_REMOVE_ITEM_UNSAFE(head, item, prev, next) \
- do { \
- fatal_assert((head) != NULL); \
- fatal_assert((item)->prev != NULL); \
- \
- if((item)->prev == (item)) \
- /* it is the only item in the list */ \
- (head) = NULL; \
- \
- else if((item) == (head)) { \
- /* it is the first item */ \
- fatal_assert((item)->next != NULL); \
- (item)->next->prev = (item)->prev; \
- (head) = (item)->next; \
- } \
- else { \
- /* it is any other item */ \
- (item)->prev->next = (item)->next; \
- \
- if ((item)->next) \
- (item)->next->prev = (item)->prev; \
- else \
- (head)->prev = (item)->prev; \
- } \
- \
- (item)->next = NULL; \
- (item)->prev = NULL; \
- } while (0)
-
-#define DOUBLE_LINKED_LIST_INSERT_ITEM_BEFORE_UNSAFE(head, existing, item, prev, next) \
- do { \
- if (existing) { \
- fatal_assert((head) != NULL); \
- fatal_assert((item) != NULL); \
- \
- (item)->next = (existing); \
- (item)->prev = (existing)->prev; \
- (existing)->prev = (item); \
- \
- if ((head) == (existing)) \
- (head) = (item); \
- else \
- (item)->prev->next = (item); \
- \
- } \
- else \
- DOUBLE_LINKED_LIST_APPEND_ITEM_UNSAFE(head, item, prev, next); \
- \
- } while (0)
-
-#define DOUBLE_LINKED_LIST_INSERT_ITEM_AFTER_UNSAFE(head, existing, item, prev, next) \
- do { \
- if (existing) { \
- fatal_assert((head) != NULL); \
- fatal_assert((item) != NULL); \
- \
- (item)->next = (existing)->next; \
- (item)->prev = (existing); \
- (existing)->next = (item); \
- \
- if ((item)->next) \
- (item)->next->prev = (item); \
- else \
- (head)->prev = (item); \
- } \
- else \
- DOUBLE_LINKED_LIST_PREPEND_ITEM_UNSAFE(head, item, prev, next); \
- \
- } while (0)
-
-#define DOUBLE_LINKED_LIST_APPEND_LIST_UNSAFE(head, head2, prev, next) \
- do { \
- if (head2) { \
- if (head) { \
- __typeof(head2) _head2_last_item = (head2)->prev; \
- \
- (head2)->prev = (head)->prev; \
- (head)->prev->next = (head2); \
- \
- (head)->prev = _head2_last_item; \
- } \
- else \
- (head) = (head2); \
- } \
- } while (0)
-
-#define DOUBLE_LINKED_LIST_FOREACH_FORWARD(head, var, prev, next) \
- for ((var) = (head); (var) ; (var) = (var)->next)
-
-#define DOUBLE_LINKED_LIST_FOREACH_BACKWARD(head, var, prev, next) \
- for ((var) = (head) ? (head)->prev : NULL ; (var) ; (var) = ((var) == (head)) ? NULL : (var)->prev)
-
-// ---------------------------------------------------------------------------------------------
-
-#include "storage_number/storage_number.h"
-
-typedef struct storage_point {
- NETDATA_DOUBLE min; // when count > 1, this is the minimum among them
- NETDATA_DOUBLE max; // when count > 1, this is the maximum among them
- NETDATA_DOUBLE sum; // the point sum - divided by count gives the average
-
- // end_time - start_time = point duration
- time_t start_time_s; // the time the point starts
- time_t end_time_s; // the time the point ends
-
- uint32_t count; // the number of original points aggregated
- uint32_t anomaly_count; // the number of original points found anomalous
-
- SN_FLAGS flags; // flags stored with the point
-} STORAGE_POINT;
-
-#define storage_point_unset(x) do { \
- (x).min = (x).max = (x).sum = NAN; \
- (x).count = 0; \
- (x).anomaly_count = 0; \
- (x).flags = SN_FLAG_NONE; \
- (x).start_time_s = 0; \
- (x).end_time_s = 0; \
- } while(0)
-
-#define storage_point_empty(x, start_s, end_s) do { \
- (x).min = (x).max = (x).sum = NAN; \
- (x).count = 1; \
- (x).anomaly_count = 0; \
- (x).flags = SN_FLAG_NONE; \
- (x).start_time_s = start_s; \
- (x).end_time_s = end_s; \
- } while(0)
-
-#define STORAGE_POINT_UNSET (STORAGE_POINT){ .min = NAN, .max = NAN, .sum = NAN, .count = 0, .anomaly_count = 0, .flags = SN_FLAG_NONE, .start_time_s = 0, .end_time_s = 0 }
-
-#define storage_point_is_unset(x) (!(x).count)
-#define storage_point_is_gap(x) (!netdata_double_isnumber((x).sum))
-#define storage_point_is_zero(x) (!(x).count || (netdata_double_is_zero((x).min) && netdata_double_is_zero((x).max) && netdata_double_is_zero((x).sum) && (x).anomaly_count == 0))
-
-#define storage_point_merge_to(dst, src) do { \
- if(storage_point_is_unset(dst)) \
- (dst) = (src); \
- \
- else if(!storage_point_is_unset(src) && \
- !storage_point_is_gap(src)) { \
- \
- if((src).start_time_s < (dst).start_time_s) \
- (dst).start_time_s = (src).start_time_s;\
- \
- if((src).end_time_s > (dst).end_time_s) \
- (dst).end_time_s = (src).end_time_s; \
- \
- if((src).min < (dst).min) \
- (dst).min = (src).min; \
- \
- if((src).max > (dst).max) \
- (dst).max = (src).max; \
- \
- (dst).sum += (src).sum; \
- \
- (dst).count += (src).count; \
- (dst).anomaly_count += (src).anomaly_count; \
- \
- (dst).flags |= (src).flags & SN_FLAG_RESET; \
- } \
-} while(0)
-
-#define storage_point_add_to(dst, src) do { \
- if(storage_point_is_unset(dst)) \
- (dst) = (src); \
- \
- else if(!storage_point_is_unset(src) && \
- !storage_point_is_gap(src)) { \
- \
- if((src).start_time_s < (dst).start_time_s) \
- (dst).start_time_s = (src).start_time_s;\
- \
- if((src).end_time_s > (dst).end_time_s) \
- (dst).end_time_s = (src).end_time_s; \
- \
- (dst).min += (src).min; \
- (dst).max += (src).max; \
- (dst).sum += (src).sum; \
- \
- (dst).count += (src).count; \
- (dst).anomaly_count += (src).anomaly_count; \
- \
- (dst).flags |= (src).flags & SN_FLAG_RESET; \
- } \
-} while(0)
-
-#define storage_point_make_positive(sp) do { \
- if(!storage_point_is_unset(sp) && \
- !storage_point_is_gap(sp)) { \
- \
- if(unlikely(signbit((sp).sum))) \
- (sp).sum = -(sp).sum; \
- \
- if(unlikely(signbit((sp).min))) \
- (sp).min = -(sp).min; \
- \
- if(unlikely(signbit((sp).max))) \
- (sp).max = -(sp).max; \
- \
- if(unlikely((sp).min > (sp).max)) { \
- NETDATA_DOUBLE t = (sp).min; \
- (sp).min = (sp).max; \
- (sp).max = t; \
- } \
- } \
-} while(0)
-
-#define storage_point_anomaly_rate(sp) \
- (NETDATA_DOUBLE)(storage_point_is_unset(sp) ? 0.0 : (NETDATA_DOUBLE)((sp).anomaly_count) * 100.0 / (NETDATA_DOUBLE)((sp).count))
-
-#define storage_point_average_value(sp) \
- ((sp).count ? (sp).sum / (NETDATA_DOUBLE)((sp).count) : 0.0)
-
-// ---------------------------------------------------------------------------------------------
+#include "linked-lists.h"
+#include "storage-point.h"
void netdata_fix_chart_id(char *s);
void netdata_fix_chart_name(char *s);
@@ -600,80 +352,7 @@ char *find_and_replace(const char *src, const char *find, const char *replace, c
// Taken from linux kernel
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
-#ifdef ENV32BIT
-
-typedef struct bitmapX {
- uint32_t bits;
- uint32_t data[];
-} BITMAPX;
-
-typedef struct bitmap256 {
- uint32_t bits;
- uint32_t data[256 / 32];
-} BITMAP256;
-
-typedef struct bitmap1024 {
- uint32_t bits;
- uint32_t data[1024 / 32];
-} BITMAP1024;
-
-static inline BITMAPX *bitmapX_create(uint32_t bits) {
- BITMAPX *bmp = (BITMAPX *)callocz(1, sizeof(BITMAPX) + sizeof(uint32_t) * ((bits + 31) / 32));
- uint32_t *p = (uint32_t *)&bmp->bits;
- *p = bits;
- return bmp;
-}
-
-#define bitmapX_get_bit(ptr, idx) ((ptr)->data[(idx) >> 5] & (1U << ((idx) & 31)))
-#define bitmapX_set_bit(ptr, idx, value) do { \
- register uint32_t _bitmask = 1U << ((idx) & 31); \
- if (value) \
- (ptr)->data[(idx) >> 5] |= _bitmask; \
- else \
- (ptr)->data[(idx) >> 5] &= ~_bitmask; \
-} while(0)
-
-#else // 64bit version of bitmaps
-
-typedef struct bitmapX {
- uint32_t bits;
- uint64_t data[];
-} BITMAPX;
-
-typedef struct bitmap256 {
- uint32_t bits;
- uint64_t data[256 / 64];
-} BITMAP256;
-
-typedef struct bitmap1024 {
- uint32_t bits;
- uint64_t data[1024 / 64];
-} BITMAP1024;
-
-static inline BITMAPX *bitmapX_create(uint32_t bits) {
- BITMAPX *bmp = (BITMAPX *)callocz(1, sizeof(BITMAPX) + sizeof(uint64_t) * ((bits + 63) / 64));
- bmp->bits = bits;
- return bmp;
-}
-
-#define bitmapX_get_bit(ptr, idx) ((ptr)->data[(idx) >> 6] & (1ULL << ((idx) & 63)))
-#define bitmapX_set_bit(ptr, idx, value) do { \
- register uint64_t _bitmask = 1ULL << ((idx) & 63); \
- if (value) \
- (ptr)->data[(idx) >> 6] |= _bitmask; \
- else \
- (ptr)->data[(idx) >> 6] &= ~_bitmask; \
-} while(0)
-
-#endif // 64bit version of bitmaps
-
-#define BITMAPX_INITIALIZER(wanted_bits) { .bits = (wanted_bits), .data = {0} }
-#define BITMAP256_INITIALIZER (BITMAP256)BITMAPX_INITIALIZER(256)
-#define BITMAP1024_INITIALIZER (BITMAP1024)BITMAPX_INITIALIZER(1024)
-#define bitmap256_get_bit(ptr, idx) bitmapX_get_bit((BITMAPX *)ptr, idx)
-#define bitmap256_set_bit(ptr, idx, value) bitmapX_set_bit((BITMAPX *)ptr, idx, value)
-#define bitmap1024_get_bit(ptr, idx) bitmapX_get_bit((BITMAPX *)ptr, idx)
-#define bitmap1024_set_bit(ptr, idx, value) bitmapX_set_bit((BITMAPX *)ptr, idx, value)
+#include "bitmap.h"
#define COMPRESSION_MAX_CHUNK 0x4000
#define COMPRESSION_MAX_OVERHEAD 128