/* Create a human readable report of latency events for this Redis instance. */
sdscreateLatencyReport(void){
sdsreport=sdsempty();
/* Return ASAP if the latency engine is disabled and it looks like it
* was never enabled so far. */
if(dictSize(server.latency_events)==0&&
server.latency_monitor_threshold==0)
{
report=sdscat(report,"I'm sorry, Dave, I can't do that. Latency monitoring is disabled in this Redis instance. You may use \"CONFIG SET latency-monitor-threshold <milliseconds>.\" in order to enable it. If we weren't in a deep space mission I'd suggest to take a look at http://redis.io/topics/latency-monitor.");
returnreport;
}
/* Show all the events stats and add for each event some event-related
* comment depending on the values. */
dictIterator*di;
dictEntry*de;
inteventnum=0;
di=dictGetIterator(server.latency_events);
while((de=dictNext(di))!=NULL){
char*event=dictGetKey(de);
structlatencyTimeSeries*ts=dictGetVal(de);
structlatencyStatsls;
intnontrivial,severe;
if(ts==NULL)continue;
eventnum++;
if(eventnum==1){
report=sdscat(report,"Dave, I have observed latency spikes in this Redis instance. You don't mind talking about it, do you Dave?\n\n");
}
analyzeLatencyForEvent(event,&ls);
report=sdscatprintf(report,
"%d. %s: %d latency spikes (average %lums, mean deviation %lums, period %lu sec). Worst all time event %lums.",
eventnum,event,
ls.samples,
(unsignedlong)ls.avg,
(unsignedlong)ls.mad,
(unsignedlong)ls.period/ls.samples,
(unsignedlong)ts->max);
/* Add some event specific information. */
nontrivial=ts->max>100;
severe=ts->max>500;
/* Fork */
if(!strcasecmp(event,"fork")){
doublefork_bandwidth=(double)zmalloc_used_memory()*1000000/server.stat_fork_time/(1024*1024);/* GB per second. */
}
report=sdscatlen(report,"\n",1);
}
dictReleaseIterator(di);
if(eventnum==0){
report=sdscat(report,"Dave, no latency spike was observed during the lifetime of this Redis instance, not in the slightest bit. I honestly think you ought to sit down calmly, take a stress pill, and think things over.\n");