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

Function latencyMode

src/redis-cli.c:5940–5998  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5938#define LATENCY_SAMPLE_RATE 10 /* milliseconds. */
5939#define LATENCY_HISTORY_DEFAULT_INTERVAL 15000 /* milliseconds. */
5940static void latencyMode(void) {
5941 redisReply *reply;
5942 long long start, latency, min = 0, max = 0, tot = 0, count = 0;
5943 long long history_interval =
5944 config.interval ? config.interval/1000 :
5945 LATENCY_HISTORY_DEFAULT_INTERVAL;
5946 double avg;
5947 long long history_start = mstime();
5948
5949 /* Set a default for the interval in case of --latency option
5950 * with --raw, --csv or when it is redirected to non tty. */
5951 if (config.interval == 0) {
5952 config.interval = 1000;
5953 } else {
5954 config.interval /= 1000; /* We need to convert to milliseconds. */
5955 }
5956
5957 if (!context) exit(1);
5958 while(1) {
5959 start = mstime();
5960 reply = reconnectingRedisCommand(context,"PING");
5961 if (reply == NULL) {
5962 fprintf(stderr,"\nI/O error\n");
5963 exit(1);
5964 }
5965 latency = mstime()-start;
5966 freeReplyObject(reply);
5967 count++;
5968 if (count == 1) {
5969 min = max = tot = latency;
5970 avg = (double) latency;
5971 } else {
5972 if (latency < min) min = latency;
5973 if (latency > max) max = latency;
5974 tot += latency;
5975 avg = (double) tot/count;
5976 }
5977
5978 if (config.output == OUTPUT_STANDARD) {
5979 printf("\x1b[0G\x1b[2K"); /* Clear the line. */
5980 latencyModePrint(min,max,avg,count);
5981 } else {
5982 if (config.latency_history) {
5983 latencyModePrint(min,max,avg,count);
5984 } else if (mstime()-history_start > config.interval) {
5985 latencyModePrint(min,max,avg,count);
5986 exit(0);
5987 }
5988 }
5989
5990 if (config.latency_history && mstime()-history_start > history_interval)
5991 {
5992 printf(" -- %.2f seconds range\n", (float)(mstime()-history_start)/1000);
5993 history_start = mstime();
5994 min = max = tot = count = 0;
5995 }
5996 usleep(LATENCY_SAMPLE_RATE * 1000);
5997 }

Callers 1

mainFunction · 0.85

Calls 4

reconnectingRedisCommandFunction · 0.85
freeReplyObjectFunction · 0.85
latencyModePrintFunction · 0.85
mstimeFunction · 0.70

Tested by

no test coverage detected