summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-07-07 12:34:54 +0200
committerantirez <antirez@gmail.com>2014-07-09 20:01:27 +0200
commitc145854bacd854ebcfa5fdcbeced8d449358bceb (patch)
treec8b735fb003800e11ac8317ca27fb29ff416ec66
parent65dbb3546a7637294719286e6cbadb46e185633f (diff)
downloadredis-c145854bacd854ebcfa5fdcbeced8d449358bceb.tar.gz
LATENCY RESET implemented.
-rw-r--r--src/latency.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/latency.c b/src/latency.c
index d9c422ad8..80810d98c 100644
--- a/src/latency.c
+++ b/src/latency.c
@@ -35,8 +35,7 @@
#include "redis.h"
-/* Dictionary type for latency events. Key/Val destructors are set to NULL
- * since we never delete latency time series at runtime. */
+/* Dictionary type for latency events. */
int dictStringKeyCompare(void *privdata, const void *key1, const void *key2) {
return strcmp(key1,key2) == 0;
}
@@ -45,13 +44,15 @@ unsigned int dictStringHash(const void *key) {
return dictGenHashFunction(key, strlen(key));
}
+void dictVanillaFree(void *privdata, void *val);
+
dictType latencyTimeSeriesDictType = {
dictStringHash, /* hash function */
NULL, /* key dup */
NULL, /* val dup */
dictStringKeyCompare, /* key compare */
- NULL, /* key destructor */
- NULL /* val destructor */
+ dictVanillaFree, /* key destructor */
+ dictVanillaFree /* val destructor */
};
/* ---------------------------- Latency API --------------------------------- */
@@ -98,6 +99,29 @@ void latencyAddSample(char *event, mstime_t latency) {
if (ts->idx == LATENCY_TS_LEN) ts->idx = 0;
}
+/* Reset data for the specified event, or all the events data if 'event' is
+ * NULL.
+ *
+ * Note: this is O(N) even when event_to_reset is not NULL because makes
+ * the code simpler and we have a small fixed max number of events. */
+int latencyResetEvent(char *event_to_reset) {
+ dictIterator *di;
+ dictEntry *de;
+ int resets = 0;
+
+ di = dictGetSafeIterator(server.latency_events);
+ while((de = dictNext(di)) != NULL) {
+ char *event = dictGetKey(de);
+
+ if (event_to_reset == NULL || strcasecmp(event,event_to_reset) == 0) {
+ dictDelete(server.latency_events, event);
+ resets++;
+ }
+ }
+ dictReleaseIterator(di);
+ return resets;
+}
+
/* ---------------------- Latency command implementation -------------------- */
/* latencyCommand() helper to produce a time-delay reply for all the samples
@@ -219,6 +243,17 @@ void latencyCommand(redisClient *c) {
} else if (!strcasecmp(c->argv[1]->ptr,"latest") && c->argc == 2) {
/* LATENCY LATEST */
latencyCommandReplyWithLatestEvents(c);
+ } else if (!strcasecmp(c->argv[1]->ptr,"reset") && c->argc >= 2) {
+ /* LATENCY RESET */
+ if (c->argc == 2) {
+ addReplyLongLong(c,latencyResetEvent(NULL));
+ } else {
+ int j, resets = 0;
+
+ for (j = 2; j < c->argc; j++)
+ resets += latencyResetEvent(c->argv[j]->ptr);
+ addReplyLongLong(c,resets);
+ }
} else {
addReply(c,shared.syntaxerr);
}