metric.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef DBENGINE_METRIC_H
  2. #define DBENGINE_METRIC_H
  3. #include "../rrd.h"
  4. #define MRG_CACHE_LINE_PADDING(x) uint8_t padding##x[64]
  5. typedef struct metric METRIC;
  6. typedef struct mrg MRG;
  7. typedef struct mrg_entry {
  8. uuid_t uuid;
  9. Word_t section;
  10. time_t first_time_s;
  11. time_t last_time_s;
  12. uint32_t latest_update_every_s;
  13. } MRG_ENTRY;
  14. struct mrg_statistics {
  15. // --- non-atomic --- under a write lock
  16. size_t entries;
  17. size_t size; // total memory used, with indexing
  18. size_t additions;
  19. size_t additions_duplicate;
  20. size_t deletions;
  21. size_t delete_having_retention_or_referenced;
  22. size_t delete_misses;
  23. MRG_CACHE_LINE_PADDING(0);
  24. // --- atomic --- multiple readers / writers
  25. size_t entries_referenced;
  26. MRG_CACHE_LINE_PADDING(1);
  27. size_t entries_with_retention;
  28. MRG_CACHE_LINE_PADDING(2);
  29. size_t current_references;
  30. MRG_CACHE_LINE_PADDING(3);
  31. size_t search_hits;
  32. size_t search_misses;
  33. MRG_CACHE_LINE_PADDING(4);
  34. size_t writers;
  35. size_t writers_conflicts;
  36. };
  37. MRG *mrg_create(ssize_t partitions);
  38. void mrg_destroy(MRG *mrg);
  39. METRIC *mrg_metric_dup(MRG *mrg, METRIC *metric);
  40. bool mrg_metric_release(MRG *mrg, METRIC *metric);
  41. METRIC *mrg_metric_add_and_acquire(MRG *mrg, MRG_ENTRY entry, bool *ret);
  42. METRIC *mrg_metric_get_and_acquire(MRG *mrg, uuid_t *uuid, Word_t section);
  43. bool mrg_metric_release_and_delete(MRG *mrg, METRIC *metric);
  44. Word_t mrg_metric_id(MRG *mrg, METRIC *metric);
  45. uuid_t *mrg_metric_uuid(MRG *mrg, METRIC *metric);
  46. Word_t mrg_metric_section(MRG *mrg, METRIC *metric);
  47. bool mrg_metric_set_first_time_s(MRG *mrg, METRIC *metric, time_t first_time_s);
  48. bool mrg_metric_set_first_time_s_if_bigger(MRG *mrg, METRIC *metric, time_t first_time_s);
  49. time_t mrg_metric_get_first_time_s(MRG *mrg, METRIC *metric);
  50. bool mrg_metric_set_clean_latest_time_s(MRG *mrg, METRIC *metric, time_t latest_time_s);
  51. bool mrg_metric_set_hot_latest_time_s(MRG *mrg, METRIC *metric, time_t latest_time_s);
  52. time_t mrg_metric_get_latest_time_s(MRG *mrg, METRIC *metric);
  53. bool mrg_metric_set_update_every(MRG *mrg, METRIC *metric, time_t update_every_s);
  54. bool mrg_metric_set_update_every_s_if_zero(MRG *mrg, METRIC *metric, time_t update_every_s);
  55. time_t mrg_metric_get_update_every_s(MRG *mrg, METRIC *metric);
  56. void mrg_metric_expand_retention(MRG *mrg, METRIC *metric, time_t first_time_s, time_t last_time_s, time_t update_every_s);
  57. void mrg_metric_get_retention(MRG *mrg, METRIC *metric, time_t *first_time_s, time_t *last_time_s, time_t *update_every_s);
  58. bool mrg_metric_zero_disk_retention(MRG *mrg __maybe_unused, METRIC *metric);
  59. bool mrg_metric_set_writer(MRG *mrg, METRIC *metric);
  60. bool mrg_metric_clear_writer(MRG *mrg, METRIC *metric);
  61. void mrg_get_statistics(MRG *mrg, struct mrg_statistics *s);
  62. size_t mrg_aral_structures(void);
  63. size_t mrg_aral_overhead(void);
  64. void mrg_update_metric_retention_and_granularity_by_uuid(
  65. MRG *mrg, Word_t section, uuid_t *uuid,
  66. time_t first_time_s, time_t last_time_s,
  67. time_t update_every_s, time_t now_s);
  68. #endif // DBENGINE_METRIC_H