summaryrefslogtreecommitdiffstats
path: root/libnetdata/string
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-06 16:11:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-02-06 16:11:30 +0000
commitaa2fe8ccbfcb117efa207d10229eeeac5d0f97c7 (patch)
tree941cbdd387b41c1a81587c20a6df9f0e5e0ff7ab /libnetdata/string
parentAdding upstream version 1.37.1. (diff)
downloadnetdata-aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7.tar.xz
netdata-aa2fe8ccbfcb117efa207d10229eeeac5d0f97c7.zip
Adding upstream version 1.38.0.upstream/1.38.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/string')
-rw-r--r--libnetdata/string/README.md7
-rw-r--r--libnetdata/string/string.c35
2 files changed, 31 insertions, 11 deletions
diff --git a/libnetdata/string/README.md b/libnetdata/string/README.md
index e73ab2696..b1c6e61c3 100644
--- a/libnetdata/string/README.md
+++ b/libnetdata/string/README.md
@@ -1,5 +1,10 @@
<!--
+title: "String"
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/string/README.md
+sidebar_label: "String"
+learn_status: "Published"
+learn_topic_type: "Tasks"
+learn_rel_path: "Developers/libnetdata libraries"
-->
# STRING
@@ -17,4 +22,4 @@ index lookup to find it.
Once there is a `STRING *`, the actual `const char *` can be accessed with `string2str()`.
-All STRING should be constant. Changing the contents of a `const char *` that has been acquired by `string2str()` should never happen. \ No newline at end of file
+All STRING should be constant. Changing the contents of a `const char *` that has been acquired by `string2str()` should never happen.
diff --git a/libnetdata/string/string.c b/libnetdata/string/string.c
index d2db8aab4..4e232523c 100644
--- a/libnetdata/string/string.c
+++ b/libnetdata/string/string.c
@@ -56,14 +56,29 @@ static struct string_hashtable {
#define string_stats_atomic_decrement(var) __atomic_sub_fetch(&string_base.var, 1, __ATOMIC_RELAXED)
void string_statistics(size_t *inserts, size_t *deletes, size_t *searches, size_t *entries, size_t *references, size_t *memory, size_t *duplications, size_t *releases) {
- *inserts = string_base.inserts;
- *deletes = string_base.deletes;
- *searches = string_base.searches;
- *entries = (size_t)string_base.entries;
- *references = (size_t)string_base.active_references;
- *memory = (size_t)string_base.memory;
- *duplications = string_base.duplications;
- *releases = string_base.releases;
+ if(inserts)
+ *inserts = string_base.inserts;
+
+ if(deletes)
+ *deletes = string_base.deletes;
+
+ if(searches)
+ *searches = string_base.searches;
+
+ if(entries)
+ *entries = (size_t)string_base.entries;
+
+ if(references)
+ *references = (size_t)string_base.active_references;
+
+ if(memory)
+ *memory = (size_t)string_base.memory;
+
+ if(duplications)
+ *duplications = string_base.duplications;
+
+ if(releases)
+ *releases = string_base.releases;
}
#define string_entry_acquire(se) __atomic_add_fetch(&((se)->refcount), 1, __ATOMIC_SEQ_CST);
@@ -186,7 +201,7 @@ static inline STRING *string_index_insert(const char *str, size_t length) {
*ptr = string;
string_base.inserts++;
string_base.entries++;
- string_base.memory += (long)mem_size;
+ string_base.memory += (long)(mem_size + JUDYHS_INDEX_SIZE_ESTIMATE(length));
}
else {
// the item is already in the index
@@ -240,7 +255,7 @@ static inline void string_index_delete(STRING *string) {
size_t mem_size = sizeof(STRING) + string->length;
string_base.deletes++;
string_base.entries--;
- string_base.memory -= (long)mem_size;
+ string_base.memory -= (long)(mem_size + JUDYHS_INDEX_SIZE_ESTIMATE(string->length));
freez(string);
}