Skip to content

Commit

Permalink
Add start time to execlog Spawn
Browse files Browse the repository at this point in the history
RELNOTES: The compact and full execution logs now contain start times for spawns (if available).

Closes #22281.

PiperOrigin-RevId: 633108842
Change-Id: I3b7fbf8559b7583dcfe5ed0ff5eaf736de4f1f8d
  • Loading branch information
fmeum authored and copybara-github committed May 13, 2024
1 parent 62e3370 commit 73b0faf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.protobuf.util.Durations;
import com.google.protobuf.util.Timestamps;
import java.io.IOException;
import java.time.Duration;
import java.util.Map;
Expand Down Expand Up @@ -235,6 +236,9 @@ protected static Protos.SpawnMetrics getSpawnMetricsProto(SpawnResult result) {
if (metrics.timeLimitInMs() != 0L) {
builder.setTimeLimit(millisToProto(metrics.timeLimitInMs()));
}
if (result.getStartTime() != null) {
builder.setStartTime(Timestamps.fromMillis(result.getStartTime().toEpochMilli()));
}
return builder.build();
}

Expand Down
1 change: 1 addition & 0 deletions src/main/protobuf/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ proto_library(
srcs = ["spawn.proto"],
deps = [
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:timestamp_proto",
],
)

Expand Down
3 changes: 3 additions & 0 deletions src/main/protobuf/spawn.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ syntax = "proto3";
package tools.protos;

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option java_package = "com.google.devtools.build.lib.exec";
option java_outer_classname = "Protos";
Expand Down Expand Up @@ -111,6 +112,8 @@ message SpawnMetrics {
int64 memory_bytes_limit = 18;
// Time limit or 0 if unavailable.
google.protobuf.Duration time_limit = 19;
// Instant when the spawn started to execute.
google.protobuf.Timestamp start_time = 20;
}

// Details of an executed spawn.
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/google/devtools/build/lib/exec/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ java_library(
"//third_party:junit4",
"//third_party:mockito",
"//third_party:truth",
"//third_party/protobuf:protobuf_java_util",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
"@zstd-jni",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
import com.google.protobuf.util.Timestamps;
import com.google.testing.junit.testparameterinjector.TestParameter;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
Expand Down Expand Up @@ -898,18 +901,22 @@ public void testSpawnMetrics() throws Exception {

SpawnLogContext context = createSpawnLogContext();

Instant now = Instant.now();
context.logSpawn(
defaultSpawn(),
createInputMetadataProvider(),
createInputMap(),
fs,
defaultTimeout(),
defaultSpawnResultBuilder().setSpawnMetrics(metrics).build());
defaultSpawnResultBuilder().setSpawnMetrics(metrics).setStartTime(now).build());

closeAndAssertLog(
context,
defaultSpawnExecBuilder()
.setMetrics(Protos.SpawnMetrics.newBuilder().setTotalTime(millisToProto(1)))
.setMetrics(
Protos.SpawnMetrics.newBuilder()
.setTotalTime(millisToProto(1))
.setStartTime(Timestamps.fromDate(Date.from(now))))
.build());
}

Expand Down

0 comments on commit 73b0faf

Please sign in to comment.