Add system property that triggers printing of dependency analyzer summary report

This commit is contained in:
Alexey Andreev 2018-06-29 17:32:26 +03:00
parent f160ce2f2f
commit 3653e39bec

View File

@ -21,6 +21,7 @@ import com.carrotsearch.hppc.cursors.IntCursor;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator;
import java.util.Deque; import java.util.Deque;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -63,6 +64,7 @@ public class DependencyAnalyzer implements DependencyInfo {
static final boolean shouldLog = System.getProperty("org.teavm.logDependencies", "false").equals("true"); static final boolean shouldLog = System.getProperty("org.teavm.logDependencies", "false").equals("true");
static final boolean shouldTag = System.getProperty("org.teavm.tagDependencies", "false").equals("true") static final boolean shouldTag = System.getProperty("org.teavm.tagDependencies", "false").equals("true")
|| shouldLog; || shouldLog;
static final boolean dependencyReport = System.getProperty("org.teavm.dependencyReport", "false").equals("true");
private int classNameSuffix; private int classNameSuffix;
private DependencyClassSource classSource; private DependencyClassSource classSource;
private ClassLoader classLoader; private ClassLoader classLoader;
@ -636,6 +638,47 @@ public class DependencyAnalyzer implements DependencyInfo {
listener.completing(agent); listener.completing(agent);
} }
} }
if (dependencyReport) {
reportDependencies();
}
}
private void reportDependencies() {
List<ReportEntry> report = new ArrayList<>();
for (MethodReference reachableMethod : getReachableMethods()) {
MethodDependency dependency = getMethod(reachableMethod);
if (dependency == null) {
continue;
}
for (int i = 0; i <= reachableMethod.parameterCount(); ++i) {
DependencyNode param = dependency.getVariable(i);
if (param == null) {
continue;
}
report.add(new ReportEntry(reachableMethod + " param " + i, param.getTypes().length));
}
if (dependency.getResult() != null) {
report.add(new ReportEntry(reachableMethod + " result", dependency.getResult().getTypes().length));
}
}
report.sort(Comparator.comparingInt(n -> -n.count));
for (ReportEntry entry : report) {
System.out.println(entry.title + ": " + entry.count);
}
}
static class ReportEntry {
String title;
int count;
ReportEntry(String title, int count) {
this.title = title;
this.count = count;
}
} }
private void lock() { private void lock() {