// File: /workspace/github_cpp_makefile_star2_O2/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 0x244a
movl %edi, %r14d
pushq $0x1
popq %r12
leaq 0x1cd8(%rip), %r15      # 0x40af
movq 0x3bea(%rip), %r13      # 0x5fc8
movl %r12d, -0x30(%rbp)
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2060
cmpl $0x63, %eax
je 0x2421
cmpl $0x73, %eax
je 0x2410
cmpl $0x74, %eax
jne 0x2432
movq (%r13), %rdi
callq 0x2230
movl %eax, 0x3d5e(%rip)      # 0x616c
jmp 0x23e2
movq (%r13), %rdi
callq 0x2230
movl %eax, 0x3d51(%rip)      # 0x6170
jmp 0x23e2
movq (%r13), %rdi
callq 0x2230
movl %eax, 0x3d38(%rip)      # 0x6168
jmp 0x23e2
cmpl $-0x1, %eax
je 0x24ae
cmpl $0x41, %eax
jne 0x2445
movl $0x0, -0x30(%rbp)
jmp 0x23e2
cmpl $0x53, %eax
je 0x23de
movq 0x3b87(%rip), %r14      # 0x5fd8
movq (%r14), %rdi
movq (%rbx), %rdx
leaq 0x1bb2(%rip), %rsi      # 0x4010
xorl %eax, %eax
callq 0x2200
movq (%r14), %rcx
leaq 0x1be4(%rip), %rdi      # 0x4053
pushq $0x1c
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x2290
movq (%r14), %rcx
leaq 0x1be9(%rip), %rdi      # 0x4070
pushq $0x23
popq %rsi
movq %rbx, %rdx
callq 0x2290
movq (%r14), %rcx
leaq 0x1bf8(%rip), %rdi      # 0x4094
pushq $0x1a
popq %rsi
movq %rbx, %rdx
callq 0x2290
xorl %edi, %edi
callq 0x21c0
movq 0x3b2b(%rip), %rax      # 0x5fe0
movslq (%rax), %rax
cmpl %r14d, %eax
jge 0x244a
movq (%rbx,%rax,8), %rdi
callq 0x2280
movq %rax, 0x3cab(%rip)      # 0x6178
movslq 0x3c98(%rip), %r13      # 0x616c
leaq (,%r13,8), %rax
testq %r13, %r13
pushq $-0x1
popq %r12
cmovnsq %rax, %r12
movq %r12, %rdi
callq 0x2030
movq %rax, %rbx
movq %rax, 0x3c8f(%rip)      # 0x6188
movq %r12, %rdi
callq 0x2030
movq %rax, %r14
movq %rax, 0x3c85(%rip)      # 0x6190
movq %r12, %rdi
callq 0x2030
movq %rax, %r15
movq %rax, 0x3c7b(%rip)      # 0x6198
movq %r12, %rdi
callq 0x2030
movq %rax, 0x3c74(%rip)      # 0x61a0
xorl %ecx, %ecx
testl %r13d, %r13d
movl $0x0, %edx
cmovgl %r13d, %edx
cmpq %rcx, %rdx
je 0x2564
movq $0x0, (%rax,%rcx,8)
movq (%rax,%rcx,8), %rsi
movq %rsi, (%r14,%rcx,8)
movq (%r14,%rcx,8), %rsi
movq %rsi, (%r15,%rcx,8)
movq (%r15,%rcx,8), %rsi
movq %rsi, (%rbx,%rcx,8)
incq %rcx
jmp 0x253a
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x2170
movl %eax, %edi
callq 0x2070
movq 0x3a3d(%rip), %rax      # 0x5fb8
movq (%rax), %rdi
xorl %esi, %esi
callq 0x21f0
movl 0x3be1(%rip), %eax      # 0x616c
movq %rsp, %r14
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
subq %rcx, %r14
movq %r14, %rsp
cmpl $0x0, -0x30(%rbp)
leaq 0x317(%rip), %rcx       # 0x28c2
leaq 0x1b5(%rip), %r15       # 0x2767
cmoveq %rcx, %r15
cltq
cmpq %rax, %rbx
jge 0x25f0
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2270
movl %eax, %r12d
callq 0x2040
movl %r12d, (%rax)
testl %r12d, %r12d
jne 0x2745
incq %rbx
movl 0x3b82(%rip), %eax      # 0x616c
addq $0x8, %r14
jmp 0x25b6
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x2250
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %r13, -0x48(%rbp)
movq %r15, -0x50(%rbp)
movq %rbx, -0x58(%rbp)
movq %r12, -0x30(%rbp)
pushq $0xa
popq %rdi
callq 0x2130
movl 0x3b48(%rip), %eax      # 0x616c
movq 0x3b5d(%rip), %rcx      # 0x6188
movq 0x3b5e(%rip), %rdx      # 0x6190
movq 0x3b5f(%rip), %rsi      # 0x6198
movq 0x3b60(%rip), %rdi      # 0x61a0
testl %eax, %eax
movl $0x0, %r8d
cmovlel %r8d, %eax
xorl %r8d, %r8d
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq %r8, %rax
je 0x2674
addq (%rcx,%r8,8), %r13
addq (%rdx,%r8,8), %r15
addq (%rsi,%r8,8), %rbx
addq (%rdi,%r8,8), %r12
incq %r8
jmp 0x265a
leaq -0x68(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2250
movq %r14, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x20e0
movq -0x68(%rbp), %rcx
subq -0x40(%rbp), %rcx
cvtsi2sd %rcx, %xmm4
movq -0x60(%rbp), %rcx
subq -0x38(%rbp), %rcx
cvtsi2sd %rcx, %xmm0
movsd 0x1955(%rip), %xmm5     # 0x4008
divsd %xmm5, %xmm0
mulsd %xmm5, %xmm4
addsd %xmm0, %xmm4
movq %r13, %r9
subq -0x48(%rbp), %r9
movq %r15, %rcx
subq -0x50(%rbp), %rcx
movq 0x38e4(%rip), %rdx      # 0x5fb8
movq (%rdx), %rdi
cvtsi2sd %rcx, %xmm1
movq %rbx, %r10
subq -0x58(%rbp), %r10
movq %r12, %rcx
subq -0x30(%rbp), %rcx
movl 0x8(%rax), %edx
cvtsi2sd %rcx, %xmm3
movl (%rax), %r8d
movl 0x4(%rax), %ecx
cvtsi2sd %r9, %xmm0
mulsd %xmm5, %xmm0
divsd %xmm4, %xmm0
divsd %xmm4, %xmm1
divsd %xmm5, %xmm1
cvtsi2sd %r10, %xmm2
mulsd %xmm5, %xmm2
divsd %xmm4, %xmm2
divsd %xmm4, %xmm3
divsd %xmm5, %xmm3
subq $0x8, %rsp
leaq 0x19af(%rip), %rsi      # 0x40dc
movb $0x4, %al
pushq %r10
callq 0x2200
popq %rcx
popq %rdx
movups -0x68(%rbp), %xmm0
movaps %xmm0, -0x40(%rbp)
jmp 0x2606
movq 0x386c(%rip), %rax      # 0x5fb8
movq (%rax), %rdi
leaq 0x1963(%rip), %rsi      # 0x40b9
movl %ebx, %edx
xorl %eax, %eax
callq 0x2200
pushq $0x1
popq %rdi
callq 0x21c0