-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add profiler to ExternalHooks, as a Java interface
The entry point API of Zinc, xsbti.compile.IncrementalCompiler, is defined in compiler-interface and is, therefore, entirely in Java, only. Therefore, in order to allow a user (e.g. an external build tool) to define their own profiler using this interface I extracted a Java-only interface for InvalidationProfiler and its components. Having done that I could add it to compiler-interface's xsbti.compile.ExternalHooks. I've kept the original, Scala variant, interface methods (e.g. using Scala's Iterable instead of Array or java.util.Set) for backwards compatibility and I've created an AdaptedRunProfiler that knows how to adapt the calls to the underlying XRunProfiler it contains.
- Loading branch information
Showing
11 changed files
with
304 additions
and
80 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
internal/compiler-interface/src/main/java/xsbti/compile/APIChange.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,19 @@ | ||
/* | ||
* Zinc - The incremental compiler for Scala. | ||
* Copyright Lightbend, Inc. and Mark Harrah | ||
* | ||
* Licensed under Apache License 2.0 | ||
* (http://www.apache.org/licenses/LICENSE-2.0). | ||
* | ||
* See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. | ||
*/ | ||
|
||
package xsbti.compile; | ||
|
||
import java.util.Set; | ||
|
||
public interface APIChange { | ||
String getModifiedClass(); | ||
Set<UsedName> getModifiedNames(); | ||
} |
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
23 changes: 23 additions & 0 deletions
23
internal/compiler-interface/src/main/java/xsbti/compile/InitialChanges.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,23 @@ | ||
/* | ||
* Zinc - The incremental compiler for Scala. | ||
* Copyright Lightbend, Inc. and Mark Harrah | ||
* | ||
* Licensed under Apache License 2.0 | ||
* (http://www.apache.org/licenses/LICENSE-2.0). | ||
* | ||
* See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. | ||
*/ | ||
|
||
package xsbti.compile; | ||
|
||
import xsbti.VirtualFileRef; | ||
|
||
import java.util.Set; | ||
|
||
public interface InitialChanges { | ||
Changes<VirtualFileRef> getInternalSrc(); | ||
Set<VirtualFileRef> getRemovedProducts(); | ||
Set<VirtualFileRef> getLibraryDeps(); | ||
APIChange[] getExternal(); | ||
} |
22 changes: 22 additions & 0 deletions
22
internal/compiler-interface/src/main/java/xsbti/compile/InvalidationProfiler.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,22 @@ | ||
/* | ||
* Zinc - The incremental compiler for Scala. | ||
* Copyright Lightbend, Inc. and Mark Harrah | ||
* | ||
* Licensed under Apache License 2.0 | ||
* (http://www.apache.org/licenses/LICENSE-2.0). | ||
* | ||
* See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. | ||
*/ | ||
|
||
package xsbti.compile; | ||
|
||
public interface InvalidationProfiler { | ||
RunProfiler profileRun(); | ||
|
||
enum EMPTY implements InvalidationProfiler { | ||
INSTANCE; | ||
|
||
@Override public RunProfiler profileRun() { return RunProfiler.EMPTY.INSTANCE; } | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
internal/compiler-interface/src/main/java/xsbti/compile/RunProfiler.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,92 @@ | ||
/* | ||
* Zinc - The incremental compiler for Scala. | ||
* Copyright Lightbend, Inc. and Mark Harrah | ||
* | ||
* Licensed under Apache License 2.0 | ||
* (http://www.apache.org/licenses/LICENSE-2.0). | ||
* | ||
* See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. | ||
*/ | ||
|
||
package xsbti.compile; | ||
|
||
import xsbti.VirtualFileRef; | ||
|
||
public interface RunProfiler { | ||
void timeCompilation(long startNanos, long durationNanos); | ||
void registerInitial(InitialChanges changes); | ||
void registerEvent(String kind, String[] inputs, String[] outputs, String reason); | ||
void registerCycle( | ||
String[] invalidatedClasses, | ||
String[] invalidatedPackageObjects, | ||
VirtualFileRef[] initialSources, | ||
VirtualFileRef[] invalidatedSources, | ||
String[] recompiledClasses, | ||
APIChange[] changesAfterRecompilation, | ||
String[] nextInvalidations, | ||
boolean shouldCompileIncrementally | ||
); | ||
void registerRun(); | ||
|
||
enum EMPTY implements RunProfiler { | ||
INSTANCE; | ||
|
||
@Override public void timeCompilation(long startNanos, long durationNanos) {} | ||
@Override public void registerInitial(InitialChanges changes) {} | ||
@Override public void registerEvent(String kind, String[] inputs, String[] outputs, String reason) {} | ||
@Override public void registerCycle( | ||
String[] invalidatedClasses, | ||
String[] invalidatedPackageObjects, | ||
VirtualFileRef[] initialSources, | ||
VirtualFileRef[] invalidatedSources, | ||
String[] recompiledClasses, | ||
APIChange[] changesAfterRecompilation, | ||
String[] nextInvalidations, | ||
boolean shouldCompileIncrementally | ||
) {} | ||
@Override public void registerRun() {} | ||
} | ||
|
||
interface DelegatingRunProfiler extends RunProfiler { | ||
RunProfiler profiler(); | ||
|
||
default void timeCompilation(long startNanos, long durationNanos) { | ||
profiler().timeCompilation(startNanos, durationNanos); | ||
} | ||
|
||
default void registerInitial(InitialChanges changes) { | ||
profiler().registerInitial(changes); | ||
} | ||
|
||
default void registerEvent(String kind, String[] inputs, String[] outputs, String reason) { | ||
profiler().registerEvent(kind, inputs, outputs, reason); | ||
} | ||
|
||
default public void registerCycle( | ||
String[] invalidatedClasses, | ||
String[] invalidatedPackageObjects, | ||
VirtualFileRef[] initialSources, | ||
VirtualFileRef[] invalidatedSources, | ||
String[] recompiledClasses, | ||
APIChange[] changesAfterRecompilation, | ||
String[] nextInvalidations, | ||
boolean shouldCompileIncrementally | ||
) { | ||
profiler().registerCycle( | ||
invalidatedClasses, | ||
invalidatedPackageObjects, | ||
initialSources, | ||
invalidatedSources, | ||
recompiledClasses, | ||
changesAfterRecompilation, | ||
nextInvalidations, | ||
shouldCompileIncrementally | ||
); | ||
} | ||
|
||
default void registerRun() { | ||
profiler().registerRun(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
internal/compiler-interface/src/main/java/xsbti/compile/UsedName.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,20 @@ | ||
/* | ||
* Zinc - The incremental compiler for Scala. | ||
* Copyright Lightbend, Inc. and Mark Harrah | ||
* | ||
* Licensed under Apache License 2.0 | ||
* (http://www.apache.org/licenses/LICENSE-2.0). | ||
* | ||
* See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. | ||
*/ | ||
|
||
package xsbti.compile; | ||
|
||
import xsbti.UseScope; | ||
|
||
public interface UsedName { | ||
String getName(); | ||
java.util.EnumSet<UseScope> getScopes(); | ||
} | ||
|
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
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
Oops, something went wrong.