Add compression statistics output
- Track compressed files count - Track skipped files count - Track compressed bytes - Display compression ratio and savings in sync complete message Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -198,6 +198,9 @@ typedef struct {
|
|||||||
|
|
||||||
static atomic_uint_fast64_t g_bytes_sent = 0;
|
static atomic_uint_fast64_t g_bytes_sent = 0;
|
||||||
static atomic_uint_fast32_t g_files_sent = 0;
|
static atomic_uint_fast32_t g_files_sent = 0;
|
||||||
|
static atomic_uint_fast64_t g_bytes_compressed = 0;
|
||||||
|
static atomic_uint_fast32_t g_files_compressed = 0;
|
||||||
|
static atomic_uint_fast32_t g_files_skipped = 0;
|
||||||
|
|
||||||
// ─── UDP session setup (called once per worker if -u) ─────────────────────
|
// ─── UDP session setup (called once per worker if -u) ─────────────────────
|
||||||
|
|
||||||
@@ -841,6 +844,16 @@ static int send_batch_files(sync_ctx_t *ctx, file_task_t **tasks, int count) {
|
|||||||
|
|
||||||
close(fds[i]);
|
close(fds[i]);
|
||||||
atomic_fetch_add(&g_bytes_sent, (uint64_t)stats[i].st_size);
|
atomic_fetch_add(&g_bytes_sent, (uint64_t)stats[i].st_size);
|
||||||
|
|
||||||
|
// Update compression statistics
|
||||||
|
if (meta.compress == COMPRESS_LZ4) {
|
||||||
|
atomic_fetch_add(&g_files_compressed, 1);
|
||||||
|
atomic_fetch_add(&g_bytes_compressed, (uint64_t)meta.compressed_size);
|
||||||
|
} else if (use_sendfile) {
|
||||||
|
// File was skipped for compression (already compressed or too small)
|
||||||
|
atomic_fetch_add(&g_files_skipped, 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Note: data_to_send points to batch-level buffers (file_buf/comp_buf), NOT freed per-file
|
// Note: data_to_send points to batch-level buffers (file_buf/comp_buf), NOT freed per-file
|
||||||
printf("[thread] Sent (pipelined+%s): %s\n", meta.compress == COMPRESS_LZ4 ? "compress" : "buffered", tasks[i]->rel_path);
|
printf("[thread] Sent (pipelined+%s): %s\n", meta.compress == COMPRESS_LZ4 ? "compress" : "buffered", tasks[i]->rel_path);
|
||||||
}
|
}
|
||||||
@@ -1221,10 +1234,24 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
uint64_t total_bytes = atomic_load(&g_bytes_sent);
|
uint64_t total_bytes = atomic_load(&g_bytes_sent);
|
||||||
uint32_t total_files = atomic_load(&g_files_sent);
|
uint32_t total_files = atomic_load(&g_files_sent);
|
||||||
|
uint32_t files_compressed = atomic_load(&g_files_compressed);
|
||||||
|
uint32_t files_skipped = atomic_load(&g_files_skipped);
|
||||||
|
uint64_t bytes_compressed = atomic_load(&g_bytes_compressed);
|
||||||
double throughput = (total_bytes / 1048576.0) / (elapsed_ms / 1000.0);
|
double throughput = (total_bytes / 1048576.0) / (elapsed_ms / 1000.0);
|
||||||
|
|
||||||
printf("\n=== Sync complete: %u files, %lu bytes, %.1f ms, %.2f MB/s ===\n",
|
printf("\n=== Sync complete: %u files, %lu bytes, %.1f ms, %.2f MB/s ===\n",
|
||||||
total_files, (unsigned long)total_bytes, elapsed_ms, throughput);
|
total_files, (unsigned long)total_bytes, elapsed_ms, throughput);
|
||||||
|
|
||||||
|
// Print compression statistics if compression was enabled
|
||||||
|
if (use_compress && total_files > 0) {
|
||||||
|
if (files_compressed > 0 || files_skipped > 0) {
|
||||||
|
double compress_ratio = (bytes_compressed > 0) ?
|
||||||
|
(double)(total_bytes - bytes_compressed) / (double)bytes_compressed : 0;
|
||||||
|
printf("Compression stats: %u compressed, %u skipped (%.1f%% savings)\n",
|
||||||
|
files_compressed, files_skipped, compress_ratio * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Machine-readable line for benchmark.sh to parse */
|
/* Machine-readable line for benchmark.sh to parse */
|
||||||
printf("BENCH: connections=%d bytes=%lu ms=%.1f throughput_mbs=%.2f\n",
|
printf("BENCH: connections=%d bytes=%lu ms=%.1f throughput_mbs=%.2f\n",
|
||||||
nconn, (unsigned long)total_bytes, elapsed_ms, throughput);
|
nconn, (unsigned long)total_bytes, elapsed_ms, throughput);
|
||||||
|
|||||||
Reference in New Issue
Block a user