From 112ff1861873de1eb2c40b521346ddb3db8b2fd3 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 15 Apr 2025 13:29:31 +0200 Subject: just profile: include subcommand and its arguments As parsing the the command-line is non-trivial, we include all the relevant information about the command line in the profile. This should also include the subcommand. For sake of completeness, we also include the non-option arguments of the subcommand. --- src/buildtool/profile/profile.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/buildtool/profile/profile.cpp') diff --git a/src/buildtool/profile/profile.cpp b/src/buildtool/profile/profile.cpp index 225542e6..22d6d89e 100644 --- a/src/buildtool/profile/profile.cpp +++ b/src/buildtool/profile/profile.cpp @@ -18,6 +18,7 @@ #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/cli.hpp" #include "src/utils/cpp/expected.hpp" void Profile::Write(int exit_code) { @@ -62,6 +63,42 @@ void Profile::SetConfiguration(nlohmann::json configuration) { profile_["configuration"] = std::move(configuration); } +void Profile::SetCLI(CommandLineArguments const& cli) { + switch (cli.cmd) { + case SubCommand::kDescribe: + profile_["subcommand"] = "describe"; + break; + case SubCommand::kAnalyse: + profile_["subcommand"] = "analyse"; + break; + case SubCommand::kBuild: + profile_["subcommand"] = "build"; + break; + case SubCommand::kInstall: + profile_["subcommand"] = "install"; + break; + case SubCommand::kRebuild: + profile_["subcommand"] = "rebuild"; + break; + default: + // We only log information on the commands that support profiling. + return; + } + if (cli.analysis.target) { + if (cli.analysis.target->is_array()) { + profile_["subcommand args"] = *cli.analysis.target; + } + else { + auto args = nlohmann::json::array(); + args.push_back(*cli.analysis.target); + profile_["subcommand args"] = args; + } + } + else { + profile_["subcommand args"] = nlohmann::json::array(); + } +} + void Profile::NoteActionCompleted(std::string const& id, IExecutionResponse::Ptr const& response) { std::unique_lock lock{mutex_}; -- cgit v1.2.3