Skip to content

Commit ab8574c

Browse files
reddevillgdengbo11
authored andcommitted
feat: add ll-cli analyze size subcommand
Add a new `analyze size` subcommand to ll-cli that reports on-disk usage of installed layers, breaking each module's footprint into: - exclusive: bytes unique to that module - shared: bytes shared with at least one other module - logical: exclusive + shared (apparent size to the module) - actual: shared bytes divided across the sharing modules Sizes are computed from st_blocks (real block usage, not file size), and hard-linked inodes are deduplicated by (st_dev, st_ino) so they are counted once per sharing module. A separate pass reports the total real disk usage of the repository directory for cross-reference. Options: --sort {actual|logical|exclusive|shared|id} (default: actual) --asc (default: descending) Signed-off-by: reddevillg <reddevillg@gmail.com>
1 parent 0aeb0f3 commit ab8574c

9 files changed

Lines changed: 506 additions & 5 deletions

File tree

apps/ll-cli/src/main.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,40 @@ ll-cli list --upgradable
432432
"application(s), base(s) or runtime(s)"));
433433
}
434434

435+
// Function to add the analyze size subcommand
436+
void addAnalyzeSizeCommand(CLI::App &cliAnalyze, SizeOptions &sizeOptions)
437+
{
438+
auto *cliSize =
439+
cliAnalyze.add_subcommand("size", _("Show installed module sizes and repository real size"))
440+
->fallthrough();
441+
cliSize->usage(_(R"(Usage: ll-cli analyze size [OPTIONS]
442+
443+
Example:
444+
# show installed module sizes
445+
ll-cli analyze size
446+
)"));
447+
cliSize
448+
->add_option(
449+
"--sort",
450+
sizeOptions.sortBy,
451+
_(R"(Sort result by specify field. One of "actual", "logical", "exclusive", "shared" or "id")"))
452+
->type_name("FIELD")
453+
->capture_default_str()
454+
->check(CLI::IsMember({ "actual", "logical", "exclusive", "shared", "id" }));
455+
cliSize->add_flag("--asc", sizeOptions.ascending, _("Sort in ascending order"));
456+
}
457+
458+
// Function to add the analyze subcommands
459+
void addAnalyzeCommand(CLI::App &commandParser, SizeOptions &sizeOptions, const std::string &group)
460+
{
461+
auto *cliAnalyze = commandParser.add_subcommand("analyze", _("Analyze installed applications"))
462+
->group(group)
463+
->usage(_("Usage: ll-cli analyze SUBCOMMAND [OPTIONS]"));
464+
cliAnalyze->require_subcommand(1);
465+
466+
addAnalyzeSizeCommand(*cliAnalyze, sizeOptions);
467+
}
468+
435469
// Function to add the info subcommand
436470
void addInfoCommand(CLI::App &commandParser, InfoOptions &infoOptions, const std::string &group)
437471
{
@@ -566,6 +600,7 @@ You can report bugs to the linyaps team under this project: https://github.com/O
566600
SearchOptions searchOptions{};
567601
UninstallOptions uninstallOptions{};
568602
ListOptions listOptions{};
603+
SizeOptions sizeOptions{};
569604
InfoOptions infoOptions{};
570605
ContentOptions contentOptions{};
571606
linglong::common::cli::RepoOptions repoOptions{};
@@ -587,6 +622,7 @@ You can report bugs to the linyaps team under this project: https://github.com/O
587622
addUpgradeCommand(commandParser, upgradeOptions, CliBuildInGroup);
588623
addSearchCommand(commandParser, searchOptions, CliSearchGroup);
589624
addListCommand(commandParser, listOptions, CliBuildInGroup);
625+
addAnalyzeCommand(commandParser, sizeOptions, CliBuildInGroup);
590626
linglong::common::cli::addRepoCommand(commandParser,
591627
repoOptions,
592628
CliRepoGroup,
@@ -743,6 +779,14 @@ You can report bugs to the linyaps team under this project: https://github.com/O
743779
result = cli->uninstall(uninstallOptions);
744780
} else if (name == "list") {
745781
result = cli->list(listOptions);
782+
} else if (name == "analyze") {
783+
const auto &subcommands = (*ret)->get_subcommands();
784+
auto subcommand = std::find_if(subcommands.begin(), subcommands.end(), [](CLI::App *app) {
785+
return app->parsed();
786+
});
787+
if (subcommand != subcommands.end() && (*subcommand)->get_name() == "size") {
788+
result = cli->size(sizeOptions);
789+
}
746790
} else if (name == "info") {
747791
result = cli->info(infoOptions);
748792
} else if (name == "content") {

0 commit comments

Comments
 (0)