summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-27 18:10:38 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-28 16:33:57 +0200
commit3a795ed32935968218ce6feb8ab2459e8c215ee8 (patch)
tree756c0d13603bd131d38f7fcc6d2093cbbffaaad2
parentf7fa69e896f0971629f938be93cb30865f92943c (diff)
Add some nice statistics output to tar2sqfs and gensquashfs
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/highlevel.h3
-rw-r--r--lib/Makemodule.am2
-rw-r--r--lib/sqfs/statistics.c73
-rw-r--r--mkfs/mkfs.c3
-rw-r--r--tar/tar2sqfs.c3
5 files changed, 83 insertions, 1 deletions
diff --git a/include/highlevel.h b/include/highlevel.h
index cef6190..2a29410 100644
--- a/include/highlevel.h
+++ b/include/highlevel.h
@@ -87,4 +87,7 @@ int write_xattr(int outfd, fstree_t *fs, sqfs_super_t *super,
int write_export_table(int outfd, fstree_t *fs, sqfs_super_t *super,
compressor_t *cmp);
+/* Print out fancy statistics for squashfs packing tools */
+void sqfs_print_statistics(fstree_t *fs, sqfs_super_t *super);
+
#endif /* HIGHLEVEL_H */
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index 5f0cdae..8258136 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -37,7 +37,7 @@ libsquashfs_a_SOURCES += lib/sqfs/data_writer.c lib/sqfs/write_xattr.c
libsquashfs_a_SOURCES += include/data_writer.h
libsquashfs_a_SOURCES += include/data_reader.h lib/sqfs/data_reader.c
libsquashfs_a_SOURCES += lib/sqfs/write_export_table.c
-libsquashfs_a_SOURCES += lib/sqfs/read_table.c
+libsquashfs_a_SOURCES += lib/sqfs/read_table.c lib/sqfs/statistics.c
libutil_a_SOURCES = lib/util/canonicalize_name.c lib/util/write_data.c
libutil_a_SOURCES += lib/util/read_data.c include/util.h
diff --git a/lib/sqfs/statistics.c b/lib/sqfs/statistics.c
new file mode 100644
index 0000000..2bd4acf
--- /dev/null
+++ b/lib/sqfs/statistics.c
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include "config.h"
+#include "highlevel.h"
+
+#include <stdio.h>
+
+void sqfs_print_statistics(fstree_t *fs, sqfs_super_t *super)
+{
+ size_t blocks_written = 0, duplicate_blocks = 0, sparse_blocks = 0;
+ size_t ratio, file_count = 0, file_dup_count = 0;
+ size_t frag_count = 0, frag_dup = 0;
+ size_t i, num_blocks, sparse;
+ uint64_t output_bytes = 0;
+ uint64_t input_bytes = 0;
+ file_info_t *fi;
+
+ for (fi = fs->files; fi != NULL; fi = fi->next) {
+ num_blocks = fi->size / fs->block_size;
+
+ if ((fi->size % fs->block_size) &&
+ !(fi->flags & FILE_FLAG_HAS_FRAGMENT)) {
+ ++num_blocks;
+ }
+
+ for (sparse = 0, i = 0; i < num_blocks; ++i) {
+ if (fi->blocks[i].size == 0)
+ sparse += 1;
+ }
+
+ if (fi->flags & FILE_FLAG_BLOCKS_ARE_DUPLICATE) {
+ duplicate_blocks += num_blocks - sparse;
+ } else {
+ blocks_written += num_blocks - sparse;
+ }
+
+ if ((fi->flags & FILE_FLAG_FRAGMENT_IS_DUPLICATE) &&
+ (fi->flags & FILE_FLAG_BLOCKS_ARE_DUPLICATE)) {
+ file_dup_count += 1;
+ }
+
+ if (fi->flags & FILE_FLAG_HAS_FRAGMENT) {
+ if (fi->flags & FILE_FLAG_FRAGMENT_IS_DUPLICATE) {
+ frag_dup += 1;
+ } else {
+ frag_count += 1;
+ }
+ }
+
+ sparse_blocks += sparse;
+ file_count += 1;
+ input_bytes += fi->size;
+ }
+
+ if (input_bytes > 0) {
+ output_bytes = super->inode_table_start - sizeof(*super);
+ ratio = (100 * output_bytes) / input_bytes;
+ } else {
+ ratio = 100;
+ }
+
+ fputs("---------------------------------------------------\n", stdout);
+ printf("Input files processed: %zu\n", file_count);
+ printf("Files that were complete duplicates: %zu\n", file_dup_count);
+ printf("Data blocks actually written: %zu\n", blocks_written);
+ printf("Fragment blocks written: %u\n", super->fragment_entry_count);
+ printf("Duplicate data blocks omitted: %zu\n", duplicate_blocks);
+ printf("Sparse blocks omitted: %zu\n", sparse_blocks);
+ printf("Fragments actually written: %zu\n", frag_count);
+ printf("Duplicated fragments omitted: %zu\n", frag_dup);
+ 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: %zu%%\n", ratio);
+}
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index b5c514b..a5719cd 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -190,6 +190,9 @@ int main(int argc, char **argv)
if (padd_file(outfd, super.bytes_used, opt.devblksz))
goto out_data;
+ if (!opt.quiet)
+ sqfs_print_statistics(&fs, &super);
+
status = EXIT_SUCCESS;
out_data:
data_writer_destroy(data);
diff --git a/tar/tar2sqfs.c b/tar/tar2sqfs.c
index 836df21..ffb1c99 100644
--- a/tar/tar2sqfs.c
+++ b/tar/tar2sqfs.c
@@ -429,6 +429,9 @@ int main(int argc, char **argv)
if (padd_file(outfd, super.bytes_used, devblksize))
goto out;
+ if (!quiet)
+ sqfs_print_statistics(&fs, &super);
+
status = EXIT_SUCCESS;
out:
id_table_cleanup(&idtbl);