From aff8ee2242b6faf853337b6aca727f02e14e7995 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 16 Apr 2025 10:44:51 +0200 Subject: just profile: include exit code of actions Extend the profile by including non-zero exit codes of individual actions. When looking at an individual build invocation, the actions with non-zero exit code are often the interesting ones, like root cause of a build failure, or failing tests. Therefore, it is useful information to include this information; by leaving out the exit code if it is zero, we do not significantly increase the profile. --- share/man/just-profile.5.md | 2 ++ src/buildtool/profile/profile.cpp | 5 +++++ src/buildtool/profile/profile.hpp | 1 + 3 files changed, 8 insertions(+) diff --git a/share/man/just-profile.5.md b/share/man/just-profile.5.md index 70895efe..c04712af 100644 --- a/share/man/just-profile.5.md +++ b/share/man/just-profile.5.md @@ -53,6 +53,8 @@ The profile file contains the following information. - For the key *`"time"`* for non-cached actions the build time in seconds. + - For the key *`"exit code"`* the exit code of the action, if not 0. + - For the key *`"artifacts"`* an object with keys the output paths and values the hashes of the corresponding artifacts as hex-encoded strings. diff --git a/src/buildtool/profile/profile.cpp b/src/buildtool/profile/profile.cpp index 6d1cc34d..225542e6 100644 --- a/src/buildtool/profile/profile.cpp +++ b/src/buildtool/profile/profile.cpp @@ -33,6 +33,9 @@ void Profile::Write(int exit_code) { if (not v.cached) { entry["duration"] = v.duration; } + if (v.exit_code != 0) { + entry["exit code"] = v.exit_code; + } entry["artifacts"] = v.artifacts; if (v.out) { entry["stdout"] = *v.out; @@ -81,6 +84,7 @@ void Profile::NoteActionCompleted(std::string const& id, actions_[id] = ActionData{ .cached = response->IsCached(), .duration = response->ExecutionDuration(), + .exit_code = response->ExitCode(), .out = out, .err = err, .artifacts = std::unordered_map()}; @@ -89,6 +93,7 @@ void Profile::NoteActionCompleted(std::string const& id, actions_[id] = ActionData{ .cached = response->IsCached(), .duration = response->ExecutionDuration(), + .exit_code = response->ExitCode(), .out = out, .err = err, .artifacts = std::unordered_map( diff --git a/src/buildtool/profile/profile.hpp b/src/buildtool/profile/profile.hpp index 71511245..d90ad2a5 100644 --- a/src/buildtool/profile/profile.hpp +++ b/src/buildtool/profile/profile.hpp @@ -42,6 +42,7 @@ class Profile { struct ActionData { bool cached; double duration; + int exit_code; std::optional out; std::optional err; std::unordered_map artifacts; -- cgit v1.2.3