From 42453a89d18d9cad169172e2803fca9609abf34d Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 4 Mar 2025 16:41:26 +0100 Subject: just execute: set basic timing meta data While there, increase the time precision to nanoseconds, which is the resolution of the underlying timestamp proto. --- .../execution_service/execution_server.cpp | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/buildtool/execution_api/execution_service/execution_server.cpp') diff --git a/src/buildtool/execution_api/execution_service/execution_server.cpp b/src/buildtool/execution_api/execution_service/execution_server.cpp index 6e57fdb1..91c13d94 100644 --- a/src/buildtool/execution_api/execution_service/execution_server.cpp +++ b/src/buildtool/execution_api/execution_service/execution_server.cpp @@ -15,6 +15,7 @@ #include "src/buildtool/execution_api/execution_service/execution_server.hpp" #include +#include #include #include #include @@ -46,13 +47,21 @@ #include "src/utils/cpp/path.hpp" namespace { +void SetTimeStamp( + gsl::not_null<::google::protobuf::Timestamp*> const& t, + std::chrono::time_point const& tvalue) { + const int64_t k_nanoseconds_per_second = 1'000'000'000; + auto nanos = std::chrono::duration_cast( + tvalue.time_since_epoch()) + .count(); + t->set_seconds(nanos / k_nanoseconds_per_second); + t->set_nanos(static_cast(nanos % k_nanoseconds_per_second)); +} + void UpdateTimeStamp( gsl::not_null<::google::longrunning::Operation*> const& op) { ::google::protobuf::Timestamp t; - t.set_seconds( - std::chrono::duration_cast( - std::chrono::high_resolution_clock::now().time_since_epoch()) - .count()); + SetTimeStamp(&t, std::chrono::high_resolution_clock::now()); op->mutable_metadata()->PackFrom(t); } @@ -246,11 +255,20 @@ auto ExecutionServiceImpl::Execute( return ::grpc::Status{grpc::StatusCode::INTERNAL, std::move(execute_response).error()}; } + ::bazel_re::ExecuteResponse response = *execute_response; + SetTimeStamp(response.mutable_result() + ->mutable_execution_metadata() + ->mutable_worker_start_timestamp(), + t0); + SetTimeStamp(response.mutable_result() + ->mutable_execution_metadata() + ->mutable_worker_completed_timestamp(), + t1); // Store the result in action cache if (i_execution_response->ExitCode() == 0 and not action->do_not_cache()) { - if (not storage_.ActionCache().StoreResult( - *action_digest, execute_response->result())) { + if (not storage_.ActionCache().StoreResult(*action_digest, + response.result())) { auto const str = fmt::format("Could not store action result for action {}", action_digest->hash()); @@ -260,7 +278,7 @@ auto ExecutionServiceImpl::Execute( } } - WriteResponse(*execute_response, writer, std::move(op)); + WriteResponse(response, writer, std::move(op)); return ::grpc::Status::OK; } -- cgit v1.2.3