nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

ht_trace.h (1693B)


      1 #ifndef HT_TRACE_H
      2 #define HT_TRACE_H
      3 
      4 #ifdef HT_TRACE_ON
      5 #ifndef HT_TRACE_OUT
      6 #define HT_TRACE_OUT stderr
      7 #endif
      8 
      9 #include <stdio.h>
     10 #define ht_trace(s) fprintf(HT_TRACE_OUT, "trace: %s\n", s)
     11 #define ht_tracei(s, i) fprintf(HT_TRACE_OUT, "trace: %s: %d\n", s, (int)i)
     12 #define ht_tracex(s, x) fprintf(HT_TRACE_OUT, "trace: %s: 0x%lx\n", s, (long)x)
     13 #define ht_traces(s, s2, len) fprintf(HT_TRACE_OUT, "trace: %s: %.*s\n", s, (int)len, s2)
     14 
     15 static void ht_trace_buckets(hash_table_t *ht, char *msg, int first, int count)
     16 {
     17     int i, j, N, n;
     18 
     19     n = ht->buckets;
     20     N = n - 1;
     21 
     22     if (count == 0) {
     23         count = 32;
     24     }
     25     if (count > n) {
     26         count = n;
     27     }
     28 
     29     first = first & N;
     30     fprintf(HT_TRACE_OUT, "bucket trace: %s\n", msg);
     31     if (n > count) {
     32         n = count;
     33     }
     34     fprintf(HT_TRACE_OUT, "item count: %ld, bucket count %ld, utilization: %0.1f%%\n",
     35             ht->count, ht->buckets, (double)ht->count / ht->buckets * 100);
     36 
     37     if (ht->offsets) {
     38         for (i = 0; i < n; ++i) {
     39             j = (first + i) & N;
     40             fprintf(HT_TRACE_OUT, "%03d:%08x:[%02d]\n",
     41                     j, (unsigned int)((void **)ht->table)[j], (unsigned int)ht->offsets[j]);
     42         }
     43     } else {
     44         for (i = 0; i < n; ++i) {
     45             j = (first + i) & N;
     46             fprintf(HT_TRACE_OUT, "%03d:%08x\n", j, (unsigned int)((void **)ht->table)[j]);
     47         }
     48     }
     49     fprintf(HT_TRACE_OUT, "--\n");
     50 }
     51 #else
     52 #define ht_trace(arg1) ((void)0)
     53 #define ht_tracei(arg1, arg2) ((void)0)
     54 #define ht_tracex(arg1, arg2) ((void)0)
     55 #define ht_traces(arg1, arg2, arg3) ((void)0)
     56 #define ht_trace_buckets(arg1, arg2, arg3, arg4) ((void)0)
     57 #endif
     58 
     59 #endif /* HT_TRACE_H */