Skip to content

Commit

Permalink
[GR-22552] Added Dashboard dumper.
Browse files Browse the repository at this point in the history
PullRequest: graal/5982
Ondrej-Douda committed Apr 23, 2020
2 parents 0ee434c + 66eef11 commit 2706967
Showing 6 changed files with 1,033 additions and 1 deletion.
9 changes: 8 additions & 1 deletion substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
@@ -61,7 +61,13 @@
"version" : "2.6.2-jaxb-1.0.6",
},
},

"GSON_SHADOWED": {
"sha1": "b304ee4a635a313ea49552d8afe8bc5218752d64",
"sourceSha1": "47c5969e5a9c4b3d0abb4ca8d80b43acf8f18b5f",
"urlbase": "https://lafo.ssw.uni-linz.ac.at/pub/graal-external-deps",
"urls": ["{urlbase}/gson-shadowed-2.8.5.jar"],
"sourceUrls": ["{urlbase}/gson-shadowed-2.8.5-sources.jar"],
},
"LLVM_WRAPPER_SHADOWED": {
"sha1" : "f2d365a8d432d6b2127acda19c5d3418126db9b0",
"sourceSha1" : "0801daf22b189bbd9d515614a2b79c92af225d56",
@@ -324,6 +330,7 @@
"sourceDirs": ["src"],
"dependencies": [
"com.oracle.svm.util",
"GSON_SHADOWED",
],
"checkstyle": "com.oracle.graal.pointsto",
"javaCompliance": "8+",
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.hosted.dashboard;

import com.oracle.shadowed.com.google.gson.JsonArray;
import com.oracle.svm.hosted.FeatureImpl;
import com.oracle.svm.hosted.code.CompileQueue;
import com.oracle.svm.hosted.meta.HostedMethod;
import org.graalvm.nativeimage.hosted.Feature;

import com.oracle.shadowed.com.google.gson.JsonObject;

import java.util.Collection;

class CodeBreakdownDumper {

JsonObject dump(Feature.AfterCompilationAccess access) {
FeatureImpl.AfterCompilationAccessImpl config = (FeatureImpl.AfterCompilationAccessImpl) access;
final Collection<CompileQueue.CompileTask> compilationTasks = config.getCompilationTasks();
JsonArray methodInfos = new JsonArray(compilationTasks.size());
for (CompileQueue.CompileTask task : compilationTasks) {
JsonObject methodInfo = new JsonObject();
final HostedMethod method = task.method;
final int targetSize = task.result.getTargetCodeSize();
methodInfo.addProperty("name", method.format("%H.%n(%p) %r"));
methodInfo.addProperty("size", targetSize);
methodInfos.add(methodInfo);
}
final JsonObject breakdown = new JsonObject();
breakdown.add("code-size", methodInfos);
return breakdown;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.hosted.dashboard;

import com.oracle.graal.pointsto.reports.ReportUtils;
import com.oracle.shadowed.com.google.gson.Gson;
import com.oracle.shadowed.com.google.gson.GsonBuilder;
import com.oracle.shadowed.com.google.gson.JsonObject;
import org.graalvm.nativeimage.hosted.Feature;

import com.oracle.svm.core.annotate.AutomaticFeature;

import java.io.File;

@AutomaticFeature
public class DashboardDumpFeature implements Feature {
private static boolean isHeapBreakdownDumped() {
return DashboardOptions.DashboardAll.getValue() || DashboardOptions.DashboardHeap.getValue();
}

private static boolean isPointsToDumped() {
return DashboardOptions.DashboardAll.getValue() || DashboardOptions.DashboardPointsTo.getValue();
}

private static boolean isCodeBreakdownDumped() {
return DashboardOptions.DashboardAll.getValue() || DashboardOptions.DashboardCode.getValue();
}

private static void dumpToFile(String dumpContent, String dumpPath) {
final File file = new File(dumpPath).getAbsoluteFile();
ReportUtils.report("Dashboard dump output", file.toPath(), writer -> writer.write(dumpContent));
}

private final JsonObject dumpRoot;

public DashboardDumpFeature() {
dumpRoot = new JsonObject();
}

@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
return DashboardOptions.DashboardDump.getValue() != null;
}

@Override
public void onAnalysisExit(OnAnalysisExitAccess access) {
if (isPointsToDumped()) {
final PointsToDumper pointsToDumper = new PointsToDumper();
final JsonObject pointsTo = pointsToDumper.dump(access);
dumpRoot.add("points-to", pointsTo);
}
}

@Override
public void afterCompilation(AfterCompilationAccess access) {
if (isCodeBreakdownDumped()) {
final CodeBreakdownDumper codeBreakdownDumper = new CodeBreakdownDumper();
final JsonObject breakdown = codeBreakdownDumper.dump(access);
dumpRoot.add("code-breakdown", breakdown);
}
}

@Override
public void afterHeapLayout(AfterHeapLayoutAccess access) {
if (isHeapBreakdownDumped()) {
final HeapBreakdownDumper heapBreakdownDumper = new HeapBreakdownDumper();
final JsonObject breakdown = heapBreakdownDumper.dump(access);
dumpRoot.add("heap-breakdown", breakdown);
}
}

@Override
public void cleanup() {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
final String dump = gson.toJson(dumpRoot);
dumpToFile(dump, DashboardOptions.DashboardDump.getValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.hosted.dashboard;

import com.oracle.svm.core.option.HostedOptionKey;
import org.graalvm.compiler.options.Option;
import org.graalvm.compiler.options.OptionType;

class DashboardOptions {
@Option(help = "Enable dashboard dumps to the specified file.", type = OptionType.Expert)//
static final HostedOptionKey<String> DashboardDump = new HostedOptionKey<>(null);

@Option(help = "In the dashboard dump, include all available information about the native image (this takes precedence over more specific flags).", type = OptionType.Expert)//
static final HostedOptionKey<Boolean> DashboardAll = new HostedOptionKey<>(false);

@Option(help = "In the dashboard dump, include the breakdown of the object sizes in the heap across different classes.", type = OptionType.Expert)//
static final HostedOptionKey<Boolean> DashboardHeap = new HostedOptionKey<>(false);

@Option(help = "In the dashboard dump, include the breakdown of the code size across different packages.", type = OptionType.Expert)//
static final HostedOptionKey<Boolean> DashboardCode = new HostedOptionKey<>(false);

@Option(help = "In the dashboard dump, include the information about the points-to analysis.", type = OptionType.Expert)//
static final HostedOptionKey<Boolean> DashboardPointsTo = new HostedOptionKey<>(false);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.hosted.dashboard;

import java.util.HashMap;
import java.util.Map;

import org.graalvm.nativeimage.hosted.Feature;

import com.oracle.shadowed.com.google.gson.JsonArray;
import com.oracle.shadowed.com.google.gson.JsonObject;
import com.oracle.shadowed.com.google.gson.JsonPrimitive;
import com.oracle.svm.hosted.FeatureImpl;
import com.oracle.svm.hosted.image.NativeImageHeap;

class HeapBreakdownDumper {
private class Statistics {
long size = 0;
long count = 0;
}

JsonObject dump(Feature.AfterHeapLayoutAccess access) {
// Create the size histogram.
FeatureImpl.AfterHeapLayoutAccessImpl config = (FeatureImpl.AfterHeapLayoutAccessImpl) access;
NativeImageHeap heap = config.getHeap();
final HashMap<String, Statistics> sizes = new HashMap<>();
for (NativeImageHeap.ObjectInfo info : heap.getObjects()) {
final String className = info.getClazz().getName();
Statistics stats = sizes.get(className);
if (stats == null) {
stats = new Statistics();
sizes.put(className, stats);
}
stats.size += info.getSize();
stats.count += 1;
}

// Create JSON data.
JsonArray classInfos = new JsonArray();
for (Map.Entry<String, Statistics> entry : sizes.entrySet()) {
final String className = entry.getKey();
final Statistics stats = entry.getValue();
JsonObject classInfo = new JsonObject();
classInfo.add("name", new JsonPrimitive(className));
classInfo.add("size", new JsonPrimitive(stats.size));
classInfo.add("count", new JsonPrimitive(stats.count));
classInfos.add(classInfo);
}
JsonObject root = new JsonObject();
root.add("heap-size", classInfos);
return root;
}
}

Large diffs are not rendered by default.

0 comments on commit 2706967

Please sign in to comment.