src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugValuesPrinter.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
*** old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugValuesPrinter.java Mon Mar 20 17:37:54 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugValuesPrinter.java Mon Mar 20 17:37:54 2017
*** 33,50 ****
--- 33,51 ----
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.graalvm.compiler.debug.CSVUtil;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.debug.LogStream;
import org.graalvm.compiler.debug.TTY;
import org.graalvm.compiler.debug.internal.method.MethodMetricsImpl;
import org.graalvm.compiler.debug.internal.method.MethodMetricsPrinter;
+ import org.graalvm.compiler.options.OptionValues;
+ import org.graalvm.util.CollectionsUtil;
/**
* Facility for printing the {@linkplain KeyRegistry#getDebugValues() values} collected across all
* {@link DebugValueMap#getTopLevelMaps() threads}.
*/
*** 59,122 ****
--- 60,123 ----
public DebugValuesPrinter(MethodMetricsPrinter mmPrinter) {
this.mmPrinter = mmPrinter;
}
! public void printDebugValues(OptionValues options) throws GraalError {
TTY.println();
TTY.println("<DebugValues>");
List<DebugValueMap> topLevelMaps = DebugValueMap.getTopLevelMaps();
List<DebugValue> debugValues = KeyRegistry.getDebugValues();
if (debugValues.size() > 0) {
try {
ArrayList<DebugValue> sortedValues = new ArrayList<>(debugValues);
Collections.sort(sortedValues);
! String summary = DebugValueSummary.getValue(options);
if (summary == null) {
summary = "Complete";
}
! if (DebugValueThreadFilter.getValue(options) != null && topLevelMaps.size() != 0) {
! topLevelMaps = topLevelMaps.stream().filter(map -> Pattern.compile(DebugValueThreadFilter.getValue()).matcher(map.getName()).find()).collect(Collectors.toList());
! topLevelMaps = CollectionsUtil.filterToList(topLevelMaps, map -> Pattern.compile(DebugValueThreadFilter.getValue(options)).matcher(map.getName()).find());
if (topLevelMaps.size() == 0) {
! TTY.println("Warning: DebugValueThreadFilter=%s eliminated all maps so nothing will be printed", DebugValueThreadFilter.getValue(options));
}
}
switch (summary) {
case "Name": {
! LogStream log = getLogStream(options);
! printSummary(options, log, topLevelMaps, sortedValues);
break;
}
case "Partial": {
DebugValueMap globalMap = new DebugValueMap("Global");
for (DebugValueMap map : topLevelMaps) {
flattenChildren(map, globalMap);
}
globalMap.normalize();
! LogStream log = getLogStream(options);
! printMap(options, log, new DebugValueScope(null, globalMap), sortedValues);
break;
}
case "Complete": {
DebugValueMap globalMap = new DebugValueMap("Global");
for (DebugValueMap map : topLevelMaps) {
globalMap.addChild(map);
}
globalMap.group();
globalMap.normalize();
! LogStream log = getLogStream(options);
! printMap(options, log, new DebugValueScope(null, globalMap), sortedValues);
break;
}
case "Thread":
for (DebugValueMap map : topLevelMaps) {
TTY.println("Showing the results for thread: " + map.getName());
map.group();
map.normalize();
! LogStream log = getLogStream(options, map.getName().replace(' ', '_'));
! printMap(options, log, new DebugValueScope(null, map), sortedValues);
}
break;
default:
throw new GraalError("Unknown summary type: %s", summary);
}
*** 134,149 ****
--- 135,150 ----
mmPrinter.printMethodMetrics(MethodMetricsImpl.collectedMetrics());
}
TTY.println("</DebugValues>");
}
! private static LogStream getLogStream(OptionValues options) {
! return getLogStream(options, null);
}
! private static LogStream getLogStream(OptionValues options, String prefix) {
! String debugValueFile = DebugValueFile.getValue(options);
if (debugValueFile != null) {
try {
final String fileName;
if (prefix != null) {
fileName = prefix + '-' + debugValueFile;
*** 166,184 ****
--- 167,185 ----
flattenChildren(child, globalMap);
}
map.clearChildren();
}
! private void printSummary(OptionValues options, LogStream log, List<DebugValueMap> topLevelMaps, List<DebugValue> debugValues) {
DebugValueMap result = new DebugValueMap("Summary");
for (int i = debugValues.size() - 1; i >= 0; i--) {
DebugValue debugValue = debugValues.get(i);
int index = debugValue.getIndex();
long total = collectTotal(topLevelMaps, index);
result.setCurrentValue(index, total);
}
! printMap(options, log, new DebugValueScope(null, result), debugValues);
}
private long collectTotal(List<DebugValueMap> maps, int index) {
long total = 0;
for (int i = 0; i < maps.size(); i++) {
*** 226,274 ****
--- 227,275 ----
return sb.append(map.getName());
}
}
! private void printMap(OptionValues options, LogStream log, DebugValueScope scope, List<DebugValue> debugValues) {
! if (DebugValueHumanReadable.getValue(options)) {
! printMapHumanReadable(options, log, scope, debugValues);
} else {
! printMapComputerReadable(options, log, scope, debugValues);
}
}
! private void printMapComputerReadable(OptionValues options, LogStream log, DebugValueScope scope, List<DebugValue> debugValues) {
for (DebugValue value : debugValues) {
long l = scope.map.getCurrentValue(value.getIndex());
! if (l != 0 || !SuppressZeroDebugValues.getValue(options)) {
CSVUtil.Escape.println(log, COMPUTER_READABLE_FMT, scope.toRawString(), value.getName(), value.toRawString(l), value.rawUnit());
}
}
List<DebugValueMap> children = scope.map.getChildren();
for (int i = 0; i < children.size(); i++) {
DebugValueMap child = children.get(i);
! printMapComputerReadable(options, log, new DebugValueScope(scope, child), debugValues);
}
}
! private void printMapHumanReadable(OptionValues options, LogStream log, DebugValueScope scope, List<DebugValue> debugValues) {
for (DebugValue value : debugValues) {
long l = scope.map.getCurrentValue(value.getIndex());
! if (l != 0 || !SuppressZeroDebugValues.getValue(options)) {
scope.print(log);
printIndent(log, scope.level + 1);
log.println(value.getName() + "=" + value.toString(l));
}
}
List<DebugValueMap> children = scope.map.getChildren();
for (int i = 0; i < children.size(); i++) {
DebugValueMap child = children.get(i);
! printMapHumanReadable(options, log, new DebugValueScope(scope, child), debugValues);
}
}
private static void printIndent(LogStream log, int level) {
for (int i = 0; i < level; ++i) {
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/DebugValuesPrinter.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File