bin: move memaslap to contrib
[m6w6/libmemcached] / src / bin / contrib / memaslap / ms_memslap.h
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #ifndef MS_MEMSLAP_H
17 #define MS_MEMSLAP_H
18
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <errno.h>
22 #include <string.h>
23 #include <assert.h>
24 #include <unistd.h>
25 #include <stdint.h>
26 #include <pthread.h>
27 #if !defined(__cplusplus)
28 # include <stdbool.h>
29 #endif
30 #include <math.h>
31
32 #include "ms_stats.h"
33 #include "ms_atomic.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /* command line option */
40 typedef enum {
41 OPT_VERSION = 'V',
42 OPT_HELP = 'h',
43 OPT_UDP = 'U',
44 OPT_SERVERS = 's',
45 OPT_EXECUTE_NUMBER = 'x',
46 OPT_THREAD_NUMBER = 'T',
47 OPT_CONCURRENCY = 'c',
48 OPT_FIXED_LTH = 'X',
49 OPT_VERIFY = 'v',
50 OPT_GETS_DIVISION = 'd',
51 OPT_TIME = 't',
52 OPT_CONFIG_CMD = 'F',
53 OPT_WINDOW_SIZE = 'w',
54 OPT_EXPIRE = 'e',
55 OPT_STAT_FREQ = 'S',
56 OPT_RECONNECT = 'R',
57 OPT_VERBOSE = 'b',
58 OPT_FACEBOOK_TEST = 'a',
59 OPT_SOCK_PER_CONN = 'n',
60 OPT_BINARY_PROTOCOL = 'B',
61 OPT_OVERWRITE = 'o',
62 OPT_TPS = 'P',
63 OPT_REP_WRITE_SRV = 'p'
64 } ms_options_t;
65
66 /* global statistic of response time */
67 typedef struct statistic {
68 pthread_mutex_t stat_mutex; /* synchronize the following members */
69
70 ms_stat_t get_stat; /* statistics of get command */
71 ms_stat_t set_stat; /* statistics of set command */
72 ms_stat_t total_stat; /* statistics of both get and set commands */
73 } ms_statistic_t;
74
75 /* global status statistic structure */
76 typedef struct stats {
77 ATOMIC uint32_t active_conns; /* active connections */
78 ATOMIC size_t bytes_read; /* read bytes */
79 ATOMIC size_t bytes_written; /* written bytes */
80 ATOMIC size_t obj_bytes; /* object bytes */
81 ATOMIC size_t pre_cmd_get; /* previous total get command count */
82 ATOMIC size_t pre_cmd_set; /* previous total set command count */
83 ATOMIC size_t cmd_get; /* current total get command count */
84 ATOMIC size_t cmd_set; /* current total set command count */
85 ATOMIC size_t get_misses; /* total objects of get miss */
86 ATOMIC size_t vef_miss; /* total objects of verification miss */
87 ATOMIC size_t vef_failed; /* total objects of verification failed */
88 ATOMIC size_t unexp_unget; /* total objects which is unexpired but not get */
89 ATOMIC size_t exp_get; /* total objects which is expired but get */
90 ATOMIC size_t pkt_disorder; /* disorder packages of UDP */
91 ATOMIC size_t pkt_drop; /* packages dropped of UDP */
92 ATOMIC size_t udp_timeout; /* how many times timeout of UDP happens */
93 } ms_stats_t;
94
95 /* lock adapter */
96 typedef struct sync_lock {
97 uint32_t count;
98 pthread_mutex_t lock;
99 pthread_cond_t cond;
100 } ms_sync_lock_t;
101
102 /* global variable structure */
103 typedef struct global {
104 /* synchronize lock */
105 ms_sync_lock_t init_lock;
106 ms_sync_lock_t warmup_lock;
107 ms_sync_lock_t run_lock;
108
109 /* mutex for outputing error log synchronously when memslap crashes */
110 pthread_mutex_t quit_mutex;
111
112 /* mutex for generating key prefix */
113 pthread_mutex_t seq_mutex;
114
115 /* global synchronous flags for slap mode */
116 bool finish_warmup;
117 bool time_out;
118 } ms_global_t;
119
120 /* global structure */
121 extern ms_global_t ms_global;
122
123 /* global stats information structure */
124 extern ms_stats_t ms_stats;
125
126 /* global statistic structure */
127 extern ms_statistic_t ms_statistic;
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif /* end of MS_MEMSLAP_H */