Skip to content

Commit e659a3f

Browse files
committed
Improve compiler logging with some new timing statistics
- Show the classes-per-second rate in the logs - Show the compiler name in the logs - Show how many compilation units and user-provided class nams are being compiled in the logs
1 parent f1bf2b5 commit e659a3f

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

java-compiler-testing/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
</dependency>
9696

9797
<dependency>
98-
<!-- v5.0.0 uses the inline mock maker by default -->
9998
<groupId>org.mockito</groupId>
10099
<artifactId>mockito-core</artifactId>
101100
<scope>test</scope>

java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImpl.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.List;
3535
import java.util.Set;
3636
import javax.tools.JavaCompiler;
37-
import javax.tools.JavaFileManager.Location;
3837
import javax.tools.JavaFileObject;
3938
import javax.tools.JavaFileObject.Kind;
4039
import javax.tools.StandardLocation;
@@ -110,19 +109,38 @@ private JctCompilation createCheckedCompilation(
110109
task.setProcessors(processors);
111110
}
112111

113-
LOGGER.info("Starting compilation");
112+
LOGGER
113+
.atInfo()
114+
.setMessage(
115+
"Starting compilation with {} (found {} compilation units, {} user-provided class names)"
116+
)
117+
.addArgument(compiler::getName)
118+
.addArgument(compilationUnits::size)
119+
.addArgument(classNames == null
120+
? () -> "no"
121+
: classNames::size
122+
)
123+
.log();
114124

115125
var start = System.nanoTime();
116126
var success = requireNonNull(
117-
task.call(), "Compiler task .call() method returned null unexpectedly!"
127+
task.call(),
128+
() -> "Compiler " + compiler.getName() + " task .call() method returned null unexpectedly!"
118129
);
119130
var delta = (System.nanoTime() - start) / 1_000_000L;
120131

121132
LOGGER
122133
.atInfo()
123-
.setMessage("Compilation {} after approximately {}ms")
134+
.setMessage("Compilation with {} {} after approximately {}ms (roughly {} classes/sec)")
135+
.addArgument(compiler::getName)
124136
.addArgument(() -> success ? "completed successfully" : "failed")
125137
.addArgument(delta)
138+
.addArgument(() -> String.format(
139+
"%.2f",
140+
classNames == null
141+
? 1000.0 * compilationUnits.size() / delta
142+
: 1000.0 * classNames.size() / delta
143+
))
126144
.log();
127145

128146
return JctCompilationImpl
@@ -137,7 +155,7 @@ private JctCompilation createCheckedCompilation(
137155
}
138156

139157
private Set<JavaFileObject> findCompilationUnits(JctFileManager fileManager) throws IOException {
140-
Collection<Location> locations = IterableUtils
158+
var locations = IterableUtils
141159
.flatten(fileManager.listLocationsForModules(StandardLocation.MODULE_SOURCE_PATH));
142160

143161
if (locations.isEmpty()) {

0 commit comments

Comments
 (0)