MySQL  8.0.18
Source Code Documentation
topkeys.h
Go to the documentation of this file.
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 */
42 
43 typedef struct topkeys {
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);
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
void topkeys_free(topkeys_t *topkeys)
Definition: topkeys.c:63
topkey_item_t * topkeys_item_get_or_create(topkeys_t *tk, const void *key, size_t nkey, const rel_time_t ctime)
Definition: topkeys.c:105
struct dlist dlist_t
ENGINE_ERROR_CODE topkeys_stats(topkeys_t *tk, const void *cookie, const rel_time_t current_time, ADD_STAT add_stat)
Definition: topkeys.c:167
#define TK_OPS(C)
Definition: topkeys.h:8
int nkeys
Definition: topkeys.h:47
topkeys_t * topkeys_init(int max_keys)
Definition: topkeys.c:36
int max_keys
Definition: topkeys.h:48
int nkey
Definition: topkeys.h:35
Definition: topkeys.h:33
rel_time_t ctime
Definition: topkeys.h:36
struct dlist * next
Definition: topkeys.h:29
dlist_t list
Definition: topkeys.h:44
char key[]
Definition: topkeys.h:40
Definition: topkeys.h:43
static const char * key
Definition: suite_stubs.c:14
rel_time_t atime
Definition: topkeys.h:36
#define TK_CUR(name)
Definition: topkeys.h:37
pthread_mutex_t mutex
Definition: topkeys.h:45
struct dlist * prev
Definition: topkeys.h:30
dlist_t list
Definition: topkeys.h:34
genhash_t * hash
Definition: topkeys.h:46
Definition: topkeys.h:28
struct topkey_item topkey_item_t
volatile rel_time_t current_time
Definition: memcached.c:162
struct topkeys topkeys_t