// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/latency.c
// Function: latencyCommandGenSparkeline
sds latencyCommandGenSparkeline(char *event, struct latencyTimeSeries *ts) {
    int j;
    struct sequence *seq = createSparklineSequence();
    sds graph = sdsempty();
    uint32_t min = 0, max = 0;

    for (j = 0; j < LATENCY_TS_LEN; j++) {
        int i = (ts->idx + j) % LATENCY_TS_LEN;
        int elapsed;
        char buf[64];

        if (ts->samples[i].time == 0) continue;
        /* Update min and max. */
        if (seq->length == 0) {
            min = max = ts->samples[i].latency;
        } else {
            if (ts->samples[i].latency > max) max = ts->samples[i].latency;
            if (ts->samples[i].latency < min) min = ts->samples[i].latency;
        }
        /* Use as label the number of seconds / minutes / hours / days
         * ago the event happened. */
        elapsed = time(NULL) - ts->samples[i].time;
        if (elapsed < 60)
            snprintf(buf,sizeof(buf),"%ds",elapsed);
        else if (elapsed < 3600)
            snprintf(buf,sizeof(buf),"%dm",elapsed/60);
        else if (elapsed < 3600*24)
            snprintf(buf,sizeof(buf),"%dh",elapsed/3600);
        else
            snprintf(buf,sizeof(buf),"%dd",elapsed/(3600*24));
        sparklineSequenceAddSample(seq,ts->samples[i].latency,buf);
    }

    graph = sdscatprintf(graph,
        "%s - high %lu ms, low %lu ms (all time high %lu ms)\n", event,
        (unsigned long) max, (unsigned long) min, (unsigned long) ts->max);
    for (j = 0; j < LATENCY_GRAPH_COLS; j++)
        graph = sdscatlen(graph,"-",1);
    graph = sdscatlen(graph,"\n",1);
    graph = sparklineRender(graph,seq,LATENCY_GRAPH_COLS,4,SPARKLINE_FILL);
    freeSparklineSequence(seq);
    return graph;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r15
movq %rdi, 0x18(%rsp)
callq 0x72cac
movq %rax, 0x8(%rsp)
callq 0x3114c
movq %rax, 0x10(%rsp)
xorl %esi, %esi
xorl %r12d, %r12d
xorl %r14d, %r14d
cmpl $0xa0, %r14d
je 0x729e7
movl (%r15), %eax
addl %r14d, %eax
cltd
movl $0xa0, %ecx
idivl %ecx
movslq %edx, %rbp
cmpl $0x0, 0x8(%r15,%rbp,8)
je 0x729df
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
movl 0xc(%r15,%rbp,8), %r13d
je 0x72936
cmpl %r12d, %r13d
cmoval %r13d, %r12d
cmpl %esi, %r13d
cmovael %esi, %r13d
jmp 0x72939
movl %r13d, %r12d
xorl %edi, %edi
callq 0x26cd0
subl 0x8(%r15,%rbp,8), %eax
cmpl $0x3b, %eax
jg 0x72960
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
pushq $0x40
popq %rsi
leaq 0x4d4c2(%rip), %rdx     # 0xbfe1e
movl %eax, %ecx
jmp 0x729be
cmpl $0xe0f, %eax            # imm = 0xE0F
leaq 0x20(%rsp), %rdi
ja 0x72987
xorl %edx, %edx
movw $0x3c, %cx
divw %cx
movzwl %ax, %ecx
movq %rdi, %rbx
pushq $0x40
popq %rsi
leaq 0x4d49d(%rip), %rdx     # 0xbfe22
jmp 0x729be
cmpl $0x1517f, %eax          # imm = 0x1517F
ja 0x729a6
xorl %edx, %edx
movl $0xe10, %ecx            # imm = 0xE10
divl %ecx
movq %rdi, %rbx
pushq $0x40
popq %rsi
leaq 0x4d482(%rip), %rdx     # 0xbfe26
jmp 0x729bc
xorl %edx, %edx
movl $0x15180, %ecx          # imm = 0x15180
divl %ecx
movq %rdi, %rbx
pushq $0x40
popq %rsi
leaq 0x4d46e(%rip), %rdx     # 0xbfe2a
movl %eax, %ecx
xorl %eax, %eax
callq 0x26120
movl 0xc(%r15,%rbp,8), %eax
cvtsi2sd %rax, %xmm0
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x72cbf
movl %r13d, %esi
incl %r14d
jmp 0x728ed
movl %r12d, %ecx
movl %esi, %r8d
movl 0x4(%r15), %r9d
leaq 0x4d436(%rip), %rsi     # 0xbfe2e
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x31a38
pushq $0x50
popq %rbp
leaq 0x4f5eb(%rip), %r14     # 0xc1ffe
pushq $0x1
popq %r15
subl $0x1, %ebp
jb 0x72a2c
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x31758
jmp 0x72a17
leaq 0x3e386(%rip), %rsi     # 0xb0db9
pushq $0x1
popq %rdx
movq %rax, %rdi
callq 0x31758
pushq $0x50
popq %rdx
pushq $0x4
popq %rcx
pushq $0x1
popq %r8
movq %rax, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x72fe5
movq %rax, %r14
movq %rbx, %rdi
callq 0x72d57
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq