Refactors `ProfilerStartedEvent` by making `getName()` meaningful and remove `getFormat()` method.
The `getName()` method was never used previously. `BuildSummaryStatsModule` determined the profile name based on what `getFormat()` returns. This change simplifies the logic.
This change also adds some test coverage for `ProfilerStartedEvent`.
PiperOrigin-RevId: 658757362
Change-Id: I6cc0767dbb1b3116a8743673723a0fac22bb7501
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java
index 6d3802a..70fe506 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java
@@ -39,7 +39,6 @@
import com.google.devtools.build.lib.profiler.SilentCloseable;
import com.google.devtools.build.lib.skyframe.ExecutionFinishedEvent;
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TopLevelTargetPendingExecutionEvent;
-import com.google.devtools.build.lib.vfs.Path;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -64,8 +63,7 @@
private long executionStartMillis;
private long executionEndMillis;
private SpawnStats spawnStats;
- private Path profilePath;
- private Profiler.Format profileFormat;
+ private ProfilerStartedEvent profileEvent;
private AtomicBoolean executionStarted;
@Override
@@ -123,8 +121,7 @@
@Subscribe
public void profileStarting(ProfilerStartedEvent event) {
- this.profilePath = event.getProfilePath();
- this.profileFormat = event.getFormat();
+ this.profileEvent = event;
}
@Subscribe
@@ -182,7 +179,7 @@
}
}
}
- if (profilePath != null) {
+ if (profileEvent != null && profileEvent.getProfilePath() != null) {
// This leads to missing the afterCommand profiles of the other modules in the profile.
// Since the BEP currently shuts down at the BuildCompleteEvent, we cannot just move posting
// the BuildToolLogs to afterCommand of this module.
@@ -191,12 +188,7 @@
event
.getResult()
.getBuildToolLogCollection()
- .addLocalFile(
- switch (profileFormat) {
- case JSON_TRACE_FILE_FORMAT -> "command.profile.json";
- case JSON_TRACE_FILE_COMPRESSED_FORMAT -> "command.profile.gz";
- },
- profilePath);
+ .addLocalFile(profileEvent.getName(), profileEvent.getProfilePath());
} catch (IOException e) {
reporter.handle(Event.error("Error while writing profile file: " + e.getMessage()));
}
@@ -237,7 +229,6 @@
eventBus.unregister(criticalPathComputer);
criticalPathComputer = null;
}
- profilePath = null;
}
}
}