mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:03:02 +01:00
Add run time, avg. kb/s and packets/s to netprof log dump
This commit is contained in:
parent
b91f5a8758
commit
15ab58aa13
@ -230,7 +230,7 @@ void dump_packet_bytes_totals(const Tox *m, FILE *fp, const uint64_t total_bytes
|
|||||||
fprintf(fp, "\n\n");
|
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) {
|
if (fp == NULL) {
|
||||||
fprintf(stderr, "Failed to dump network statistics: null file pointer\n");
|
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_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;
|
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_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_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);
|
dump_packet_id_counts(m, fp, total_count, TOX_NETPROF_PACKET_TYPE_TCP);
|
||||||
|
@ -23,8 +23,10 @@
|
|||||||
#ifndef TOXIC_NETPROF
|
#ifndef TOXIC_NETPROF
|
||||||
#define TOXIC_NETPROF
|
#define TOXIC_NETPROF
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
#include <tox/tox.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
|
#endif // TOXIC_NETPROF
|
||||||
|
21
src/toxic.c
21
src/toxic.c
@ -195,7 +195,7 @@ void free_global_data(void)
|
|||||||
void exit_toxic_success(Tox *m)
|
void exit_toxic_success(Tox *m)
|
||||||
{
|
{
|
||||||
if (arg_opts.netprof_log_dump) {
|
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);
|
store_data(m, DATA_FILE);
|
||||||
@ -1455,6 +1455,25 @@ static void parse_args(int argc, char *argv[])
|
|||||||
break;
|
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': {
|
case 'u': {
|
||||||
arg_opts.unencrypt_data = 1;
|
arg_opts.unencrypt_data = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -143,6 +143,7 @@ struct arg_opts {
|
|||||||
FILE *log_fp;
|
FILE *log_fp;
|
||||||
|
|
||||||
bool netprof_log_dump;
|
bool netprof_log_dump;
|
||||||
|
time_t netprof_start_time;
|
||||||
FILE *netprof_fp;
|
FILE *netprof_fp;
|
||||||
|
|
||||||
char proxy_address[256];
|
char proxy_address[256];
|
||||||
|
Loading…
Reference in New Issue
Block a user