summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildtool/computed_roots/evaluate.cpp3
-rw-r--r--src/buildtool/execution_engine/executor/TARGETS2
-rw-r--r--src/buildtool/execution_engine/executor/context.hpp4
-rw-r--r--src/buildtool/execution_engine/executor/executor.hpp34
-rw-r--r--src/buildtool/main/main.cpp3
-rw-r--r--src/buildtool/profile/TARGETS5
-rw-r--r--src/buildtool/profile/profile.cpp17
-rw-r--r--src/buildtool/profile/profile.hpp14
-rw-r--r--src/buildtool/serve_api/serve_service/target.cpp3
-rw-r--r--test/buildtool/execution_engine/executor/executor.test.cpp27
-rw-r--r--test/buildtool/execution_engine/executor/executor_api.test.hpp24
-rw-r--r--test/buildtool/graph_traverser/graph_traverser.test.hpp30
12 files changed, 124 insertions, 42 deletions
diff --git a/src/buildtool/computed_roots/evaluate.cpp b/src/buildtool/computed_roots/evaluate.cpp
index 839f9f98..507f13a9 100644
--- a/src/buildtool/computed_roots/evaluate.cpp
+++ b/src/buildtool/computed_roots/evaluate.cpp
@@ -205,7 +205,8 @@ void ComputeAndFill(
context->apis,
context->remote_context,
&statistics,
- &progress};
+ &progress,
+ std::nullopt};
auto cache_lookup =
expected<std::optional<std::string>, std::monostate>(std::nullopt);
diff --git a/src/buildtool/execution_engine/executor/TARGETS b/src/buildtool/execution_engine/executor/TARGETS
index 4e3d1abd..049efe44 100644
--- a/src/buildtool/execution_engine/executor/TARGETS
+++ b/src/buildtool/execution_engine/executor/TARGETS
@@ -30,6 +30,7 @@
, ["src/buildtool/file_system", "object_type"]
, ["src/buildtool/logging", "log_level"]
, ["src/buildtool/logging", "logging"]
+ , ["src/buildtool/profile", "profile"]
, ["src/buildtool/progress_reporting", "progress"]
, ["src/buildtool/progress_reporting", "task_tracker"]
, ["src/utils/cpp", "back_map"]
@@ -50,6 +51,7 @@
, ["src/buildtool/common", "statistics"]
, ["src/buildtool/execution_api/common", "api_bundle"]
, ["src/buildtool/execution_api/remote", "context"]
+ , ["src/buildtool/profile", "profile"]
, ["src/buildtool/progress_reporting", "progress"]
]
, "stage": ["src", "buildtool", "execution_engine", "executor"]
diff --git a/src/buildtool/execution_engine/executor/context.hpp b/src/buildtool/execution_engine/executor/context.hpp
index 315ab805..cbc2af15 100644
--- a/src/buildtool/execution_engine/executor/context.hpp
+++ b/src/buildtool/execution_engine/executor/context.hpp
@@ -15,11 +15,14 @@
#ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_ENGINE_EXECUTOR_CONTEXT_HPP
#define INCLUDED_SRC_BUILDTOOL_EXECUTION_ENGINE_EXECUTOR_CONTEXT_HPP
+#include <optional>
+
#include "gsl/gsl"
#include "src/buildtool/common/repository_config.hpp"
#include "src/buildtool/common/statistics.hpp"
#include "src/buildtool/execution_api/common/api_bundle.hpp"
#include "src/buildtool/execution_api/remote/context.hpp"
+#include "src/buildtool/profile/profile.hpp"
#include "src/buildtool/progress_reporting/progress.hpp"
/// \brief Aggregate to be passed to graph traverser.
@@ -30,6 +33,7 @@ struct ExecutionContext final {
gsl::not_null<RemoteContext const*> const remote_context;
gsl::not_null<Statistics*> const statistics;
gsl::not_null<Progress*> const progress;
+ std::optional<gsl::not_null<Profile*>> const profile;
};
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_ENGINE_EXECUTOR_CONTEXT_HPP
diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp
index 93cb9655..e030d2d6 100644
--- a/src/buildtool/execution_engine/executor/executor.hpp
+++ b/src/buildtool/execution_engine/executor/executor.hpp
@@ -64,6 +64,7 @@
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
+#include "src/buildtool/profile/profile.hpp"
#include "src/buildtool/progress_reporting/progress.hpp"
#include "src/buildtool/progress_reporting/task_tracker.hpp"
#include "src/utils/cpp/back_map.hpp"
@@ -828,11 +829,19 @@ class Executor {
context_.statistics,
context_.progress);
// check response and save digests of results
- return not response or Impl::ParseResponse(*logger_,
- *response,
- action,
- context_.statistics,
- context_.progress);
+ if (not response) {
+ return true;
+ }
+ auto result = Impl::ParseResponse(*logger_,
+ *response,
+ action,
+ context_.statistics,
+ context_.progress);
+ if (context_.profile) {
+ (*context_.profile)
+ ->NoteActionCompleted(action->Content().Id(), *response);
+ }
+ return result;
}
Logger logger("action:" + action->Content().Id());
@@ -851,11 +860,16 @@ class Executor {
context_.progress);
// check response and save digests of results
- return not response or Impl::ParseResponse(logger,
- *response,
- action,
- context_.statistics,
- context_.progress);
+ if (not response) {
+ return true;
+ }
+ auto result = Impl::ParseResponse(
+ logger, *response, action, context_.statistics, context_.progress);
+ if (context_.profile) {
+ (*context_.profile)
+ ->NoteActionCompleted(action->Content().Id(), *response);
+ }
+ return result;
}
/// \brief Check artifact is available to the CAS or upload it.
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 2f41ca72..108b9798 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -999,7 +999,8 @@ auto main(int argc, char* argv[]) -> int {
.apis = &main_apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = profile};
const GraphTraverser::CommandLineArguments traverse_args{
jobs,
std::move(arguments.build),
diff --git a/src/buildtool/profile/TARGETS b/src/buildtool/profile/TARGETS
index c2bde05e..657758ba 100644
--- a/src/buildtool/profile/TARGETS
+++ b/src/buildtool/profile/TARGETS
@@ -3,7 +3,10 @@
, "name": ["profile"]
, "hdrs": ["profile.hpp"]
, "srcs": ["profile.cpp"]
- , "deps": [["@", "json", "", "json"]]
+ , "deps":
+ [ ["@", "json", "", "json"]
+ , ["src/buildtool/execution_api/common", "common"]
+ ]
, "stage": ["src", "buildtool", "profile"]
}
}
diff --git a/src/buildtool/profile/profile.cpp b/src/buildtool/profile/profile.cpp
index 543cd681..3ee7f2a6 100644
--- a/src/buildtool/profile/profile.cpp
+++ b/src/buildtool/profile/profile.cpp
@@ -20,6 +20,17 @@ void Profile::Write(int exit_code) {
if (not output_file_) {
return;
}
+
+ if (not actions_.empty()) {
+ auto actions = nlohmann::json::object();
+ for (auto const& [k, v] : actions_) {
+ auto entry = nlohmann::json::object();
+ entry["cached"] = v.cached;
+ actions[k] = entry;
+ }
+ profile_["actions"] = actions;
+ }
+
profile_["exit code"] = exit_code;
std::ofstream os(*output_file_);
@@ -33,3 +44,9 @@ void Profile::SetTarget(nlohmann::json target) {
void Profile::SetConfiguration(nlohmann::json configuration) {
profile_["configuration"] = std::move(configuration);
}
+
+void Profile::NoteActionCompleted(std::string const& id,
+ IExecutionResponse::Ptr const& response) {
+ std::unique_lock lock{mutex_};
+ actions_[id] = ActionData{.cached = response->IsCached()};
+}
diff --git a/src/buildtool/profile/profile.hpp b/src/buildtool/profile/profile.hpp
index 0d4e14b6..6cf222e1 100644
--- a/src/buildtool/profile/profile.hpp
+++ b/src/buildtool/profile/profile.hpp
@@ -15,26 +15,38 @@
#ifndef INCLUDED_SRC_BUILDTOOL_PROFILE_PROFILE_HPP
#define INCLUDED_SRC_BUILDTOOL_PROFILE_PROFILE_HPP
+#include <functional>
+#include <mutex>
#include <optional>
#include <string>
+#include <unordered_map>
#include <utility>
#include "nlohmann/json.hpp"
+#include "src/buildtool/execution_api/common/execution_response.hpp"
class Profile {
public:
explicit Profile(std::optional<std::string> output_file)
- : output_file_{std::move(output_file)} {
+ : output_file_{std::move(output_file)}, actions_{}, mutex_{} {
profile_ = nlohmann::json::object();
}
void Write(int exit_code);
void SetTarget(nlohmann::json target);
void SetConfiguration(nlohmann::json configuration);
+ void NoteActionCompleted(std::string const& id,
+ IExecutionResponse::Ptr const& response);
private:
+ struct ActionData {
+ bool cached;
+ };
+
std::optional<std::string> output_file_;
nlohmann::json profile_;
+ std::unordered_map<std::string, ActionData> actions_;
+ std::mutex mutex_;
};
#endif
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp
index 6b46157c..e8a0714e 100644
--- a/src/buildtool/serve_api/serve_service/target.cpp
+++ b/src/buildtool/serve_api/serve_service/target.cpp
@@ -558,7 +558,8 @@ auto TargetService::ServeTarget(
.apis = &local_apis,
.remote_context = &dispatch_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
GraphTraverser const traverser{
std::move(traverser_args),
diff --git a/test/buildtool/execution_engine/executor/executor.test.cpp b/test/buildtool/execution_engine/executor/executor.test.cpp
index 9af21383..b929412f 100644
--- a/test/buildtool/execution_engine/executor/executor.test.cpp
+++ b/test/buildtool/execution_engine/executor/executor.test.cpp
@@ -353,7 +353,8 @@ TEST_CASE("Executor: Process artifact", "[executor]") {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id)));
@@ -371,7 +372,8 @@ TEST_CASE("Executor: Process artifact", "[executor]") {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK(not runner.Process(g.ArtifactNodeWithId(local_cpp_id)));
@@ -389,7 +391,8 @@ TEST_CASE("Executor: Process artifact", "[executor]") {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id)));
@@ -436,7 +439,8 @@ TEST_CASE("Executor: Process action", "[executor]") {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id)));
@@ -457,7 +461,8 @@ TEST_CASE("Executor: Process action", "[executor]") {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id)));
@@ -478,7 +483,8 @@ TEST_CASE("Executor: Process action", "[executor]") {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id)));
@@ -502,7 +508,8 @@ TEST_CASE("Executor: Process action", "[executor]") {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id)));
@@ -523,7 +530,8 @@ TEST_CASE("Executor: Process action", "[executor]") {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id)));
@@ -547,7 +555,8 @@ TEST_CASE("Executor: Process action", "[executor]") {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id)));
diff --git a/test/buildtool/execution_engine/executor/executor_api.test.hpp b/test/buildtool/execution_engine/executor/executor_api.test.hpp
index 6a8f409e..8ec43fb0 100644
--- a/test/buildtool/execution_engine/executor/executor_api.test.hpp
+++ b/test/buildtool/execution_engine/executor/executor_api.test.hpp
@@ -159,7 +159,8 @@ static inline void RunHelloWorldCompilation(
.apis = &apis,
.remote_context = &remote_context,
.statistics = stats,
- .progress = progress};
+ .progress = progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
// upload local artifacts
@@ -290,7 +291,8 @@ static inline void RunGreeterCompilation(
.apis = &apis,
.remote_context = &remote_context,
.statistics = stats,
- .progress = progress};
+ .progress = progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
// upload local artifacts
@@ -457,7 +459,8 @@ static inline void TestUploadAndDownloadTrees(
.apis = &apis,
.remote_context = &remote_context,
.statistics = stats,
- .progress = progress};
+ .progress = progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
REQUIRE(runner.Process(g.ArtifactNodeWithId(foo_id)));
@@ -629,7 +632,8 @@ static inline void TestRetrieveOutputDirectories(
.apis = &apis,
.remote_context = &remote_context,
.statistics = stats,
- .progress = progress};
+ .progress = progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
REQUIRE(runner.Process(action));
@@ -683,7 +687,8 @@ static inline void TestRetrieveOutputDirectories(
.apis = &apis,
.remote_context = &remote_context,
.statistics = stats,
- .progress = progress};
+ .progress = progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
REQUIRE(runner.Process(action));
@@ -754,7 +759,8 @@ static inline void TestRetrieveOutputDirectories(
.apis = &apis,
.remote_context = &remote_context,
.statistics = stats,
- .progress = progress};
+ .progress = progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
REQUIRE(runner.Process(action));
@@ -828,7 +834,8 @@ static inline void TestRetrieveOutputDirectories(
.apis = &apis,
.remote_context = &remote_context,
.statistics = stats,
- .progress = progress};
+ .progress = progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK_FALSE(runner.Process(action));
}
@@ -855,7 +862,8 @@ static inline void TestRetrieveOutputDirectories(
.apis = &apis,
.remote_context = &remote_context,
.statistics = stats,
- .progress = progress};
+ .progress = progress,
+ .profile = std::nullopt};
Executor runner{&exec_context};
CHECK_FALSE(runner.Process(action));
}
diff --git a/test/buildtool/graph_traverser/graph_traverser.test.hpp b/test/buildtool/graph_traverser/graph_traverser.test.hpp
index b3340ab9..2b10271e 100644
--- a/test/buildtool/graph_traverser/graph_traverser.test.hpp
+++ b/test/buildtool/graph_traverser/graph_traverser.test.hpp
@@ -201,7 +201,8 @@ class TestProject {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
GraphTraverser const gt{
clargs.gtargs, &exec_context, [](auto /*done*/, auto /*cv*/) {}};
@@ -277,7 +278,8 @@ class TestProject {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
GraphTraverser const gt{
clargs.gtargs, &exec_context, [](auto /*done*/, auto /*cv*/) {}};
@@ -327,7 +329,8 @@ class TestProject {
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
GraphTraverser const gt{
clargs.gtargs, &exec_context, [](auto /*done*/, auto /*cv*/) {}};
@@ -393,7 +396,8 @@ class TestProject {
.apis = &full_apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
GraphTraverser const gt_upload{clargs_update_cpp.gtargs,
&full_context,
@@ -422,7 +426,8 @@ class TestProject {
.apis = &apis_known,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
GraphTraverser const gt{
clargs.gtargs, &context_known, [](auto /*done*/, auto /*cv*/) {}};
auto const result =
@@ -474,7 +479,8 @@ static void TestBlobsUploadedAndUsed(
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
GraphTraverser gt{
clargs.gtargs, &exec_context, [](auto /*done*/, auto /*cv*/) {}};
@@ -532,7 +538,8 @@ static void TestEnvironmentVariablesSetAndUsed(
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
GraphTraverser gt{
clargs.gtargs, &exec_context, [](auto /*done*/, auto /*cv*/) {}};
@@ -590,7 +597,8 @@ static void TestTreesUsed(
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
GraphTraverser gt{
clargs.gtargs, &exec_context, [](auto /*done*/, auto /*cv*/) {}};
@@ -648,7 +656,8 @@ static void TestNestedTreesUsed(
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
GraphTraverser gt{
clargs.gtargs, &exec_context, [](auto /*done*/, auto /*cv*/) {}};
@@ -705,7 +714,8 @@ static void TestFlakyHelloWorldDetected(
.apis = &apis,
.remote_context = &remote_context,
.statistics = &stats,
- .progress = &progress};
+ .progress = &progress,
+ .profile = std::nullopt};
{
auto clargs = p.CmdLineArgs("_entry_points_ctimes");