diff options
author | David Goulet <dgoulet@torproject.org> | 2023-03-07 09:49:53 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2023-03-07 09:49:53 -0500 |
commit | 3fa08dc9a7041b82fd100d2fc30331c534723e17 (patch) | |
tree | 8150266c064a783d80fa35becf074c138f3df2df /src/lib | |
parent | 85f5318f7fd2e376272daad264da2cb79c6837be (diff) | |
parent | 16c6788fbc30cf0a2611dd021d1797931a53a86d (diff) | |
download | tor-3fa08dc9a7041b82fd100d2fc30331c534723e17.tar.gz tor-3fa08dc9a7041b82fd100d2fc30331c534723e17.zip |
Merge branch 'tor-gitlab/mr/697'
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/metrics/metrics_store_entry.c | 20 | ||||
-rw-r--r-- | src/lib/metrics/metrics_store_entry.h | 3 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/metrics/metrics_store_entry.c b/src/lib/metrics/metrics_store_entry.c index 482ec8d7d9..971d9379bd 100644 --- a/src/lib/metrics/metrics_store_entry.c +++ b/src/lib/metrics/metrics_store_entry.c @@ -127,3 +127,23 @@ metrics_store_entry_has_label(const metrics_store_entry_t *entry, return smartlist_contains_string(entry->labels, label); } + +/** Return the first entry that has the given label, or NULL if none + * of the entries have the label. */ +metrics_store_entry_t * +metrics_store_find_entry_with_label(const smartlist_t *entries, + const char *label) +{ + tor_assert(entries); + tor_assert(label); + + SMARTLIST_FOREACH_BEGIN(entries, metrics_store_entry_t *, entry) { + tor_assert(entry); + + if (smartlist_contains_string(entry->labels, label)) { + return entry; + } + } SMARTLIST_FOREACH_END(entry); + + return NULL; +} diff --git a/src/lib/metrics/metrics_store_entry.h b/src/lib/metrics/metrics_store_entry.h index e4dc7a8b9a..0e09e099fe 100644 --- a/src/lib/metrics/metrics_store_entry.h +++ b/src/lib/metrics/metrics_store_entry.h @@ -12,6 +12,7 @@ #include "lib/cc/torint.h" #include "lib/metrics/metrics_common.h" +#include "lib/container/smartlist.h" #ifdef METRICS_STORE_ENTRY_PRIVATE @@ -57,6 +58,8 @@ void metrics_store_entry_free_(metrics_store_entry_t *entry); int64_t metrics_store_entry_get_value(const metrics_store_entry_t *entry); bool metrics_store_entry_has_label(const metrics_store_entry_t *entry, const char *label); +metrics_store_entry_t *metrics_store_find_entry_with_label( + const smartlist_t *entries, const char *label); /* Modifiers. */ void metrics_store_entry_add_label(metrics_store_entry_t *entry, |