Search in sources :

Example 11 with FileSystemSnapshot

use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.

the class CaptureStateAfterExecutionStep method captureStateAfterExecution.

private Optional<AfterExecutionState> captureStateAfterExecution(UnitOfWork work, BeforeExecutionContext context, BeforeExecutionState beforeExecutionState, Duration duration) {
    return operation(operationContext -> {
        try {
            Timer timer = Time.startTimer();
            ImmutableSortedMap<String, FileSystemSnapshot> outputsProducedByWork = captureOutputs(work, context, beforeExecutionState);
            long snapshotOutputDuration = timer.getElapsedMillis();
            // The origin execution time is recorded as “work duration” + “output snapshotting duration”,
            // As this is _roughly_ the amount of time that is avoided by reusing the outputs,
            // which is currently the _only_ thing this value is used for.
            Duration originExecutionTime = duration.plus(Duration.ofMillis(snapshotOutputDuration));
            OriginMetadata originMetadata = new OriginMetadata(buildInvocationScopeId.asString(), originExecutionTime);
            AfterExecutionState afterExecutionState = new DefaultAfterExecutionState(beforeExecutionState, outputsProducedByWork, originMetadata, false);
            operationContext.setResult(Operation.Result.INSTANCE);
            return Optional.of(afterExecutionState);
        } catch (OutputSnapshotter.OutputFileSnapshottingException e) {
            work.handleUnreadableOutputs(e);
            operationContext.setResult(Operation.Result.INSTANCE);
            return Optional.empty();
        }
    }, BuildOperationDescriptor.displayName("Snapshot outputs after executing " + work.getDisplayName()).details(Operation.Details.INSTANCE));
}
Also used : DefaultAfterExecutionState(org.gradle.internal.execution.history.impl.DefaultAfterExecutionState) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) Timer(org.gradle.internal.time.Timer) OutputSnapshotter(org.gradle.internal.execution.OutputSnapshotter) DefaultAfterExecutionState(org.gradle.internal.execution.history.impl.DefaultAfterExecutionState) Duration(java.time.Duration) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot)

Example 12 with FileSystemSnapshot

use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.

the class TarBuildCacheEntryPacker method pack.

private long pack(CacheableEntity entity, Map<String, ? extends FileSystemSnapshot> snapshots, TarArchiveOutputStream tarOutput) {
    AtomicLong entries = new AtomicLong();
    entity.visitOutputTrees((treeName, type, root) -> {
        FileSystemSnapshot treeSnapshots = snapshots.get(treeName);
        try {
            long entryCount = packTree(treeName, type, treeSnapshots, tarOutput);
            entries.addAndGet(entryCount);
        } catch (Exception ex) {
            throw new RuntimeException(String.format("Could not pack tree '%s': %s", treeName, ex.getMessage()), ex);
        }
    });
    return entries.get();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) UncheckedIOException(java.io.UncheckedIOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Aggregations

FileSystemSnapshot (org.gradle.internal.snapshot.FileSystemSnapshot)12 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 OriginMetadata (org.gradle.caching.internal.origin.OriginMetadata)3 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)2 Duration (java.time.Duration)2 Nonnull (javax.annotation.Nonnull)2 AfterExecutionState (org.gradle.internal.execution.history.AfterExecutionState)2 OutputsCleaner (org.gradle.internal.execution.history.OutputsCleaner)2 OverlappingOutputs (org.gradle.internal.execution.history.OverlappingOutputs)2 DefaultBeforeExecutionState (org.gradle.internal.execution.history.impl.DefaultBeforeExecutionState)2 FileCollectionFingerprint (org.gradle.internal.fingerprint.FileCollectionFingerprint)2 ValueSnapshot (org.gradle.internal.snapshot.ValueSnapshot)2 ImplementationSnapshot (org.gradle.internal.snapshot.impl.ImplementationSnapshot)2 Timer (org.gradle.internal.time.Timer)2 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1