diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2025-04-15 13:29:31 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2025-04-16 13:09:11 +0200 |
commit | 112ff1861873de1eb2c40b521346ddb3db8b2fd3 (patch) | |
tree | d6ed02e3c31419a11136f38beb6a2cffe2794024 /src | |
parent | bed0e82c24b123799764309a2468ccfe7eee8adc (diff) | |
download | justbuild-112ff1861873de1eb2c40b521346ddb3db8b2fd3.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/main/main.cpp | 1 | ||||
-rw-r--r-- | src/buildtool/profile/TARGETS | 2 | ||||
-rw-r--r-- | src/buildtool/profile/profile.cpp | 37 | ||||
-rw-r--r-- | src/buildtool/profile/profile.hpp | 2 |
4 files changed, 42 insertions, 0 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 75c7ca73..7a7dc3f4 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -917,6 +917,7 @@ auto main(int argc, char* argv[]) -> int { Profile profile_data(arguments.analysis.profile); if (arguments.analysis.profile) { profile = &profile_data; + (*profile)->SetCLI(arguments); } // If no execution endpoint was given, the client should default to the diff --git a/src/buildtool/profile/TARGETS b/src/buildtool/profile/TARGETS index 9f4db4d8..318ed075 100644 --- a/src/buildtool/profile/TARGETS +++ b/src/buildtool/profile/TARGETS @@ -6,9 +6,11 @@ , "deps": [ ["@", "json", "", "json"] , ["src/buildtool/execution_api/common", "common"] + , ["src/buildtool/main", "cli"] ] , "private-deps": [ ["@", "gsl", "", "gsl"] + , ["src/buildtool/common", "cli"] , ["src/buildtool/common", "common"] , ["src/utils/cpp", "expected"] ] 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_}; diff --git a/src/buildtool/profile/profile.hpp b/src/buildtool/profile/profile.hpp index d90ad2a5..20360d3f 100644 --- a/src/buildtool/profile/profile.hpp +++ b/src/buildtool/profile/profile.hpp @@ -24,6 +24,7 @@ #include "nlohmann/json.hpp" #include "src/buildtool/execution_api/common/execution_response.hpp" +#include "src/buildtool/main/cli.hpp" class Profile { public: @@ -33,6 +34,7 @@ class Profile { } void Write(int exit_code); + void SetCLI(CommandLineArguments const& cli); void SetTarget(nlohmann::json target); void SetConfiguration(nlohmann::json configuration); void NoteActionCompleted(std::string const& id, |