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;
}
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);
}
Aggregations