btrfs-progs: inspect tree-stats: support to show a specified tree
tree-stats currently displays only some global trees and fs-tree 5. Add support to show the stats of a specified tree. Issue: #268 Signed-off-by: Chung-Chiang Cheng <cccheng@synology.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
2eadd15e6b
commit
ef8e050d64
|
@ -228,6 +228,9 @@ tree-stats [options] <device>
|
||||||
-b
|
-b
|
||||||
Print raw numbers in bytes.
|
Print raw numbers in bytes.
|
||||||
|
|
||||||
|
-t <treeid>
|
||||||
|
Print stats only for the given treeid.
|
||||||
|
|
||||||
EXIT STATUS
|
EXIT STATUS
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "common/help.h"
|
#include "common/help.h"
|
||||||
#include "common/messages.h"
|
#include "common/messages.h"
|
||||||
#include "common/open-utils.h"
|
#include "common/open-utils.h"
|
||||||
|
#include "common/string-utils.h"
|
||||||
#include "common/units.h"
|
#include "common/units.h"
|
||||||
#include "cmds/commands.h"
|
#include "cmds/commands.h"
|
||||||
|
|
||||||
|
@ -441,6 +442,7 @@ static const char * const cmd_inspect_tree_stats_usage[] = {
|
||||||
"Print various stats for trees",
|
"Print various stats for trees",
|
||||||
"",
|
"",
|
||||||
OPTLINE("-b", "raw numbers in bytes"),
|
OPTLINE("-b", "raw numbers in bytes"),
|
||||||
|
OPTLINE("-t <rootid>", "print only tree with the given rootid"),
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -451,9 +453,10 @@ static int cmd_inspect_tree_stats(const struct cmd_struct *cmd,
|
||||||
struct btrfs_root *root;
|
struct btrfs_root *root;
|
||||||
int opt;
|
int opt;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
u64 tree_id = 0;
|
||||||
|
|
||||||
optind = 0;
|
optind = 0;
|
||||||
while ((opt = getopt(argc, argv, "vb")) != -1) {
|
while ((opt = getopt(argc, argv, "vbt:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose++;
|
verbose++;
|
||||||
|
@ -461,6 +464,13 @@ static int cmd_inspect_tree_stats(const struct cmd_struct *cmd,
|
||||||
case 'b':
|
case 'b':
|
||||||
no_pretty = true;
|
no_pretty = true;
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
tree_id = arg_strtou64(optarg);
|
||||||
|
if (!tree_id) {
|
||||||
|
error("unrecognized tree id: %s", optarg);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage_unknown_option(cmd, argv);
|
usage_unknown_option(cmd, argv);
|
||||||
}
|
}
|
||||||
|
@ -485,6 +495,14 @@ static int cmd_inspect_tree_stats(const struct cmd_struct *cmd,
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tree_id) {
|
||||||
|
pr_verbose(LOG_DEFAULT, "Calculating size of tree (%llu)\n", tree_id);
|
||||||
|
key.objectid = tree_id;
|
||||||
|
key.offset = (u64)-1;
|
||||||
|
ret = calc_root_size(root, &key, 1);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
pr_verbose(LOG_DEFAULT, "Calculating size of root tree\n");
|
pr_verbose(LOG_DEFAULT, "Calculating size of root tree\n");
|
||||||
key.objectid = BTRFS_ROOT_TREE_OBJECTID;
|
key.objectid = BTRFS_ROOT_TREE_OBJECTID;
|
||||||
ret = calc_root_size(root, &key, 0);
|
ret = calc_root_size(root, &key, 0);
|
||||||
|
|
Loading…
Reference in New Issue