Source formatting in preparation for additional data printing formats

This commit is contained in:
tedbullock 2008-09-18 06:56:35 +00:00
parent 29518656e1
commit 50a30da590

View File

@ -1,38 +1,38 @@
/*
httperf -- a tool for measuring web server performance
Copyright 2000-2007 Hewlett-Packard Company and Contributors listed in
AUTHORS file. Originally contributed by David Mosberger-Tang
This file is part of httperf, a web server performance measurment
tool.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
In addition, as a special exception, the copyright holders give
permission to link the code of this work with the OpenSSL project's
"OpenSSL" library (or with modified versions of it that use the same
license as the "OpenSSL" library), and distribute linked combinations
including the two. You must obey the GNU General Public License in
all respects for all of the code used other than "OpenSSL". If you
modify this file, you may extend this exception to your version of the
file, but you are not obligated to do so. If you do not wish to do
so, delete this exception statement from your version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA
* httperf -- a tool for measuring web server performance Copyright 2000-2007
* Hewlett-Packard Company and Contributors listed in AUTHORS file. Originally
* contributed by David Mosberger-Tang
*
* This file is part of httperf, a web server performance measurment tool.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* In addition, as a special exception, the copyright holders give permission
* to link the code of this work with the OpenSSL project's "OpenSSL" library
* (or with modified versions of it that use the same license as the "OpenSSL"
* library), and distribute linked combinations including the two. You must
* obey the GNU General Public License in all respects for all of the code
* used other than "OpenSSL". If you modify this file, you may extend this
* exception to your version of the file, but you are not obligated to do so.
* If you do not wish to do so, delete this exception statement from your
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* Basic statistics collector. */
/*
* Basic statistics collector.
*/
#include "config.h"
@ -53,18 +53,19 @@
#include <localevent.h>
#include <stats.h>
/* Increase this if it does not cover at least 50% of all response
times. */
/*
* Increase this if it does not cover at least 50% of all response times.
*/
#define MAX_LIFETIME 100.0 /* max. conn. lifetime in seconds */
#define BIN_WIDTH 1e-3
#define NUM_BINS ((u_int) (MAX_LIFETIME / BIN_WIDTH))
static struct
{
u_int num_conns_issued; /* total # of connections issued */
static struct {
u_int num_conns_issued; /* total # of connections * issued */
u_int num_replies[6]; /* completion count per status class */
u_int num_client_timeouts; /* # of client timeouts */
u_int num_sock_fdunavail; /* # of times out of filedescriptors */
u_int num_sock_fdunavail; /* # of times out of *
* filedescriptors */
u_int num_sock_ftabfull; /* # of times file table was full */
u_int num_sock_refused; /* # of ECONNREFUSED */
u_int num_sock_reset; /* # of ECONNRESET */
@ -75,7 +76,8 @@ static struct
u_int num_lifetimes;
Time conn_lifetime_sum; /* sum of connection lifetimes */
Time conn_lifetime_sum2; /* sum of connection lifetimes squared */
Time conn_lifetime_sum2; /* sum of connection lifetimes
* squared */
Time conn_lifetime_min; /* minimum connection lifetime */
Time conn_lifetime_max; /* maximum connection lifetime */
@ -101,9 +103,9 @@ static struct
u_wide reply_bytes_received; /* sum of all data bytes */
u_wide footer_bytes_received; /* sum of all footer bytes */
u_int conn_lifetime_hist[NUM_BINS]; /* histogram of connection lifetimes */
}
basic;
u_int conn_lifetime_hist[NUM_BINS]; /* histogram of
* connection lifetimes */
} basic;
static u_int num_active_conns;
static u_int num_replies; /* # of replies received in this interval */
@ -129,7 +131,9 @@ perf_sample (Event_Type et, Object *obj, Any_Type reg_arg, Any_Type call_arg)
basic.reply_rate_max = rate;
++basic.num_reply_rates;
/* prepare for next sample interval: */
/*
* prepare for next sample interval:
*/
num_replies = 0;
}
@ -149,15 +153,23 @@ conn_fail (Event_Type et, Object *obj, Any_Type reg_arg, Any_Type call_arg)
assert(et == EV_CONN_FAILED);
switch (err)
{
switch (err) {
#ifdef __linux__
case EINVAL: /* Linux has a strange way of saying "out of fds"... */
case EINVAL: /* Linux has a strange way of saying "out of
* * fds"... */
#endif
case EMFILE: ++basic.num_sock_fdunavail; break;
case ENFILE: ++basic.num_sock_ftabfull; break;
case ECONNREFUSED: ++basic.num_sock_refused; break;
case ETIMEDOUT: ++basic.num_sock_timeouts; break;
case EMFILE:
++basic.num_sock_fdunavail;
break;
case ENFILE:
++basic.num_sock_ftabfull;
break;
case ECONNREFUSED:
++basic.num_sock_refused;
break;
case ETIMEDOUT:
++basic.num_sock_timeouts;
break;
case EPIPE:
case ECONNRESET:
@ -165,10 +177,10 @@ conn_fail (Event_Type et, Object *obj, Any_Type reg_arg, Any_Type call_arg)
break;
default:
if (first_time)
{
if (first_time) {
first_time = 0;
fprintf (stderr, "%s: connection failed with unexpected error %d\n",
fprintf(stderr,
"%s: connection failed with unexpected error %d\n",
prog_name, errno);
}
++basic.num_other_errors;
@ -216,8 +228,7 @@ conn_destroyed (Event_Type et, Object *obj, Any_Type reg_arg, Any_Type c_arg)
assert(et == EV_CONN_DESTROYED && object_is_conn(s)
&& num_active_conns > 0);
if (s->basic.num_calls_completed > 0)
{
if (s->basic.num_calls_completed > 0) {
lifetime = timer_now() - s->basic.time_connect_start;
basic.conn_lifetime_sum += lifetime;
basic.conn_lifetime_sum2 += SQUARE(lifetime);
@ -321,8 +332,10 @@ dump (void)
{
Time conn_period = 0.0, call_period = 0.0;
Time conn_time = 0.0, resp_time = 0.0, xfer_time = 0.0;
Time call_size = 0.0, hdr_size = 0.0, reply_size = 0.0, footer_size = 0.0;
Time lifetime_avg = 0.0, lifetime_stddev = 0.0, lifetime_median = 0.0;
Time call_size = 0.0, hdr_size = 0.0, reply_size =
0.0, footer_size = 0.0;
Time lifetime_avg = 0.0, lifetime_stddev =
0.0, lifetime_median = 0.0;
double reply_rate_avg = 0.0, reply_rate_stddev = 0.0;
int i, total_replies = 0;
Time delta, user, sys;
@ -335,23 +348,21 @@ dump (void)
delta = test_time_stop - test_time_start;
if (verbose > 1)
{
if (verbose > 1) {
printf("\nConnection lifetime histogram (time in ms):\n");
for (i = 0; i < NUM_BINS; ++i)
if (basic.conn_lifetime_hist[i])
{
if (basic.conn_lifetime_hist[i]) {
if (i > 0 && basic.conn_lifetime_hist[i - 1] == 0)
printf("%14c\n", ':');
time = (i + 0.5) * BIN_WIDTH;
printf ("%16.1f %u\n", 1e3*time, basic.conn_lifetime_hist[i]);
printf("%16.1f %u\n", 1e3 * time,
basic.conn_lifetime_hist[i]);
}
}
printf("\nTotal: connections %u requests %u replies %u "
"test-duration %.3f s\n",
basic.num_conns_issued, basic.num_sent, total_replies,
delta);
basic.num_conns_issued, basic.num_sent, total_replies, delta);
putchar('\n');
@ -359,21 +370,19 @@ dump (void)
conn_period = delta / basic.num_conns_issued;
printf("Connection rate: %.1f conn/s (%.1f ms/conn, "
"<=%u concurrent connections)\n",
basic.num_conns_issued / delta, 1e3*conn_period, basic.max_conns);
basic.num_conns_issued / delta, 1e3 * conn_period,
basic.max_conns);
if (basic.num_lifetimes > 0)
{
if (basic.num_lifetimes > 0) {
lifetime_avg = (basic.conn_lifetime_sum / basic.num_lifetimes);
if (basic.num_lifetimes > 1)
lifetime_stddev = STDDEV(basic.conn_lifetime_sum,
basic.conn_lifetime_sum2,
basic.num_lifetimes);
n = 0;
for (i = 0; i < NUM_BINS; ++i)
{
for (i = 0; i < NUM_BINS; ++i) {
n += basic.conn_lifetime_hist[i];
if (n >= 0.5*basic.num_lifetimes)
{
if (n >= 0.5 * basic.num_lifetimes) {
lifetime_median = (i + 0.5) * BIN_WIDTH;
break;
}
@ -404,19 +413,19 @@ dump (void)
putchar('\n');
if (basic.num_reply_rates > 0)
{
if (basic.num_reply_rates > 0) {
reply_rate_avg = (basic.reply_rate_sum / basic.num_reply_rates);
if (basic.num_reply_rates > 1)
reply_rate_stddev = STDDEV(basic.reply_rate_sum,
basic.reply_rate_sum2,
basic.num_reply_rates);
}
printf ("Reply rate [replies/s]: min %.1f avg %.1f max %.1f stddev %.1f "
printf
("Reply rate [replies/s]: min %.1f avg %.1f max %.1f stddev %.1f "
"(%u samples)\n",
basic.num_reply_rates > 0 ? basic.reply_rate_min : 0.0,
reply_rate_avg, basic.reply_rate_max,
reply_rate_stddev, basic.num_reply_rates);
reply_rate_avg, basic.reply_rate_max, reply_rate_stddev,
basic.num_reply_rates);
if (basic.num_responses > 0)
resp_time = basic.call_response_sum / basic.num_responses;
@ -425,8 +434,7 @@ dump (void)
printf("Reply time [ms]: response %.1f transfer %.1f\n",
1e3 * resp_time, 1e3 * xfer_time);
if (total_replies)
{
if (total_replies) {
hdr_size = basic.hdr_bytes_received / total_replies;
reply_size = basic.reply_bytes_received / total_replies;
footer_size = basic.footer_bytes_received / total_replies;
@ -436,8 +444,8 @@ dump (void)
hdr_size + reply_size + footer_size);
printf("Reply status: 1xx=%u 2xx=%u 3xx=%u 4xx=%u 5xx=%u\n",
basic.num_replies[1], basic.num_replies[2], basic.num_replies[3],
basic.num_replies[4], basic.num_replies[5]);
basic.num_replies[1], basic.num_replies[2],
basic.num_replies[3], basic.num_replies[4], basic.num_replies[5]);
putchar('\n');
@ -445,9 +453,10 @@ dump (void)
- TV_TO_SEC(test_rusage_start.ru_utime));
sys = (TV_TO_SEC(test_rusage_stop.ru_stime)
- TV_TO_SEC(test_rusage_start.ru_stime));
printf ("CPU time [s]: user %.2f system %.2f (user %.1f%% system %.1f%% "
"total %.1f%%)\n", user, sys, 100.0*user/delta, 100.0*sys/delta,
100.0*(user + sys)/delta);
printf
("CPU time [s]: user %.2f system %.2f (user %.1f%% system %.1f%% "
"total %.1f%%)\n", user, sys, 100.0 * user / delta,
100.0 * sys / delta, 100.0 * (user + sys) / delta);
total_size = (basic.req_bytes_sent
+ basic.hdr_bytes_received + basic.reply_bytes_received);
@ -469,8 +478,7 @@ dump (void)
basic.num_sock_ftabfull, basic.num_other_errors);
}
Stat_Collector stats_basic =
{
Stat_Collector stats_basic = {
"Basic statistics",
init,
no_op,