// File: /workspace/github_cpp_makefile_star2_O2/narges64[P]SIMBA/ssd.cpp
// Function: print_epoch_statistics(ssd_info*, int)
void print_epoch_statistics(ssd_info * ssd, int app_id){
	int epoch_num = ssd->current_time / EPOCH_LENGTH;
	fprintf(ssd->statisticfile, "epoch %d , current_time %lld \n", epoch_num, ssd->current_time);
	// =================== LATENCY ================================================================
	ssd->stats->total_flash_erase_count += ssd->stats->flash_erase_count;

	fprintf(ssd->statisticfile, "Latency epoch: %d \n", epoch_num);
	fprintf(ssd->statisticfile, "read RT avg %lld us , var %lld ms2, count %lld , max %lld us\n", ssd->stats->read_RT.get_average() , ssd->stats->read_RT.get_variance(), ssd->stats->read_RT.get_count(), ssd->stats->read_RT.get_max());
	fprintf(ssd->statisticfile, "write RT avg %lld us , var %lld ms2, count %lld , max %lld us \n", ssd->stats->write_RT.get_average(),ssd->stats->write_RT.get_variance(), ssd->stats->write_RT.get_count(), ssd->stats->write_RT.get_max());
	fprintf(ssd->statisticfile, "erase(gc) count %lld , total %lld\n", ssd->stats->flash_erase_count, ssd->stats->total_flash_erase_count);
	fprintf(ssd->statisticfile, "GC move count %d \n" , ssd->stats->gc_moved_page);
	ssd->stats->flash_erase_count = 0;

	// =================== SUBREQ STATES ===========================================================
	fprintf(ssd->statisticfile, "SUBREQ ep: %d time:\t", epoch_num);
	for (int i = 0; i < SR_MODE_NUM; i++){
		fprintf(ssd->statisticfile, "%lld\t",ssd->stats->subreq_state_time[i]);
		ssd->stats->subreq_state_time[i] = 0;
	}
	fprintf(ssd->statisticfile, "\n");

	// =================== LUN STATES ============================================================
	for (int i = 0; i < ssd->parameter->lun_num; i++){
		int channel_num = i % ssd->parameter->channel_number;
		int lun_num = (i / ssd->parameter->channel_number) % ssd->channel_head[channel_num]->lun_num;
		lun_info * the_lun = ssd->channel_head[channel_num]->lun_head[lun_num];
		fprintf(ssd->statisticfile, "lun ep: %d (%d,%d): ",epoch_num , channel_num, lun_num);
		for (int i = 0; i < LUN_MODE_NUM; i++){
			fprintf(ssd->statisticfile, "%lld\t", the_lun->state_time[i]);
			the_lun->state_time[i] = 0;
		}
		fprintf(ssd->statisticfile, "\n");
		for (int j = 0; j < ssd->parameter->plane_lun; j++){
			int plane_num = j;
			plane_info * the_plane = ssd->channel_head[channel_num]->lun_head[lun_num]->plane_head[plane_num];
			fprintf(ssd->statisticfile, "plane ep: %d (%d,%d,%d) ", epoch_num, channel_num, lun_num, plane_num);
			for (int i = 0; i < PLANE_MODE_NUM; i++){
				fprintf(ssd->statisticfile, "%lld\t",the_plane->state_time[i]);
				the_plane->state_time[i] = 0;
			}
			fprintf(ssd->statisticfile, "\n");
		}

	}
	// ==================== OTHER STATS ===================================
	fprintf(ssd->statisticfile, "Multiplane ep: %d read %lld , write %lld , erase %lld \n", epoch_num, ssd->stats->read_multiplane_count , ssd->stats->write_multiplane_count , ssd->stats->erase_multiplane_count);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movq (%rdi), %rcx
movq 0x50(%rdi), %rdi
movabsq $0x2540be400, %rsi      # imm = 0x2540BE400
movq %rcx, %rax
cqto
idivq %rsi
movq %rax, %r15
leaq 0x26a6(%rip), %rsi      # 0x9c26
xorl %ebx, %ebx
movl %r15d, %edx
xorl %eax, %eax
callq 0x2250
movq 0x98(%r14), %rax
movq 0x98(%rax), %rcx
addq %rcx, 0xa0(%rax)
movq 0x50(%r14), %rdi
leaq 0x2699(%rip), %rsi      # 0x9c45
movq %r15, (%rsp)
movl %r15d, %edx
xorl %eax, %eax
callq 0x2250
movq 0x50(%r14), %r12
movq 0x98(%r14), %rax
leaq 0x8(%rax), %rdi
movslq 0x8(%rax), %rcx
testq %rcx, %rcx
je 0x75de
movq 0x10(%rax), %rax
cqto
idivq %rcx
movq %rax, %rbx
callq 0x8914
movq 0x98(%r14), %rcx
movl 0x8(%rcx), %r8d
movq 0x20(%rcx), %r9
leaq 0x2660(%rip), %rsi      # 0x9c59
xorl %r15d, %r15d
movq %r12, %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2250
movq 0x50(%r14), %rbx
movq 0x98(%r14), %rax
leaq 0x30(%rax), %rdi
movslq 0x30(%rax), %rcx
testq %rcx, %rcx
je 0x7630
movq 0x38(%rax), %rax
cqto
idivq %rcx
movq %rax, %r15
callq 0x8914
movq 0x98(%r14), %rcx
movl 0x30(%rcx), %r8d
movq 0x48(%rcx), %r9
leaq 0x2785(%rip), %rsi      # 0x9dd0
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2250
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rax
movq 0x98(%rax), %rdx
movq 0xa0(%rax), %rcx
leaq 0x261c(%rip), %rsi      # 0x9c97
xorl %eax, %eax
callq 0x2250
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rax
movl 0xc8(%rax), %edx
leaq 0x2620(%rip), %rsi      # 0x9cba
xorl %eax, %eax
callq 0x2250
movq 0x98(%r14), %rax
andq $0x0, 0x98(%rax)
movq 0x50(%r14), %rdi
leaq 0x2612(%rip), %rsi      # 0x9ccd
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x2250
leaq 0x2615(%rip), %rbx      # 0x9ce2
xorl %r15d, %r15d
movq 0x50(%r14), %rsi
cmpq $0xa, %r15
je 0x7711
movq 0x98(%r14), %rax
movq 0x188(%rax), %rax
movq (%rax,%r15,8), %rdx
movq %rsi, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2250
movq 0x98(%r14), %rax
movq 0x188(%rax), %rax
andq $0x0, (%rax,%r15,8)
incq %r15
jmp 0x76d0
pushq $0xa
popq %rdi
callq 0x21f0
movq 0x58(%r14), %rcx
leaq 0x25be(%rip), %r13      # 0x9ce2
xorl %eax, %eax
cmpl 0x88(%rcx), %eax
jae 0x784f
movl %eax, 0xc(%rsp)
xorl %edx, %edx
divl 0x98(%rcx)
movl %edx, %ecx
movq 0x50(%r14), %rdi
movq 0x90(%r14), %rdx
movq (%rdx,%rcx,8), %rsi
xorl %edx, %edx
divl (%rsi)
movl %edx, %ebx
movq 0x50(%rsi), %rax
movq (%rax,%rbx,8), %r12
leaq 0x2584(%rip), %rsi      # 0x9ce8
movq (%rsp), %rdx
movq %rcx, 0x10(%rsp)
movl %ebx, %r8d
xorl %eax, %eax
callq 0x2250
xorl %ebp, %ebp
movq 0x50(%r14), %rsi
cmpq $0x3, %rbp
je 0x77ae
movq 0x90(%r12), %rax
movq (%rax,%rbp,8), %rdx
movq %rsi, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2250
movq 0x90(%r12), %rax
andq $0x0, (%rax,%rbp,8)
incq %rbp
jmp 0x7779
pushq $0xa
popq %rdi
callq 0x21f0
xorl %ebp, %ebp
movq 0x58(%r14), %rcx
movl 0x22c(%rcx), %eax
cmpq %rax, %rbp
jae 0x7844
movq 0x50(%r14), %rdi
movq 0x90(%r14), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rax
movq (%rax,%rbp,8), %r12
leaq 0x250c(%rip), %rsi      # 0x9cfd
movq (%rsp), %rdx
movl %ebx, %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0x2250
xorl %r15d, %r15d
movq 0x50(%r14), %rsi
cmpq $0x3, %r15
je 0x7834
movq 0x60(%r12), %rax
movq (%rax,%r15,8), %rdx
movq %rsi, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2250
movq 0x60(%r12), %rax
andq $0x0, (%rax,%r15,8)
incq %r15
jmp 0x7805
pushq $0xa
popq %rdi
callq 0x21f0
incq %rbp
jmp 0x77b8
movl 0xc(%rsp), %eax
incl %eax
jmp 0x7726
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rax
movq 0xe0(%rax), %rcx
movq 0xe8(%rax), %r8
movq 0xf0(%rax), %r9
leaq 0x24a0(%rip), %rsi      # 0x9d16
movq (%rsp), %rdx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2250