Skip to content

Commit

Permalink
6670: Harmonize ~ Unclassifiable ~ across Flame View and Stacktrace View
Browse files Browse the repository at this point in the history
Reviewed-by: hirt
  • Loading branch information
mirage22 authored and thegreystone committed Jan 24, 2020
1 parent 2dd271f commit 875abcd
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.openjdk.jmc.common.item.IItemCollection;
import org.openjdk.jmc.common.util.FormatToolkit;
import org.openjdk.jmc.flightrecorder.stacktrace.FrameSeparator;
import org.openjdk.jmc.flightrecorder.stacktrace.Messages;
import org.openjdk.jmc.flightrecorder.stacktrace.StacktraceModel;
import org.openjdk.jmc.flightrecorder.stacktrace.StacktraceModel.Branch;
import org.openjdk.jmc.flightrecorder.stacktrace.StacktraceModel.Fork;
Expand All @@ -58,8 +59,7 @@ public class TraceTreeUtils {
*/
public static TraceNode createTree(StacktraceModel model, String rootName) {
Fork rootFork = model.getRootFork();
TraceNode root = new TraceNode(rootName == null ? DEFAULT_ROOT_NAME : rootName, rootFork.getItemsInFork(),
DEFAULT_ROOT_PACKAGE_NAME);
TraceNode root = getRootTraceNode(rootName, rootFork);
for (Branch branch : rootFork.getBranches()) {
addBranch(root, branch);
}
Expand All @@ -80,11 +80,10 @@ public static TraceNode createTree(

private static void addBranch(TraceNode root, Branch branch) {
StacktraceFrame firstFrame = branch.getFirstFrame();
TraceNode currentNode = new TraceNode(format(firstFrame), firstFrame.getItemCount(),
formatPackageName(firstFrame));
TraceNode currentNode = getTraceNodeByStacktraceFrame(firstFrame);
root.addChild(currentNode);
for (StacktraceFrame frame : branch.getTailFrames()) {
TraceNode newNode = new TraceNode(format(frame), frame.getItemCount(), formatPackageName(frame));
TraceNode newNode = getTraceNodeByStacktraceFrame(frame);
currentNode.addChild(newNode);
currentNode = newNode;
}
Expand All @@ -97,18 +96,6 @@ private static void addFork(TraceNode node, Fork fork) {
}
}

private static String format(StacktraceFrame sFrame) {
IMCFrame frame = sFrame.getFrame();
IMCMethod method = frame.getMethod();
return FormatToolkit.getHumanReadable(method, false, false, true, false, true, false);
}

private static String formatPackageName(StacktraceFrame sFrame) {
IMCFrame frame = sFrame.getFrame();
IMCMethod method = frame.getMethod();
return FormatToolkit.getPackage(method.getType().getPackage());
}

public static String printTree(TraceNode node) {
StringBuilder builder = new StringBuilder();
builder.append("=== Tree Printout ===");
Expand All @@ -131,4 +118,22 @@ private static String indent(int indentation) {
}
return builder.toString();
}

private static TraceNode getRootTraceNode(String rootName, Fork rootFork) {
return new TraceNode(rootName == null ? DEFAULT_ROOT_NAME : rootName, rootFork.getItemsInFork(),
DEFAULT_ROOT_PACKAGE_NAME);
}

private static TraceNode getTraceNodeByStacktraceFrame(StacktraceFrame sFrame) {
IMCFrame frame = sFrame.getFrame();
IMCMethod method = frame.getMethod();
String packageName = FormatToolkit.getPackage(method.getType().getPackage());
if (frame == StacktraceModel.UNKNOWN_FRAME) {
return new TraceNode(Messages.getString(Messages.STACKTRACE_UNCLASSIFIABLE_FRAME), sFrame.getItemCount(),
packageName);
} else {
String name = FormatToolkit.getHumanReadable(method, false, false, true, false, true, false);
return new TraceNode(name, sFrame.getItemCount(), packageName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
*/
package org.openjdk.jmc.flightrecorder.flameview.views;

import static org.openjdk.jmc.flightrecorder.stacktrace.Messages.STACKTRACE_UNCLASSIFIABLE_FRAME;
import static org.openjdk.jmc.flightrecorder.stacktrace.Messages.STACKTRACE_UNCLASSIFIABLE_FRAME_DESC;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.concurrent.CancellationException;
Expand Down Expand Up @@ -78,6 +81,8 @@
import org.openjdk.jmc.ui.misc.DisplayToolkit;

public class FlameGraphView extends ViewPart implements ISelectionListener {
private static final String UNCLASSIFIABLE_FRAME = getStacktraceMessage(STACKTRACE_UNCLASSIFIABLE_FRAME);
private static final String UNCLASSIFIABLE_FRAME_DESC = getStacktraceMessage(STACKTRACE_UNCLASSIFIABLE_FRAME_DESC);
private static final String HTML_PAGE;
static {
// from: https://cdn.jsdelivr.net/gh/spiermar/d3-flame-graph@2.0.3/dist/d3-flamegraph.css
Expand Down Expand Up @@ -253,8 +258,8 @@ private static String render(TraceNode root) {
}

private static void render(StringBuilder builder, TraceNode node) {
String start = String.format("{%s,%s,%s, \"c\": [ ", toJSonKeyValue("n", node.getName()),
toJSonKeyValue("p", node.getPackageName()), toJSonKeyValue("v", String.valueOf(node.getValue())));
String start = UNCLASSIFIABLE_FRAME.equals(node.getName()) ? createJsonDescTraceNode(node)
: createJsonTraceNode(node);
builder.append(start);
for (int i = 0; i < node.getChildren().size(); i++) {
render(builder, node.getChildren().get(i));
Expand All @@ -265,6 +270,17 @@ private static void render(StringBuilder builder, TraceNode node) {
builder.append("]}");
}

private static String createJsonTraceNode(TraceNode node) {
return String.format("{%s,%s,%s, \"c\": [ ", toJSonKeyValue("n", node.getName()),
toJSonKeyValue("p", node.getPackageName()), toJSonKeyValue("v", String.valueOf(node.getValue())));
}

private static String createJsonDescTraceNode(TraceNode node) {
return String.format("{%s,%s,%s,%s, \"c\": [ ", toJSonKeyValue("n", node.getName()),
toJSonKeyValue("p", node.getPackageName()), toJSonKeyValue("d", UNCLASSIFIABLE_FRAME_DESC),
toJSonKeyValue("v", String.valueOf(node.getValue())));
}

private static String toJSonKeyValue(String key, String value) {
return "\"" + key + "\": " + "\"" + value + "\"";
}
Expand All @@ -286,4 +302,8 @@ private static String fileContent(String fileName) {
return "";
}
}

private static String getStacktraceMessage(String key) {
return org.openjdk.jmc.flightrecorder.stacktrace.Messages.getString(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ String.prototype.hashCode = function () {
return hash;
};

const htmlTagBr = "\u003Cbr\u002F\u003E";
const rootPackageColor = "darkred";
const invalidPackageColor = "snow";
const packageJavaColorLightGray = "lightgray";
Expand Down Expand Up @@ -120,5 +121,12 @@ const colorCell = function (d) {
};

const adjustTip = function (d) {
return d.data.n + "\u003Cbr\u002F\u003Epackage: " + d.data.p + "\u003Cbr\u002F\u003Esamples: " + d.data.v;
var tipMessage = d.data.n + htmlTagBr;
if( d.data.d === undefined) {
tipMessage += "package: " + d.data.p + htmlTagBr;
} else {
tipMessage += "description: " + d.data.d + htmlTagBr;
}
tipMessage += "samples: " + d.data.v;
return tipMessage;
};
1 change: 1 addition & 0 deletions core/org.openjdk.jmc.flightrecorder/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Export-Package: org.openjdk.jmc.flightrecorder,
org.openjdk.jmc.flightrecorder.parser,
org.openjdk.jmc.flightrecorder.parser.filter,
org.openjdk.jmc.flightrecorder.stacktrace,
org.openjdk.jmc.flightrecorder.stacktrace.messages.internal,
org.openjdk.jmc.flightrecorder.util
Require-Bundle: org.openjdk.jmc.common;visibility:=reexport
Eclipse-BuddyPolicy: app
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, Datadog, Inc. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The contents of this file are subject to the terms of either the Universal Permissive License
* v 1.0 as shown at http://oss.oracle.com/licenses/upl
*
* or the following license:
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.openjdk.jmc.flightrecorder.stacktrace;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class Messages {
private static final String BUNDLE_NAME = "org.openjdk.jmc.flightrecorder.stacktrace.messages"; //$NON-NLS-1$

private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

public static final String STACKTRACE_UNCLASSIFIABLE_FRAME = "STACKTRACE_UNCLASSIFIABLE_FRAME"; //$NON-NLS-1$
public static final String STACKTRACE_UNCLASSIFIABLE_FRAME_DESC = "STACKTRACE_UNCLASSIFIABLE_FRAME_DESC"; //$NON-NLS-1$

private Messages() {
}

public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import org.openjdk.jmc.common.IMCFrame;
import org.openjdk.jmc.common.util.FormatToolkit;
import org.openjdk.jmc.flightrecorder.stacktrace.messages.internal.Messages;

/**
* Toolkit for presenting stack traces and stack frames in textual form.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class Messages {
public static final String STACKTRACE_LINE_NUMBER = "STACKTRACE_LINE_NUMBER"; //$NON-NLS-1$
public static final String STACKTRACE_METHOD = "STACKTRACE_METHOD"; //$NON-NLS-1$
public static final String STACKTRACE_PACKAGE = "STACKTRACE_PACKAGE"; //$NON-NLS-1$
public static final String STACKTRACE_UNCLASSIFIABLE_FRAME = "STACKTRACE_UNCLASSIFIABLE_FRAME"; //$NON-NLS-1$

private Messages() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2020, Datadog, Inc. All rights reserved.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The contents of this file are subject to the terms of either the Universal Permissive License
# v 1.0 as shown at http://oss.oracle.com/licenses/upl
#
# or the following license:
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided with
# the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
# endorse or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
STACKTRACE_UNCLASSIFIABLE_FRAME=~ UNCLASSIFIABLE ~
STACKTRACE_UNCLASSIFIABLE_FRAME_DESC=Unclassified means the stacktrace reached the stackdepth limit
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ STACKTRACE_CLASS=Class
STACKTRACE_LINE_NUMBER=Line Number
STACKTRACE_METHOD=Method
STACKTRACE_PACKAGE=Package
STACKTRACE_UNCLASSIFIABLE_FRAME=~ UNCLASSIFIABLE ~
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ STACKTRACE_CLASS=\u30AF\u30E9\u30B9
STACKTRACE_LINE_NUMBER=\u884C\u756A\u53F7
STACKTRACE_METHOD=\u30E1\u30BD\u30C3\u30C9
STACKTRACE_PACKAGE=\u30D1\u30C3\u30B1\u30FC\u30B8
STACKTRACE_UNCLASSIFIABLE_FRAME=~ UNCLASSIFIABLE ~
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ STACKTRACE_CLASS=\u7C7B
STACKTRACE_LINE_NUMBER=\u884C\u53F7
STACKTRACE_METHOD=\u65B9\u6CD5
STACKTRACE_PACKAGE=\u5305
STACKTRACE_UNCLASSIFIABLE_FRAME=~ UNCLASSIFIABLE ~
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2020, Datadog, Inc. All rights reserved.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The contents of this file are subject to the terms of either the Universal Permissive License
# v 1.0 as shown at http://oss.oracle.com/licenses/upl
#
# or the following license:
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided with
# the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
# endorse or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
STACKTRACE_UNCLASSIFIABLE_FRAME=~ UNCLASSIFIABLE ~
STACKTRACE_UNCLASSIFIABLE_FRAME_DESC=Unclassified means the stacktrace reached the stackdepth limit
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2020, Datadog, Inc. All rights reserved.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The contents of this file are subject to the terms of either the Universal Permissive License
# v 1.0 as shown at http://oss.oracle.com/licenses/upl
#
# or the following license:
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided with
# the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
# endorse or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
STACKTRACE_UNCLASSIFIABLE_FRAME=~ UNCLASSIFIABLE ~
STACKTRACE_UNCLASSIFIABLE_FRAME_DESC=Unclassified means the stacktrace reached the stackdepth limit

0 comments on commit 875abcd

Please sign in to comment.