Skip to content

Commit

Permalink
Reference the JSON profile as build tool log in the BEP.
Browse files Browse the repository at this point in the history
RELNOTES: None

Closes bazelbuild#9159.

PiperOrigin-RevId: 263132427
  • Loading branch information
meisterT authored and copybara-github committed Aug 13, 2019
1 parent bb54224 commit 522099d
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.devtools.build.lib.buildtool.BuildRequest;
import com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent;
import com.google.devtools.build.lib.buildtool.buildevent.ExecutionStartingEvent;
import com.google.devtools.build.lib.buildtool.buildevent.ProfilerStartedEvent;
import com.google.devtools.build.lib.clock.BlazeClock;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.Reporter;
Expand All @@ -31,6 +32,8 @@
import com.google.devtools.build.lib.profiler.ProfilerTask;
import com.google.devtools.build.lib.profiler.SilentCloseable;
import com.google.devtools.build.lib.skyframe.ExecutionFinishedEvent;
import com.google.devtools.build.lib.vfs.Path;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -54,6 +57,7 @@ public class BuildSummaryStatsModule extends BlazeModule {
private long executionStartMillis;
private long executionEndMillis;
private SpawnStats spawnStats;
private Path profilePath;

@Override
public void beforeCommand(CommandEnvironment env) {
Expand Down Expand Up @@ -88,6 +92,11 @@ public void executionPhaseStarting(ExecutionStartingEvent event) {
}
}

@Subscribe
public void profileStarting(ProfilerStartedEvent event) {
this.profilePath = event.getProfilePath();
}

@Subscribe
public void executionPhaseFinish(@SuppressWarnings("unused") ExecutionFinishedEvent event) {
executionEndMillis = BlazeClock.instance().currentTimeMillis();
Expand Down Expand Up @@ -137,6 +146,20 @@ public void buildComplete(BuildCompleteEvent event) {
}
}
}
if (profilePath != 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.
try {
Profiler.instance().stop();
event
.getResult()
.getBuildToolLogCollection()
.addLocalFile(profilePath.getBaseName(), profilePath);
} catch (IOException e) {
reporter.handle(Event.error("Error while writing profile file: " + e.getMessage()));
}
}

String spawnSummary = spawnStats.getSummary();
if (statsSummary) {
Expand Down Expand Up @@ -167,6 +190,7 @@ public void buildComplete(BuildCompleteEvent event) {
.addDirectValue("process stats", spawnSummary.getBytes(StandardCharsets.UTF_8));
} finally {
criticalPathComputer = null;
profilePath = null;
}
}
}

0 comments on commit 522099d

Please sign in to comment.