use of com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent in project intellij by bazelbuild.
the class TimingScope method onScopeEnd.
@Override
public void onScopeEnd(BlazeContext context) {
if (context.isCancelled()) {
duration = Optional.of(Duration.ZERO);
return;
}
Duration elapsedTime = Duration.between(startTime, Instant.now());
duration = Optional.of(elapsedTime);
if (!scopeListeners.isEmpty()) {
ImmutableList<TimedEvent> output = collectTimedEvents();
scopeListeners.forEach(l -> l.onScopeEnd(output, elapsedTime));
}
if (parentScope == null && elapsedTime.toMillis() > 100) {
logTimingData();
}
}
use of com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent in project intellij by bazelbuild.
the class SyncPhaseCoordinator method doFilterProjectTargets.
private void doFilterProjectTargets(BlazeSyncParams params, Predicate<TargetKey> filter, BlazeContext context) {
Instant startTime = Instant.now();
SyncResult syncResult = SyncResult.FAILURE;
SyncStats.Builder stats = SyncStats.builder();
try {
SaveUtil.saveAllFiles();
onSyncStart(project, context, params.syncMode());
if (!context.shouldContinue()) {
return;
}
BlazeProjectData oldProjectData = getOldProjectData(context, params.syncMode());
if (oldProjectData == null) {
String message = "Can't filter project targets: project has never been synced.";
context.output(PrintOutput.error(message));
IssueOutput.warn(message).submit(context);
return;
}
List<TimedEvent> timedEvents = SyncScope.runWithTiming(context, childContext -> {
SyncProjectState projectState = ProjectStateSyncTask.collectProjectState(project, context);
if (projectState == null) {
return;
}
ProjectTargetData targetData = oldProjectData.getTargetData().filter(filter, projectState.getLanguageSettings());
fillInBuildStats(stats, projectState, /* buildResult= */
null);
ProjectUpdateSyncTask.runProjectUpdatePhase(project, params.syncMode(), projectState, targetData, oldProjectData.getBlazeInfo(), childContext);
}, new TimingScope("Filtering project targets", EventType.Other));
stats.addTimedEvents(timedEvents);
syncResult = context.getSyncResult();
} catch (Throwable e) {
logSyncError(context, e);
} finally {
finishSync(params, startTime, context, ProjectViewManager.getInstance(project).getProjectViewSet(), ImmutableSet.of(), syncResult, stats);
}
}
use of com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent in project intellij by bazelbuild.
the class SyncPhaseCoordinator method outputTimingSummary.
private static void outputTimingSummary(BlazeContext context, ImmutableList<TimedEvent> timedEvents) {
Map<EventType, Long> totalTimes = new LinkedHashMap<>();
for (EventType type : EventType.values()) {
long totalTimeMillis = timedEvents.stream().filter(e -> e.isLeafEvent && e.type == type).mapToLong(e -> e.duration.toMillis()).sum();
totalTimes.put(type, totalTimeMillis);
}
if (totalTimes.values().stream().mapToLong(l -> l).sum() < 1000) {
return;
}
String summary = totalTimes.entrySet().stream().map(e -> String.format("%s: %s", e.getKey(), durationStr(e.getValue()))).collect(joining(", "));
context.output(PrintOutput.log("\nTiming summary:\n" + summary));
}
use of com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent in project intellij by bazelbuild.
the class SyncPhaseCoordinator method updateProjectAndFinishSync.
private void updateProjectAndFinishSync(UpdatePhaseTask updateTask, BlazeContext context) {
SyncStats.Builder stats = SyncStats.builder();
stats.setSyncBinaryType(updateTask.buildBinaryType());
SyncResult syncResult = updateTask.syncResult();
try {
fillInBuildStats(stats, updateTask.projectState(), updateTask.buildResult());
if (!syncResult.successful() || !updateTask.buildResult().isValid()) {
return;
}
List<TimedEvent> timedEvents = SyncScope.runWithTiming(context, childContext -> {
ProjectTargetData targetData = updateTargetData(updateTask, childContext);
if (targetData == null) {
childContext.setHasError();
throw new SyncFailedException();
}
ProjectUpdateSyncTask.runProjectUpdatePhase(project, updateTask.syncParams().syncMode(), updateTask.projectState(), targetData, updateTask.buildResult().getBlazeInfo(), childContext);
}, new TimingScope("Project update phase", EventType.Other));
stats.addTimedEvents(timedEvents);
if (!context.shouldContinue()) {
syncResult = context.getSyncResult();
}
} catch (Throwable e) {
logSyncError(context, e);
syncResult = SyncResult.FAILURE;
} finally {
SyncProjectState projectState = updateTask.projectState();
finishSync(updateTask.syncParams(), updateTask.startTime(), context, projectState != null ? projectState.getProjectViewSet() : null, updateTask.buildIds(), syncResult, stats);
}
}
use of com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent in project intellij by bazelbuild.
the class SyncPhaseCoordinator method updateInMemoryState.
private static List<TimedEvent> updateInMemoryState(Project project, BlazeContext parentContext, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, SyncMode syncMode) {
List<TimedEvent> timedEvents = new ArrayList<>();
Scope.push(parentContext, context -> {
context.push(new TimingScope("UpdateInMemoryState", EventType.Other).addScopeListener((events, duration) -> timedEvents.addAll(events)));
context.output(new StatusOutput("Updating in-memory state..."));
Module workspaceModule = ModuleFinder.getInstance(project).findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
for (BlazeSyncPlugin blazeSyncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
blazeSyncPlugin.updateInMemoryState(project, context, WorkspaceRoot.fromProject(project), projectViewSet, blazeProjectData, workspaceModule, syncMode);
}
});
return timedEvents;
}
Aggregations