Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add -D flag to print timestamp in front of output lines. #42

Merged
merged 2 commits into from

3 participants

@tohojo

I'm looking to support fping as an ICMP measurement tool in the netperf-wrappers utility for testing bufferbloat (see https://github.com/tohojo/netperf-wrappers). In order to do this, I need to be able to timestamp output, to correlate it with bandwidth measurements.

This pull request contains a patch to add a -D flag which will print a UNIX timestamp before each output line, similar to how the Linux ping utility works.

src/fping.c
@@ -1823,6 +1828,11 @@ int wait_for_reply(long wait_time)
if( per_recv_flag )
{
+ if(timestamp_flag) {
+ printf("[%lu.%04lu] ",

why dont use %06lu for usec?

@tohojo
tohojo added a note

Hmm, good question. No particular reason; I think it may be a remnant from another place I was using the same code that had buffer size constraints. Changing it to %06lu is fine by me. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tohojo

So any chance to get this merged?

@schweikert
Owner

Yes, I still want to test it, but I don't see right now why it shouldn't.

@tohojo
@schweikert schweikert merged commit 543d221 into schweikert:master
@tohojo

Excellent; thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/fping.c
View
13 src/fping.c
@@ -314,6 +314,7 @@ int verbose_flag, quiet_flag, stats_flag, unreachable_flag, alive_flag;
int elapsed_flag, version_flag, count_flag, loop_flag;
int per_recv_flag, report_all_rtts_flag, name_flag, addr_flag, backoff_flag;
int multif_flag;
+int timestamp_flag = 0;
#if defined( DEBUG ) || defined( _DEBUG )
int randomly_lose_flag, sent_times_flag, trace_flag, print_per_system_flag;
int lose_factor;
@@ -492,7 +493,7 @@ int main( int argc, char **argv )
/* get command line options */
- while( ( c = getopt( argc, argv, "gedhlmnqusaAvz:t:H:i:p:f:r:c:b:C:Q:B:S:I:T:O:" ) ) != EOF )
+ while( ( c = getopt( argc, argv, "gedhlmnqusaAvDz:t:H:i:p:f:r:c:b:C:Q:B:S:I:T:O:" ) ) != EOF )
{
switch( c )
{
@@ -583,6 +584,10 @@ int main( int argc, char **argv )
stats_flag = 1;
break;
+ case 'D':
+ timestamp_flag = 1;
+ break;
+
case 'l':
loop_flag = 1;
backoff_flag = 0;
@@ -1823,6 +1828,11 @@ int wait_for_reply(long wait_time)
if( per_recv_flag )
{
+ if(timestamp_flag) {
+ printf("[%lu.%06lu] ",
+ (unsigned long)current_time.tv_sec,
+ (unsigned long)current_time.tv_usec);
+ }
avg = h->total_time / h->num_recv;
printf( "%s%s : [%d], %d bytes, %s ms",
h->host, h->pad, this_count, result, sprint_tm( this_reply ) );
@@ -2810,6 +2820,7 @@ void usage(int is_error)
fprintf(out, " -B f set exponential backoff factor to f\n" );
fprintf(out, " -c n count of pings to send to each target (default %d)\n", count );
fprintf(out, " -C n same as -c, report results in verbose format\n" );
+ fprintf(out, " -D print timestamp before each output line\n" );
fprintf(out, " -e show elapsed time on return packets\n" );
fprintf(out, " -f file read list of targets from a file ( - means stdin) (only if no -g specified)\n" );
fprintf(out, " -g generate target list (only if no -f specified)\n" );
Something went wrong with that request. Please try again.