summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Makemodule.am1
-rw-r--r--lib/common/print_size.c38
-rw-r--r--lib/common/statistics.c21
3 files changed, 55 insertions, 5 deletions
diff --git a/lib/common/Makemodule.am b/lib/common/Makemodule.am
index ac1a4e9..c59ab4c 100644
--- a/lib/common/Makemodule.am
+++ b/lib/common/Makemodule.am
@@ -6,6 +6,7 @@ libcommon_a_SOURCES += lib/common/data_writer.c include/common.h
libcommon_a_SOURCES += lib/common/get_path.c lib/common/io_stdin.c
libcommon_a_SOURCES += lib/common/writer.c lib/common/perror.c
libcommon_a_SOURCES += lib/common/mkdir_p.c lib/common/parse_size.c
+libcommon_a_SOURCES += lib/common/print_size.c
libcommon_a_CFLAGS = $(AM_CFLAGS) $(LZO_CFLAGS)
if WITH_LZO
diff --git a/lib/common/print_size.c b/lib/common/print_size.c
new file mode 100644
index 0000000..6e76805
--- /dev/null
+++ b/lib/common/print_size.c
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * print_size.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+#include "common.h"
+
+void print_size(sqfs_u64 size, char *buffer, bool round_to_int)
+{
+ static const char *fractions = "0112334456678899";
+ static const char *suffices = "kMGTPEZY";
+ unsigned int fraction;
+ int suffix = -1;
+
+ while (size > 1024) {
+ ++suffix;
+ fraction = size % 1024;
+ size /= 1024;
+ }
+
+ if (suffix >= 0) {
+ fraction /= 64;
+
+ if (round_to_int) {
+ size = fraction >= 8 ? (size + 1) : size;
+
+ sprintf(buffer, "%u%c", (unsigned int)size,
+ suffices[suffix]);
+ } else {
+ sprintf(buffer, "%u.%c%c", (unsigned int)size,
+ fractions[fraction], suffices[suffix]);
+ }
+ } else {
+ sprintf(buffer, "%u", (unsigned int)size);
+ }
+}
diff --git a/lib/common/statistics.c b/lib/common/statistics.c
index eabe037..92d365c 100644
--- a/lib/common/statistics.c
+++ b/lib/common/statistics.c
@@ -14,6 +14,7 @@ void sqfs_print_statistics(const sqfs_super_t *super,
{
const sqfs_block_processor_stats_t *proc_stats;
const sqfs_block_writer_stats_t *wr_stats;
+ char read_sz[32], written_sz[32];
size_t ratio;
proc_stats = sqfs_block_processor_get_stats(blk);
@@ -26,18 +27,28 @@ void sqfs_print_statistics(const sqfs_super_t *super,
ratio = 100;
}
+ print_size(proc_stats->input_bytes_read, read_sz, false);
+ print_size(wr_stats->bytes_written, written_sz, false);
+
fputs("---------------------------------------------------\n", stdout);
- 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",
+ printf("Data bytes read: %s\n", read_sz);
+ printf("Data bytes written: %s\n", written_sz);
+ printf("Data compression ratio: " PRI_SZ "%%\n", ratio);
+ fputc('\n', stdout);
+
+ printf("Data blocks written: %lu\n", wr_stats->blocks_written);
+ printf("Out of which where fragment blocks: %lu\n",
+ proc_stats->frag_block_count);
+ printf("Duplicate blocks omitted: %lu\n",
wr_stats->blocks_submitted - wr_stats->blocks_written);
printf("Sparse blocks omitted: %lu\n", proc_stats->sparse_block_count);
+ fputc('\n', stdout);
+
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);
+ fputc('\n', stdout);
}