// File: /workspace/github_c_makefile_star2_O0/erikdubbelboer[P]discnt/src/latency.c
// Function: createLatencyReport
sds createLatencyReport(void) {
    sds report = sdsempty();
    int advise_disk_contention = 0; /* Try to lower disk contention. */
    int advise_scheduler = 0;       /* Intrinsic latency. */
    int advise_local_disk = 0;      /* Avoid remote disks. */
    int advise_ssd = 0;             /* Use an SSD drive. */
    int advise_hz = 0;              /* Use higher HZ. */
    int advices = 0;

    /* 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 Discnt 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.\n");
        return report;
    }

    /* Show all the events stats and add for each event some event-related
     * comment depending on the values. */
    dictIterator *di;
    dictEntry *de;
    int eventnum = 0;

    di = dictGetSafeIterator(server.latency_events);
    while((de = dictNext(di)) != NULL) {
        char *event = dictGetKey(de);
        struct latencyTimeSeries *ts = dictGetVal(de);
        struct latencyStats ls;

        if (ts == NULL) continue;
        eventnum++;
        if (eventnum == 1) {
            report = sdscat(report,"Dave, I have observed latency spikes in this Discnt 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 %.2f sec). Worst all time event %lums.",
            eventnum, event,
            ls.samples,
            (unsigned long) ls.avg,
            (unsigned long) ls.mad,
            (double) ls.period/ls.samples,
            (unsigned long) ts->max);

        /* Potentially commands. */
        if (!strcasecmp(event,"command")) {
            advices += 2;
        }

        /* fast-command. */
        if (!strcasecmp(event,"fast-command")) {
            advise_scheduler = 1;
            advices++;
        }

        if (!strcasecmp(event,"ddb-unlink-temp-file")) {
            advise_disk_contention = 1;
            advise_local_disk = 1;
            advices += 2;
        }

        report = sdscatlen(report,"\n",1);
    }
    dictReleaseIterator(di);

    if (eventnum == 0) {
        report = sdscat(report,"Dave, no latency spike was observed during the lifetime of this Discnt instance, not in the slightest bit. I honestly think you ought to sit down calmly, take a stress pill, and think things over.\n");
    } else if (advices == 0) {
        report = sdscat(report,"\nWhile there are latency events logged, I'm not able to suggest any easy fix. Please use the Discnt community to get some help, providing this report in your help request.\n");
    } else {
        /* Add all the suggestions accumulated so far. */

        report = sdscat(report,"\nI have a few advices for you:\n\n");

        /* Intrinsic latency. */
        if (advise_scheduler) {
            report = sdscat(report,"- The system is slow to execute Discnt code paths not containing system calls. This usually means the system does not provide Discnt CPU time to run for long periods. You should try to:\n"
            "  1) Lower the system load.\n"
            "  2) Use a computer / VM just for Discnt if you are running other softawre in the same system.\n"
            "  3) Check if you have a \"noisy neighbour\" problem.\n"
            "  4) Check with 'discnt-cli --intrinsic-latency 100' what is the intrinsic latency in your system.\n"
            "  5) Check if the problem is allocator-related by recompiling Discnt with MALLOC=libc, if you are using Jemalloc. However this may create fragmentation problems.\n");
        }

        /* Disk latency. */
        if (advise_local_disk) {
            report = sdscat(report,"- It is strongly advised to use local disks for persistence. Remote disks provided by platform-as-a-service providers are known to be slow.\n");
        }

        if (advise_ssd) {
            report = sdscat(report,"- SSD disks are able to reduce fsync latency, and total time needed for snapshotting. With extremely high write load SSD disks can be a good option. However Discnt should perform reasonably with high load using normal disks. Use this advice as a last resort.\n");
        }

        if (advise_disk_contention) {
            report = sdscat(report,"- Try to lower the disk contention. This is often caused by other disk intensive processes running in the same computer (including other Redis instances).\n");
        }

        if (advise_hz && server.hz < 100) {
            report = sdscat(report,"- In order to make the Discnt internal processes more incremental, try to set the 'hz' configuration parameter to 100 using 'CONFIG SET hz 100'.\n");
        }
    }

    return report;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
callq 0x1e290
movq %rax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
leaq 0x86c83(%rip), %rax     # 0xbf0e8
movq 0x678(%rax), %rax
movq 0x28(%rax), %rax
leaq 0x86c71(%rip), %rcx     # 0xbf0e8
movq 0x678(%rcx), %rcx
addq 0x48(%rcx), %rax
cmpq $0x0, %rax
jne 0x384ba
leaq 0x86c59(%rip), %rax     # 0xbf0e8
cmpq $0x0, 0x670(%rax)
jne 0x384ba
movq -0x10(%rbp), %rdi
leaq 0x7048c(%rip), %rsi     # 0xa8930
callq 0x1ee70
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3870e
movl $0x0, -0x3c(%rbp)
leaq 0x86c20(%rip), %rax     # 0xbf0e8
movq 0x678(%rax), %rdi
callq 0x17370
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x173a0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x38618
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x3850f
jmp 0x384d8
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x1, -0x3c(%rbp)
jne 0x38532
movq -0x10(%rbp), %rdi
leaq 0x70528(%rip), %rsi     # 0xa8a51
callq 0x1ee70
movq %rax, -0x10(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x38180
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %edx
movq -0x48(%rbp), %rcx
movl -0x5c(%rbp), %eax
movl %eax, %r8d
movl -0x6c(%rbp), %r9d
movl -0x60(%rbp), %esi
movl %esi, %r10d
cvtsi2sdq -0x58(%rbp), %xmm0
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
leaq 0x70548(%rip), %rsi     # 0xa8abf
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x1, %al
callq 0x1f350
movq %rax, -0x10(%rbp)
movq -0x48(%rbp), %rdi
leaq 0x6bb74(%rip), %rsi     # 0xa410a
callq 0x12070
cmpl $0x0, %eax
jne 0x385a9
movl -0x28(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x28(%rbp)
movq -0x48(%rbp), %rdi
leaq 0x6bb0c(%rip), %rsi     # 0xa40c0
callq 0x12070
cmpl $0x0, %eax
jne 0x385ce
movl $0x1, -0x18(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x48(%rbp), %rdi
leaq 0x70554(%rip), %rsi     # 0xa8b2d
callq 0x12070
cmpl $0x0, %eax
jne 0x385fa
movl $0x1, -0x14(%rbp)
movl $0x1, -0x1c(%rbp)
movl -0x28(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x6c7a3(%rip), %rsi     # 0xa4da8
movl $0x1, %edx
callq 0x1ede0
movq %rax, -0x10(%rbp)
jmp 0x384d8
movq -0x30(%rbp), %rdi
callq 0x17510
cmpl $0x0, -0x3c(%rbp)
jne 0x38640
movq -0x10(%rbp), %rdi
leaq 0x70510(%rip), %rsi     # 0xa8b42
callq 0x1ee70
movq %rax, -0x10(%rbp)
jmp 0x38706
cmpl $0x0, -0x28(%rbp)
jne 0x3865f
movq -0x10(%rbp), %rdi
leaq 0x705b7(%rip), %rsi     # 0xa8c08
callq 0x1ee70
movq %rax, -0x10(%rbp)
jmp 0x38704
movq -0x10(%rbp), %rdi
leaq 0x7064b(%rip), %rsi     # 0xa8cb5
callq 0x1ee70
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x3868d
movq -0x10(%rbp), %rdi
leaq 0x70652(%rip), %rsi     # 0xa8cd6
callq 0x1ee70
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x386a7
movq -0x10(%rbp), %rdi
leaq 0x708a7(%rip), %rsi     # 0xa8f45
callq 0x1ee70
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x386c1
movq -0x10(%rbp), %rdi
leaq 0x7091a(%rip), %rsi     # 0xa8fd2
callq 0x1ee70
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x386db
movq -0x10(%rbp), %rdi
leaq 0x70a04(%rip), %rsi     # 0xa90d6
callq 0x1ee70
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x38702
leaq 0x86a00(%rip), %rax     # 0xbf0e8
cmpl $0x64, 0x20(%rax)
jge 0x38702
movq -0x10(%rbp), %rdi
leaq 0x70a79(%rip), %rsi     # 0xa9172
callq 0x1ee70
movq %rax, -0x10(%rbp)
jmp 0x38704
jmp 0x38706
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)