diff options
-rw-r--r-- | TODOS.md | 1 | ||||
-rw-r--r-- | src/main/java/org/javacs/JavaCompilerService.java | 41 |
2 files changed, 40 insertions, 2 deletions
@@ -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); } |