| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #define PULSE_INTERNALS 1 |
| 4 | #include "pulse-gorilla.h" |
| 5 | |
| 6 | static struct gorilla_statistics { |
| 7 | bool enabled; |
| 8 | |
| 9 | PAD64(uint64_t) tier0_hot_gorilla_buffers; |
| 10 | |
| 11 | PAD64(uint64_t) gorilla_tier0_disk_actual_bytes; |
| 12 | PAD64(uint64_t) gorilla_tier0_disk_optimal_bytes; |
| 13 | PAD64(uint64_t) gorilla_tier0_disk_original_bytes; |
| 14 | } gorilla_statistics = { 0 }; |
| 15 | |
| 16 | void pulse_gorilla_hot_buffer_added() { |
| 17 | if(!gorilla_statistics.enabled) return; |
| 18 | |
| 19 | __atomic_fetch_add(&gorilla_statistics.tier0_hot_gorilla_buffers, 1, __ATOMIC_RELAXED); |
| 20 | } |
| 21 | |
| 22 | void pulse_gorilla_tier0_page_flush(uint32_t actual, uint32_t optimal, uint32_t original) { |
| 23 | if(!gorilla_statistics.enabled) return; |
| 24 | |
| 25 | __atomic_fetch_add(&gorilla_statistics.gorilla_tier0_disk_actual_bytes, actual, __ATOMIC_RELAXED); |
| 26 | __atomic_fetch_add(&gorilla_statistics.gorilla_tier0_disk_optimal_bytes, optimal, __ATOMIC_RELAXED); |
| 27 | __atomic_fetch_add(&gorilla_statistics.gorilla_tier0_disk_original_bytes, original, __ATOMIC_RELAXED); |
| 28 | } |
| 29 | |
| 30 | static inline void global_statistics_copy(struct gorilla_statistics *gs) { |
| 31 | gs->tier0_hot_gorilla_buffers = __atomic_load_n(&gorilla_statistics.tier0_hot_gorilla_buffers, __ATOMIC_RELAXED); |
| 32 | gs->gorilla_tier0_disk_actual_bytes = __atomic_load_n(&gorilla_statistics.gorilla_tier0_disk_actual_bytes, __ATOMIC_RELAXED); |
| 33 | gs->gorilla_tier0_disk_optimal_bytes = __atomic_load_n(&gorilla_statistics.gorilla_tier0_disk_optimal_bytes, __ATOMIC_RELAXED); |
| 34 | gs->gorilla_tier0_disk_original_bytes = __atomic_load_n(&gorilla_statistics.gorilla_tier0_disk_original_bytes, __ATOMIC_RELAXED); |
| 35 | } |
| 36 | |
| 37 | void pulse_gorilla_do(bool extended __maybe_unused) { |
| 38 | #ifdef ENABLE_DBENGINE |
| 39 | if(!extended) return; |
| 40 | gorilla_statistics.enabled = true; |
| 41 | |
| 42 | struct gorilla_statistics gs; |
| 43 | global_statistics_copy(&gs); |
| 44 | |
| 45 | if (tier_page_type[0] == RRDENG_PAGE_TYPE_GORILLA_32BIT) |
| 46 | { |
| 47 | static RRDSET *st_tier0_gorilla_pages = NULL; |
| 48 | static RRDDIM *rd_num_gorilla_pages = NULL; |
| 49 | |
| 50 | if (unlikely(!st_tier0_gorilla_pages)) { |
| 51 | st_tier0_gorilla_pages = rrdset_create_localhost( |
| 52 | "netdata" |
| 53 | , "tier0_gorilla_pages" |
| 54 | , NULL |
| 55 | , "dbengine gorilla" |
| 56 | , NULL |
| 57 | , "Number of gorilla_pages" |
| 58 | , "count" |
| 59 | , "netdata" |
| 60 | , "pulse" |
| 61 | , 131004 |
| 62 | , localhost->rrd_update_every |
| 63 | , RRDSET_TYPE_LINE |
| 64 | ); |
| 65 | |
| 66 | rd_num_gorilla_pages = rrddim_add(st_tier0_gorilla_pages, "count", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 67 | } |
| 68 | |
| 69 | rrddim_set_by_pointer(st_tier0_gorilla_pages, rd_num_gorilla_pages, (collected_number)gs.tier0_hot_gorilla_buffers); |
| 70 | |
| 71 | rrdset_done(st_tier0_gorilla_pages); |
| 72 | } |
| 73 | |
| 74 | if (tier_page_type[0] == RRDENG_PAGE_TYPE_GORILLA_32BIT) |
| 75 | { |
| 76 | static RRDSET *st_tier0_compression_info = NULL; |
| 77 | |
| 78 | static RRDDIM *rd_actual_bytes = NULL; |
| 79 | static RRDDIM *rd_optimal_bytes = NULL; |
| 80 | static RRDDIM *rd_uncompressed_bytes = NULL; |
| 81 | |
| 82 | if (unlikely(!st_tier0_compression_info)) { |
| 83 | st_tier0_compression_info = rrdset_create_localhost( |
| 84 | "netdata" |
| 85 | , "tier0_gorilla_efficiency" |
| 86 | , NULL |
| 87 | , "dbengine gorilla" |
| 88 | , NULL |
| 89 | , "DBENGINE Gorilla Compression Efficiency on Tier 0" |
| 90 | , "bytes" |
| 91 | , "netdata" |
| 92 | , "pulse" |
| 93 | , 131005 |
| 94 | , localhost->rrd_update_every |
| 95 | , RRDSET_TYPE_LINE |
| 96 | ); |
| 97 | |
| 98 | rd_actual_bytes = rrddim_add(st_tier0_compression_info, "actual", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 99 | rd_optimal_bytes = rrddim_add(st_tier0_compression_info, "optimal", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 100 | rd_uncompressed_bytes = rrddim_add(st_tier0_compression_info, "uncompressed", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 101 | } |
| 102 | |
| 103 | rrddim_set_by_pointer(st_tier0_compression_info, rd_actual_bytes, (collected_number)gs.gorilla_tier0_disk_actual_bytes); |
| 104 | rrddim_set_by_pointer(st_tier0_compression_info, rd_optimal_bytes, (collected_number)gs.gorilla_tier0_disk_optimal_bytes); |
| 105 | rrddim_set_by_pointer(st_tier0_compression_info, rd_uncompressed_bytes, (collected_number)gs.gorilla_tier0_disk_original_bytes); |
| 106 | |
| 107 | rrdset_done(st_tier0_compression_info); |
| 108 | } |
| 109 | #endif |
| 110 | } |