|
Packit |
4e8bc4 |
#ifndef STATS_PREFIX_H
|
|
Packit |
4e8bc4 |
#define STATS_PREFIX_H
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
/* The stats prefix subsystem stores detailed statistics for each key prefix.
|
|
Packit |
4e8bc4 |
* Simple statistics like total number of GETS are stored by the Stats
|
|
Packit |
4e8bc4 |
* subsystem defined elsewhere.
|
|
Packit |
4e8bc4 |
*
|
|
Packit |
4e8bc4 |
* Suppose the prefix delimiter is ":", then "user:123" and "user:456" both
|
|
Packit |
4e8bc4 |
* have the same prefix "user".
|
|
Packit |
4e8bc4 |
*/
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
/* Initialize the stats prefix subsystem. Should be called once before other
|
|
Packit |
4e8bc4 |
* functions are called. The global hash initialization should be done before
|
|
Packit |
4e8bc4 |
* using this subsystem.
|
|
Packit |
4e8bc4 |
*/
|
|
Packit |
4e8bc4 |
void stats_prefix_init(char prefix_delimiter);
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
/* Clear previously collected stats. Requires you to have the acquired
|
|
Packit |
4e8bc4 |
* the STATS_LOCK() first.
|
|
Packit |
4e8bc4 |
*/
|
|
Packit |
4e8bc4 |
void stats_prefix_clear(void);
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
/* Record a GET for a key */
|
|
Packit |
4e8bc4 |
void stats_prefix_record_get(const char *key, const size_t nkey, const bool is_hit);
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
/* Record a DELETE for a key */
|
|
Packit |
4e8bc4 |
void stats_prefix_record_delete(const char *key, const size_t nkey);
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
/* Record a SET for a key */
|
|
Packit |
4e8bc4 |
void stats_prefix_record_set(const char *key, const size_t nkey);
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
/* Return the collected stats in a textual for suitable for writing to a client.
|
|
Packit |
4e8bc4 |
* The size of the output text is stored in the length parameter.
|
|
Packit |
4e8bc4 |
* Returns NULL on error
|
|
Packit |
4e8bc4 |
*/
|
|
Packit |
4e8bc4 |
char *stats_prefix_dump(int *length);
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
/* Visible for testing */
|
|
Packit |
4e8bc4 |
#define PREFIX_HASH_SIZE 256
|
|
Packit |
4e8bc4 |
typedef struct _prefix_stats PREFIX_STATS;
|
|
Packit |
4e8bc4 |
struct _prefix_stats {
|
|
Packit |
4e8bc4 |
char *prefix;
|
|
Packit |
4e8bc4 |
size_t prefix_len;
|
|
Packit |
4e8bc4 |
uint64_t num_gets;
|
|
Packit |
4e8bc4 |
uint64_t num_sets;
|
|
Packit |
4e8bc4 |
uint64_t num_deletes;
|
|
Packit |
4e8bc4 |
uint64_t num_hits;
|
|
Packit |
4e8bc4 |
PREFIX_STATS *next;
|
|
Packit |
4e8bc4 |
};
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
/* Return the PREFIX_STATS structure for the specified key, creating it if
|
|
Packit |
4e8bc4 |
* it does not already exist. Returns NULL if the key does not contain
|
|
Packit |
4e8bc4 |
* prefix delimiter, or if there was an error. Requires you to have acquired
|
|
Packit |
4e8bc4 |
* STATS_LOCK() first.
|
|
Packit |
4e8bc4 |
*/
|
|
Packit |
4e8bc4 |
PREFIX_STATS *stats_prefix_find(const char *key, const size_t nkey);
|
|
Packit |
4e8bc4 |
|
|
Packit |
4e8bc4 |
#endif
|