Search in sources :

Example 1 with TimedEvent

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();
    }
}
Also used : Duration(java.time.Duration) TimedEvent(com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent)

Example 2 with TimedEvent

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);
    }
}
Also used : TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) Instant(java.time.Instant) BuildPhaseSyncStats(com.google.idea.blaze.base.logging.utils.BuildPhaseSyncStats) SyncStats(com.google.idea.blaze.base.logging.utils.SyncStats) ProjectTargetData(com.google.idea.blaze.base.model.ProjectTargetData) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) TimedEvent(com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent)

Example 3 with TimedEvent

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));
}
Also used : ProblemsViewScope(com.google.idea.blaze.base.scope.scopes.ProblemsViewScope) ModuleFinder(com.google.idea.blaze.base.sync.projectstructure.ModuleFinder) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) BuildBinaryType(com.google.idea.blaze.base.settings.BuildBinaryType) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Future(java.util.concurrent.Future) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) SaveUtil(com.google.idea.blaze.base.util.SaveUtil) AppExecutorUtil(com.intellij.util.concurrency.AppExecutorUtil) Task(com.google.idea.blaze.base.toolwindow.Task) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) BuildSystem(com.google.idea.blaze.base.bazel.BuildSystem) Blaze(com.google.idea.blaze.base.settings.Blaze) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Instant(java.time.Instant) GuardedBy(javax.annotation.concurrent.GuardedBy) Collectors.joining(java.util.stream.Collectors.joining) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) Executors(java.util.concurrent.Executors) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) ProjectTargetData(com.google.idea.blaze.base.model.ProjectTargetData) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) FocusBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior) ServiceManager(com.intellij.openapi.components.ServiceManager) ImportSection(com.google.idea.blaze.base.projectview.section.sections.ImportSection) BuildPhaseSyncStats(com.google.idea.blaze.base.logging.utils.BuildPhaseSyncStats) AutoValue(com.google.auto.value.AutoValue) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) NetworkTrafficTrackingScope(com.google.idea.blaze.base.scope.scopes.NetworkTrafficTrackingScope) Optional(java.util.Optional) BlazeProjectDataManagerImpl(com.google.idea.blaze.base.sync.data.BlazeProjectDataManagerImpl) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ToolWindowScope(com.google.idea.blaze.base.scope.scopes.ToolWindowScope) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) NotificationScope(com.google.idea.blaze.base.scope.scopes.NotificationScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) TimedEvent(com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ContextType(com.google.idea.blaze.base.command.BlazeInvocationContext.ContextType) PerformanceWarningScope(com.google.idea.blaze.base.scope.scopes.PerformanceWarningScope) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) SyncStats(com.google.idea.blaze.base.logging.utils.SyncStats) ProgressIndicatorScope(com.google.idea.blaze.base.scope.scopes.ProgressIndicatorScope) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SyncCanceledException(com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SharedStringPoolScope(com.google.idea.blaze.base.scope.scopes.SharedStringPoolScope) ImmutableList(com.google.common.collect.ImmutableList) Scope(com.google.idea.blaze.base.scope.Scope) BlazeDataStorage(com.google.idea.blaze.base.sync.data.BlazeDataStorage) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Project(com.intellij.openapi.project.Project) Nullable(javax.annotation.Nullable) Prefix(com.google.idea.blaze.base.scope.output.SummaryOutput.Prefix) BlazeLibraryCollector(com.google.idea.blaze.base.sync.libraries.BlazeLibraryCollector) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) SyncFailedException(com.google.idea.blaze.base.sync.SyncScope.SyncFailedException) SyncStrategy(com.google.idea.blaze.base.bazel.BuildSystem.SyncStrategy) SummaryOutput(com.google.idea.blaze.base.scope.output.SummaryOutput) BlazeUserSettings(com.google.idea.blaze.base.settings.BlazeUserSettings) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ConcurrencyUtil(com.google.idea.common.util.ConcurrencyUtil) BlazeIssueParser(com.google.idea.blaze.base.issueparser.BlazeIssueParser) EventLoggingService(com.google.idea.blaze.base.logging.EventLoggingService) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ProgressiveTaskWithProgressIndicator(com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with TimedEvent

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);
    }
}
Also used : TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BuildPhaseSyncStats(com.google.idea.blaze.base.logging.utils.BuildPhaseSyncStats) SyncStats(com.google.idea.blaze.base.logging.utils.SyncStats) ProjectTargetData(com.google.idea.blaze.base.model.ProjectTargetData) TimedEvent(com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent) SyncFailedException(com.google.idea.blaze.base.sync.SyncScope.SyncFailedException)

Example 5 with TimedEvent

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;
}
Also used : ProblemsViewScope(com.google.idea.blaze.base.scope.scopes.ProblemsViewScope) ModuleFinder(com.google.idea.blaze.base.sync.projectstructure.ModuleFinder) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) BuildBinaryType(com.google.idea.blaze.base.settings.BuildBinaryType) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Future(java.util.concurrent.Future) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) SaveUtil(com.google.idea.blaze.base.util.SaveUtil) AppExecutorUtil(com.intellij.util.concurrency.AppExecutorUtil) Task(com.google.idea.blaze.base.toolwindow.Task) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) BuildSystem(com.google.idea.blaze.base.bazel.BuildSystem) Blaze(com.google.idea.blaze.base.settings.Blaze) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Instant(java.time.Instant) GuardedBy(javax.annotation.concurrent.GuardedBy) Collectors.joining(java.util.stream.Collectors.joining) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) Executors(java.util.concurrent.Executors) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) ProjectTargetData(com.google.idea.blaze.base.model.ProjectTargetData) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) FocusBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior) ServiceManager(com.intellij.openapi.components.ServiceManager) ImportSection(com.google.idea.blaze.base.projectview.section.sections.ImportSection) BuildPhaseSyncStats(com.google.idea.blaze.base.logging.utils.BuildPhaseSyncStats) AutoValue(com.google.auto.value.AutoValue) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) NetworkTrafficTrackingScope(com.google.idea.blaze.base.scope.scopes.NetworkTrafficTrackingScope) Optional(java.util.Optional) BlazeProjectDataManagerImpl(com.google.idea.blaze.base.sync.data.BlazeProjectDataManagerImpl) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ToolWindowScope(com.google.idea.blaze.base.scope.scopes.ToolWindowScope) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) NotificationScope(com.google.idea.blaze.base.scope.scopes.NotificationScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) TimedEvent(com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ContextType(com.google.idea.blaze.base.command.BlazeInvocationContext.ContextType) PerformanceWarningScope(com.google.idea.blaze.base.scope.scopes.PerformanceWarningScope) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) SyncStats(com.google.idea.blaze.base.logging.utils.SyncStats) ProgressIndicatorScope(com.google.idea.blaze.base.scope.scopes.ProgressIndicatorScope) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SyncCanceledException(com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SharedStringPoolScope(com.google.idea.blaze.base.scope.scopes.SharedStringPoolScope) ImmutableList(com.google.common.collect.ImmutableList) Scope(com.google.idea.blaze.base.scope.Scope) BlazeDataStorage(com.google.idea.blaze.base.sync.data.BlazeDataStorage) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Project(com.intellij.openapi.project.Project) Nullable(javax.annotation.Nullable) Prefix(com.google.idea.blaze.base.scope.output.SummaryOutput.Prefix) BlazeLibraryCollector(com.google.idea.blaze.base.sync.libraries.BlazeLibraryCollector) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) SyncFailedException(com.google.idea.blaze.base.sync.SyncScope.SyncFailedException) SyncStrategy(com.google.idea.blaze.base.bazel.BuildSystem.SyncStrategy) SummaryOutput(com.google.idea.blaze.base.scope.output.SummaryOutput) BlazeUserSettings(com.google.idea.blaze.base.settings.BlazeUserSettings) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ConcurrencyUtil(com.google.idea.common.util.ConcurrencyUtil) BlazeIssueParser(com.google.idea.blaze.base.issueparser.BlazeIssueParser) EventLoggingService(com.google.idea.blaze.base.logging.EventLoggingService) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ProgressiveTaskWithProgressIndicator(com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ArrayList(java.util.ArrayList) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) TimedEvent(com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent) Module(com.intellij.openapi.module.Module)

Aggregations

TimedEvent (com.google.idea.blaze.base.scope.scopes.TimingScopeListener.TimedEvent)5 BuildPhaseSyncStats (com.google.idea.blaze.base.logging.utils.BuildPhaseSyncStats)4 SyncStats (com.google.idea.blaze.base.logging.utils.SyncStats)4 ProjectTargetData (com.google.idea.blaze.base.model.ProjectTargetData)4 TimingScope (com.google.idea.blaze.base.scope.scopes.TimingScope)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)3 AutoValue (com.google.auto.value.AutoValue)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions (com.google.common.base.Preconditions)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 ProgressiveTaskWithProgressIndicator (com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator)2 BuildSystem (com.google.idea.blaze.base.bazel.BuildSystem)2 SyncStrategy (com.google.idea.blaze.base.bazel.BuildSystem.SyncStrategy)2 ContextType (com.google.idea.blaze.base.command.BlazeInvocationContext.ContextType)2 ExperimentScope (com.google.idea.blaze.base.experiments.ExperimentScope)2 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)2