void print_statistics(StatRecord *records, int count)
{
size_t total_send = 0, total_recv = 0;
int send_count = 0, recv_count = 0;
int success_send = 0, success_recv = 0;
printf("\n===== Communication Statistics =====\n");
for (int i = 0; i < count; i++)
{
char timestr[32];
time_t sec = records[i].time.tv_sec;
struct tm *tm_info = localtime(&sec);
strftime(timestr, sizeof(timestr), "%H:%M:%S", tm_info);
long msec = records[i].time.tv_usec / 1000;
if (records[i].is_send)
{
printf("SEND[%d] | %s.%03ld | Size: %4zu bytes | %s | Retry: %d\n",
send_count, timestr, msec,
records[i].size,
records[i].status ? "SUCCESS" : "FAIL ",
records[i].retry_count);
total_send += records[i].size;
if (records[i].status)
{
success_send++;
}
send_count++;
}
else
{
printf("RECV[%d] | %s.%03ld | Size: %4zu bytes | %s\n",
recv_count, timestr, msec,
records[i].size,
records[i].status ? "SUCCESS" : "FAIL ");
total_recv += records[i].size;
if (records[i].status)
{
success_recv++;
}
recv_count++;
}
}
printf("\nTotal Send: %zu bytes (%d packets, %d success)\n",
total_send, send_count, success_send);
printf("Total Recv: %zu bytes (%d packets, %d success)\n",
total_recv, recv_count, success_recv);
printf("====================================\n");
}
void print_statistics(StatRecord *records, int count)
{
size_t total_send = 0, total_recv = 0;
int send_count = 0, recv_count = 0;
int success_send = 0, success_recv = 0;
printf("\n===== Communication Statistics =====\n");
for (int i = 0; i < count; i++)
{
char timestr[32];
time_t sec = records[i].time.tv_sec;
struct tm *tm_info = localtime(&sec);
strftime(timestr, sizeof(timestr), "%H:%M:%S", tm_info);
long msec = records[i].time.tv_usec / 1000;
if (records[i].is_send)
{
printf("SEND[%d] | %s.%03ld | Size: %4zu bytes | %s | Retry: %d\n",
send_count, timestr, msec,
records[i].size,
records[i].status ? "SUCCESS" : "FAIL ",
records[i].retry_count);
total_send += records[i].size;
if (records[i].status)
{
success_send++;
}
send_count++;
}
else
{
printf("RECV[%d] | %s.%03ld | Size: %4zu bytes | %s\n",
recv_count, timestr, msec,
records[i].size,
records[i].status ? "SUCCESS" : "FAIL ");
total_recv += records[i].size;
if (records[i].status)
success_recv++;
recv_count++;
}
}
printf("\nTotal Send: %zu bytes (%d packets, %d success)\n",
total_send, send_count, success_send);
printf("Total Recv: %zu bytes (%d packets, %d success)\n",
total_recv, recv_count, success_recv);
printf("====================================\n");
}
这两个函数是不是一样的?
最新发布