1 #ifndef TOPKEYS_H 2 #define TOPKEYS_H 1 3 4 #include <memcached/engine.h> 5 #include <memcached/genhash.h> 6 7 /* A list of operations for which we have int stats */ 8 #define TK_OPS(C) C(get_hits) C(get_misses) C(cmd_set) C(incr_hits) \ 9 C(incr_misses) C(decr_hits) C(decr_misses) \ 10 C(delete_hits) C(delete_misses) C(evictions) \ 11 C(cas_hits) C(cas_badval) C(cas_misses) 12 13 #define TK_MAX_VAL_LEN 250 14 15 /* Update the correct stat for a given operation */ 16 #define TK(tk, op, key, nkey, ctime) { \ 17 if (tk) { \ 18 assert(key); \ 19 assert(nkey > 0); \ 20 pthread_mutex_lock(&tk->mutex); \ 21 topkey_item_t *tmp = topkeys_item_get_or_create( \ 22 (tk), (key), (nkey), (ctime)); \ 23 tmp->op++; \ 24 pthread_mutex_unlock(&tk->mutex); \ 25 } \ 26 } 27 28 typedef struct dlist { 29 struct dlist *next; 30 struct dlist *prev; 31 } dlist_t; 32 33 typedef struct topkey_item { 34 dlist_t list; /* Must be at the beginning because we downcast! */ 35 int nkey; 36 rel_time_t ctime, atime; /* Time this item was created/last accessed */ 37 #define TK_CUR(name) int name; 38 TK_OPS(TK_CUR) 39 #undef TK_CUR 40 char key[]; /* A variable length array in the struct itself */ 41 } topkey_item_t; 42 43 typedef struct topkeys { 44 dlist_t list; 45 pthread_mutex_t mutex; 46 genhash_t *hash; 47 int nkeys; 48 int max_keys; 49 } topkeys_t; 50 51 topkeys_t *topkeys_init(int max_keys); 52 void topkeys_free(topkeys_t *topkeys); 53 topkey_item_t *topkeys_item_get_or_create(topkeys_t *tk, const void *key, size_t nkey, const rel_time_t ctime); 54 ENGINE_ERROR_CODE topkeys_stats(topkeys_t *tk, const void *cookie, const rel_time_t current_time, ADD_STAT add_stat); 55 56 #endif 57