Search in sources :

Example 21 with TimingScope

use of com.google.idea.blaze.base.scope.scopes.TimingScope in project intellij by bazelbuild.

the class JdepsFileReader method loadJdepsFiles.

/**
 * Loads any updated jdeps files since the last invocation of this method.
 */
@Nullable
public JdepsMap loadJdepsFiles(Project project, BlazeContext parentContext, ArtifactLocationDecoder artifactLocationDecoder, Iterable<TargetIdeInfo> targetsToLoad, SyncState.Builder syncStateBuilder, @Nullable SyncState previousSyncState) {
    JdepsState oldState = previousSyncState != null ? previousSyncState.get(JdepsState.class) : null;
    JdepsState jdepsState = Scope.push(parentContext, (context) -> {
        context.push(new TimingScope("LoadJdepsFiles", EventType.Other));
        return doLoadJdepsFiles(project, context, artifactLocationDecoder, oldState, targetsToLoad);
    });
    if (jdepsState == null) {
        return null;
    }
    syncStateBuilder.put(JdepsState.class, jdepsState);
    return targetKey -> jdepsState.targetToJdeps.get(targetKey);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) Callable(java.util.concurrent.Callable) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) Lists(com.google.common.collect.Lists) Scope(com.google.idea.blaze.base.scope.Scope) Map(java.util.Map) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) FileDiffer(com.google.idea.blaze.base.filecache.FileDiffer) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) SyncState(com.google.idea.blaze.base.model.SyncState) FileInputStream(java.io.FileInputStream) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Maps(com.google.common.collect.Maps) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Serializable(java.io.Serializable) ExecutionException(java.util.concurrent.ExecutionException) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Deps(com.google.devtools.build.lib.view.proto.Deps) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) InputStream(java.io.InputStream) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) Nullable(javax.annotation.Nullable)

Example 22 with TimingScope

use of com.google.idea.blaze.base.scope.scopes.TimingScope in project intellij by bazelbuild.

the class FileCaches method onSync.

/**
 * Call on sync. Updates the file cache and deletes any old files.
 */
public static void onSync(Project project, BlazeContext context, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, BlazeSyncParams.SyncMode syncMode) {
    for (FileCache fileCache : FileCache.EP_NAME.getExtensions()) {
        Scope.push(context, childContext -> {
            childContext.push(new TimingScope(fileCache.getName(), EventType.Other));
            childContext.output(new StatusOutput("Updating " + fileCache.getName() + "..."));
            fileCache.onSync(project, context, projectViewSet, blazeProjectData, syncMode);
        });
    }
    LocalFileSystem.getInstance().refresh(true);
}
Also used : TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput)

Example 23 with TimingScope

use of com.google.idea.blaze.base.scope.scopes.TimingScope in project intellij by bazelbuild.

the class BlazeSyncTask method doSyncProject.

/**
 * @return true if sync successfully completed
 */
private SyncResult doSyncProject(BlazeContext context, @Nullable BlazeProjectData oldBlazeProjectData) {
    long syncStartTime = System.currentTimeMillis();
    if (!FileOperationProvider.getInstance().exists(workspaceRoot.directory())) {
        IssueOutput.error(String.format("Workspace '%s' doesn't exist.", workspaceRoot.directory())).submit(context);
        return SyncResult.FAILURE;
    }
    BlazeVcsHandler vcsHandler = BlazeVcsHandler.vcsHandlerForProject(project);
    if (vcsHandler == null) {
        IssueOutput.error("Could not find a VCS handler").submit(context);
        return SyncResult.FAILURE;
    }
    ListeningExecutorService executor = BlazeExecutor.getInstance().getExecutor();
    WorkspacePathResolverAndProjectView workspacePathResolverAndProjectView = computeWorkspacePathResolverAndProjectView(context, vcsHandler, executor);
    if (workspacePathResolverAndProjectView == null) {
        return SyncResult.FAILURE;
    }
    ProjectViewSet projectViewSet = workspacePathResolverAndProjectView.projectViewSet;
    List<String> syncFlags = BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.INFO, BlazeInvocationContext.Sync);
    syncStats.setSyncFlags(syncFlags);
    ListenableFuture<BlazeInfo> blazeInfoFuture = BlazeInfoRunner.getInstance().runBlazeInfo(context, importSettings.getBuildSystem(), Blaze.getBuildSystemProvider(project).getSyncBinaryPath(), workspaceRoot, syncFlags);
    ListenableFuture<WorkingSet> workingSetFuture = vcsHandler.getWorkingSet(project, context, workspaceRoot, executor);
    BlazeInfo blazeInfo = FutureUtil.waitForFuture(context, blazeInfoFuture).timed(Blaze.buildSystemName(project) + "Info", EventType.BlazeInvocation).withProgressMessage(String.format("Running %s info...", Blaze.buildSystemName(project))).onError(String.format("Could not run %s info", Blaze.buildSystemName(project))).run().result();
    if (blazeInfo == null) {
        return SyncResult.FAILURE;
    }
    BlazeVersionData blazeVersionData = BlazeVersionData.build(importSettings.getBuildSystem(), workspaceRoot, blazeInfo);
    if (!BuildSystemVersionChecker.verifyVersionSupported(context, blazeVersionData)) {
        return SyncResult.FAILURE;
    }
    WorkspacePathResolver workspacePathResolver = workspacePathResolverAndProjectView.workspacePathResolver;
    ArtifactLocationDecoder artifactLocationDecoder = new ArtifactLocationDecoderImpl(blazeInfo, workspacePathResolver);
    WorkspaceLanguageSettings workspaceLanguageSettings = LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
    syncStats.setLanguagesActive(new ArrayList<>(workspaceLanguageSettings.activeLanguages));
    syncStats.setWorkspaceType(workspaceLanguageSettings.getWorkspaceType());
    for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
        syncPlugin.installSdks(context);
    }
    if (!ProjectViewVerifier.verifyProjectView(project, context, workspacePathResolver, projectViewSet, workspaceLanguageSettings)) {
        return SyncResult.FAILURE;
    }
    final BlazeProjectData newBlazeProjectData;
    WorkingSet workingSet = FutureUtil.waitForFuture(context, workingSetFuture).timed("WorkingSet", EventType.Other).withProgressMessage("Computing VCS working set...").onError("Could not compute working set").run().result();
    if (context.isCancelled()) {
        return SyncResult.CANCELLED;
    }
    if (context.hasErrors()) {
        return SyncResult.FAILURE;
    }
    if (workingSet != null) {
        printWorkingSet(context, workingSet);
    }
    SyncState.Builder syncStateBuilder = new SyncState.Builder();
    SyncState previousSyncState = oldBlazeProjectData != null ? oldBlazeProjectData.syncState : null;
    List<TargetExpression> targets = Lists.newArrayList();
    if (syncParams.addProjectViewTargets) {
        Collection<TargetExpression> projectViewTargets = projectViewSet.listItems(TargetSection.KEY);
        if (!projectViewTargets.isEmpty()) {
            syncStats.setBlazeProjectTargets(new ArrayList<>(projectViewTargets));
            targets.addAll(projectViewTargets);
            printTargets(context, "project view", projectViewTargets);
        }
    }
    if (syncParams.addWorkingSet && workingSet != null) {
        Collection<? extends TargetExpression> workingSetTargets = getWorkingSetTargets(projectViewSet, workingSet);
        if (!workingSetTargets.isEmpty()) {
            targets.addAll(workingSetTargets);
            syncStats.setWorkingSetTargets(new ArrayList<>(workingSetTargets));
            printTargets(context, "working set", workingSetTargets);
        }
    }
    if (!syncParams.targetExpressions.isEmpty()) {
        targets.addAll(syncParams.targetExpressions);
        printTargets(context, syncParams.title, syncParams.targetExpressions);
    }
    ShardedTargetsResult shardedTargetsResult = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, projectViewSet, workspacePathResolver, targets);
    if (shardedTargetsResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
        return SyncResult.FAILURE;
    }
    ShardedTargetList shardedTargets = shardedTargetsResult.shardedTargets;
    syncStats.setSyncSharded(shardedTargets.shardedTargets.size() > 1);
    BlazeConfigurationHandler configHandler = new BlazeConfigurationHandler(blazeInfo);
    boolean mergeWithOldState = !syncParams.addProjectViewTargets;
    BlazeIdeInterface.IdeResult ideQueryResult = getIdeQueryResult(project, context, projectViewSet, blazeVersionData, configHandler, shardedTargets, workspaceLanguageSettings, artifactLocationDecoder, syncStateBuilder, previousSyncState, mergeWithOldState);
    if (context.isCancelled()) {
        return SyncResult.CANCELLED;
    }
    context.output(PrintOutput.log("ide-query result: " + ideQueryResult.buildResult.status));
    if (ideQueryResult.targetMap == null || ideQueryResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
        context.setHasError();
        if (ideQueryResult.buildResult.outOfMemory()) {
            SuggestBuildShardingNotification.syncOutOfMemoryError(project, context);
        }
        return SyncResult.FAILURE;
    }
    TargetMap targetMap = ideQueryResult.targetMap;
    context.output(PrintOutput.log("Target map size: " + ideQueryResult.targetMap.targets().size()));
    BuildResult ideInfoResult = ideQueryResult.buildResult;
    ListenableFuture<ImmutableMultimap<TargetKey, TargetKey>> reverseDependenciesFuture = BlazeExecutor.getInstance().submit(() -> ReverseDependencyMap.createRdepsMap(targetMap));
    BuildResult ideResolveResult = resolveIdeArtifacts(project, context, workspaceRoot, projectViewSet, blazeVersionData, workspaceLanguageSettings, shardedTargets);
    if (ideResolveResult.status == BuildResult.Status.FATAL_ERROR) {
        context.setHasError();
        if (ideResolveResult.outOfMemory()) {
            SuggestBuildShardingNotification.syncOutOfMemoryError(project, context);
        }
        return SyncResult.FAILURE;
    }
    if (context.isCancelled()) {
        return SyncResult.CANCELLED;
    }
    Scope.push(context, (childContext) -> {
        childContext.push(new TimingScope("UpdateSyncState", EventType.Other));
        for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
            syncPlugin.updateSyncState(project, childContext, workspaceRoot, projectViewSet, workspaceLanguageSettings, blazeInfo, workingSet, workspacePathResolver, artifactLocationDecoder, targetMap, syncStateBuilder, previousSyncState);
        }
    });
    ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = FutureUtil.waitForFuture(context, reverseDependenciesFuture).timed("ReverseDependencies", EventType.Other).onError("Failed to compute reverse dependency map").run().result();
    if (reverseDependencies == null) {
        return SyncResult.FAILURE;
    }
    newBlazeProjectData = new BlazeProjectData(syncStartTime, targetMap, blazeInfo, blazeVersionData, workspacePathResolver, artifactLocationDecoder, workspaceLanguageSettings, syncStateBuilder.build(), reverseDependencies);
    FileCaches.onSync(project, context, projectViewSet, newBlazeProjectData, syncParams.syncMode);
    ListenableFuture<?> prefetch = PrefetchService.getInstance().prefetchProjectFiles(project, projectViewSet, newBlazeProjectData);
    FutureUtil.waitForFuture(context, prefetch).withProgressMessage("Prefetching files...").timed("PrefetchFiles", EventType.Prefetching).onError("Prefetch failed").run();
    ListenableFuture<DirectoryStructure> directoryStructureFuture = DirectoryStructure.getRootDirectoryStructure(project, workspaceRoot, projectViewSet);
    refreshVirtualFileSystem(context, newBlazeProjectData);
    DirectoryStructure directoryStructure = FutureUtil.waitForFuture(context, directoryStructureFuture).withProgressMessage("Computing directory structure...").timed("DirectoryStructure", EventType.Other).onError("Directory structure computation failed").run().result();
    if (directoryStructure == null) {
        return SyncResult.FAILURE;
    }
    boolean success = updateProject(context, projectViewSet, blazeVersionData, directoryStructure, oldBlazeProjectData, newBlazeProjectData);
    if (!success) {
        return SyncResult.FAILURE;
    }
    SyncResult syncResult = SyncResult.SUCCESS;
    if (ideInfoResult.status == BuildResult.Status.BUILD_ERROR || ideResolveResult.status == BuildResult.Status.BUILD_ERROR) {
        final String errorType = ideInfoResult.status == BuildResult.Status.BUILD_ERROR ? "BUILD file errors" : "compilation errors";
        String message = String.format("Sync was successful, but there were %s. " + "The project may not be fully updated or resolve until fixed. " + "If the errors are from your working set, please uncheck " + "'Blaze > Sync > Expand Sync to Working Set' and try again.", errorType);
        context.output(PrintOutput.error(message));
        IssueOutput.warn(message).submit(context);
        syncResult = SyncResult.PARTIAL_SUCCESS;
    }
    return syncResult;
}
Also used : ShardedTargetsResult(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult) Builder(com.google.idea.blaze.base.model.SyncState.Builder) BlazeIdeInterface(com.google.idea.blaze.base.sync.aspects.BlazeIdeInterface) Builder(com.google.idea.blaze.base.model.SyncState.Builder) BlazeVersionData(com.google.idea.blaze.base.model.BlazeVersionData) BlazeConfigurationHandler(com.google.idea.blaze.base.command.info.BlazeConfigurationHandler) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) SyncState(com.google.idea.blaze.base.model.SyncState) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) ArtifactLocationDecoderImpl(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoderImpl) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) WorkingSet(com.google.idea.blaze.base.sync.workspace.WorkingSet) SyncResult(com.google.idea.blaze.base.sync.SyncListener.SyncResult) DirectoryStructure(com.google.idea.blaze.base.sync.projectstructure.DirectoryStructure) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) ShardedTargetList(com.google.idea.blaze.base.sync.sharding.ShardedTargetList) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeVcsHandler(com.google.idea.blaze.base.vcs.BlazeVcsHandler)

Example 24 with TimingScope

use of com.google.idea.blaze.base.scope.scopes.TimingScope in project intellij by bazelbuild.

the class BlazeSyncTask method updateProject.

private boolean updateProject(BlazeContext parentContext, ProjectViewSet projectViewSet, BlazeVersionData blazeVersionData, DirectoryStructure directoryStructure, @Nullable BlazeProjectData oldBlazeProjectData, BlazeProjectData newBlazeProjectData) {
    return Scope.push(parentContext, context -> {
        context.push(new TimingScope("UpdateProjectStructure", EventType.Other));
        context.output(new StatusOutput("Committing project structure..."));
        try {
            Transactions.submitWriteActionTransactionAndWait(() -> ProjectRootManagerEx.getInstanceEx(this.project).mergeRootsChangesDuring(() -> updateProjectStructure(context, importSettings, projectViewSet, blazeVersionData, directoryStructure, newBlazeProjectData, oldBlazeProjectData)));
        } catch (ProcessCanceledException e) {
            context.setCancelled();
            throw e;
        } catch (Throwable e) {
            IssueOutput.error("Internal error. Error: " + e).submit(context);
            logger.error(e);
            return false;
        }
        BlazeProjectDataManagerImpl.getImpl(project).saveProject(importSettings, newBlazeProjectData);
        return true;
    });
}
Also used : TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 25 with TimingScope

use of com.google.idea.blaze.base.scope.scopes.TimingScope in project intellij by bazelbuild.

the class BlazeSyncTask method syncProject.

/**
 * Returns true if sync successfully completed
 */
@VisibleForTesting
boolean syncProject(BlazeContext context) {
    TimingScope timingScope = new TimingScope("Sync", EventType.Other);
    timingScope.addScopeListener(timingScopeListener, true);
    context.push(timingScope);
    long syncStartTime = System.currentTimeMillis();
    SyncResult syncResult = SyncResult.FAILURE;
    syncStats.setStartTimeInEpochTime(System.currentTimeMillis());
    try {
        SaveUtil.saveAllFiles();
        BlazeProjectData oldBlazeProjectData = syncParams.syncMode != SyncMode.FULL ? getOldProjectData(context) : null;
        if (oldBlazeProjectData == null && syncParams.syncMode != SyncMode.NO_BUILD) {
            syncParams = BlazeSyncParams.Builder.copy(syncParams).setSyncMode(SyncMode.FULL).addProjectViewTargets(true).build();
        }
        syncStats.setSyncMode(syncParams.syncMode);
        onSyncStart(project, context, syncParams.syncMode);
        if (syncParams.syncMode != SyncMode.STARTUP) {
            syncResult = doSyncProject(context, oldBlazeProjectData);
            if (context.isCancelled()) {
                syncResult = SyncResult.CANCELLED;
            }
        } else {
            syncResult = SyncResult.SUCCESS;
        }
        if (syncResult.successful()) {
            ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
            BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
            updateInMemoryState(project, context, projectViewSet, blazeProjectData);
            onSyncComplete(project, context, projectViewSet, blazeProjectData, syncResult);
        }
    } catch (Throwable e) {
        logSyncError(context, e);
    } finally {
        try {
            syncStats.setTotalExecTimeMs(System.currentTimeMillis() - syncStartTime);
            syncStats.setSyncResult(syncResult);
            EventLoggingService.getInstance().ifPresent(s -> s.log(buildStats(syncStats)));
        } catch (Exception e) {
            logSyncError(context, e);
        }
        afterSync(project, context, syncResult);
    }
    return syncResult == SyncResult.SUCCESS || syncResult == SyncResult.PARTIAL_SUCCESS;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) SyncResult(com.google.idea.blaze.base.sync.SyncListener.SyncResult) IOException(java.io.IOException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

TimingScope (com.google.idea.blaze.base.scope.scopes.TimingScope)27 StatusOutput (com.google.idea.blaze.base.scope.output.StatusOutput)8 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)7 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)7 Nullable (javax.annotation.Nullable)7 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)6 EventType (com.google.idea.blaze.base.scope.scopes.TimingScope.EventType)6 Logger (com.intellij.openapi.diagnostic.Logger)6 List (java.util.List)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Lists (com.google.common.collect.Lists)5 Maps (com.google.common.collect.Maps)5 Futures (com.google.common.util.concurrent.Futures)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)5 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)5 Scope (com.google.idea.blaze.base.scope.Scope)5 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)5 Project (com.intellij.openapi.project.Project)5