// File: /workspace/github_cpp_makefile_star2_O2/yangwanyuan[P]HLKVDS/tools/Benchmark.cc
// Function: Bench_Overwrite(benchmark_arg)
void Bench_Overwrite(benchmark_arg bm_arg) {
    string file_path = bm_arg.file_path;
    int db_size = bm_arg.db_size;
    int record_num =bm_arg.record_num;
    int thread_num = bm_arg.thread_num;
    int segment_K = bm_arg.segment_K;
    int shards_num = bm_arg.shards_num;
    int ds_type = bm_arg.ds_type;
    int aggregate = bm_arg.aggregate;

    vector<string> key_list;
    Create_Keys(record_num, key_list);
    if (Create_DB(file_path, db_size, segment_K, shards_num, ds_type) < 0) {
        cout << "Create DB Fail!!!" <<endl;
        return;
    }

    KVDS *db = Open_DB(file_path, shards_num, aggregate);

    double total_time;
    LatMgr *total_lat_mgr = new LatMgr;
    for (int i = 0; i < OVERWRITE_TIMES; i++) {
        cout << "======================";
        cout << "Insert " << i << " Start!!!";
        cout << "======================" << endl;

        total_time += Bench_Insert(db, record_num, key_list, thread_num, total_lat_mgr);

        cout << "======================";
        cout << "Insert " << i << " Completed!!!";
        cout << "======================" << endl;
    }
    cout << "======================";
    cout << "Finsh All Insert!!!";
    cout << "======================" << endl;

    Lat_Stats lat_stats;
    total_lat_mgr->GetStatistics(lat_stats);

    uint64_t total_record_num = record_num * OVERWRITE_TIMES;
    double iops = total_record_num / total_time;

    uint64_t total_size = (uint64_t)total_record_num * (KEY_SIZE + VALUE_SIZE);
    double throughput = total_size / (total_time * 1024 * 1024);

    uint64_t avg = total_lat_mgr->GetAvg();
    uint64_t min = total_lat_mgr->GetMin();
    uint64_t max = total_lat_mgr->GetMax();

    cout << "Overwrite Bench Finish. Total time: " << total_time << "s" <<endl;
    cout << "Performance Report     :   IOPS = " <<  iops << ", Average Latency = "
            << avg << "us, Throughput = " << throughput << "MB/s." << endl;
    cout << "Latency Report(usec)   :   Min = " << min << ", Max = "
            << max << ", Med = " << lat_stats.med << "." << endl;
    cout << "Latency Statistic(usec):   P50 = " << lat_stats.P_50 << ", P75 = "
            << lat_stats.P_75 << ", P99 = " << lat_stats.P_99 << ", P999 = "
            << lat_stats.P_999 << ", P9999 = " << lat_stats.P_9999 << endl;

    delete total_lat_mgr;
    delete db;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x6560
movl 0x20(%rbx), %r12d
movl 0x24(%rbx), %ebp
movl 0x28(%rbx), %eax
movl %eax, 0x14(%rsp)
movl 0x2c(%rbx), %r13d
movl 0x30(%rbx), %r15d
movl 0x34(%rbx), %r14d
movl 0x38(%rbx), %ebx
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rsi
movapd %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movl %ebp, %edi
callq 0x6cf8
leaq 0xb8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x6560
leaq 0xb8(%rsp), %rdi
movl %r12d, %esi
movl %r13d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0x6aa9
movl %eax, %r14d
leaq 0xb8(%rsp), %rdi
callq 0x67f8
testl %r14d, %r14d
js 0x8535
leaq 0x98(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x6560
leaq 0x98(%rsp), %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0x6be7
movq %rax, 0x20(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x67f8
pushq $0x18
popq %rdi
callq 0x6430
movq %rax, %r15
movslq %ebp, %rax
movq %rax, 0x18(%rsp)
xorpd %xmm0, %xmm0
andq $0x0, 0x10(%r15)
movupd %xmm0, (%r15)
xorl %r12d, %r12d
movq 0x2be1d(%rip), %r13     # 0x33fd0
leaq 0x18282(%rip), %rbx     # 0x2043c
leaq 0x18292(%rip), %r14     # 0x20453
cmpl $0xa, %r12d
je 0x8289
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6420
movq %r13, %rdi
movq %r14, %rsi
callq 0x6420
movq %rax, %rdi
movl %r12d, %esi
callq 0x66e0
movq %rax, %rdi
leaq 0x18265(%rip), %rsi     # 0x2045b
callq 0x6420
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6420
movq %rax, %rdi
callq 0x61c0
movq 0x20(%rsp), %rdi
movl %ebp, %esi
leaq 0x30(%rsp), %rdx
movl 0x14(%rsp), %ecx
movq %r15, %r8
callq 0x6f65
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6420
movq %r13, %rdi
movq %r14, %rsi
callq 0x6420
movq %rax, %rdi
movl %r12d, %esi
callq 0x66e0
movq %rax, %rdi
leaq 0x1820e(%rip), %rsi     # 0x20465
callq 0x6420
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6420
movq %rax, %rdi
callq 0x61c0
movsd 0x8(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
incl %r12d
jmp 0x81c1
movq 0x2bd40(%rip), %rdi     # 0x33fd0
leaq 0x181a5(%rip), %rsi     # 0x2043c
callq 0x6420
movq 0x2bd2d(%rip), %rdi     # 0x33fd0
leaq 0x181c9(%rip), %rsi     # 0x20473
callq 0x6420
movq 0x2bd1a(%rip), %rdi     # 0x33fd0
leaq 0x1817f(%rip), %rsi     # 0x2043c
callq 0x6420
movq %rax, %rdi
callq 0x61c0
leaq 0x68(%rsp), %rsi
movq %r15, %r14
movq %r15, %rdi
callq 0x882a
movq %r14, %rdi
callq 0x88ee
movq %rax, %rbx
movq %r14, %rdi
callq 0x8916
movq %rax, %r12
movq %r14, %rdi
callq 0x892c
movq %rax, %r15
movq 0x2bcce(%rip), %rdi     # 0x33fd0
leaq 0x1817e(%rip), %rsi     # 0x20487
callq 0x6420
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x6650
leaq 0x1808f(%rip), %rsi     # 0x203b2
movq %rax, %rdi
callq 0x6420
movq %rax, %rdi
callq 0x61c0
movq 0x2bc96(%rip), %rdi     # 0x33fd0
leaq 0x17eb4(%rip), %rsi     # 0x201f5
callq 0x6420
imulq $0xa, 0x18(%rsp), %rcx
movq %rcx, %xmm1
punpckldq 0x17cc7(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x17ccf(%rip), %xmm1    # 0x20030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x8(%rsp), %xmm0
movq %rax, %rdi
callq 0x6650
leaq 0x17e96(%rip), %rsi     # 0x20218
movq %rax, %rdi
callq 0x6420
movq %rax, %rdi
movq %rbx, %rsi
callq 0x62c0
leaq 0x17e91(%rip), %rsi     # 0x2022d
movq %rax, %rdi
callq 0x6420
imulq $0xa064, 0x18(%rsp), %rcx # imm = 0xA064
movq %rcx, %xmm1
punpckldq 0x17c66(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x17c6e(%rip), %xmm1    # 0x20030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x17c3a(%rip), %xmm1    # 0x20010
movsd 0x8(%rsp), %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movq %rax, %rdi
callq 0x6650
leaq 0x17e48(%rip), %rsi     # 0x2023f
movq %rax, %rdi
callq 0x6420
movq %rax, %rdi
callq 0x61c0
movq 0x2bbc2(%rip), %rdi     # 0x33fd0
leaq 0x17e30(%rip), %rsi     # 0x20245
callq 0x6420
movq %rax, %rdi
movq %r12, %rsi
callq 0x62c0
leaq 0x17e3b(%rip), %rsi     # 0x20267
movq %rax, %rdi
callq 0x6420
movq %rax, %rdi
movq %r15, %rsi
callq 0x62c0
leaq 0x17e2a(%rip), %rsi     # 0x20270
movq %rax, %rdi
callq 0x6420
movq 0x68(%rsp), %rsi
movq %rax, %rdi
callq 0x62c0
leaq 0x17cd7(%rip), %rsi     # 0x20139
movq %rax, %rdi
callq 0x6420
movq %rax, %rdi
callq 0x61c0
movq 0x2bb57(%rip), %rdi     # 0x33fd0
leaq 0x17df9(%rip), %rsi     # 0x20279
callq 0x6420
movq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x62c0
leaq 0x17e02(%rip), %rsi     # 0x2029b
movq %rax, %rdi
callq 0x6420
movq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x62c0
leaq 0x17def(%rip), %rsi     # 0x202a4
movq %rax, %rdi
callq 0x6420
movq 0x80(%rsp), %rsi
movq %rax, %rdi
callq 0x62c0
leaq 0x17dd9(%rip), %rsi     # 0x202ad
movq %rax, %rdi
callq 0x6420
movq 0x88(%rsp), %rsi
movq %rax, %rdi
callq 0x62c0
leaq 0x17dc4(%rip), %rsi     # 0x202b7
movq %rax, %rdi
callq 0x6420
movq 0x90(%rsp), %rsi
movq %rax, %rdi
callq 0x62c0
movq %rax, %rdi
callq 0x61c0
movq %r14, %rdi
callq 0x8942
movq %r14, %rdi
callq 0x6410
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x8550
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x8550
movq 0x2ba94(%rip), %rdi     # 0x33fd0
leaq 0x17ee7(%rip), %rsi     # 0x2042a
callq 0x6420
movq %rax, %rdi
callq 0x61c0
leaq 0x30(%rsp), %rdi
callq 0x8958
leaq 0x48(%rsp), %rdi
callq 0x67f8
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x85a1
jmp 0x85a1
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x8594
jmp 0x85a1
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x67f8
jmp 0x85a4
jmp 0x85a1
jmp 0x85a1
jmp 0x85a1
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x8958
leaq 0x48(%rsp), %rdi
callq 0x67f8
movq %rbx, %rdi
callq 0x66f0