50 std::cerr <<
"SIGNAL " << sig <<
" Interrupted." << std::endl;
58 struct sigaction sa, osa;
59 if (sigaction(SIGINT,
nullptr, &osa) == 0 && osa.sa_handler == SIG_DFL) {
62 sigemptyset(&sa.sa_mask);
63 (void) sigaction(SIGINT, &sa,
nullptr);
67 if ((osig = signal(SIGINT,
catchSignal)) != SIG_DFL)
68 (
void) signal(SIGINT, osig);
76static struct timeval tv1,
tv2;
84#if GETTIMEOFDAY_NO_TZP
85 (void)gettimeofday(&tv1);
87 (void)gettimeofday(&tv1,
nullptr);
101#if GETTIMEOFDAY_NO_TZP
102 (void)gettimeofday(&
tv2);
104 (void)gettimeofday(&
tv2,
nullptr);
109 tmp = localtime(&t2s);
111 snprintf(tbuf,
sizeof(tbuf)-1,
"%d-%02d-%02d %02d:%02d:%02d [%ld]: %ld.%03ld secs, %f KB/s",
112 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
113 tmp->tm_hour, tmp->tm_min, tmp->tm_sec,
stats.
counted + 1,
114 elapsed_msec / 1000, elapsed_msec % 1000,
115 elapsed_msec ? (
double) fsize / elapsed_msec : -1.0);
116 std::cerr << tbuf << std::endl;
134 tvs.tv_sec = msec_left / 1000;
135 tvs.tv_usec = (msec_left % 1000) * 1000;
136 select(0,
nullptr,
nullptr,
nullptr, &tvs);
145 std::cerr << std::endl
146 <<
stats.
counted <<
" requests, round-trip (secs) min/avg/max = "
148 <<
"/" << (mean/1000) <<
"." << (mean%1000)
157 std::cerr <<
"Ping Mode" << std::endl
158 <<
" --ping [options] Enable ping mode." << std::endl
160 <<
" options:" << std::endl
161 <<
" -g count Ping iteration count (default, loop until interrupted)." << std::endl
162 <<
" -I interval Ping interval in seconds (default 1 second)." << std::endl
177 static struct option pingOptions[] = {
178 {
"count", no_argument,
nullptr,
'g'},
179 {
"interval", no_argument,
nullptr,
'I'},
180 {
nullptr, 0,
nullptr, 0}
183 int saved_opterr =
opterr;
185 while ((c = getopt_long(argc, argv,
shortOpStr, pingOptions, &optIndex)) != -1) {
191 std::cerr <<
"ERROR: -g ping count missing parameter." << std::endl;
198 std::cerr <<
"ERROR: -I ping interval missing parameter." << std::endl;
200 }
else if ((interval = atoi(
optarg) * 1000) <= 0) {
201 std::cerr <<
"ERROR: -I ping interval out of range (0-" << (
INT_MAX/1000) <<
")." << std::endl;
static struct timeval tv1 tv2
static void catchSignal(int sig)
parameters controlling 'ping' mode message looping.
void usage()
display Ping Options command line help to stderr
bool parseCommandOpts(int argc, char *argv[], int c, int &optIndex)
measurements collected by the squidclient ping mode logics
long counted
number of transactions which have so far been measured
long pMax
longest transaction time seen
long pMin
shortest transaction time seen
long sum
total time so far spent waiting on transactions
static const char * shortOpStr
bool LoopDone(int i)
whether ping loop is completed at the given iteration.
uint32_t Init()
initialize the squidclient ping mode
void TimerStop(size_t fsize)
class Ping::pingStats_ stats
void TimerStart()
start timing a new transaction
void DisplayStats()
display summary of ping data collected
int tvSubMsec(struct timeval t1, struct timeval t2)