1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 15:23:02 +01:00

Add run time, avg. kb/s and packets/s to netprof log dump

This commit is contained in:
jfreegman 2022-01-31 12:45:35 -05:00
parent b91f5a8758
commit 15ab58aa13
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
4 changed files with 37 additions and 5 deletions

View File

@ -230,7 +230,7 @@ void dump_packet_bytes_totals(const Tox *m, FILE *fp, const uint64_t total_bytes
fprintf(fp, "\n\n");
}
void netprof_log_dump(const Tox *m, FILE *fp)
void netprof_log_dump(const Tox *m, FILE *fp, time_t run_time)
{
if (fp == NULL) {
fprintf(stderr, "Failed to dump network statistics: null file pointer\n");
@ -257,6 +257,16 @@ void netprof_log_dump(const Tox *m, FILE *fp)
const uint64_t total_count = UDP_count_sent + UDP_count_recv + TCP_count_sent + TCP_count_recv;
const uint64_t total_bytes = UDP_bytes_sent + UDP_bytes_recv + TCP_bytes_sent + TCP_bytes_recv;
fprintf(fp, "--- Tox network profile log dump ---\n");
fprintf(fp, "Run time: %lu seconds\n", run_time);
if (run_time && total_count && total_bytes) {
fprintf(fp, "Average kilobytes per second: %.2f\n", ((float)total_bytes / run_time) / 1000.0);
fprintf(fp, "Average packets per second: %lu\n", total_count / run_time);
fprintf(fp, "Average packet size: %lu bytes\n", total_bytes / total_count);
fprintf(fp, "\n");
}
dump_packet_count_totals(m, fp, total_count, UDP_count_sent, UDP_count_recv, TCP_count_sent, TCP_count_recv);
dump_packet_bytes_totals(m, fp, total_bytes, UDP_bytes_sent, UDP_bytes_recv, TCP_bytes_sent, TCP_bytes_recv);
dump_packet_id_counts(m, fp, total_count, TOX_NETPROF_PACKET_TYPE_TCP);

View File

@ -23,8 +23,10 @@
#ifndef TOXIC_NETPROF
#define TOXIC_NETPROF
#include <stdio.h>
#include <time.h>
#include <tox/tox.h>
void netprof_log_dump(const Tox *m, FILE *fp);
void netprof_log_dump(const Tox *m, FILE *fp, time_t run_time);
#endif // TOXIC_NETPROF

View File

@ -195,7 +195,7 @@ void free_global_data(void)
void exit_toxic_success(Tox *m)
{
if (arg_opts.netprof_log_dump) {
netprof_log_dump(m, arg_opts.netprof_fp);
netprof_log_dump(m, arg_opts.netprof_fp, get_unix_time() - arg_opts.netprof_start_time);
}
store_data(m, DATA_FILE);
@ -1455,6 +1455,25 @@ static void parse_args(int argc, char *argv[])
break;
}
case 's': {
if (optarg == NULL) {
queue_init_message("Invalid argument for option: %d", opt);
break;
}
arg_opts.netprof_fp = fopen(optarg, "w");
if (arg_opts.netprof_fp != NULL) {
queue_init_message("Network profile logging enabled. Logging to file: '%s'", optarg);
arg_opts.netprof_log_dump = true;
arg_opts.netprof_start_time = time(NULL);
} else {
queue_init_message("Failed to open file '%s' for network profile logging.", optarg);
}
break;
}
case 'u': {
arg_opts.unencrypt_data = 1;
break;

View File

@ -142,8 +142,9 @@ struct arg_opts {
bool logging;
FILE *log_fp;
bool netprof_log_dump;
FILE *netprof_fp;
bool netprof_log_dump;
time_t netprof_start_time;
FILE *netprof_fp;
char proxy_address[256];
uint8_t proxy_type;