struct report_segment report_real_time_throughput()

in src/throughputmanagement.c [40:82]


struct report_segment report_real_time_throughput(struct ntttcp_test_endpoint *tep,
						   struct report_segment last_checkpoint,
						   uint total_test_threads)
{
	struct report_segment this_checkpoint;

	uint64_t this_total_bytes = 0;
	uint64_t last_total_bytes = last_checkpoint.bytes;
	uint64_t total_bytes = 0;

	struct timeval this_check_time;
	struct timeval last_check_time = last_checkpoint.time;
	double test_time = 0;
	uint n = 0;

	for (n = 0; n < total_test_threads; n++) {
		if (tep->test->client_role == true)
			this_total_bytes += tep->client_streams[n]->total_bytes_transferred;
		else
			this_total_bytes += tep->server_streams[n]->total_bytes_transferred;
	}
	gettimeofday(&this_check_time, NULL);
	test_time = get_time_diff(&this_check_time, &last_check_time);
	total_bytes = this_total_bytes - last_total_bytes;

	if (!tep->test->quiet) {
		char *throughput = format_throughput(total_bytes, test_time);
		char line_end = '\n';
		if (tep->running_tty) {
			printf("%c[2K", 27); /* cleanup current line */
			line_end = '\r';
		}
		printf("%s: %s%c", "Real-time throughput", throughput, line_end);
		fflush(stdout);
		free(throughput);
	}

	this_checkpoint.interval_sec = test_time;
	this_checkpoint.time = this_check_time;
	this_checkpoint.bytes = this_total_bytes;

	return this_checkpoint;
}