disabled dictionary statistics to save memory
Costa Tsaousis (ktsaou) committed
May 19, 2016 at 23:39 UTC
cc2bd3d0774ab38ffb6a31bd2cf571132234668c
2 files changed
+21
-5
src/dictionary.c
+5
-5
@@ -46,15 +46,15 @@ static int name_value_compare(void* a, void* b) {
46
else return strcmp(((NAME_VALUE *)a)->name, ((NAME_VALUE *)b)->name);
47
}
48
49
-#define dictionary_name_value_index_add_nolock(dict, nv) do { (dict)->inserts++; avl_insert(&((dict)->values_index), (avl *)(nv)); } while(0)
50
-#define dictionary_name_value_index_del_nolock(dict, nv) do { (dict)->deletes++; avl_remove(&(dict->values_index), (avl *)(nv)); } while(0)
49
+#define dictionary_name_value_index_add_nolock(dict, nv) do { NETDATA_DICTIONARY_STATS_INSERTS_PLUS1(dict); avl_insert(&((dict)->values_index), (avl *)(nv)); } while(0)
50
+#define dictionary_name_value_index_del_nolock(dict, nv) do { NETDATA_DICTIONARY_STATS_DELETES_PLUS1(dict); avl_remove(&(dict->values_index), (avl *)(nv)); } while(0)
51
52
static inline NAME_VALUE *dictionary_name_value_index_find_nolock(DICTIONARY *dict, const char *name, uint32_t hash) {
53
NAME_VALUE tmp;
54
tmp.hash = (hash)?hash:simple_hash(name);
55
tmp.name = (char *)name;
56
57
- dict->searches++;
57
+ NETDATA_DICTIONARY_STATS_SEARCHES_PLUS1(dict);
58
return (NAME_VALUE *)avl_search(&(dict->values_index), (avl *) &tmp);
59
}
60
@@ -89,7 +89,7 @@ static NAME_VALUE *dictionary_name_value_create_nolock(DICTIONARY *dict, const c
89
90
// index it
91
dictionary_name_value_index_add_nolock(dict, nv);
92
- dict->entries++;
92
+ NETDATA_DICTIONARY_STATS_ENTRIES_PLUS1(dict);
93
94
return nv;
95
}
@@ -99,7 +99,7 @@ static void dictionary_name_value_destroy_nolock(DICTIONARY *dict, NAME_VALUE *n
99
100
dictionary_name_value_index_del_nolock(dict, nv);
101
102
- dict->entries--;
102
+ NETDATA_DICTIONARY_STATS_ENTRIES_MINUS1(dict);
103
104
if(!(dict->flags & DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE)) {
105
debug(D_REGISTRY, "Dictionary freeing value of '%s'", nv->name);
src/dictionary.h
+16
@@ -21,14 +21,30 @@ typedef struct dictionary {
21
22
uint8_t flags;
23
24
+#ifdef NETDATA_DICTIONARY_WITH_STATISTICS
25
unsigned long long inserts;
26
unsigned long long deletes;
27
unsigned long long searches;
28
unsigned long long entries;
29
+#endif /* NETDATA_DICTIONARY_WITH_STATISTICS */
30
31
pthread_rwlock_t rwlock;
32
} DICTIONARY;
33
34
+#ifdef NETDATA_DICTIONARY_WITH_STATISTICS
35
+#define NETDATA_DICTIONARY_STATS_INSERTS_PLUS1(dict) (dict)->inserts++
36
+#define NETDATA_DICTIONARY_STATS_DELETES_PLUS1(dict) (dict)->deletes++
37
+#define NETDATA_DICTIONARY_STATS_SEARCHES_PLUS1(dict) (dict)->searches++
38
+#define NETDATA_DICTIONARY_STATS_ENTRIES_PLUS1(dict) (dict)->entries++
39
+#define NETDATA_DICTIONARY_STATS_ENTRIES_MINUS1(dict) (dict)->entries--
40
+#else /* NETDATA_DICTIONARY_WITH_STATISTICS */
41
+#define NETDATA_DICTIONARY_STATS_INSERTS_PLUS1(dict)
42
+#define NETDATA_DICTIONARY_STATS_DELETES_PLUS1(dict)
43
+#define NETDATA_DICTIONARY_STATS_SEARCHES_PLUS1(dict)
44
+#define NETDATA_DICTIONARY_STATS_ENTRIES_PLUS1(dict)
45
+#define NETDATA_DICTIONARY_STATS_ENTRIES_MINUS1(dict)
46
+#endif /* NETDATA_DICTIONARY_WITH_STATISTICS */
47
+
48
#define DICTIONARY_FLAG_DEFAULT 0x00000000
49
#define DICTIONARY_FLAG_SINGLE_THREADED 0x00000001
50
#define DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE 0x00000002