summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODOS.md1
-rw-r--r--src/main/java/org/javacs/JavaCompilerService.java41
2 files changed, 40 insertions, 2 deletions
diff --git a/TODOS.md b/TODOS.md
index 211ed9b..318db9e 100644
--- a/TODOS.md
+++ b/TODOS.md
@@ -6,6 +6,7 @@
- testMethod/testClass doesn't work for bazel
- Find-all-references doesn't work on constructors
- Files created in session don't autocomplete
+- EnumMap default methods don't autocomplete
## Autocomplete
- Annotation fields
diff --git a/src/main/java/org/javacs/JavaCompilerService.java b/src/main/java/org/javacs/JavaCompilerService.java
index 1f43a56..8855c5c 100644
--- a/src/main/java/org/javacs/JavaCompilerService.java
+++ b/src/main/java/org/javacs/JavaCompilerService.java
@@ -177,6 +177,36 @@ public class JavaCompilerService {
return Collections.unmodifiableList(new ArrayList<>(diags));
}
+ class Profiler implements TaskListener {
+ Map<TaskEvent.Kind, Instant> started = new EnumMap<>(TaskEvent.Kind.class);
+ Map<TaskEvent.Kind, Duration> profile = new EnumMap<>(TaskEvent.Kind.class);
+
+ @Override
+ public void started(TaskEvent e) {
+ started.put(e.getKind(), Instant.now());
+ }
+
+ @Override
+ public void finished(TaskEvent e) {
+ var k = e.getKind();
+ var start = started.getOrDefault(k, Instant.now());
+ var elapsed = Duration.between(start, Instant.now());
+ var soFar = profile.getOrDefault(k, Duration.ZERO);
+ var total = soFar.plus(elapsed);
+ profile.put(k, total);
+ }
+
+ void print() {
+ var lines = new StringJoiner("\n\t");
+ for (var k : TaskEvent.Kind.values()) {
+ var elapsed = profile.getOrDefault(k, Duration.ZERO);
+ var ms = elapsed.getSeconds() * 1000 + elapsed.getNano() / 1000 / 1000;
+ lines.add(String.format("%s: %dms", k, ms));
+ }
+ LOG.info("Compilation profile:\n\t" + lines);
+ }
+ };
+
/** Stores the compiled version of a single file */
class Cache {
final String contents;
@@ -199,6 +229,11 @@ public class JavaCompilerService {
}
this.file = file;
this.task = singleFileTask(file, this.contents);
+ this.line = line;
+ this.character = character;
+
+ var profiler = new Profiler();
+ task.addTaskListener(profiler);
try {
var it = task.parse().iterator();
this.root = it.hasNext() ? it.next() : null;
@@ -208,8 +243,7 @@ public class JavaCompilerService {
} catch (IOException e) {
throw new RuntimeException(e);
}
- this.line = line;
- this.character = character;
+ profiler.print();
}
}
@@ -1242,12 +1276,15 @@ public class JavaCompilerService {
private Batch compileBatch(List<Path> files) {
var task = batchTask(files, false);
var result = new ArrayList<CompilationUnitTree>();
+ var profiler = new Profiler();
+ task.addTaskListener(profiler);
try {
for (var t : task.parse()) result.add(t);
task.analyze();
} catch (IOException e) {
throw new RuntimeException(e);
}
+ profiler.print();
return new Batch(task, result);
}