mirror of
https://github.com/fluencelabs/redis
synced 2025-04-22 00:52:13 +00:00
LATENCY RESET implemented.
This commit is contained in:
parent
2de5bab368
commit
f8934657b2
@ -35,8 +35,7 @@
|
|||||||
|
|
||||||
#include "redis.h"
|
#include "redis.h"
|
||||||
|
|
||||||
/* Dictionary type for latency events. Key/Val destructors are set to NULL
|
/* Dictionary type for latency events. */
|
||||||
* since we never delete latency time series at runtime. */
|
|
||||||
int dictStringKeyCompare(void *privdata, const void *key1, const void *key2) {
|
int dictStringKeyCompare(void *privdata, const void *key1, const void *key2) {
|
||||||
return strcmp(key1,key2) == 0;
|
return strcmp(key1,key2) == 0;
|
||||||
}
|
}
|
||||||
@ -45,13 +44,15 @@ unsigned int dictStringHash(const void *key) {
|
|||||||
return dictGenHashFunction(key, strlen(key));
|
return dictGenHashFunction(key, strlen(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dictVanillaFree(void *privdata, void *val);
|
||||||
|
|
||||||
dictType latencyTimeSeriesDictType = {
|
dictType latencyTimeSeriesDictType = {
|
||||||
dictStringHash, /* hash function */
|
dictStringHash, /* hash function */
|
||||||
NULL, /* key dup */
|
NULL, /* key dup */
|
||||||
NULL, /* val dup */
|
NULL, /* val dup */
|
||||||
dictStringKeyCompare, /* key compare */
|
dictStringKeyCompare, /* key compare */
|
||||||
NULL, /* key destructor */
|
dictVanillaFree, /* key destructor */
|
||||||
NULL /* val destructor */
|
dictVanillaFree /* val destructor */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ---------------------------- Latency API --------------------------------- */
|
/* ---------------------------- Latency API --------------------------------- */
|
||||||
@ -98,6 +99,29 @@ void latencyAddSample(char *event, mstime_t latency) {
|
|||||||
if (ts->idx == LATENCY_TS_LEN) ts->idx = 0;
|
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 -------------------- */
|
/* ---------------------- Latency command implementation -------------------- */
|
||||||
|
|
||||||
/* latencyCommand() helper to produce a time-delay reply for all the samples
|
/* 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) {
|
} else if (!strcasecmp(c->argv[1]->ptr,"latest") && c->argc == 2) {
|
||||||
/* LATENCY LATEST */
|
/* LATENCY LATEST */
|
||||||
latencyCommandReplyWithLatestEvents(c);
|
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 {
|
} else {
|
||||||
addReply(c,shared.syntaxerr);
|
addReply(c,shared.syntaxerr);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user