Skip to content

Commit

Permalink
Print timestamp over print_timestamp_format()
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnw-sebast committed May 30, 2024
1 parent 209c340 commit 047ee47
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void host_add_timeout_event(HOST_ENTRY *h, int index, int64_t ev_time);
struct event *host_get_timeout_event(HOST_ENTRY *h, int index);
void stats_add(HOST_ENTRY *h, int index, int success, int64_t latency);
void update_current_time();
void print_human_readable_time(int64_t current_time_ns);
void print_timestamp_format(int64_t current_time_ns, int timestamp_format);

/************************************************************
Expand Down Expand Up @@ -1382,10 +1382,8 @@ void main_loop()
stats_add(h, event->ping_index, 0, -1);

if (per_recv_flag) {
if (timestamp_flag && timestamp_format_flag == 0) {
printf("[%.5f] ", (double)current_time_ns / 1e9);
} else if(timestamp_flag && timestamp_format_flag == 1) {
print_human_readable_time(current_time_ns);
if (timestamp_flag) {
print_timestamp_format(current_time_ns, timestamp_format_flag);
}
printf("%-*s : [%d], timed out",
max_hostname_len, h->host, event->ping_index);
Expand Down Expand Up @@ -2497,10 +2495,8 @@ int wait_for_reply(int64_t wait_time)

/* print received ping (unless --quiet) */
if (per_recv_flag) {
if (timestamp_flag && timestamp_format_flag == 0) {
printf("[%.5f] ", (double)recv_time / 1e9);
} else if (timestamp_flag && timestamp_format_flag == 1) {
print_human_readable_time(recv_time);
if (timestamp_flag) {
print_timestamp_format(recv_time, timestamp_format_flag);
}
avg = h->total_time / h->num_recv;
printf("%-*s : [%d], %d bytes, %s ms",
Expand Down Expand Up @@ -2956,12 +2952,22 @@ void ev_remove(struct event_queue *queue, struct event *event)
Function: print_human_readable_time from current_time_ns
*************************************************************/
void print_human_readable_time(int64_t current_time_ns) {
time_t current_time_s = current_time_ns / 1000000000;
struct tm *local_time = localtime(&current_time_s);
void print_timestamp_format(int64_t current_time_ns, int timestamp_format)
{
char time_buffer[100];
strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%d %H:%M:%S", local_time);
printf("[%s] ", time_buffer);
time_t current_time_s;
struct tm *local_time;

if(timestamp_format == 1)
{
current_time_s = current_time_ns / 1000000000;
local_time = localtime(&current_time_s);
strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%d %H:%M:%S", local_time);
printf("[%s] ", time_buffer);
}else{
printf("[%.5f] ", (double)current_time_ns / 1e9);
}

}

/************************************************************
Expand Down

0 comments on commit 047ee47

Please sign in to comment.