forked from google/error-prone
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In verbose mode, log Error Prone performance details
This change introduces a `TaskListener` which logs collected `ErrorProneTimings` post compilation. Additionally, since `SuggestedFixes#compilesWithFix` is a very heavy operation which significantly contributes to overall runtime, any usage of this method is also logged. Rationale behind this decision is that if many `compilesWithFix` checks fail, then this can "silently" slow down the build. By logging such cases one can either invest time in optimizing the associated check, or manually improving the code that triggers the compilation attempts. See google#1474.
- Loading branch information
1 parent
7a28964
commit 92e050a
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
check_api/src/main/java/com/google/errorprone/TimingReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.google.errorprone; | ||
|
||
import static java.util.stream.Collectors.joining; | ||
|
||
import com.sun.source.util.TaskEvent; | ||
import com.sun.source.util.TaskEvent.Kind; | ||
import com.sun.source.util.TaskListener; | ||
import com.sun.tools.javac.util.Log; | ||
import java.time.Duration; | ||
import java.util.Map; | ||
|
||
final class TimingReporter implements TaskListener { | ||
private final ErrorProneTimings errorProneTimings; | ||
private final Log log; | ||
|
||
TimingReporter(ErrorProneTimings errorProneTimings, Log log) { | ||
this.errorProneTimings = errorProneTimings; | ||
this.log = log; | ||
} | ||
|
||
@Override | ||
public void finished(TaskEvent event) { | ||
if (event.getKind() != Kind.COMPILATION) { | ||
return; | ||
} | ||
|
||
Map<String, Duration> timings = errorProneTimings.timings(); | ||
if (timings.isEmpty()) { | ||
return; | ||
} | ||
|
||
Duration totalTime = timings.values().stream().reduce(Duration.ZERO, Duration::plus); | ||
String slowestChecks = | ||
timings.entrySet().stream() | ||
.sorted(Map.Entry.<String, Duration>comparingByValue().reversed()) | ||
.limit(10) | ||
.map(e -> e.getValue() + ": " + e.getKey()) | ||
.collect(joining("\n ", " ", "")); | ||
|
||
log.printVerbose( | ||
"error.prone.timing", totalTime, errorProneTimings.initializationTime(), slowestChecks); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters