From 23e06428674750c59c17ae2a22d17ecd42056b02 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 28 May 2020 20:54:21 +0200 Subject: cleanup: libsqfs: eliminate block writer statistics - the "bytes submitted" can be moved over to the block processor - the number of blocks submitted are already there (implcitily, by adding the data block count to the fragment block count) - actual data bytes written can be computed from the super block - the remaining block count can be changed to simple counter that can be obtained through a function. Signed-off-by: David Oberhollenzer --- include/sqfs/block_processor.h | 9 ++++++++ include/sqfs/block_writer.h | 48 ++++----------------------------------- lib/common/statistics.c | 18 +++++++++------ lib/sqfs/block_processor/common.c | 2 ++ lib/sqfs/block_writer.c | 17 ++++---------- 5 files changed, 31 insertions(+), 63 deletions(-) diff --git a/include/sqfs/block_processor.h b/include/sqfs/block_processor.h index be10ef0..8b50033 100644 --- a/include/sqfs/block_processor.h +++ b/include/sqfs/block_processor.h @@ -68,6 +68,15 @@ struct sqfs_block_processor_stats_t { */ sqfs_u64 input_bytes_read; + /** + * @brief Total number of bytes sent down to the block processor. + * + * This is the sum of generated, compressed blocks, including blocks + * that were possibly deduplicated by the block writer and not + * counting padding that the block writer may have added. + */ + sqfs_u64 output_bytes_generated; + /** * @brief Total number of data blocks produced. */ diff --git a/include/sqfs/block_writer.h b/include/sqfs/block_writer.h index 1fd110a..8cfb9a2 100644 --- a/include/sqfs/block_writer.h +++ b/include/sqfs/block_writer.h @@ -38,46 +38,6 @@ * This object is not copyable, i.e. @ref sqfs_copy will always return NULL. */ -/** - * @struct sqfs_block_writer_stats_t - * - * @brief Collects run time statistics of the @ref sqfs_block_writer_t - */ -struct sqfs_block_writer_stats_t { - /** - * @brief Holds the size of the structure. - * - * If a later version of libsquashfs expands this structure, the value - * of this field can be used to check at runtime whether the newer - * fields are avaialable or not. - */ - size_t size; - - /** - * @brief Total number of bytes submitted, including blocks that were - * removed by deduplication and not counting any padding. - */ - sqfs_u64 bytes_submitted; - - /** - * @brief Actual number of bytes written to disk, excluding deduplicated - * blocks and including padding. - */ - sqfs_u64 bytes_written; - - /** - * @brief Total number of submitted blocks, including ones later - * removed by deduplication. - */ - sqfs_u64 blocks_submitted; - - /** - * @brief Total number of blocks actually written, excluding - * deduplicated blocks. - */ - sqfs_u64 blocks_written; -}; - #ifdef __cplusplus extern "C" { #endif @@ -128,16 +88,16 @@ SQFS_API int sqfs_block_writer_write(sqfs_block_writer_t *wr, sqfs_u64 *location); /** - * @brief Get access to a block writers run time statistics. + * @brief Get the number of blocks actually written to disk. * * @memberof sqfs_block_writer_t * * @param wr A pointer to a block writer. * - * @return A pointer to the internal statistics counters. + * @return The number of blocks written, excluding deduplicated blocks. */ -SQFS_API const sqfs_block_writer_stats_t -*sqfs_block_writer_get_stats(const sqfs_block_writer_t *wr); +SQFS_API +sqfs_u64 sqfs_block_writer_get_block_count(const sqfs_block_writer_t *wr); #ifdef __cplusplus } diff --git a/lib/common/statistics.c b/lib/common/statistics.c index 2f729cb..079c1b1 100644 --- a/lib/common/statistics.c +++ b/lib/common/statistics.c @@ -13,22 +13,23 @@ void sqfs_print_statistics(const sqfs_super_t *super, const sqfs_block_writer_t *wr) { const sqfs_block_processor_stats_t *proc_stats; - const sqfs_block_writer_stats_t *wr_stats; + sqfs_u64 bytes_written, blocks_written; char read_sz[32], written_sz[32]; size_t ratio; proc_stats = sqfs_block_processor_get_stats(blk); - wr_stats = sqfs_block_writer_get_stats(wr); + blocks_written = sqfs_block_writer_get_block_count(wr); + + bytes_written = super->inode_table_start - sizeof(*super); if (proc_stats->input_bytes_read > 0) { - ratio = (100 * wr_stats->bytes_written) / - proc_stats->input_bytes_read; + ratio = (100 * bytes_written) / proc_stats->input_bytes_read; } else { ratio = 100; } print_size(proc_stats->input_bytes_read, read_sz, false); - print_size(wr_stats->bytes_written, written_sz, false); + print_size(bytes_written, written_sz, false); fputs("---------------------------------------------------\n", stdout); printf("Data bytes read: %s\n", read_sz); @@ -36,11 +37,14 @@ void sqfs_print_statistics(const sqfs_super_t *super, printf("Data compression ratio: " PRI_SZ "%%\n", ratio); fputc('\n', stdout); - printf("Data blocks written: " PRI_U64 "\n", wr_stats->blocks_written); + printf("Data blocks written: " PRI_U64 "\n", blocks_written); printf("Out of which where fragment blocks: " PRI_U64 "\n", proc_stats->frag_block_count); + printf("Duplicate blocks omitted: " PRI_U64 "\n", - wr_stats->blocks_submitted - wr_stats->blocks_written); + proc_stats->data_block_count + proc_stats->frag_block_count - + blocks_written); + printf("Sparse blocks omitted: " PRI_U64 "\n", proc_stats->sparse_block_count); fputc('\n', stdout); diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c index bd37068..757544a 100644 --- a/lib/sqfs/block_processor/common.c +++ b/lib/sqfs/block_processor/common.c @@ -73,6 +73,8 @@ int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk) if (err) goto out; + proc->stats.output_bytes_generated += blk->size; + if (blk->flags & SQFS_BLK_IS_SPARSE) { sqfs_inode_make_extended(*(blk->inode)); (*(blk->inode))->data.file_ext.sparse += blk->size; diff --git a/lib/sqfs/block_writer.c b/lib/sqfs/block_writer.c index b819b58..06cbd37 100644 --- a/lib/sqfs/block_writer.c +++ b/lib/sqfs/block_writer.c @@ -34,8 +34,7 @@ struct sqfs_block_writer_t { blk_info_t *blocks; size_t devblksz; - sqfs_block_writer_stats_t stats; - + sqfs_u64 blocks_written; sqfs_u64 data_area_start; sqfs_u64 start; @@ -132,7 +131,6 @@ sqfs_block_writer_t *sqfs_block_writer_create(sqfs_file_t *file, wr->file = file; wr->devblksz = devblksz; wr->max_blocks = INIT_BLOCK_COUNT; - wr->stats.size = sizeof(wr->stats); wr->data_area_start = wr->file->get_size(wr->file); wr->blocks = alloc_array(sizeof(wr->blocks[0]), wr->max_blocks); @@ -180,10 +178,7 @@ int sqfs_block_writer_write(sqfs_block_writer_t *wr, sqfs_u32 size, if (err) return err; - wr->stats.bytes_submitted += size; - wr->stats.blocks_submitted += 1; - wr->stats.blocks_written = wr->num_blocks; - wr->stats.bytes_written = offset + size - wr->data_area_start; + wr->blocks_written = wr->num_blocks; } if (flags & SQFS_BLK_LAST_BLOCK) { @@ -218,15 +213,13 @@ int sqfs_block_writer_write(sqfs_block_writer_t *wr, sqfs_u32 size, return err; } - wr->stats.blocks_written = wr->num_blocks; - wr->stats.bytes_written = wr->start - wr->data_area_start; + wr->blocks_written = wr->num_blocks; } return 0; } -const sqfs_block_writer_stats_t -*sqfs_block_writer_get_stats(const sqfs_block_writer_t *wr) +sqfs_u64 sqfs_block_writer_get_block_count(const sqfs_block_writer_t *wr) { - return &wr->stats; + return wr->blocks_written; } -- cgit v1.2.3