Search in sources :

Example 1 with MapBasedActionGraph

use of com.google.devtools.build.lib.actions.MapBasedActionGraph in project bazel by bazelbuild.

the class BuildViewTestCase method initializeSkyframeExecutor.

@Before
public final void initializeSkyframeExecutor() throws Exception {
    analysisMock = getAnalysisMock();
    directories = new BlazeDirectories(outputBase, outputBase, rootDirectory, analysisMock.getProductName());
    binTools = BinTools.forUnitTesting(directories, analysisMock.getEmbeddedTools());
    mockToolsConfig = new MockToolsConfig(rootDirectory, false);
    analysisMock.setupMockClient(mockToolsConfig);
    analysisMock.setupMockWorkspaceFiles(directories.getEmbeddedBinariesRoot());
    packageCacheOptions = parsePackageCacheOptions();
    workspaceStatusActionFactory = new AnalysisTestUtil.DummyWorkspaceStatusActionFactory(directories);
    mutableActionGraph = new MapBasedActionGraph();
    ruleClassProvider = getRuleClassProvider();
    configurationFactory = analysisMock.createConfigurationFactory(ruleClassProvider.getConfigurationFragments());
    pkgFactory = analysisMock.getPackageFactoryForTesting().create(ruleClassProvider, getPlatformSetRegexps(), getEnvironmentExtensions(), scratch.getFileSystem());
    tsgm = new TimestampGranularityMonitor(BlazeClock.instance());
    skyframeExecutor = SequencedSkyframeExecutor.create(pkgFactory, directories, binTools, workspaceStatusActionFactory, ruleClassProvider.getBuildInfoFactories(), ImmutableList.<DiffAwareness.Factory>of(), Predicates.<PathFragment>alwaysFalse(), getPreprocessorFactorySupplier(), analysisMock.getSkyFunctions(), getPrecomputedValues(), ImmutableList.<SkyValueDirtinessChecker>of(), analysisMock.getProductName(), CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD));
    packageCacheOptions.defaultVisibility = ConstantRuleVisibility.PUBLIC;
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = 7;
    skyframeExecutor.preparePackageLoading(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)), packageCacheOptions, "", UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), tsgm);
    useConfiguration();
    setUpSkyframe();
    // Also initializes ResourceManager.
    ResourceManager.instance().setAvailableResources(getStartingResources());
}
Also used : MockToolsConfig(com.google.devtools.build.lib.packages.util.MockToolsConfig) PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) BlazeDirectories(com.google.devtools.build.lib.analysis.BlazeDirectories) MapBasedActionGraph(com.google.devtools.build.lib.actions.MapBasedActionGraph) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) PackageFactory(com.google.devtools.build.lib.packages.PackageFactory) MiddlemanFactory(com.google.devtools.build.lib.actions.MiddlemanFactory) ConfigurationFactory(com.google.devtools.build.lib.analysis.config.ConfigurationFactory) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor) SkyValueDirtinessChecker(com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker) Before(org.junit.Before)

Example 2 with MapBasedActionGraph

use of com.google.devtools.build.lib.actions.MapBasedActionGraph in project bazel by bazelbuild.

the class SkyframeActionExecutor method constructActionGraphAndPathMap.

/**
   * Simultaneously construct an action graph for all the actions in Skyframe and a map from
   * {@link PathFragment}s to their respective {@link Artifact}s. We do this in a threadpool to save
   * around 1.5 seconds on a mid-sized build versus a single-threaded operation.
   */
private static Pair<ActionGraph, SortedMap<PathFragment, Artifact>> constructActionGraphAndPathMap(Iterable<ActionLookupValue> values, ConcurrentMap<ActionAnalysisMetadata, ConflictException> badActionMap) throws InterruptedException {
    MutableActionGraph actionGraph = new MapBasedActionGraph();
    ConcurrentNavigableMap<PathFragment, Artifact> artifactPathMap = new ConcurrentSkipListMap<>();
    // Action graph construction is CPU-bound.
    int numJobs = Runtime.getRuntime().availableProcessors();
    // No great reason for expecting 5000 action lookup values, but not worth counting size of
    // values.
    Sharder<ActionLookupValue> actionShards = new Sharder<>(numJobs, 5000);
    for (ActionLookupValue value : values) {
        actionShards.add(value);
    }
    ThrowableRecordingRunnableWrapper wrapper = new ThrowableRecordingRunnableWrapper("SkyframeActionExecutor#constructActionGraphAndPathMap");
    ExecutorService executor = Executors.newFixedThreadPool(numJobs, new ThreadFactoryBuilder().setNameFormat("ActionLookupValue Processor %d").build());
    for (List<ActionLookupValue> shard : actionShards) {
        executor.execute(wrapper.wrap(actionRegistration(shard, actionGraph, artifactPathMap, badActionMap)));
    }
    boolean interrupted = ExecutorUtil.interruptibleShutdown(executor);
    Throwables.propagateIfPossible(wrapper.getFirstThrownError());
    if (interrupted) {
        throw new InterruptedException();
    }
    return Pair.<ActionGraph, SortedMap<PathFragment, Artifact>>of(actionGraph, artifactPathMap);
}
Also used : Sharder(com.google.devtools.build.lib.concurrent.Sharder) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) MutableActionGraph(com.google.devtools.build.lib.actions.MutableActionGraph) MapBasedActionGraph(com.google.devtools.build.lib.actions.MapBasedActionGraph) ActionGraph(com.google.devtools.build.lib.actions.ActionGraph) MapBasedActionGraph(com.google.devtools.build.lib.actions.MapBasedActionGraph) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) MutableActionGraph(com.google.devtools.build.lib.actions.MutableActionGraph) Artifact(com.google.devtools.build.lib.actions.Artifact) SortedMap(java.util.SortedMap) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ThrowableRecordingRunnableWrapper(com.google.devtools.build.lib.concurrent.ThrowableRecordingRunnableWrapper)

Aggregations

MapBasedActionGraph (com.google.devtools.build.lib.actions.MapBasedActionGraph)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ActionGraph (com.google.devtools.build.lib.actions.ActionGraph)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 MiddlemanFactory (com.google.devtools.build.lib.actions.MiddlemanFactory)1 MutableActionGraph (com.google.devtools.build.lib.actions.MutableActionGraph)1 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1 ConfigurationFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFactory)1 Sharder (com.google.devtools.build.lib.concurrent.Sharder)1 ThrowableRecordingRunnableWrapper (com.google.devtools.build.lib.concurrent.ThrowableRecordingRunnableWrapper)1 PackageFactory (com.google.devtools.build.lib.packages.PackageFactory)1 MockToolsConfig (com.google.devtools.build.lib.packages.util.MockToolsConfig)1 PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)1 SkyValueDirtinessChecker (com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker)1 TimestampGranularityMonitor (com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)1 SortedMap (java.util.SortedMap)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Before (org.junit.Before)1