Skip to content

Commit 5b64567

Browse files
committed
btrfs-progs: tree-stats: add options for size output units
Add the usual long options for all byte size related values in the output. Issue: #268 Signed-off-by: David Sterba <[email protected]>
1 parent 8a35f9d commit 5b64567

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

Documentation/btrfs-inspect-internal.rst

+18-2
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,27 @@ tree-stats [options] <device>
229229

230230
``Options``
231231

232-
-b
233-
Print raw numbers in bytes.
232+
-b|--raw
233+
raw numbers in bytes, without the *B* suffix
234234

235235
-t <treeid>
236236
Print stats only for the given treeid.
237+
--human-readable
238+
print human friendly numbers, base 1024, this is the default
239+
240+
--iec
241+
select the 1024 base for the following options, according to the IEC standard
242+
--si
243+
select the 1000 base for the following options, according to the SI standard
244+
245+
--kbytes
246+
show sizes in KiB, or kB with --si
247+
--mbytes
248+
show sizes in MiB, or MB with --si
249+
--gbytes
250+
show sizes in GiB, or GB with --si
251+
--tbytes
252+
show sizes in TiB, or TB with --si
237253

238254
EXIT STATUS
239255
-----------

cmds/inspect-tree-stats.c

+19-16
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static void timeval_subtract(struct timeval *result, struct timeval *x,
316316
}
317317

318318
static int calc_root_size(struct btrfs_root *tree_root, struct btrfs_key *key,
319-
int find_inline)
319+
int find_inline, unsigned int unit_mode)
320320
{
321321
struct btrfs_root *root;
322322
struct btrfs_path path = { 0 };
@@ -385,26 +385,25 @@ static int calc_root_size(struct btrfs_root *tree_root, struct btrfs_key *key,
385385
pr_verbose(LOG_DEFAULT, "\tTotal read time: %d s %d us\n", (int)diff.tv_sec,
386386
(int)diff.tv_usec);
387387
} else {
388-
pr_verbose(LOG_DEFAULT, "\tTotal size: %s\n", pretty_size(stat.total_bytes));
389-
pr_verbose(LOG_DEFAULT, "\t\tInline data: %s\n", pretty_size(stat.total_inline));
388+
pr_verbose(LOG_DEFAULT, "\tTotal size: %s\n", pretty_size_mode(stat.total_bytes, unit_mode));
389+
pr_verbose(LOG_DEFAULT, "\t\tInline data: %s\n", pretty_size_mode(stat.total_inline, unit_mode));
390390
pr_verbose(LOG_DEFAULT, "\tTotal seeks: %llu\n", stat.total_seeks);
391391
pr_verbose(LOG_DEFAULT, "\t\tForward seeks: %llu\n", stat.forward_seeks);
392392
pr_verbose(LOG_DEFAULT, "\t\tBackward seeks: %llu\n", stat.backward_seeks);
393393
pr_verbose(LOG_DEFAULT, "\t\tAvg seek len: %s\n", stat.total_seeks ?
394-
pretty_size(stat.total_seek_len / stat.total_seeks) :
395-
pretty_size(0));
394+
pretty_size_mode(stat.total_seek_len / stat.total_seeks, unit_mode) :
395+
pretty_size_mode(0, unit_mode));
396396
print_seek_histogram(&stat);
397397
pr_verbose(LOG_DEFAULT, "\tTotal clusters: %llu\n", stat.total_clusters);
398398
pr_verbose(LOG_DEFAULT, "\t\tAvg cluster size: %s\n",
399-
pretty_size((stat.total_cluster_size /
400-
stat.total_clusters)));
399+
pretty_size_mode((stat.total_cluster_size /
400+
stat.total_clusters), unit_mode));
401401
pr_verbose(LOG_DEFAULT, "\t\tMin cluster size: %s\n",
402-
pretty_size(stat.min_cluster_size));
402+
pretty_size_mode(stat.min_cluster_size, unit_mode));
403403
pr_verbose(LOG_DEFAULT, "\t\tMax cluster size: %s\n",
404-
pretty_size(stat.max_cluster_size));
404+
pretty_size_mode(stat.max_cluster_size, unit_mode));
405405
pr_verbose(LOG_DEFAULT, "\tTotal disk spread: %s\n",
406-
pretty_size(stat.highest_bytenr -
407-
stat.lowest_bytenr));
406+
pretty_size_mode(stat.highest_bytenr - stat.lowest_bytenr, unit_mode));
408407
pr_verbose(LOG_DEFAULT, "\tTotal read time: %d s %d us\n", (int)diff.tv_sec,
409408
(int)diff.tv_usec);
410409
}
@@ -442,6 +441,7 @@ static const char * const cmd_inspect_tree_stats_usage[] = {
442441
"Print various stats for trees",
443442
"",
444443
OPTLINE("-b", "raw numbers in bytes"),
444+
HELPINFO_UNITS_LONG,
445445
OPTLINE("-t <rootid>", "print only tree with the given rootid"),
446446
NULL
447447
};
@@ -451,10 +451,13 @@ static int cmd_inspect_tree_stats(const struct cmd_struct *cmd,
451451
{
452452
struct btrfs_key key = { .type = BTRFS_ROOT_ITEM_KEY };
453453
struct btrfs_root *root;
454+
unsigned int unit_mode;
454455
int opt;
455456
int ret = 0;
456457
u64 tree_id = 0;
457458

459+
unit_mode = get_unit_mode_from_arg(&argc, argv, 0);
460+
458461
optind = 0;
459462
while ((opt = getopt(argc, argv, "vbt:")) != -1) {
460463
switch (opt) {
@@ -499,32 +502,32 @@ static int cmd_inspect_tree_stats(const struct cmd_struct *cmd,
499502
pr_verbose(LOG_DEFAULT, "Calculating size of tree (%llu)\n", tree_id);
500503
key.objectid = tree_id;
501504
key.offset = (u64)-1;
502-
ret = calc_root_size(root, &key, 1);
505+
ret = calc_root_size(root, &key, 1, unit_mode);
503506
goto out;
504507
}
505508

506509
pr_verbose(LOG_DEFAULT, "Calculating size of root tree\n");
507510
key.objectid = BTRFS_ROOT_TREE_OBJECTID;
508-
ret = calc_root_size(root, &key, 0);
511+
ret = calc_root_size(root, &key, 0, unit_mode);
509512
if (ret)
510513
goto out;
511514

512515
pr_verbose(LOG_DEFAULT, "Calculating size of extent tree\n");
513516
key.objectid = BTRFS_EXTENT_TREE_OBJECTID;
514-
ret = calc_root_size(root, &key, 0);
517+
ret = calc_root_size(root, &key, 0, unit_mode);
515518
if (ret)
516519
goto out;
517520

518521
pr_verbose(LOG_DEFAULT, "Calculating size of csum tree\n");
519522
key.objectid = BTRFS_CSUM_TREE_OBJECTID;
520-
ret = calc_root_size(root, &key, 0);
523+
ret = calc_root_size(root, &key, 0, unit_mode);
521524
if (ret)
522525
goto out;
523526

524527
key.objectid = BTRFS_FS_TREE_OBJECTID;
525528
key.offset = (u64)-1;
526529
pr_verbose(LOG_DEFAULT, "Calculating size of fs tree\n");
527-
ret = calc_root_size(root, &key, 1);
530+
ret = calc_root_size(root, &key, 1, unit_mode);
528531
if (ret)
529532
goto out;
530533
out:

0 commit comments

Comments
 (0)