Пример #1
0
static void print_detailed_data(int loop, FILE* fp)
{
	char buf[256], buf2[256];
	int i;

	for (i = 0; i < N; ++i) {
		struct tm tbuf, *ptm = localtime_r(&conn_times[i].t_connection_start.tv_sec, &tbuf);
		fprintf(detailed_fp, "%05d-%05d %s -> %s total: %5.2f dns: %5.2f conn: %5.2f start at %02d:%02d:%02d.%06ld"
		       " send: %5.2f first-byte: %5.2f, rest-bytes: %5.2f close: %5.2f\n",
			loop, i,
			in_addr2n(&conn_times[i].addr_local, buf, sizeof buf),
			in_addr2n(&conn_times[i].addr_peer, buf2, sizeof buf2),
			DMS(&conn_times[i].t_dns_start, &conn_times[i].t_close_end),
			DMS(&conn_times[i].t_dns_start, &conn_times[i].t_dns_end),
			DMS(&conn_times[i].t_connection_start, &conn_times[i].t_connection_end),
			ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (long)conn_times[i].t_connection_start.tv_usec,	
			DMS(&conn_times[i].t_connection_end, &conn_times[i].t_sent),
			DMS(&conn_times[i].t_sent, &conn_times[i].t_first_byte),
			DMS(&conn_times[i].t_first_byte, &conn_times[i].t_last_byte),
			DMS(&conn_times[i].t_last_byte, &conn_times[i].t_close_end));
	}
}
Пример #2
0
static void summary_and_print_stat(int loop, time_t time, FILE* fp)
{
	int i, n;
	struct connection_stat_raw *raw;

	// get the maximum time
	double max = 0.0;
	for (i = 0; i < N; ++i) {
		double dms = DMS(&conn_times[i].t_dns_start, &conn_times[i].t_close_end);
		if (max < dms) max = dms;
	}

	n = (int)(max + gap) / gap;
	raw = (struct connection_stat_raw *)calloc(n, sizeof(*raw));

	for (i = 0; i < N; ++i) {
		double dms, tot = DMS(&conn_times[i].t_dns_start, &conn_times[i].t_close_end);
		double threshold = tot * per;
		int bn = 0, idx = (int)tot / gap;

		++raw[idx].count;
		raw[idx].tot_total += tot;
		
		dms = DMS(&conn_times[i].t_dns_start, &conn_times[i].t_dns_end);
		raw[idx].tot_dns += dms;
		if (dms >= threshold) { ++raw[idx].per_dns; ++bn; }

		dms = DMS(&conn_times[i].t_connection_start, &conn_times[i].t_connection_end);
		raw[idx].tot_connect += dms;
		if (dms >= threshold) { ++raw[idx].per_connect; ++bn; }

		dms = DMS(&conn_times[i].t_connection_end, &conn_times[i].t_sent);
		raw[idx].tot_send += dms;
		if (dms >= threshold) { ++raw[idx].per_send; ++bn; }

		dms = DMS(&conn_times[i].t_sent, &conn_times[i].t_first_byte);
		raw[idx].tot_first_byte += dms;
		if (dms >= threshold) { ++raw[idx].per_first_byte; ++bn; }

		dms = DMS(&conn_times[i].t_first_byte, &conn_times[i].t_last_byte);
		raw[idx].tot_rest_byte += dms;
		if (dms >= threshold) { ++raw[idx].per_rest_byte; ++bn; }

		dms = DMS(&conn_times[i].t_last_byte, &conn_times[i].t_close_end);
		raw[idx].tot_close += dms;
		if (dms >= threshold) { ++raw[idx].per_close; ++bn; }

		if (!bn) ++raw[idx].per_other;
	}

	conn_stats[loop].time = time;
	conn_stats[loop].count = n;
	conn_stats[loop].stats = (struct connection_stat_sum *)calloc(n, sizeof *conn_stats[loop].stats);
	if (conn_stats[loop].stats == NULL) {
		perror("calloc failed");
		exit(9);
	}

	for (i = 0; i < n; ++i) {
		if (raw[i].count < 1) continue;
		conn_stats[loop].stats[i].count = raw[i].count;
		conn_stats[loop].stats[i].avg_total = raw[i].tot_total / raw[i].count;
		conn_stats[loop].stats[i].avg_dns = raw[i].tot_dns / raw[i].count;
		conn_stats[loop].stats[i].avg_connect = raw[i].tot_connect / raw[i].count;
		conn_stats[loop].stats[i].avg_send = raw[i].tot_send / raw[i].count;
		conn_stats[loop].stats[i].avg_first_byte = raw[i].tot_first_byte / raw[i].count;
		conn_stats[loop].stats[i].avg_rest_byte = raw[i].tot_rest_byte / raw[i].count;
		conn_stats[loop].stats[i].avg_close = raw[i].tot_close / raw[i].count;

		conn_stats[loop].stats[i].per_total = (double)raw[i].count / N;
		conn_stats[loop].stats[i].per_dns = (double)raw[i].per_dns / raw[i].count;
		conn_stats[loop].stats[i].per_connect = (double)raw[i].per_connect / raw[i].count;
		conn_stats[loop].stats[i].per_send = (double)raw[i].per_send / raw[i].count;
		conn_stats[loop].stats[i].per_first_byte = (double)raw[i].per_first_byte / raw[i].count;
		conn_stats[loop].stats[i].per_rest_byte = (double)raw[i].per_rest_byte / raw[i].count;
		conn_stats[loop].stats[i].per_close = (double)raw[i].per_close / raw[i].count;
		conn_stats[loop].stats[i].per_other = (double)raw[i].per_other / raw[i].count;
	}

	struct tm tbuf, *ptm = localtime_r(&conn_stats[loop].time, &tbuf);
	fprintf(fp, "***** loop: %05d %04d-%02d-%02d %02d:%02d:%02d *****\n", loop,
		ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday,
		ptm->tm_hour, ptm->tm_min, ptm->tm_sec);

	fprintf(fp, "range(ms)\tcount\tpercent(%%)\tavg-total\tavg-dns\tavg-connect\tavg-send\tavg-first-byte\t"
		    "avg-transfer\tavg-close\t\tper-dns(%%)\tper-connect(%%)\tper-send(%%)\tper-first-byte(%%)\t"
		    "per-transfer(%%)\tper-close(%%)\tper-other(%%)\n");
	for (i = 0; i < n; ++i) {
		if (conn_stats[loop].stats[i].count < 1) continue;
		fprintf(fp, "%05d[%ld, %ld)\t%ld\t%5.3f\t%5.2f\t%5.2f\t%5.2f\t%5.2f\t"
			    "%5.2f\t%5.2f\t%5.2f\t\t%3.1f\t%3.1f%\t"
			    "%3.1f\t%3.1f\t%3.1f\t%3.1f\t%3.1f\n",
			i, gap * i, gap * (i + 1),
			conn_stats[loop].stats[i].count,
			conn_stats[loop].stats[i].per_total * 100,
			conn_stats[loop].stats[i].avg_total,
			conn_stats[loop].stats[i].avg_dns,
			conn_stats[loop].stats[i].avg_connect,
			conn_stats[loop].stats[i].avg_send,
			conn_stats[loop].stats[i].avg_first_byte,
			conn_stats[loop].stats[i].avg_rest_byte,
			conn_stats[loop].stats[i].avg_close,
			conn_stats[loop].stats[i].per_dns * 100,
			conn_stats[loop].stats[i].per_connect * 100,
			conn_stats[loop].stats[i].per_send * 100,
			conn_stats[loop].stats[i].per_first_byte * 100,
			conn_stats[loop].stats[i].per_rest_byte * 100,
			conn_stats[loop].stats[i].per_close * 100,
			conn_stats[loop].stats[i].per_other * 100);
	}

	free(raw);
	return;
}
Пример #3
0
char *hms(double x)
{
return DMS(x,15+RUNDEN);
}
Пример #4
0
char *we(double x)
{
return DMS(x,12+RUNDEN);
}
Пример #5
0
char *dm(double x)
{
return DMS(x,5+RUNDEN);
}
Пример #6
0
char *ns(double x)
{
return DMS(x,11+RUNDEN);
}
Пример #7
0
char *mp(double x)
{
return DMS(x,10);
}
Пример #8
0
char *al(double x)
{
return DMS(x, 9);
}
Пример #9
0
char *TeXdms(double x)
{
return DMS(x,2);
}
Пример #10
0
char *dms(double x)
{
return DMS(x,0);
}