From 060970feee2beea37e837e0a2d557e878e5f8290 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 10 Feb 2020 21:21:57 +0100 Subject: Cleanup: Use stat structs instead of hooks in tar2sqfs/gensquashfs Signed-off-by: David Oberhollenzer --- lib/common/statistics.c | 91 ++++++++++++------------------------------------- 1 file changed, 21 insertions(+), 70 deletions(-) (limited to 'lib/common/statistics.c') diff --git a/lib/common/statistics.c b/lib/common/statistics.c index b41cd22..eabe037 100644 --- a/lib/common/statistics.c +++ b/lib/common/statistics.c @@ -8,84 +8,35 @@ #include -static void post_block_write(void *user, const sqfs_block_t *block, - sqfs_file_t *file) -{ - block_processor_stats_t *stats = user; - (void)file; - - if (block->size == 0) - return; - - if (block->flags & SQFS_BLK_FRAGMENT_BLOCK) { - stats->frag_blocks_written += 1; - } else { - stats->blocks_written += 1; - } - - stats->bytes_written += block->size; -} - -static void pre_fragment_store(void *user, sqfs_block_t *block) -{ - block_processor_stats_t *stats = user; - (void)block; - - stats->frag_count += 1; -} - -static void notify_blocks_erased(void *user, size_t count, sqfs_u64 bytes) -{ - block_processor_stats_t *stats = user; - - stats->bytes_written -= bytes; - stats->blocks_written -= count; - stats->duplicate_blocks += count; -} - -static void notify_fragment_discard(void *user, const sqfs_block_t *block) -{ - block_processor_stats_t *stats = user; - (void)block; - - stats->frag_dup += 1; -} - -static const sqfs_block_hooks_t hooks = { - .size = sizeof(hooks), - .post_block_write = post_block_write, - .pre_fragment_store = pre_fragment_store, - .notify_blocks_erased = notify_blocks_erased, - .notify_fragment_discard = notify_fragment_discard, -}; - -void register_stat_hooks(sqfs_block_processor_t *data, - block_processor_stats_t *stats) -{ - sqfs_block_processor_set_hooks(data, stats, &hooks); -} - -void sqfs_print_statistics(sqfs_super_t *super, block_processor_stats_t *stats) +void sqfs_print_statistics(const sqfs_super_t *super, + const sqfs_block_processor_t *blk, + const sqfs_block_writer_t *wr) { + const sqfs_block_processor_stats_t *proc_stats; + const sqfs_block_writer_stats_t *wr_stats; size_t ratio; - if (stats->bytes_written > 0) { - ratio = (100 * stats->bytes_written) / stats->bytes_read; + proc_stats = sqfs_block_processor_get_stats(blk); + wr_stats = sqfs_block_writer_get_stats(wr); + + if (proc_stats->input_bytes_read > 0) { + ratio = (100 * wr_stats->bytes_written) / + proc_stats->input_bytes_read; } else { ratio = 100; } fputs("---------------------------------------------------\n", stdout); - printf("Input files processed: " PRI_SZ"\n", stats->file_count); - printf("Data blocks actually written: " PRI_SZ "\n", - stats->blocks_written); - printf("Fragment blocks written: " PRI_SZ "\n", - stats->frag_blocks_written); - printf("Duplicate data blocks omitted: " PRI_SZ "\n", - stats->duplicate_blocks); - printf("Sparse blocks omitted: " PRI_SZ "\n", stats->sparse_blocks); - printf("Fragments actually written: " PRI_SZ "\n", stats->frag_count); - printf("Duplicated fragments omitted: " PRI_SZ"\n", stats->frag_dup); + printf("Input files processed: %lu\n", proc_stats->input_bytes_read); + printf("Data blocks actually written: %lu\n", wr_stats->blocks_written); + printf("Fragment blocks written: %lu\n", proc_stats->frag_block_count); + printf("Duplicate data blocks omitted: %lu\n", + wr_stats->blocks_submitted - wr_stats->blocks_written); + printf("Sparse blocks omitted: %lu\n", proc_stats->sparse_block_count); + printf("Fragments actually written: %lu\n", + proc_stats->actual_frag_count); + printf("Duplicated fragments omitted: %lu\n", + proc_stats->total_frag_count - proc_stats->actual_frag_count); printf("Total number of inodes: %u\n", super->inode_count); printf("Number of unique group/user IDs: %u\n", super->id_count); printf("Data compression ratio: " PRI_SZ "%%\n", ratio); -- cgit v1.2.3