Esempio n. 1
0
File: stats.c Progetto: FPiriz/uperf
void
update_aggr_stat(uperf_shm_t *shm)
{
	int i;

	AGG_STAT(shm)->size = 0;
	AGG_STAT(shm)->count = 0;
	for (i = 0; i < shm->no_strands; i++) {
		newstats_t *ns = STRAND_STAT(shm_get_strand(shm, i));
		AGG_STAT(shm)->size += ns->size;
		AGG_STAT(shm)->count += ns->count;
	}
}
Esempio n. 2
0
static void
print_progress(uperf_shm_t *shm, newstats_t prev)
{
	if (ENABLED_STATS(options)) {
		newstats_t pns;
		update_aggr_stat(shm);
		(void) memcpy(&pns, AGG_STAT(shm), sizeof (pns));
		pns.start_time = prev.end_time;
		pns.size -= prev.size;
		pns.end_time = GETHRTIME();
		pns.count -= prev.count;
		(void) strlcpy(pns.name, prev.name, sizeof (pns.name));
		print_summary(&pns, 1);
	}
}
Esempio n. 3
0
int
master(workorder_t *w)
{
	int rc;
	int i;
	int thr_count;
	int nthr, nproc;
	int id;
	int goodbye_timeout = UPERF_GOODBYE_TIMEOUT;
	hrtime_t start, stop;
	uperf_shm_t *shm;
	goodbye_stat_t gtotal;
	int error;

	if ((shm = master_init(w)) == NULL)
		exit(1);

	/*
	 * We need to get the total number of threads to arm the
	 * start, and end barriers.
	 */
	nproc = workorder_num_strands_bytype(w, STRAND_TYPE_PROCESS);
	nthr = workorder_num_strands_bytype(w, STRAND_TYPE_THREAD);
	thr_count = nproc + nthr;

	if (handshake(shm, w) != UPERF_SUCCESS) {
		uperf_info("Error in handshake\n");
		shm_fini(shm);
		exit(1);
	}

	if (nthr == 0 && nproc != 0) {
		(void) printf("Starting %d processes running profile:%s ... ",
		    thr_count, w->name);
	} else if (nproc == 0 && nthr != 0) {
		(void) printf("Starting %d threads running profile:%s ... ",
		    thr_count, w->name);
	} else {
	(void) printf(
		"Starting %d threads, %d processes running profile:%s ... ",
		nthr, nproc, w->name);
	}
	(void) fflush(stdout);

	start = GETHRTIME();
	/* Traverse through the worklist and create threads */
	id = 0;
	for (i = 0; i < w->ngrp; i++) {
		w->grp[i].groupid = i;
		if (shm->global_error > 0)
			break;
		if (spawn_strands_group(shm, &w->grp[i], id) != 0)
			shm->global_error++;
		id += w->grp[i].nthreads;
	}

	if (shm->global_error > 0) {
		master_prepare_to_exit(shm);
		shm_fini(shm);
		return (UPERF_FAILURE);
	}
	stop = GETHRTIME();
	(void) printf(" %5.2f seconds\n", (stop-start)/1.0e+9);
	(void) fflush(stdout);

	/* Handshake end */
	if (handshake_end_master(shm, w) != UPERF_SUCCESS) {
		return (UPERF_FAILURE);
	}

#ifdef ENABLE_NETSTAT
	if (ENABLED_PACKET_STATS(options))
		netstat_snap(SNAP_BEGIN);
#endif /* ENABLE_NETSTAT */

	/*
	 * The main Loop.
	 * if either global_error is not 0 or master_poll returns 1
	 * let wait_for_strands know that.
	 */
	newstat_begin(0, AGG_STAT(shm), 0, 0);
	error =  master_poll(shm);
	if (error == 0 && shm->global_error != 0)
		error = shm->global_error;

	(void) wait_for_strands(shm, error);
	newstat_end(0, AGG_STAT(shm), 0, 0);

	shm->current_time = GETHRTIME();

#ifdef ENABLE_NETSTAT
	if (ENABLED_PACKET_STATS(options))
		netstat_snap(SNAP_END);
#endif /* ENABLE_NETSTAT */
	if (ENABLED_STATS(options)) {
		print_summary(AGG_STAT(shm), 0);
	}

	if (shm->global_error > 0) {
		/* decrease timeout coz no point in waiting */
		goodbye_timeout = 1000;
	}

	if (ENABLED_GROUP_STATS(options))
		print_group_details(shm);
	if (ENABLED_THREAD_STATS(options))
		print_strand_details(shm);
	if (ENABLED_TXN_STATS(options))
		print_txn_averages(shm);
	if (ENABLED_FLOWOP_STATS(options))
		print_flowop_averages(shm);
#ifdef ENABLE_NETSTAT
	if (ENABLED_PACKET_STATS(options))
		print_netstat();
#endif /* ENABLE_NETSTAT */
	if (ENABLED_ERROR_STATS(options)) {
		goodbye_stat_t local;

		(void) memset(&gtotal, 0, sizeof (goodbye_stat_t));
		if ((rc = say_goodbyes_and_close(&gtotal, goodbye_timeout))
		    == 0) {
			update_aggr_stat(shm);
			local.elapsed_time = (AGG_STAT(shm))->end_time
			    - (AGG_STAT(shm))->start_time;
			local.error = 0;
			local.bytes_xfer = (AGG_STAT(shm))->size;
			local.count = (AGG_STAT(shm))->count;
			print_goodbye_stat("master", &local);
			print_difference(local, gtotal);
		}
	}
	uperf_log_flush();

	if (ENABLED_HISTORY_STATS(options)) {
		(void) fclose(options.history_fd);
	}
	/* Cleanup */
	if (shm->global_error != 0) {
		(void) printf("\nWARNING: Errors detected during run\n");
		shm_fini(shm);
		exit(1);
	}
	shm_fini(shm);

	return (rc);
}
Esempio n. 4
0
static int
master_poll(uperf_shm_t *shm)
{
	int no_txn;
	int error;
	int curr_txn = 0;
	barrier_t *curr_bar;
	double time_to_print;
	newstats_t prev_ns;

	bzero(&prev_ns, sizeof (prev_ns));

	no_txn = workorder_max_txn(shm->workorder);
	shm->current_time = GETHRTIME();
	time_to_print = shm->current_time;

	/*
	 * The main event loop. It runs roughly at options.interval
	 * frequency.
	 * We come out of the loop if any of the following is true
	 * 1. If slaves send anything (they should not in normal circumstances)
	 * 2. All Transactions except the last one are complete
	 * 3. Error
	 */
	while (curr_txn < no_txn) {
		curr_bar = &shm->bar[curr_txn];
		if (shm->global_error > 0) {
			break;
		}
		error = poll_slaves();
		if (error != 0) {	/* msg arrived */
			/* Read slave msg and process it */
			(void) printf("\n*** Slave aborted! ***\n");
			shm->global_error++;
			break;
		}
		shm->current_time = GETHRTIME();
		shm_process_callouts(shm);

		if (BARRIER_REACHED(curr_bar)) { /* goto Next Txn */
			if (ENABLED_STATS(options)) {
				if (curr_txn != 0) {
					print_progress(shm, prev_ns);
					(void) printf("\n");
				}
				update_aggr_stat(shm);
				(void) memcpy(&prev_ns, AGG_STAT(shm),
				    sizeof (prev_ns));
				prev_ns.end_time = GETHRTIME();
				(void) snprintf(prev_ns.name,
						sizeof (prev_ns.name),
						"Txn%d", curr_txn + 1);
			}
			/*
			 * Ask slaves to begin curr_txn Ok to ignore
			 * return value as number of transactions
			 * per group may not be the same
			 */
			(void) send_command_to_slaves(UPERF_CMD_NEXT_TXN,
			    curr_txn);
			/* release barrier so master can also begin curr_txn */
			shm->txn_begin = GETHRTIME();
			unlock_barrier(curr_bar);
			curr_txn++;
		}

		shm->current_time = GETHRTIME();
		if (ENABLED_STATS(options) &&
		    (time_to_print <= shm->current_time)) {
			print_progress(shm, prev_ns);
			time_to_print = shm->current_time
			    + options.interval * 1.0e+6;
		}
	}
	while (shm->global_error == 0 && shm->finished == 0) {
		shm_process_callouts(shm);
		print_progress(shm, prev_ns);
		(void) poll(NULL, 0, 100);
	}
	if (ENABLED_STATS(options)) {
		(void) printf("\n");
		uperf_line();
	}
	if (shm->global_error > 0) {
		master_prepare_to_exit(shm);
		return (1);
	}
	if (ENABLED_ERROR_STATS(options))  {
		return (send_command_to_slaves(UPERF_CMD_SEND_STATS, 0));
	} else {
		return (0);
	}
}