// File: /workspace/github_cpp_makefile_star2_O1/shancheng[P]shancheng/db/sqlite_busyhandler_test.cpp
// Function: main
int main(int argc, char* argv[]) {
  po::options_description opts("Options");
  opts.add_options()
    ("threadcount",  po::value<size_t>(), "set thread count")
    ("busytimeout",  po::value<size_t>(), "set busy timeout value (ms)")
    ("debug",                             "debug mode")
    ("help,h",                            "show the help");

  po::variables_map vm;
  po::store(po::parse_command_line(argc, argv, opts), vm);
  po::notify(vm);
  if (vm.count("help") > 0 ) {
    cout << opts << "\n";
    return 0;
  }
  if (vm.count("threadcount") > 0) {
    option.threadcount = vm["threadcount"].as<size_t>();
  }
  if (vm.count("busytimeout") > 0) {
    option.busytimeout = vm["busytimeout"].as<size_t>();
  }
  if (vm.count("debug") > 0) {
    option.debug = true;
  }
  option.Print(cout);

  boost::thread_group threadgroup;
  dbvec.resize(option.threadcount);
  time_t begin = time(NULL);
  for (size_t i = 0; i < option.threadcount; ++i) {
    if (sqlite3_open("concurrencytest.db", &dbvec[i]) != SQLITE_OK) {
      cerr << "Failed to open database\n";
      goto cleanup;
    }
    if (sqlite3_busy_handler(dbvec[i], BusyHandler, NULL) != SQLITE_OK) {
      cerr << "Failed to set busy handler (" << sqlite3_errmsg(dbvec[i]) << ")\n";
      goto cleanup;
    }
  }
  for (size_t i = 0; i < option.threadcount; ++i) {
    threadgroup.create_thread(Job(i, dbvec[i]));
  }
  for (size_t i = 0; ; ++i) {
    sleep(1);
    time_t now = time(NULL);
    cout << i << " IOPS: " << 1000L * total_iocount / (now - begin) << " busy count:" << total_busycount << "\n";
  }
  threadgroup.join_all();

cleanup:
  for (size_t i = 0; i < option.threadcount; ++i) {
    sqlite3_close(dbvec[i]);
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rsi, %rbx
movl %edi, %ebp
leaq 0xb0(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x85fb(%rip), %rsi      # 0x10020
leaq 0x85fb(%rip), %rdx      # 0x10027
leaq 0xa0(%rsp), %rdi
callq 0xa256
movq 0x10548(%rip), %rax     # 0x17f88
movl (%rax), %edx
movl %edx, %ecx
shrl %ecx
leaq 0x20(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x74e0
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x7a75
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x73b0
leaq 0x20(%rsp), %rdi
callq 0x7440
movq %rax, 0xa0(%rsp)
xorl %edi, %edi
callq 0xac1b
leaq 0x8593(%rip), %rsi      # 0x10028
leaq 0x8598(%rip), %rcx      # 0x10034
leaq 0xa0(%rsp), %rdi
movq %rax, %rdx
callq 0x7700
movq %rax, %r14
xorl %edi, %edi
callq 0xac1b
leaq 0x8588(%rip), %rsi      # 0x10045
leaq 0x858d(%rip), %rcx      # 0x10051
movq %r14, %rdi
movq %rax, %rdx
callq 0x7700
leaq 0x8597(%rip), %rsi      # 0x1006d
leaq 0x8596(%rip), %rdx      # 0x10073
movq %rax, %rdi
callq 0x76c0
leaq 0x8592(%rip), %rsi      # 0x1007e
leaq 0x8592(%rip), %rdx      # 0x10085
movq %rax, %rdi
callq 0x76c0
leaq 0x218(%rsp), %rdi
callq 0x7150
xorps %xmm0, %xmm0
leaq 0x1f0(%rsp), %r9
movaps %xmm0, (%r9)
movaps %xmm0, 0x10(%r9)
leaq 0xa0(%rsp), %rdi
leaq 0x20(%rsp), %rcx
movl %ebp, %esi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x8e03
leaq 0xa0(%rsp), %rdi
leaq 0x218(%rsp), %rsi
xorl %edx, %edx
callq 0x7670
leaq 0xa0(%rsp), %rdi
callq 0x95c0
leaq 0x1f0(%rsp), %rdi
callq 0x8efe
leaq 0x218(%rsp), %rdi
callq 0x7210
leaq 0xa0(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x8508(%rip), %rsi      # 0x1008e
leaq 0x8505(%rip), %rdx      # 0x10092
callq 0xa256
leaq 0x228(%rsp), %rbx
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdi
callq 0xe110
movq %rax, %r14
leaq 0x230(%rsp), %r12
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x7bd2
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x73b0
cmpq %r12, %r14
je 0x7c01
movq 0x103d2(%rip), %rdi     # 0x17fb0
leaq 0x20(%rsp), %rsi
callq 0x70b0
leaq 0x850e(%rip), %rsi      # 0x100fd
movl $0x1, %edx
movq %rax, %rdi
callq 0x7420
jmp 0x80f2
leaq 0xa0(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x8415(%rip), %rsi      # 0x10028
leaq 0x8419(%rip), %rdx      # 0x10033
callq 0xa256
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdi
callq 0xe110
movq %rax, %r14
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x7c4f
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x73b0
cmpq %r12, %r14
je 0x7cb6
leaq 0xa0(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x83c2(%rip), %rsi      # 0x10028
leaq 0x83c6(%rip), %rdx      # 0x10033
callq 0xa256
leaq 0x218(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x73e0
movq %rax, %rdi
callq 0xe199
movq (%rax), %rax
movq %rax, 0x10737(%rip)     # 0x183d0
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x7cb6
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x73b0
leaq 0xa0(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x837d(%rip), %rsi      # 0x10045
leaq 0x8381(%rip), %rdx      # 0x10050
callq 0xa256
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdi
callq 0xe110
movq %rax, %r14
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x7d04
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x73b0
cmpq %r12, %r14
je 0x7d6b
leaq 0xa0(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x832a(%rip), %rsi      # 0x10045
leaq 0x832e(%rip), %rdx      # 0x10050
callq 0xa256
leaq 0x218(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x73e0
movq %rax, %rdi
callq 0xe199
movq (%rax), %rax
movq %rax, 0x1068a(%rip)     # 0x183d8
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x7d6b
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x73b0
leaq 0xa0(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x82f0(%rip), %rsi      # 0x1006d
leaq 0x82ee(%rip), %rdx      # 0x10072
callq 0xa256
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdi
callq 0xe110
movq %rax, %r14
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x7db9
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x73b0
cmpq %r12, %r14
je 0x7dc5
movb $0x1, 0x1061b(%rip)     # 0x183e0
movq 0x101e4(%rip), %rdi     # 0x17fb0
leaq 0x8321(%rip), %rsi      # 0x100f4
movl $0xa, %edx
callq 0x7420
movq 0x101cc(%rip), %rdi     # 0x17fb0
leaq 0x8314(%rip), %rsi      # 0x100ff
movl $0x42, %edx
callq 0x7420
movq 0x101b4(%rip), %rdi     # 0x17fb0
leaq 0x833f(%rip), %rsi      # 0x10142
movl $0xe, %edx
callq 0x7420
movq 0x105bc(%rip), %rsi     # 0x183d0
movq 0x10195(%rip), %rdi     # 0x17fb0
callq 0x7280
leaq 0x82d6(%rip), %rsi      # 0x100fd
movl $0x1, %edx
movq %rax, %rdi
callq 0x7420
movq 0x10175(%rip), %rdi     # 0x17fb0
leaq 0x830f(%rip), %rsi      # 0x10151
movl $0xe, %edx
callq 0x7420
movq 0x10585(%rip), %rsi     # 0x183d8
movq 0x10156(%rip), %rdi     # 0x17fb0
callq 0x7280
leaq 0x8297(%rip), %rsi      # 0x100fd
movl $0x1, %edx
movq %rax, %rdi
callq 0x7420
movq 0x10136(%rip), %rdi     # 0x17fb0
leaq 0x82df(%rip), %rsi      # 0x10160
movl $0xc, %edx
callq 0x7420
movzbl 0x1054e(%rip), %esi     # 0x183e0
movq 0x10117(%rip), %rdi     # 0x17fb0
callq 0x7600
leaq 0x8258(%rip), %rsi      # 0x100fd
movl $0x1, %edx
movq %rax, %rdi
callq 0x7420
movq 0x100f7(%rip), %rdi     # 0x17fb0
leaq 0x823d(%rip), %rsi      # 0x100fd
movl $0x1, %edx
callq 0x7420
leaq 0xa0(%rsp), %rdi
callq 0x8f36
movq 0x104f2(%rip), %rsi     # 0x183d0
leaq 0x10503(%rip), %rdi     # 0x183e8
callq 0x8f84
xorl %edi, %edi
callq 0x7360
movq %rax, 0x18(%rsp)
movl $0x2, %ebp
cmpq $0x0, 0x104cd(%rip)     # 0x183d0
je 0x7ff4
xorl %r14d, %r14d
leaq 0x8180(%rip), %r12      # 0x10093
leaq 0x818c(%rip), %r15      # 0x100a6
leaq 0x5e0(%rip), %r13       # 0x8501
leaq (,%r14,8), %rsi
addq 0x104b8(%rip), %rsi     # 0x183e8
movq %r12, %rdi
callq 0x7660
testl %eax, %eax
jne 0x7f66
movq 0x104a5(%rip), %rax     # 0x183e8
movq (%rax,%r14,8), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x73d0
testl %eax, %eax
jne 0x7f6d
incq %r14
cmpq 0x10471(%rip), %r14     # 0x183d0
jb 0x7f21
jmp 0x7ff4
movl $0x18, %edx
jmp 0x7fe0
movq 0x1007c(%rip), %r15     # 0x17ff0
leaq 0x8144(%rip), %rsi      # 0x100bf
movl $0x1c, %edx
movq %r15, %rdi
callq 0x7420
movq 0x10459(%rip), %rax     # 0x183e8
movq (%rax,%r14,8), %rdi
callq 0x7380
movq %rax, %r12
testq %rax, %rax
je 0x7fbc
movq %r12, %rdi
callq 0x7160
movq 0x10041(%rip), %rdi     # 0x17ff0
movq %r12, %rsi
movq %rax, %rdx
callq 0x7420
jmp 0x7fd4
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x7630
movl $0x2, %edx
leaq 0x80fc(%rip), %r15      # 0x100dc
movl $0x5, %ebp
movq 0x10004(%rip), %rdi     # 0x17ff0
movq %r15, %rsi
callq 0x7420
cmpl $0x5, %ebp
je 0x80bc
cmpl $0x2, %ebp
jne 0x80e5
cmpq $0x0, 0x103c2(%rip)     # 0x183d0
jne 0x81a4
xorl %ebx, %ebx
movq 0xff93(%rip), %r14      # 0x17fb0
leaq 0x80c3(%rip), %r13      # 0x100e7
leaq 0x80d2(%rip), %rbp      # 0x100fd
movl $0x1, %edi
callq 0x72c0
xorl %edi, %edi
callq 0x7360
movq %rax, %r15
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7280
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x8083(%rip), %rsi      # 0x100df
callq 0x7420
movl 0x10399(%rip), %eax     # 0x18400
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
subq 0x18(%rsp), %r15
xorl %edx, %edx
idivq %r15
movq %r12, %rdi
movq %rax, %rsi
callq 0x7370
movq %rax, %r15
movl $0xc, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x7420
movl 0x10368(%rip), %esi     # 0x18404
movq %r15, %rdi
callq 0x7280
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x7420
incq %rbx
jmp 0x802b
cmpq $0x0, 0x1030c(%rip)     # 0x183d0
je 0x80e5
xorl %r14d, %r14d
movq 0x10318(%rip), %rax     # 0x183e8
movq (%rax,%r14,8), %rdi
callq 0x71a0
incq %r14
cmpq 0x102ed(%rip), %r14     # 0x183d0
jb 0x80c9
leaq 0xa0(%rsp), %rdi
callq 0x8fb6
movq 0xfec7(%rip), %rax      # 0x17fc0
addq $0x10, %rax
leaq 0x288(%rsp), %rdi
movq %rax, -0x70(%rdi)
callq 0xa036
leaq 0x258(%rsp), %rdi
callq 0xa0c8
movq %rbx, %rdi
callq 0xa140
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0xa1d2
movq -0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x8168
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x73b0
xorl %eax, %eax
movq %rax, 0x60(%rsp)
movl %eax, 0x68(%rsp)
movq %rax, 0x70(%rsp)
movl %eax, 0x78(%rsp)
movq %rax, 0x80(%rsp)
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0xa214
movq -0x28(%rbx), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x8190
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x73b0
xorl %eax, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
xorl %ebx, %ebx
movq 0x10238(%rip), %rax     # 0x183e8
movq (%rax,%rbx,8), %r14
leaq 0xb8(%rsp), %rdi
callq 0xe6f4
movl $0x10, %edi
callq 0x7390
movq %rax, %r13
movl $0x150, %edi            # imm = 0x150
callq 0x7390
movq %rax, %rbp
movq %rax, %rdi
callq 0xf68a
movq %r15, %rax
sarq $0x20, %rax
leaq 0xfaaf(%rip), %rcx      # 0x17ca0
movq %rcx, (%rbp)
movq %rax, 0x138(%rbp)
movq %r14, 0x140(%rbp)
xorl %eax, %eax
movq %rax, 0x148(%rbp)
movq %rbp, (%r13)
movq %r13, %r12
addq $0x8, %r12
movq %rax, 0x8(%r13)
movq %rax, 0x8(%rsp)
movl $0x18, %edi
callq 0x7390
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0xfaa9(%rip), %rcx      # 0x17ce8
movq %rcx, (%rax)
movq %rbp, 0x10(%rax)
movq %rax, 0x8(%rsp)
movq %rax, (%r12)
movq $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
callq 0xa004
movq 0x10(%rbp), %rax
testq %rax, %rax
je 0x8272
movl 0x8(%rax), %eax
testl %eax, %eax
jne 0x82a9
movq %rbp, 0x8(%rsp)
movq (%r12), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x8289
lock
incl 0x8(%rax)
movq %rbp, %rdi
addq $0x10, %rdi
movq %rbp, 0x8(%rbp)
leaq 0x10(%rsp), %r14
movq %r14, %rsi
callq 0xf912
movq %r14, %rdi
callq 0xa004
movq %r13, %rdi
callq 0xf610
movl $0x18, %edi
callq 0x7390
movq %r13, 0x10(%rax)
movq %rax, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x7050
incq 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xf956
incq %rbx
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r15
cmpq 0x100d5(%rip), %rbx     # 0x183d0
jb 0x81a9
jmp 0x8014
jmp 0x838b
movq %rax, %rbx
movq %r13, %rdi
callq 0x9fb4
jmp 0x835d
movq %rax, %rbx
jmp 0x833c
movq %rax, %rdi
callq 0x7140
movq (%rbp), %rax
movq %rbp, %rdi
callq *0x8(%rax)
callq 0x7530
movq %rax, %rbx
callq 0x75e0
movq %r12, %rdi
callq 0xa004
jmp 0x835d
jmp 0x838b
movq %rax, %rbx
movl $0x150, %esi            # imm = 0x150
movq %rbp, %rdi
callq 0x73b0
jmp 0x835d
movq %rax, %rbx
movl $0x10, %esi
movq %r13, %rdi
callq 0x73b0
leaq 0xb8(%rsp), %rdi
callq 0xf956
jmp 0x843f
movq %rax, %rbx
jmp 0x836a
jmp 0x843c
jmp 0x843c
movq %rax, %rdi
callq 0x8cb4
jmp 0x843c
jmp 0x844e
jmp 0x844e
jmp 0x843c
jmp 0x844e
jmp 0x83c7
jmp 0x844e
jmp 0x83c7
jmp 0x844e
jmp 0x83c7
jmp 0x844e
jmp 0x843c
jmp 0x83c7
jmp 0x83c7
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x8451
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x73b0
jmp 0x8451
jmp 0x844e
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x95c0
jmp 0x8400
movq %rax, %rbx
leaq 0x1f0(%rsp), %rdi
callq 0x8efe
jmp 0x8451
jmp 0x8489
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x84f9
movq 0xb0(%rsp), %rsi
jmp 0x84f1
movq %rax, %rbx
jmp 0x84f9
jmp 0x843c
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x8fb6
jmp 0x8451
movq %rax, %rbx
movq 0xfb68(%rip), %rax      # 0x17fc0
addq $0x10, %rax
leaq 0x288(%rsp), %rdi
movq %rax, -0x70(%rdi)
callq 0xa036
leaq 0x258(%rsp), %rdi
callq 0xa0c8
leaq 0x228(%rsp), %rdi
callq 0xa140
jmp 0x848c
movq %rax, %rbx
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0xa1d2
movq -0x28(%r14), %rdi
testq %rdi, %rdi
je 0x84d1
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x73b0
xorl %eax, %eax
movq %rax, 0x60(%rsp)
movl %eax, 0x68(%rsp)
movq %rax, 0x70(%rsp)
movl %eax, 0x78(%rsp)
movq %rax, 0x80(%rsp)
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0xa214
movq -0x28(%r14), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x84f9
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x73b0
movq %rbx, %rdi
callq 0x7680