]> arthur.barton.de Git - netdata.git/blobdiff - src/adaptive_resortable_list.h
renamed states family
[netdata.git] / src / adaptive_resortable_list.h
index ccd92b9b2791cb34753575a27dca8f2b9ef342ef..609cd0c43a2c2e55342dbd56f6c3671d685beaa8 100644 (file)
@@ -56,6 +56,8 @@ typedef struct arl_entry {
 } ARL_ENTRY;
 
 typedef struct arl_base {
+    char *name;
+
     size_t iteration;   // incremented on each iteration (arl_begin())
     size_t found;       // the number of expected keywords found in this iteration
     size_t expected;    // the number of expected keywords
@@ -63,7 +65,9 @@ typedef struct arl_base {
                         // i.e. the number of keywords found and expected
 
     size_t relinkings;  // the number of relinkings we have made so far
+
     size_t allocated;   // the number of keywords allocated
+    size_t fred;        // the number of keywords cleaned up
 
     size_t rechecks;    // the number of iterations between re-checks of the
                         // wanted number of keywords
@@ -74,6 +78,11 @@ typedef struct arl_base {
                         // this is only needed to detect new lines have
                         // been added to the file, over time.
 
+#ifdef NETDATA_INTERNAL_CHECKS
+    size_t fast;        // the number of times we have taken the fast path
+    size_t slow;        // the number of times we have taken the slow path
+#endif
+
     // the processor to do the job
     void (*processor)(const char *name, uint32_t hash, const char *value, void *dst);
 
@@ -86,7 +95,7 @@ typedef struct arl_base {
 } ARL_BASE;
 
 // create a new ARL
-extern ARL_BASE *arl_create(void (*processor)(const char *, uint32_t, const char *, void *), size_t rechecks);
+extern ARL_BASE *arl_create(const char *name, void (*processor)(const char *, uint32_t, const char *, void *), size_t rechecks);
 
 // free an ARL
 extern void arl_free(ARL_BASE *arl_base);
@@ -96,7 +105,7 @@ extern void arl_free(ARL_BASE *arl_base);
 extern ARL_ENTRY *arl_expect(ARL_BASE *base, const char *keyword, void *dst);
 
 // an internal call to complete the check() call
-extern int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, uint32_t hash, const char *value);
+extern int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, const char *value);
 
 // begin an ARL iteration
 extern void arl_begin(ARL_BASE *base);
@@ -108,12 +117,20 @@ extern void arl_begin(ARL_BASE *base);
 // it is defined in the header file in order to be inlined
 static inline int arl_check(ARL_BASE *base, const char *keyword, const char *value) {
     ARL_ENTRY *e = base->next_keyword;
-    uint32_t hash = simple_hash(keyword);
+
+#ifdef NETDATA_INTERNAL_CHECKS
+    if(unlikely((base->fast + base->slow) % (base->expected + base->allocated) == 0 && (base->fast + base->slow) > (base->expected + base->allocated) * base->iteration))
+        info("ARL '%s': Did you forget to call arl_begin()?", base->name);
+#endif
 
     // it should be the first entry (pointed by base->next_keyword)
-    if(likely(hash == e->hash && !strcmp(keyword, e->name))) {
+    if(likely(!strcmp(keyword, e->name))) {
         // it is
 
+#ifdef NETDATA_INTERNAL_CHECKS
+        base->fast++;
+#endif
+
         e->flags |= ARL_ENTRY_FLAG_FOUND;
 
         // execute the processor
@@ -134,8 +151,12 @@ static inline int arl_check(ARL_BASE *base, const char *keyword, const char *val
         return 0;
     }
 
+#ifdef NETDATA_INTERNAL_CHECKS
+    base->slow++;
+#endif
+
     // we read from source, a not-expected keyword
-    return arl_find_or_create_and_relink(base, keyword, hash, value);
+    return arl_find_or_create_and_relink(base, keyword, value);
 }
 
 #endif //NETDATA_ADAPTIVE_RESORTABLE_LIST_H