feat: add NullCollector

mem-usage
Jef Roosens 2022-12-26 14:32:19 +01:00
parent ab065681aa
commit 7f6327b01a
2 changed files with 31 additions and 5 deletions

View File

@ -44,7 +44,7 @@ pub fn (mut c DefaultCollector) counter_register(value u64, metric Metric) {
} }
} }
pub fn (mut c DefaultCollector) counter_increment(metric Metric) { pub fn (c &DefaultCollector) counter_increment(metric Metric) {
rlock c.counters { rlock c.counters {
entry := c.counter_indexes[metric.str()] entry := c.counter_indexes[metric.str()]
@ -52,7 +52,7 @@ pub fn (mut c DefaultCollector) counter_increment(metric Metric) {
} }
} }
pub fn (mut c DefaultCollector) counter_decrement(metric Metric) { pub fn (c &DefaultCollector) counter_decrement(metric Metric) {
rlock c.counters { rlock c.counters {
entry := c.counter_indexes[metric.str()] entry := c.counter_indexes[metric.str()]
@ -60,7 +60,7 @@ pub fn (mut c DefaultCollector) counter_decrement(metric Metric) {
} }
} }
pub fn (mut c DefaultCollector) counter_get(metric Metric) ?u64 { pub fn (c &DefaultCollector) counter_get(metric Metric) ?u64 {
return rlock c.counters { return rlock c.counters {
entry := c.counter_indexes[metric.str()] or { return none } entry := c.counter_indexes[metric.str()] or { return none }
@ -77,7 +77,7 @@ pub fn (mut c DefaultCollector) histogram_register(metric Metric) {
} }
} }
pub fn (mut c DefaultCollector) histogram_add(value f64, metric Metric) { pub fn (c &DefaultCollector) histogram_add(value f64, metric Metric) {
entry := rlock c.histograms { entry := rlock c.histograms {
c.histograms[metric.str()] c.histograms[metric.str()]
} }
@ -87,7 +87,7 @@ pub fn (mut c DefaultCollector) histogram_add(value f64, metric Metric) {
} }
} }
pub fn (mut c DefaultCollector) histogram_get(metric Metric) ?[]f64 { pub fn (c &DefaultCollector) histogram_get(metric Metric) ?[]f64 {
entry := rlock c.histograms { entry := rlock c.histograms {
c.histograms[metric.str()] or { return none } c.histograms[metric.str()] or { return none }
} }

26
null.v 100644
View File

@ -0,0 +1,26 @@
module metrics
[heap]
struct NullCollector {}
pub fn new_null_collector() &NullCollector {
return &NullCollector{}
}
pub fn (c &NullCollector) counter_register(value u64, metric Metric) {}
pub fn (c &NullCollector) counter_increment(metric Metric) {}
pub fn (c &NullCollector) counter_decrement(metric Metric) {}
pub fn (c &NullCollector) counter_get(metric Metric) ?u64 {
return none
}
pub fn (c &NullCollector) histogram_register(metric Metric) {}
pub fn (c &NullCollector) histogram_add(value f64, metric Metric) {}
pub fn (c &NullCollector) histogram_get(metric Metric) ?[]f64 {
return none
}