summaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-10 21:21:57 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-10 21:21:57 +0100
commit060970feee2beea37e837e0a2d557e878e5f8290 (patch)
treeca77697c9b7f67a633382ab954fde1167e6d77ec /lib/common
parent94a0b2783aa58b646260232ecfa3ff93f9b97d6d (diff)
Cleanup: Use stat structs instead of hooks in tar2sqfs/gensquashfs
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/statistics.c91
-rw-r--r--lib/common/writer.c5
2 files changed, 22 insertions, 74 deletions
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 <stdio.h>
-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);
diff --git a/lib/common/writer.c b/lib/common/writer.c
index 7f69752..84a40d2 100644
--- a/lib/common/writer.c
+++ b/lib/common/writer.c
@@ -145,9 +145,6 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg)
goto fail_fragtbl;
}
- memset(&sqfs->stats, 0, sizeof(sqfs->stats));
- register_stat_hooks(sqfs->data, &sqfs->stats);
-
sqfs->idtbl = sqfs_id_table_create(0);
if (sqfs->idtbl == NULL) {
sqfs_perror(wrcfg->filename, "creating ID table",
@@ -294,7 +291,7 @@ int sqfs_writer_finish(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *cfg)
}
if (!cfg->quiet)
- sqfs_print_statistics(&sqfs->super, &sqfs->stats);
+ sqfs_print_statistics(&sqfs->super, sqfs->data, sqfs->blkwr);
return 0;
}