summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-10 21:44:14 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-10 21:52:09 +0100
commit13a0c1b05a4b175f13decf3b15567dc71ea043ac (patch)
treee7d551fd43f69d828c58eb2b9e6d74254bafff10
parent060970feee2beea37e837e0a2d557e878e5f8290 (diff)
Cleanup statistics print out
- Give a rounded input/output byte count. - Seperate groups by new lines. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/common.h2
-rw-r--r--lib/common/Makemodule.am1
-rw-r--r--lib/common/print_size.c38
-rw-r--r--lib/common/statistics.c21
-rw-r--r--unpack/list_files.c25
5 files changed, 61 insertions, 26 deletions
diff --git a/include/common.h b/include/common.h
index a3055dc..0fd349a 100644
--- a/include/common.h
+++ b/include/common.h
@@ -162,4 +162,6 @@ sqfs_compressor_t *lzo_compressor_create(const sqfs_compressor_config_t *cfg);
int parse_size(const char *what, size_t *out, const char *str,
size_t reference);
+void print_size(sqfs_u64 size, char *buffer, bool round_to_int);
+
#endif /* COMMON_H */
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);
}
diff --git a/unpack/list_files.c b/unpack/list_files.c
index c08c2dd..238ffec 100644
--- a/unpack/list_files.c
+++ b/unpack/list_files.c
@@ -64,40 +64,23 @@ static int count_int_chars(unsigned int i)
return count;
}
-static void print_size(sqfs_u64 size, char *buffer)
-{
- static const char *suffices = "kMGTPEZY";
- int suffix = -1;
-
- while (size > 1024) {
- ++suffix;
- size /= 1024;
- }
-
- if (suffix >= 0) {
- sprintf(buffer, "%u%c", (unsigned int)size, suffices[suffix]);
- } else {
- sprintf(buffer, "%u", (unsigned int)size);
- }
-}
-
static void print_node_size(const sqfs_tree_node_t *n, char *buffer)
{
switch (n->inode->base.mode & S_IFMT) {
case S_IFLNK:
- print_size(strlen((const char *)n->inode->extra), buffer);
+ print_size(strlen((const char *)n->inode->extra), buffer, true);
break;
case S_IFREG: {
sqfs_u64 size;
sqfs_inode_get_file_size(n->inode, &size);
- print_size(size, buffer);
+ print_size(size, buffer, true);
break;
}
case S_IFDIR:
if (n->inode->base.type == SQFS_INODE_EXT_DIR) {
- print_size(n->inode->data.dir_ext.size, buffer);
+ print_size(n->inode->data.dir_ext.size, buffer, true);
} else {
- print_size(n->inode->data.dir.size, buffer);
+ print_size(n->inode->data.dir.size, buffer, true);
}
break;
case S_IFBLK: