From e199144e67338cf13f40801ca7470c4de20c3cea Mon Sep 17 00:00:00 2001 From: Chi Wang Date: Fri, 11 Jun 2021 16:38:16 +0800 Subject: [PATCH] Use AutoValue for ActionProgressEvent --- .../lib/actions/ActionProgressEvent.java | 40 ++++++------------- .../build/lib/exec/SpawnProgressEvent.java | 2 +- .../build/lib/runtime/UiStateTracker.java | 10 ++--- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionProgressEvent.java b/src/main/java/com/google/devtools/build/lib/actions/ActionProgressEvent.java index b9a67126adaa30..eb89b71250a113 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionProgressEvent.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionProgressEvent.java @@ -1,42 +1,26 @@ package com.google.devtools.build.lib.actions; +import com.google.auto.value.AutoValue; import com.google.devtools.build.lib.events.ExtendedEventHandler.ProgressLike; -/** - * Notifies that an in-flight action is making progress. - */ -public class ActionProgressEvent implements ProgressLike { - private final ActionExecutionMetadata action; - private final String progressId; - private final String progress; - private final boolean isFinished; +/** Notifies that an in-flight action is making progress. */ +@AutoValue +public abstract class ActionProgressEvent implements ProgressLike { - public ActionProgressEvent(ActionExecutionMetadata action, String progressId, String progress, boolean isFinished) { - this.action = action; - this.progressId = progressId; - this.progress = progress; - this.isFinished = isFinished; + public static ActionProgressEvent create( + ActionExecutionMetadata action, String progressId, String progress, boolean finished) { + return new AutoValue_ActionProgressEvent(action, progressId, progress, finished); } /** Gets the metadata associated with the action being scheduled. */ - public ActionExecutionMetadata getActionMetadata() { - return action; - } + public abstract ActionExecutionMetadata action(); - /** - * The id that uniquely determines the progress among all progress events within an action. - */ - public String getProgressId() { - return progressId; - } + /** The id that uniquely determines the progress among all progress events within an action. */ + public abstract String progressId(); /** Human readable description of the progress */ - public String getProgress() { - return progress; - } + public abstract String progress(); /** Whether the download progress reported about is finished already */ - public boolean isFinished() { - return isFinished; - } + public abstract boolean finished(); } diff --git a/src/main/java/com/google/devtools/build/lib/exec/SpawnProgressEvent.java b/src/main/java/com/google/devtools/build/lib/exec/SpawnProgressEvent.java index 3befbc1942d1e9..7d2fe98173f5bb 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SpawnProgressEvent.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SpawnProgressEvent.java @@ -41,6 +41,6 @@ public static SpawnProgressEvent create(String resourceId, String progress, bool @Override public void postTo(ExtendedEventHandler eventHandler, ActionExecutionMetadata action) { - eventHandler.post(new ActionProgressEvent(action, progressId(), progress(), finished())); + eventHandler.post(ActionProgressEvent.create(action, progressId(), progress(), finished())); } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/UiStateTracker.java b/src/main/java/com/google/devtools/build/lib/runtime/UiStateTracker.java index 58d2733984be6b..e68b7318a6c8f6 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/UiStateTracker.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/UiStateTracker.java @@ -313,8 +313,8 @@ synchronized void setRunning(String strategy, long nanoChangeTime) { * Handle the progress event for the action. */ synchronized void onProgressEvent(ActionProgressEvent event, long nanoChangeTime) { - String id = event.getProgressId(); - if (event.isFinished()) { + String id = event.progressId(); + if (event.finished()) { // a download is finished, clean it up runningProgress.remove(id); progressNanoStartTimes.remove(id); @@ -566,8 +566,8 @@ void runningAction(RunningActionEvent event) { } void actionProgress(ActionProgressEvent event) { - ActionExecutionMetadata action = event.getActionMetadata(); - Artifact actionId = event.getActionMetadata().getPrimaryOutput(); + ActionExecutionMetadata action = event.action(); + Artifact actionId = event.action().getPrimaryOutput(); long now = clock.nanoTime(); getActionState(action, actionId, now).onProgressEvent(event, now); } @@ -1136,7 +1136,7 @@ private void reportOneActionProgress( long nanoDownloadTime = nanoTime - actionState.progressNanoStartTimes.get(id); long downloadSeconds = nanoDownloadTime / NANOS_PER_SECOND; - String progress = download.getProgress(); + String progress = download.progress(); if (progress.isEmpty()) { progress = id; }