From 61c0da151490544d02628199e9d90687c7dbef86 Mon Sep 17 00:00:00 2001 From: aehlig Date: Thu, 26 Oct 2017 18:36:14 +0200 Subject: BEP: Add an additional event with tool statistics After the completion of the build, also report useful logs/statistics. Do so in a separate event, so that the protocol allows reporting build completion early and purely staticial information later, maybe event after some computations. Change-Id: Ibd221546de76fcffcda7819c300187eac45ebd68 PiperOrigin-RevId: 173548733 --- .../build/lib/buildeventstream/BuildEventId.java | 8 +++ .../build/lib/buildeventstream/BuildToolLogs.java | 69 ++++++++++++++++++++++ .../proto/build_event_stream.proto | 12 ++++ 3 files changed, 89 insertions(+) create mode 100644 src/main/java/com/google/devtools/build/lib/buildeventstream/BuildToolLogs.java (limited to 'src/main/java/com/google/devtools/build/lib/buildeventstream') diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java index 2479b59b3d..7e582a5794 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java @@ -273,4 +273,12 @@ public final class BuildEventId implements Serializable { return new BuildEventId( BuildEventStreamProtos.BuildEventId.newBuilder().setBuildFinished(finishedId).build()); } + + public static BuildEventId buildToolLogs() { + return new BuildEventId( + BuildEventStreamProtos.BuildEventId.newBuilder() + .setBuildToolLogs( + BuildEventStreamProtos.BuildEventId.BuildToolLogsId.getDefaultInstance()) + .build()); + } } diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildToolLogs.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildToolLogs.java new file mode 100644 index 0000000000..23e1b07e53 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildToolLogs.java @@ -0,0 +1,69 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.buildeventstream; + +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.util.Pair; +import com.google.devtools.build.lib.vfs.Path; +import com.google.protobuf.ByteString; +import java.nio.charset.StandardCharsets; +import java.util.Collection; + +/** Event reporting on statistics about the build. */ +public class BuildToolLogs implements BuildEventWithOrderConstraint { + private final Collection> directValues; + private final Collection> logFiles; + + public BuildToolLogs( + Collection> directValues, Collection> logFiles) { + this.directValues = directValues; + this.logFiles = logFiles; + } + + @Override + public BuildEventId getEventId() { + return BuildEventId.buildToolLogs(); + } + + @Override + public Collection getChildrenEvents() { + return ImmutableList.of(); + } + + @Override + public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventConverters converters) { + BuildEventStreamProtos.BuildToolLogs.Builder toolLogs = + BuildEventStreamProtos.BuildToolLogs.newBuilder(); + for (Pair direct : directValues) { + toolLogs.addLog( + BuildEventStreamProtos.File.newBuilder() + .setName(direct.getFirst()) + .setContents(ByteString.copyFrom(direct.getSecond().getBytes(StandardCharsets.UTF_8))) + .build()); + } + for (Pair logFile : logFiles) { + toolLogs.addLog( + BuildEventStreamProtos.File.newBuilder() + .setName(logFile.getFirst()) + .setUri(converters.pathConverter().apply(logFile.getSecond())) + .build()); + } + return GenericBuildEvent.protoChaining(this).setBuildToolLogs(toolLogs.build()).build(); + } + + @Override + public Collection postedAfter() { + return ImmutableList.of(BuildEventId.buildFinished()); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto b/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto index 22a5761d49..6b15e27180 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto @@ -174,6 +174,11 @@ message BuildEventId { message BuildFinishedId { } + // Identifier of an event providing additional logs/statistics after + // completion of the build. + message BuildToolLogsId { + } + oneof id { UnknownBuildEventId unknown = 1; ProgressId progress = 2; @@ -194,6 +199,7 @@ message BuildEventId { TestResultId test_result = 8; TestSummaryId test_summary = 7; BuildFinishedId build_finished = 9; + BuildToolLogsId build_tool_logs = 20; } } @@ -544,6 +550,11 @@ message BuildFinished { int64 finish_time_millis = 2; } +// Event providing additional statistics/logs after completion of the build. +message BuildToolLogs { + repeated File log = 1; +} + // Message describing a build event. Events will have an identifier that // is unique within a given build invocation; they also announce follow-up // events as children. More details, which are specific to the kind of event @@ -572,5 +583,6 @@ message BuildEvent { TestResult test_result = 10; TestSummary test_summary = 9; BuildFinished finished = 14; + BuildToolLogs build_tool_logs = 23; }; } -- cgit v1.2.3