Skip to content

Commit 8618bf8

Browse files
committed
implement total time
1 parent d72ca65 commit 8618bf8

File tree

9 files changed

+72
-22
lines changed

9 files changed

+72
-22
lines changed

src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import "src/main/protobuf/command_line.proto";
2222
import "src/main/protobuf/critical_path.proto";
2323
import "src/main/protobuf/failure_details.proto";
2424
import "src/main/protobuf/invocation_policy.proto";
25-
import "src/main/protobuf/spawn.proto";
2625

2726
option java_package = "com.google.devtools.build.lib.buildeventstream";
2827
option java_outer_classname = "BuildEventStreamProtos";
@@ -224,7 +223,7 @@ message BuildEventId {
224223
// Identifier of an event providing convenience symlinks information.
225224
message ConvenienceSymlinksIdentifiedId {}
226225

227-
// Next id: 30.
226+
// Next id: 28.
228227
oneof id {
229228
UnknownBuildEventId unknown = 1;
230229
ProgressId progress = 2;
@@ -253,8 +252,6 @@ message BuildEventId {
253252
BuildMetadataId build_metadata = 24;
254253
ConvenienceSymlinksIdentifiedId convenience_symlinks_identified = 25;
255254
build.bazel.bep.CriticalPath.BepId critical_path = 27;
256-
tools.protos.SpawnMetrics.BepId spawn_metrics = 28;
257-
build.bazel.bep.CriticalPathComponent.BepId critical_path_component = 29;
258255
}
259256
}
260257

@@ -1158,7 +1155,7 @@ message ConvenienceSymlink {
11581155
// that is observed, is provided in the payload. More options for the payload
11591156
// might be added in the future.
11601157
//
1161-
// Next id: 32.
1158+
// Next id: 30.
11621159
message BuildEvent {
11631160
reserved 11, 19;
11641161
BuildEventId id = 1;
@@ -1189,7 +1186,5 @@ message BuildEvent {
11891186
BuildMetadata build_metadata = 26;
11901187
ConvenienceSymlinksIdentified convenience_symlinks_identified = 27;
11911188
build.bazel.bep.CriticalPath critical_path = 29;
1192-
tools.protos.SpawnMetrics spawn_metrics = 30;
1193-
build.bazel.bep.CriticalPath critical_path_component = 31;
11941189
}
11951190
}

src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.google.devtools.build.lib.events.OutputFilter;
4646
import com.google.devtools.build.lib.events.Reporter;
4747
import com.google.devtools.build.lib.exec.ExecutionOptions;
48+
import com.google.devtools.build.lib.metrics.criticalpath.CriticalPathEvent;
4849
import com.google.devtools.build.lib.pkgcache.LoadingFailedException;
4950
import com.google.devtools.build.lib.profiler.ProfilePhase;
5051
import com.google.devtools.build.lib.profiler.Profiler;
@@ -694,7 +695,9 @@ public void stopRequest(
694695
new BuildCompleteEvent(
695696
result,
696697
ImmutableList.of(
697-
BuildEventIdUtil.buildToolLogs(), BuildEventIdUtil.buildMetrics())));
698+
BuildEventIdUtil.buildToolLogs(),
699+
BuildEventIdUtil.buildMetrics(),
700+
CriticalPathEvent.BEP_ID)));
698701
}
699702
// Post the build tool logs event; the corresponding local files may be contributed from
700703
// modules, and this has to happen after posting the BuildCompleteEvent because that's when

src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildCompleteEvent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import static com.google.common.base.Preconditions.checkNotNull;
1818

19+
import com.google.common.annotations.VisibleForTesting;
1920
import com.google.common.collect.ImmutableList;
2021
import com.google.devtools.build.lib.buildeventstream.BuildCompletingEvent;
2122
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId;
@@ -36,6 +37,7 @@ public BuildCompleteEvent(BuildResult result, Collection<BuildEventId> children)
3637
this.result = checkNotNull(result);
3738
}
3839

40+
@VisibleForTesting
3941
public BuildCompleteEvent(BuildResult result) {
4042
this(result, ImmutableList.of());
4143
}

src/main/java/com/google/devtools/build/lib/metrics/criticalpath/AggregatedCriticalPath.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
package com.google.devtools.build.lib.metrics.criticalpath;
1616

1717
import com.google.common.base.Joiner;
18+
import com.google.common.base.Preconditions;
1819
import com.google.common.collect.ImmutableList;
20+
import com.google.common.eventbus.EventBus;
1921
import com.google.devtools.build.lib.actions.AggregatedSpawnMetrics;
2022
import com.google.devtools.build.lib.actions.SpawnMetrics;
2123
import java.time.Duration;
@@ -103,4 +105,11 @@ public String toStringSummary() {
103105
public String toStringSummaryNoRemote() {
104106
return toString(true, false);
105107
}
108+
109+
/**Posts the {@code BEP} event for the critical path on the provided {@link EventBus}. */
110+
public void postEvent(EventBus eventBus) {
111+
Preconditions.checkNotNull(eventBus);
112+
113+
eventBus.post(new CriticalPathEvent(Duration.ofMillis(totalTimeInMs)));
114+
}
106115
}

src/main/java/com/google/devtools/build/lib/metrics/criticalpath/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ java_library(
1717
deps = [
1818
"//src/main/java/com/google/devtools/build/lib/actions",
1919
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
20+
"//src/main/java/com/google/devtools/build/lib/buildeventstream",
21+
"//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto",
2022
"//src/main/java/com/google/devtools/build/lib/clock",
2123
"//src/main/java/com/google/devtools/build/lib/cmdline",
2224
"//src/main/java/com/google/devtools/build/lib/concurrent",
25+
"//src/main/java/com/google/devtools/build/lib/events",
2326
"//src/main/java/com/google/devtools/build/lib/skyframe/rewinding:action_rewound_event",
27+
"//src/main/protobuf:critical_path_java_proto",
2428
"//third_party:flogger",
2529
"//third_party:guava",
2630
"//third_party:jsr305",
31+
"@com_google_protobuf//:protobuf_java",
2732
],
2833
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.google.devtools.build.lib.metrics.criticalpath;
2+
3+
import build.bazel.bep.CriticalPath;
4+
import com.google.common.base.Preconditions;
5+
import com.google.common.collect.ImmutableList;
6+
import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
7+
import com.google.devtools.build.lib.buildeventstream.BuildEventIdUtil;
8+
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
9+
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId;
10+
import com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint;
11+
import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent;
12+
import java.time.Duration;
13+
import java.util.Collection;
14+
15+
/** {@code Build event protocol} event for the {@code critical path} of a build. */
16+
public final class CriticalPathEvent extends GenericBuildEvent
17+
implements BuildEventWithOrderConstraint {
18+
public static final BuildEventId BEP_ID =
19+
BuildEventId.newBuilder().setCriticalPath(CriticalPath.BepId.getDefaultInstance()).build();
20+
21+
private final Duration totalTime;
22+
23+
CriticalPathEvent(Duration totalTime) {
24+
super(BEP_ID, ImmutableList.of());
25+
26+
this.totalTime = Preconditions.checkNotNull(totalTime);
27+
}
28+
29+
@Override
30+
public Collection<BuildEventId> postedAfter() {
31+
return ImmutableList.of(BuildEventIdUtil.buildFinished());
32+
}
33+
34+
@Override
35+
public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext converters) {
36+
return GenericBuildEvent.protoChaining(this)
37+
.setCriticalPath(
38+
CriticalPath.newBuilder()
39+
.setTotalTime(
40+
com.google.protobuf.Duration.newBuilder()
41+
.setSeconds(totalTime.getSeconds())
42+
.setNanos(totalTime.getNano())
43+
.build())
44+
.build())
45+
.build();
46+
}
47+
}

src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ public void buildComplete(BuildCompleteEvent event) {
225225
.getResult()
226226
.getBuildToolLogCollection()
227227
.addDirectValue("process stats", spawnSummaryString.getBytes(StandardCharsets.UTF_8));
228+
229+
criticalPath.postEvent(eventBus);
228230
} finally {
229231
if (criticalPathComputer != null) {
230232
eventBus.unregister(criticalPathComputer);

src/main/protobuf/critical_path.proto

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import "google/protobuf/duration.proto";
2121
option java_package = "build.bazel.bep";
2222
option java_outer_classname = "CriticalPathProtos";
2323
// option java_api_version = 2;
24+
option java_multiple_files = true;
2425

2526
// Represents the critical path of a build.
2627
//
2728
// This is an event in the Build Event Stream (BES) with the following
2829
// children:
29-
// - `tools.protos.SpawnMetrics`
3030
// - `build.bazel.bep.CriticalPathComponent`
3131
message CriticalPath {
3232
// Identifier of a BES event of this type.
@@ -35,11 +35,3 @@ message CriticalPath {
3535
// The total time of the critical path.
3636
google.protobuf.Duration total_time = 1;
3737
}
38-
39-
// Represents a single component in the critical path.
40-
message CriticalPathComponent {
41-
// Identifier of a BES event of this type.
42-
message BepId {
43-
string action_key = 1;
44-
}
45-
}

src/main/protobuf/spawn.proto

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ message Platform {
6363
//
6464
// Next id: 21
6565
message SpawnMetrics {
66-
// Identifier of a BES event of this type.
67-
message BepId {
68-
SpawnExecKind exec_kind = 1;
69-
}
70-
7166
enum SpawnExecKind {
7267
OTHER = 0;
7368
REMOTE = 1;

0 commit comments

Comments
 (0)