38 lines
887 B
C
38 lines
887 B
C
#include "metrics.h"
|
|
#include "exceptions.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <inttypes.h>
|
|
|
|
CEXCEPTION_T e;
|
|
|
|
static uint64_t hash_string(const char *name) {
|
|
uint64_t hash = 5381;
|
|
int c;
|
|
while ((c = *name++)) {
|
|
hash = ((hash << 5) + hash) + c;
|
|
}
|
|
return hash;
|
|
}
|
|
|
|
int main(void) {
|
|
Try {
|
|
METRICS_INIT_DEFAULT_REGISTRY();
|
|
for (int i = 0; i < 100; i++) {
|
|
char name[20];
|
|
sprintf(name, "test_metric_%d", i);
|
|
uint64_t hash = hash_string(name) % 256;
|
|
METRICS_HISTOGRAM_UPDATE("hash_string", hash);
|
|
printf("Hashed String: %s -> %" PRIu64 "\n", name, hash);
|
|
}
|
|
|
|
METRICS_Histogram h = METRICS_HISTOGRAM_VALUE("hash_string");
|
|
printf("Histogram: min=%lu, max=%lu, count=%lu, mean=%f\n", h.min, h.max, h.count, h.mean);
|
|
|
|
} Catch(e) {
|
|
printf("exception %i occurred\n", e);
|
|
}
|
|
METRICS_DESTROY_DEFAULT_REGISTRY();
|
|
}
|