// File: /workspace/github_cpp_makefile_star2_O1/roberty65[P]bServer/frame/testClient/testBenchmark.cpp
// Function: main
int main(int argc, char **argv)
{
	if (argc < 2) {
usage:
		fprintf(stderr, "Usage: %s [-c cmd ] [ -S | A ] [-t thread-cnt] [-s pkg-size] host\n", argv[0]);
		fprintf(stderr, "    cmd=0: echo, 2: forward\n");
		fprintf(stderr, "    -S sync-req-rsp mode. default.\n");
		fprintf(stderr, "    -A async-req-rsp mode\n");
		exit(0);
	}

	int ch, sync = 1;
	while ((ch = getopt(argc, argv, "c:SAt:s:h")) != EOF) {
		switch (ch) {
		case 'c': cmd = atoi(optarg); break;
		case 'S': sync = 1; break;
		case 'A': sync = 0; break;
		case 't': tcnt = atoi(optarg); break;
		case 's': pkgSize = atoi(optarg); break;
		case 'h': goto usage;
		default: goto usage;
		}
	}

	if (optind >= argc) goto usage;
	host = strdup(argv[optind]);

	pkgSent = new long[tcnt];
	byteSent = new long[tcnt];
	pkgRspd = new long[tcnt];
	byteRspd = new long[tcnt];
	for (int i = 0; i < tcnt; ++i) pkgSent[i] = pkgRspd[i] = byteSent[i] = byteRspd[i] = 0;

	srandom(time(NULL));
	setbuf(stdout, NULL);

	pthread_t tids[tcnt];
	for (int i = 0; i < tcnt; ++i) {
		errno = pthread_create(&tids[i], NULL, sync ? sync_worker : async_worker, (void *)(long)i);
		if (errno) {
			fprintf(stdout, "create the %dth thread failed: %m\n", i);
			exit(1);
		}
	}

	long lastPkgSent = 0, lastPkgRspd = 0;
	long lastByteSent = 0, lastByteRspd = 0;
	struct timeval t1, t2;

	gettimeofday(&t1, NULL);
	while (true) {
		sleep(10);
		long thisPkgSent = 0, thisPkgRspd = 0;
		long thisByteSent = 0, thisByteRspd = 0;

		for (int i = 0; i < tcnt; ++i) {
			thisPkgSent += pkgSent[i];
			thisByteSent += byteSent[i];
			thisPkgRspd += pkgRspd[i];
			thisByteRspd += byteRspd[i];
		}

		gettimeofday(&t2, NULL);
		struct tm tmbuf, *ptm = localtime_r(&t2.tv_sec, &tmbuf);
		double ms = (t2.tv_sec - t1.tv_sec) * 1000.0 + (t2.tv_usec - t1.tv_usec) / 1000.0;

		fprintf(stdout, "%02d:%02d:%02d send %8ld %.2fpkg/s %.2fMB/s recv %8ld %.2fpkg/s %.2fMB/s\n",
			ptm->tm_hour, ptm->tm_min, ptm->tm_sec,
			thisPkgSent - lastPkgSent, 1000.0 * (thisPkgSent - lastPkgSent) / ms, 
			(thisByteSent - lastByteSent) / ms / 1000.0,
			thisPkgRspd - lastPkgRspd, 1000.0 * (thisPkgRspd - lastPkgRspd) / ms,
			(thisByteRspd - lastByteRspd) / ms / 1000.0);

		t1 = t2;
		lastPkgSent = thisPkgSent;
		lastByteSent = thisByteSent;
		lastPkgRspd = thisPkgRspd;
		lastByteRspd= thisByteRspd;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
cmpl $0x2, %edi
jl 0x2737
movl %edi, %r14d
movl $0x1, %r13d
leaq 0x1cd6(%rip), %r15      # 0x40af
movq 0x3be8(%rip), %r12      # 0x5fc8
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2060
cmpl $0x62, %eax
jle 0x2417
cmpl $0x74, %eax
je 0x2443
cmpl $0x73, %eax
je 0x2432
cmpl $0x63, %eax
jne 0x2737
movq (%r12), %rdi
callq 0x2230
movl %eax, 0x3d53(%rip)      # 0x6168
jmp 0x23e0
cmpl $-0x1, %eax
je 0x2459
cmpl $0x41, %eax
je 0x2454
cmpl $0x53, %eax
jne 0x2737
movl $0x1, %r13d
jmp 0x23e0
movq (%r12), %rdi
callq 0x2230
movl %eax, 0x3d2f(%rip)      # 0x6170
jmp 0x23e0
movq (%r12), %rdi
callq 0x2230
movl %eax, 0x3d1a(%rip)      # 0x616c
jmp 0x23e0
xorl %r13d, %r13d
jmp 0x23e0
movq 0x3b80(%rip), %rax      # 0x5fe0
movslq (%rax), %rax
cmpl %r14d, %eax
jge 0x2737
movl %r13d, -0x30(%rbp)
movq (%rbx,%rax,8), %rdi
callq 0x2280
movq %rax, 0x3cf8(%rip)      # 0x6178
movslq 0x3ce5(%rip), %r13      # 0x616c
leaq (,%r13,8), %rax
testq %r13, %r13
movq $-0x1, %r12
cmovnsq %rax, %r12
movq %r12, %rdi
callq 0x2030
movq %rax, %rbx
movq %rax, 0x3cd9(%rip)      # 0x6188
movq %r12, %rdi
callq 0x2030
movq %rax, %r14
movq %rax, 0x3ccf(%rip)      # 0x6190
movq %r12, %rdi
callq 0x2030
movq %rax, %r15
movq %rax, 0x3cc5(%rip)      # 0x6198
movq %r12, %rdi
callq 0x2030
movq %rax, 0x3cbe(%rip)      # 0x61a0
testq %r13, %r13
jle 0x2511
xorl %ecx, %ecx
movq $0x0, (%rax,%rcx,8)
movq (%rax,%rcx,8), %rdx
movq %rdx, (%r14,%rcx,8)
movq (%r14,%rcx,8), %rdx
movq %rdx, (%r15,%rcx,8)
movq (%r15,%rcx,8), %rdx
movq %rdx, (%rbx,%rcx,8)
incq %rcx
cmpq %rcx, %r13
jne 0x24e9
xorl %edi, %edi
callq 0x2170
movl %eax, %edi
callq 0x2070
movq 0x3a92(%rip), %rax      # 0x5fb8
movq (%rax), %rdi
xorl %esi, %esi
callq 0x21f0
movl 0x3c36(%rip), %eax      # 0x616c
movq %rsp, %rbx
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
subq %rcx, %rbx
movq %rbx, %rsp
testl %eax, %eax
jle 0x259f
cmpl $0x0, -0x30(%rbp)
leaq 0x3a9(%rip), %rax       # 0x2903
leaq 0x243(%rip), %r15       # 0x27a4
cmoveq %rax, %r15
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0x2270
movl %eax, %r12d
callq 0x2040
movl %r12d, (%rax)
testl %r12d, %r12d
jne 0x2712
incq %r14
movslq 0x3bd6(%rip), %rax      # 0x616c
addq $0x8, %rbx
cmpq %rax, %r14
jl 0x2568
xorl %r15d, %r15d
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x2250
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r13, -0x48(%rbp)
movq %r14, -0x50(%rbp)
movq %r15, -0x58(%rbp)
movq %r12, -0x30(%rbp)
movl $0xa, %edi
callq 0x2130
movslq 0x3b95(%rip), %rax      # 0x616c
testq %rax, %rax
jle 0x2621
movq 0x3ba5(%rip), %rcx      # 0x6188
movq 0x3ba6(%rip), %rdx      # 0x6190
movq 0x3ba7(%rip), %rsi      # 0x6198
movq 0x3ba8(%rip), %rdi      # 0x61a0
xorl %r8d, %r8d
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %r15d, %r15d
addq (%rcx,%r8,8), %r15
addq (%rdx,%r8,8), %r13
addq (%rsi,%r8,8), %r14
addq (%rdi,%r8,8), %r12
incq %r8
cmpq %r8, %rax
jne 0x2607
jmp 0x262d
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
leaq -0x68(%rbp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2250
movq %rbx, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x20e0
movq -0x68(%rbp), %rcx
subq -0x40(%rbp), %rcx
xorps %xmm4, %xmm4
cvtsi2sd %rcx, %xmm4
movq -0x60(%rbp), %rcx
subq -0x38(%rbp), %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd 0x1996(%rip), %xmm5     # 0x4008
divsd %xmm5, %xmm0
mulsd %xmm5, %xmm4
addsd %xmm0, %xmm4
movq %r15, %r9
subq -0x58(%rbp), %r9
movq %r13, %rcx
subq -0x48(%rbp), %rcx
movq 0x3925(%rip), %rdx      # 0x5fb8
movq (%rdx), %rdi
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
movq %r14, %r10
subq -0x50(%rbp), %r10
movq %r12, %rcx
subq -0x30(%rbp), %rcx
movl 0x8(%rax), %edx
xorps %xmm3, %xmm3
cvtsi2sd %rcx, %xmm3
movl (%rax), %r8d
movl 0x4(%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
mulsd %xmm5, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm1
divsd %xmm5, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r10, %xmm2
mulsd %xmm5, %xmm2
divsd %xmm4, %xmm2
divsd %xmm4, %xmm3
divsd %xmm5, %xmm3
subq $0x8, %rsp
leaq 0x19e4(%rip), %rsi      # 0x40dc
movb $0x4, %al
pushq %r10
callq 0x2200
addq $0x10, %rsp
movups -0x68(%rbp), %xmm0
movaps %xmm0, -0x40(%rbp)
jmp 0x25b6
movq 0x389f(%rip), %rax      # 0x5fb8
movq (%rax), %rdi
leaq 0x1996(%rip), %rsi      # 0x40b9
movl %r14d, %edx
xorl %eax, %eax
callq 0x2200
movl $0x1, %edi
callq 0x21c0
movq 0x389a(%rip), %r14      # 0x5fd8
movq (%r14), %rdi
movq (%rbx), %rdx
leaq 0x18c5(%rip), %rsi      # 0x4010
xorl %eax, %eax
callq 0x2200
movq (%r14), %rcx
leaq 0x18f7(%rip), %rdi      # 0x4053
movl $0x1c, %esi
movl $0x1, %edx
callq 0x2290
movq (%r14), %rcx
leaq 0x18fb(%rip), %rdi      # 0x4070
movl $0x23, %esi
movl $0x1, %edx
callq 0x2290
movq (%r14), %rcx
leaq 0x1906(%rip), %rdi      # 0x4094
movl $0x1a, %esi
movl $0x1, %edx
callq 0x2290
xorl %edi, %edi
callq 0x21c0