Skip to content

Commit

Permalink
Record Error Prone initialization time
Browse files Browse the repository at this point in the history
RELNOTES=N/A
PiperOrigin-RevId: 498571979
  • Loading branch information
cushon authored and Error Prone Team committed Dec 30, 2022
1 parent 1d23141 commit 8ddb7cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ private static Supplier<CodeTransformer> scansPlugins(
() -> {
// we can't load plugins from the processorpath until the filemanager has been
// initialized, so do it lazily
try {
ErrorProneTimings timings = ErrorProneTimings.instance(context);
try (AutoCloseable unused = timings.initializationTimeSpan()) {
return ErrorProneScannerTransformer.create(
ErrorPronePlugins.loadPlugins(scannerSupplier, context)
.applyOverrides(errorProneOptions)
.get());
} catch (InvalidCommandLineOptionException e) {
throw new PropagatedException(e);
} catch (Exception e) {
// for the timing span, should be impossible
throw new AssertionError(e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,29 @@ private ErrorProneTimings(Context context) {

private final Map<String, Stopwatch> timers = new HashMap<>();

private final Stopwatch initializationTime = Stopwatch.createUnstarted();

/** Creates a timing span for the given {@link Suppressible}. */
public AutoCloseable span(Suppressible suppressible) {
String key = suppressible.canonicalName();
Stopwatch sw = timers.computeIfAbsent(key, k -> Stopwatch.createUnstarted()).start();
return () -> sw.stop();
}

/** Creates a timing span for initialization. */
public AutoCloseable initializationTimeSpan() {
initializationTime.start();
return () -> initializationTime.stop();
}

/** Returns the elapsed durations of each timer. */
public ImmutableMap<String, Duration> timings() {
return timers.entrySet().stream()
.collect(toImmutableMap(e -> e.getKey(), e -> e.getValue().elapsed()));
}

/** Returns the elapsed initialization time. */
public Duration initializationTime() {
return initializationTime.elapsed();
}
}

0 comments on commit 8ddb7cb

Please sign in to comment.