aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-10 21:06:00 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-10 21:06:00 +0100
commit94a0b2783aa58b646260232ecfa3ff93f9b97d6d (patch)
treee0f356e7df1c2894fdbf15162d8467b42a062b21
parent6a7a7aaa4c7c715577d9649657412f99c06e1a95 (diff)
Add run time statistics to the block writer and processor
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/sqfs/block_processor.h65
-rw-r--r--include/sqfs/block_writer.h43
-rw-r--r--include/sqfs/predef.h2
-rw-r--r--lib/sqfs/block_processor/common.c11
-rw-r--r--lib/sqfs/block_processor/fileapi.c8
-rw-r--r--lib/sqfs/block_processor/internal.h2
-rw-r--r--lib/sqfs/block_writer.c21
7 files changed, 152 insertions, 0 deletions
diff --git a/include/sqfs/block_processor.h b/include/sqfs/block_processor.h
index 68d1c23..fb62678 100644
--- a/include/sqfs/block_processor.h
+++ b/include/sqfs/block_processor.h
@@ -43,6 +43,59 @@
* and finally writing it to disk.
*/
+/**
+ * @struct sqfs_block_processor_stats_t
+ *
+ * @brief Used to store runtime statistics about the @ref sqf_block_processor_t.
+ */
+struct sqfs_block_processor_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 fed into the front end API.
+ */
+ sqfs_u64 input_bytes_read;
+
+ /**
+ * @brief Total number of data blocks produced.
+ */
+ sqfs_u64 data_block_count;
+
+ /**
+ * @brief Total number of fragment blocks produced.
+ */
+ sqfs_u64 frag_block_count;
+
+ /**
+ * @brief Total number of sparse blocks encountered.
+ */
+ sqfs_u64 sparse_block_count;
+
+ /**
+ * @brief Total number of tail-end fragments produced.
+ *
+ * This number also includes the fragments that have later been
+ * eliminated by deduplication.
+ */
+ sqfs_u64 total_frag_count;
+
+ /**
+ * @brief Total number of tail-end fragments actually stored in
+ * fragment blocks.
+ *
+ * This number does not include the fragments that have been
+ * eliminated by deduplication.
+ */
+ sqfs_u64 actual_frag_count;
+};
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -181,6 +234,18 @@ SQFS_API
int sqfs_block_processor_set_hooks(sqfs_block_processor_t *proc, void *user_ptr,
const sqfs_block_hooks_t *hooks);
+/**
+ * @brief Get accumulated runtime statistics from a block processor
+ *
+ * @memberof sqfs_block_processor_t
+ *
+ * @param proc A pointer to a data writer object.
+ *
+ * @return A pointer to a @ref sqfs_block_processor_stats_t structure.
+ */
+SQFS_API const sqfs_block_processor_stats_t
+*sqfs_block_processor_get_stats(const sqfs_block_processor_t *proc);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/sqfs/block_writer.h b/include/sqfs/block_writer.h
index b4d804c..421f8bd 100644
--- a/include/sqfs/block_writer.h
+++ b/include/sqfs/block_writer.h
@@ -140,6 +140,46 @@ struct sqfs_block_hooks_t {
void (*prepare_padding)(void *user, sqfs_u8 *block, size_t count);
};
+/**
+ * @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
@@ -158,6 +198,9 @@ SQFS_API int sqfs_block_writer_write(sqfs_block_writer_t *wr,
sqfs_block_t *block,
sqfs_u64 *location);
+SQFS_API const sqfs_block_writer_stats_t
+*sqfs_block_writer_get_stats(const sqfs_block_writer_t *wr);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/sqfs/predef.h b/include/sqfs/predef.h
index 40d0e5d..87d7788 100644
--- a/include/sqfs/predef.h
+++ b/include/sqfs/predef.h
@@ -84,6 +84,8 @@ typedef struct sqfs_block_hooks_t sqfs_block_hooks_t;
typedef struct sqfs_xattr_writer_t sqfs_xattr_writer_t;
typedef struct sqfs_frag_table_t sqfs_frag_table_t;
typedef struct sqfs_block_writer_t sqfs_block_writer_t;
+typedef struct sqfs_block_writer_stats_t sqfs_block_writer_stats_t;
+typedef struct sqfs_block_processor_stats_t sqfs_block_processor_stats_t;
typedef struct sqfs_fragment_t sqfs_fragment_t;
typedef struct sqfs_dir_header_t sqfs_dir_header_t;
diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c
index fe9773e..bedc923 100644
--- a/lib/sqfs/block_processor/common.c
+++ b/lib/sqfs/block_processor/common.c
@@ -29,6 +29,9 @@ int block_processor_init(sqfs_block_processor_t *proc, size_t max_block_size,
proc->cmp = cmp;
proc->frag_tbl = tbl;
proc->wr = wr;
+
+ memset(&proc->stats, 0, sizeof(proc->stats));
+ proc->stats.size = sizeof(proc->stats);
return 0;
}
@@ -149,6 +152,7 @@ int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
proc->frag_block->index = index;
proc->frag_block->flags = SQFS_BLK_FRAGMENT_BLOCK;
+ proc->stats.frag_block_count += 1;
}
err = sqfs_frag_table_add_tail_end(proc->frag_tbl,
@@ -170,6 +174,7 @@ int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
proc->frag_block->flags |= (frag->flags & SQFS_BLK_DONT_COMPRESS);
proc->frag_block->size += frag->size;
+ proc->stats.actual_frag_count += 1;
return 0;
fail:
free(*blk_out);
@@ -184,3 +189,9 @@ out_duplicate:
}
return 0;
}
+
+const sqfs_block_processor_stats_t
+*sqfs_block_processor_get_stats(const sqfs_block_processor_t *proc)
+{
+ return &proc->stats;
+}
diff --git a/lib/sqfs/block_processor/fileapi.c b/lib/sqfs/block_processor/fileapi.c
index 9e59c1d..dee1d5e 100644
--- a/lib/sqfs/block_processor/fileapi.c
+++ b/lib/sqfs/block_processor/fileapi.c
@@ -69,15 +69,21 @@ static int flush_block(sqfs_block_processor_t *proc, sqfs_block_t *block)
proc->inode->num_file_blocks += 1;
proc->inode->extra[block->index] = 0;
free(block);
+
+ proc->stats.sparse_block_count += 1;
return 0;
}
if (block->size < proc->max_block_size &&
!(block->flags & SQFS_BLK_DONT_FRAGMENT)) {
block->flags |= SQFS_BLK_IS_FRAGMENT;
+
+ proc->stats.total_frag_count += 1;
} else {
proc->inode->num_file_blocks += 1;
proc->blk_flags &= ~SQFS_BLK_FIRST_BLOCK;
+
+ proc->stats.data_block_count += 1;
}
return enqueue_block(proc, block);
@@ -121,6 +127,8 @@ int sqfs_block_processor_append(sqfs_block_processor_t *proc, const void *data,
size -= diff;
proc->blk_current->size += diff;
data = (const char *)data + diff;
+
+ proc->stats.input_bytes_read += diff;
}
if (proc->blk_current != NULL &&
diff --git a/lib/sqfs/block_processor/internal.h b/lib/sqfs/block_processor/internal.h
index 09e879b..dcf8a09 100644
--- a/lib/sqfs/block_processor/internal.h
+++ b/lib/sqfs/block_processor/internal.h
@@ -71,6 +71,8 @@ struct sqfs_block_processor_t {
const sqfs_block_hooks_t *hooks;
void *user_ptr;
+ sqfs_block_processor_stats_t stats;
+
/* file API */
sqfs_inode_generic_t *inode;
sqfs_block_t *blk_current;
diff --git a/lib/sqfs/block_writer.c b/lib/sqfs/block_writer.c
index c955532..94bd044 100644
--- a/lib/sqfs/block_writer.c
+++ b/lib/sqfs/block_writer.c
@@ -33,9 +33,13 @@ struct sqfs_block_writer_t {
blk_info_t *blocks;
size_t devblksz;
+ sqfs_block_writer_stats_t stats;
+
const sqfs_block_hooks_t *hooks;
void *user_ptr;
+ sqfs_u64 data_area_start;
+
sqfs_u64 start;
size_t file_start;
};
@@ -129,6 +133,8 @@ 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);
if (wr->blocks == NULL) {
@@ -192,6 +198,12 @@ int sqfs_block_writer_write(sqfs_block_writer_t *wr, sqfs_block_t *block,
block->data, block->size);
if (err)
return err;
+
+ wr->stats.bytes_submitted += block->size;
+ wr->stats.blocks_submitted += 1;
+ wr->stats.blocks_written = wr->num_blocks;
+ wr->stats.bytes_written = offset + block->size -
+ wr->data_area_start;
}
if (wr->hooks != NULL && wr->hooks->post_block_write != NULL)
@@ -229,7 +241,16 @@ int sqfs_block_writer_write(sqfs_block_writer_t *wr, sqfs_block_t *block,
err = wr->file->truncate(wr->file, wr->start);
if (err)
return err;
+
+ wr->stats.blocks_written = wr->num_blocks;
+ wr->stats.bytes_written = wr->start - wr->data_area_start;
}
return 0;
}
+
+const sqfs_block_writer_stats_t
+*sqfs_block_writer_get_stats(const sqfs_block_writer_t *wr)
+{
+ return &wr->stats;
+}