aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-25 13:40:48 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-25 13:40:48 +0200
commitde4fc4b7e7b4302388cc1f778025f0843ef4ab24 (patch)
treeacdd35e6ecf220f06b236f25574b8ef8f3463fb9
parente0e98b7b747f63c1b8fccd035592e3684fdb2691 (diff)
Do the statistics acocunting through data writer hooks
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/data_writer.h1
-rw-r--r--lib/sqfshelper/data_writer.c51
-rw-r--r--lib/sqfshelper/statistics.c5
3 files changed, 54 insertions, 3 deletions
diff --git a/include/data_writer.h b/include/data_writer.h
index 1ff0d69..e29881b 100644
--- a/include/data_writer.h
+++ b/include/data_writer.h
@@ -24,6 +24,7 @@ typedef struct {
size_t sparse_blocks;
size_t frag_count;
size_t frag_dup;
+ uint64_t bytes_written;
uint64_t bytes_read;
} data_writer_stats_t;
diff --git a/lib/sqfshelper/data_writer.c b/lib/sqfshelper/data_writer.c
index 4134035..96cd9ee 100644
--- a/lib/sqfshelper/data_writer.c
+++ b/lib/sqfshelper/data_writer.c
@@ -28,6 +28,55 @@ struct data_writer_t {
data_writer_stats_t stats;
};
+
+static void post_block_write(void *user, const sqfs_block_t *block,
+ sqfs_file_t *file)
+{
+ data_writer_t *data = user;
+ (void)file;
+
+ if (block->flags & SQFS_BLK_FRAGMENT_BLOCK) {
+ data->stats.frag_blocks_written += 1;
+ } else {
+ data->stats.blocks_written += 1;
+ }
+
+ data->stats.bytes_written += block->size;
+}
+
+static void pre_fragment_store(void *user, sqfs_block_t *block)
+{
+ data_writer_t *data = user;
+ (void)block;
+
+ data->stats.frag_count += 1;
+}
+
+static void notify_blocks_erased(void *user, size_t count, uint64_t bytes)
+{
+ data_writer_t *data = user;
+ (void)bytes;
+
+ data->stats.bytes_written -= bytes;
+ data->stats.blocks_written -= count;
+ data->stats.duplicate_blocks += count;
+}
+
+static void notify_fragment_discard(void *user, const sqfs_block_t *block)
+{
+ data_writer_t *data = user;
+ (void)block;
+
+ data->stats.frag_dup += 1;
+}
+
+static const sqfs_block_hooks_t 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,
+};
+
static bool is_zero_block(unsigned char *ptr, size_t size)
{
return ptr[0] == 0 && memcmp(ptr, ptr + 1, size - 1) == 0;
@@ -166,6 +215,8 @@ data_writer_t *data_writer_create(sqfs_super_t *super, sqfs_compressor_t *cmp,
return NULL;
}
+ sqfs_data_writer_set_hooks(data->proc, data, &hooks);
+
data->cmp = cmp;
data->super = super;
return data;
diff --git a/lib/sqfshelper/statistics.c b/lib/sqfshelper/statistics.c
index fda4c3f..87efc30 100644
--- a/lib/sqfshelper/statistics.c
+++ b/lib/sqfshelper/statistics.c
@@ -11,11 +11,10 @@
void sqfs_print_statistics(sqfs_super_t *super, data_writer_stats_t *stats)
{
- uint64_t bytes_written = super->inode_table_start - sizeof(*super);
size_t ratio;
- if (bytes_written > 0) {
- ratio = (100 * bytes_written) / stats->bytes_read;
+ if (stats->bytes_written > 0) {
+ ratio = (100 * stats->bytes_written) / stats->bytes_read;
} else {
ratio = 100;
}