Skip to content

add rate-tx and rate-rx to log file #10

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct log_processes
char *name;
nstats_t tot_Bps_rx; // trafego total
nstats_t tot_Bps_tx;
nstats_t avg_Bps_rx;
nstats_t avg_Bps_tx;
};

static struct log_processes *buffer = NULL;
Expand All @@ -44,7 +46,7 @@ static FILE *file = NULL;
#define TAXA 14

// TAXA + TAXA + PROGRAM + '\n'
#define LEN_HEADER TAXA * 2 + 7 + 1
#define LEN_HEADER TAXA * 4 + 7 + 1

static void
write_process_to_file ( struct log_processes *processes,
Expand All @@ -54,18 +56,31 @@ write_process_to_file ( struct log_processes *processes,
char rx_tot[LEN_STR_TOTAL];
char tx_tot[LEN_STR_TOTAL];

char tx_rate[LEN_STR_RATE];
char rx_rate[LEN_STR_RATE];


for ( size_t i = 0; i < tot_process; i++ )
{
// not log process whitout traffic
if ( !processes[i].tot_Bps_rx && !processes[i].tot_Bps_tx )
continue;

human_readable ( tx_rate, sizeof tx_rate, processes[i].avg_Bps_tx, RATE );

human_readable ( rx_rate, sizeof rx_rate, processes[i].avg_Bps_rx, RATE );

human_readable ( tx_tot, sizeof tx_tot, processes[i].tot_Bps_tx, TOTAL );

human_readable ( rx_tot, sizeof rx_tot, processes[i].tot_Bps_rx, TOTAL );


fprintf ( file,
"%*s%*s%s\n",
"%*s%*s%*s%*s%s\n",
-TAXA,
tx_rate,
-TAXA,
rx_rate,
-TAXA,
tx_tot,
-TAXA,
Expand Down Expand Up @@ -119,6 +134,8 @@ update_log_process ( process_t **new_proc,
locate = true;
log->tot_Bps_rx += new_proc[i]->net_stat.bytes_last_sec_rx;
log->tot_Bps_tx += new_proc[i]->net_stat.bytes_last_sec_tx;
log->avg_Bps_rx = new_proc[i]->net_stat.avg_Bps_rx;
log->avg_Bps_tx = new_proc[i]->net_stat.avg_Bps_tx;

// only one process with same name exist in this buffer
break;
Expand All @@ -132,6 +149,8 @@ update_log_process ( process_t **new_proc,
log->name = strndup ( new_proc[i]->name, len_name );
log->tot_Bps_rx = new_proc[i]->net_stat.tot_Bps_rx;
log->tot_Bps_tx = new_proc[i]->net_stat.tot_Bps_tx;
log->avg_Bps_rx = new_proc[i]->net_stat.avg_Bps_rx;
log->avg_Bps_tx = new_proc[i]->net_stat.avg_Bps_tx;
( *len_buff )++;
}
}
Expand All @@ -153,7 +172,7 @@ log_init ( const struct config_op *co )
}

fprintf (
file, "%*s%*s%s\n", -TAXA, "TOTAL TX", -TAXA, "TOTAL RX", "PROGRAM" );
file, "%*s%*s%*s%*s%s\n",-TAXA, "RATE TX", -TAXA, "RATE RX", -TAXA, "TOTAL TX", -TAXA, "TOTAL RX", "PROGRAM" );

return 1;
}
Expand Down