MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / latencyCommand

Function latencyCommand

src/latency.cpp:586–657  ·  view source on GitHub ↗

LATENCY command implementations. * * LATENCY HISTORY: return time-latency samples for the specified event. * LATENCY LATEST: return the latest latency for all the events classes. * LATENCY DOCTOR: returns a human readable analysis of instance latency. * LATENCY GRAPH: provide an ASCII graph of the latency of the specified event. * LATENCY RESET: reset data of a specified event or all the dat

Source from the content-addressed store, hash-verified

584 * LATENCY RESET: reset data of a specified event or all the data if no event provided.
585 */
586void latencyCommand(client *c) {
587 struct latencyTimeSeries *ts;
588
589 if (!strcasecmp(szFromObj(c->argv[1]),"history") && c->argc == 3) {
590 /* LATENCY HISTORY <event> */
591 ts = (latencyTimeSeries*)dictFetchValue(g_pserver->latency_events,ptrFromObj(c->argv[2]));
592 if (ts == NULL) {
593 addReplyArrayLen(c,0);
594 } else {
595 latencyCommandReplyWithSamples(c,ts);
596 }
597 } else if (!strcasecmp(szFromObj(c->argv[1]),"graph") && c->argc == 3) {
598 /* LATENCY GRAPH <event> */
599 sds graph;
600 dictEntry *de;
601 char *event;
602
603 de = dictFind(g_pserver->latency_events,ptrFromObj(c->argv[2]));
604 if (de == NULL) goto nodataerr;
605 ts = (latencyTimeSeries*)dictGetVal(de);
606 event = (char*)dictGetKey(de);
607
608 graph = latencyCommandGenSparkeline(event,ts);
609 addReplyVerbatim(c,graph,sdslen(graph),"txt");
610 sdsfree(graph);
611 } else if (!strcasecmp(szFromObj(c->argv[1]),"latest") && c->argc == 2) {
612 /* LATENCY LATEST */
613 latencyCommandReplyWithLatestEvents(c);
614 } else if (!strcasecmp(szFromObj(c->argv[1]),"doctor") && c->argc == 2) {
615 /* LATENCY DOCTOR */
616 sds report = createLatencyReport();
617
618 addReplyVerbatim(c,report,sdslen(report),"txt");
619 sdsfree(report);
620 } else if (!strcasecmp(szFromObj(c->argv[1]),"reset") && c->argc >= 2) {
621 /* LATENCY RESET */
622 if (c->argc == 2) {
623 addReplyLongLong(c,latencyResetEvent(NULL));
624 } else {
625 int j, resets = 0;
626
627 for (j = 2; j < c->argc; j++)
628 resets += latencyResetEvent(szFromObj(c->argv[j]));
629 addReplyLongLong(c,resets);
630 }
631 } else if (!strcasecmp(szFromObj(c->argv[1]),"help") && c->argc == 2) {
632 const char *help[] = {
633"DOCTOR",
634" Return a human readable latency analysis report.",
635"GRAPH <event>",
636" Return an ASCII latency graph for the <event> class.",
637"HISTORY <event>",
638" Return time-latency samples for the <event> class.",
639"LATEST",
640" Return the latest latency samples for all events.",
641"RESET [<event> ...]",
642" Reset latency data of one or more <event> classes.",
643" (default: reset all data for all event classes)",

Callers

nothing calls this directly

Calls 15

szFromObjFunction · 0.85
dictFetchValueFunction · 0.85
ptrFromObjFunction · 0.85
addReplyArrayLenFunction · 0.85
addReplyVerbatimFunction · 0.85
sdslenFunction · 0.85
sdsfreeFunction · 0.85
createLatencyReportFunction · 0.85
addReplyLongLongFunction · 0.85

Tested by

no test coverage detected