Search in sources :

Example 1 with ElapsedTimeReceiver

use of com.google.devtools.build.lib.profiler.AutoProfiler.ElapsedTimeReceiver in project bazel by bazelbuild.

the class FilesystemValueChecker method getDirtyValues.

private BatchDirtyResult getDirtyValues(ValueFetcher fetcher, Iterable<SkyKey> keys, final SkyValueDirtinessChecker checker, final boolean checkMissingValues) throws InterruptedException {
    ExecutorService executor = Executors.newFixedThreadPool(DIRTINESS_CHECK_THREADS, new ThreadFactoryBuilder().setNameFormat("FileSystem Value Invalidator %d").build());
    final BatchDirtyResult batchResult = new BatchDirtyResult();
    ThrowableRecordingRunnableWrapper wrapper = new ThrowableRecordingRunnableWrapper("FilesystemValueChecker#getDirtyValues");
    final AtomicInteger numKeysScanned = new AtomicInteger(0);
    final AtomicInteger numKeysChecked = new AtomicInteger(0);
    ElapsedTimeReceiver elapsedTimeReceiver = new ElapsedTimeReceiver() {

        @Override
        public void accept(long elapsedTimeNanos) {
            if (elapsedTimeNanos > 0) {
                LOG.info(String.format("Spent %d ms checking %d filesystem nodes (%d scanned)", TimeUnit.MILLISECONDS.convert(elapsedTimeNanos, TimeUnit.NANOSECONDS), numKeysChecked.get(), numKeysScanned.get()));
            }
        }
    };
    try (AutoProfiler prof = AutoProfiler.create(elapsedTimeReceiver)) {
        for (final SkyKey key : keys) {
            numKeysScanned.incrementAndGet();
            if (!checker.applies(key)) {
                continue;
            }
            final SkyValue value = fetcher.get(key);
            if (!checkMissingValues && value == null) {
                continue;
            }
            executor.execute(wrapper.wrap(new Runnable() {

                @Override
                public void run() {
                    numKeysChecked.incrementAndGet();
                    DirtyResult result = checker.check(key, value, tsgm);
                    if (result.isDirty()) {
                        batchResult.add(key, value, result.getNewValue());
                    }
                }
            }));
        }
        boolean interrupted = ExecutorUtil.interruptibleShutdown(executor);
        Throwables.propagateIfPossible(wrapper.getFirstThrownError());
        if (interrupted) {
            throw new InterruptedException();
        }
    }
    return batchResult;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) AutoProfiler(com.google.devtools.build.lib.profiler.AutoProfiler) DirtyResult(com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker.DirtyResult) ElapsedTimeReceiver(com.google.devtools.build.lib.profiler.AutoProfiler.ElapsedTimeReceiver) SkyValue(com.google.devtools.build.skyframe.SkyValue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ThrowableRecordingRunnableWrapper(com.google.devtools.build.lib.concurrent.ThrowableRecordingRunnableWrapper)

Example 2 with ElapsedTimeReceiver

use of com.google.devtools.build.lib.profiler.AutoProfiler.ElapsedTimeReceiver in project bazel by bazelbuild.

the class AutoProfilerTest method simple.

@Test
public void simple() {
    final AtomicLong elapsedTime = new AtomicLong();
    ElapsedTimeReceiver receiver = new ElapsedTimeReceiver() {

        @Override
        public void accept(long elapsedTimeNanos) {
            elapsedTime.set(elapsedTimeNanos);
        }
    };
    try (AutoProfiler profiler = AutoProfiler.create(receiver)) {
        clock.advanceMillis(42);
    }
    assertThat(elapsedTime.get()).isEqualTo(42 * 1000 * 1000);
}
Also used : ElapsedTimeReceiver(com.google.devtools.build.lib.profiler.AutoProfiler.ElapsedTimeReceiver) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Aggregations

ElapsedTimeReceiver (com.google.devtools.build.lib.profiler.AutoProfiler.ElapsedTimeReceiver)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ThrowableRecordingRunnableWrapper (com.google.devtools.build.lib.concurrent.ThrowableRecordingRunnableWrapper)1 AutoProfiler (com.google.devtools.build.lib.profiler.AutoProfiler)1 DirtyResult (com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker.DirtyResult)1 SkyKey (com.google.devtools.build.skyframe.SkyKey)1 SkyValue (com.google.devtools.build.skyframe.SkyValue)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1