Skip to content
Permalink
Browse files
7272: Method profiling page should show the frame type
Reviewed-by: jpbempel, aptmac
  • Loading branch information
thegreystone committed Jun 18, 2021
1 parent a2995a1 commit 8bc1247251a1ececc9d24a2b42f427ce5377b281
@@ -55,6 +55,7 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.openjdk.jmc.common.IDisplayable;
import org.openjdk.jmc.common.IMCFrame;
import org.openjdk.jmc.common.IMCMethod;
import org.openjdk.jmc.common.item.IAccessorFactory;
import org.openjdk.jmc.common.item.IAggregator;
@@ -217,14 +218,22 @@ public void handleEvent(Event event) {
public <T> ItemHistogram build(
Composite container, String colLabel, ContentType<? super T> keyType, IAccessorFactory<T> classifier,
TableSettings tableSettings, int border) {
List<IColumn> columns = new ArrayList<>();
IMemberAccessor<?, Object> keyAccessor = AggregationGrid::getKey;
ColumnLabelProvider keyLp = null;
if (UnitLookup.METHOD.getIdentifier().equals(keyType.getIdentifier())) {
keyLp = new DelegatingLabelProvider(new MethodLabelProvider(), keyAccessor);
ColumnLabelProvider lp = null;
if (UnitLookup.METHOD.getIdentifier().equals(keyType.getIdentifier())
|| UnitLookup.STACKTRACE_FRAME.getIdentifier().equals(keyType.getIdentifier())) {
lp = new MethodLabelProvider();
} else {
keyLp = new DelegatingLabelProvider(new KeyLabelProvider(keyType), keyAccessor);
lp = new KeyLabelProvider(keyType);
}
return build(container, colLabel, keyType, classifier, tableSettings, border, lp);
}

public <T> ItemHistogram build(
Composite container, String colLabel, ContentType<? super T> keyType, IAccessorFactory<T> classifier,
TableSettings tableSettings, int border, ColumnLabelProvider labelProvider) {
List<IColumn> columns = new ArrayList<>();
IMemberAccessor<?, Object> keyAccessor = AggregationGrid::getKey;
ColumnLabelProvider keyLp = new DelegatingLabelProvider(labelProvider, keyAccessor);
columns.add(new ColumnBuilder(colLabel, KEY_COL_ID, keyAccessor).labelProvider(keyLp).build());
columns.addAll(this.columns);
return build(container, columns, classifier, tableSettings, border);
@@ -243,6 +252,18 @@ public void handleEvent(Event event) {
return new ItemHistogram(ColumnManager.build(tableViewer, columns, tableSettings), classifier, grid);
}

public <T> ItemHistogram buildWithoutBorder(
Composite container, String colLabel, ContentType<? super T> keyType, IAccessorFactory<T> classifier,
TableSettings tableSettings, ColumnLabelProvider labelProvider) {
return build(container, colLabel, keyType, classifier, tableSettings, SWT.NONE, labelProvider);
}

public <T> ItemHistogram buildWithoutBorder(
Composite container, IAttribute<T> classifier, TableSettings tableSettings,
ColumnLabelProvider labelProvider) {
return build(container, classifier.getName(), classifier.getContentType(), classifier, tableSettings,
SWT.NONE, labelProvider);
}
}

/**
@@ -379,8 +400,13 @@ public Font getFont(Object key) {

@Override
public Image getImage(Object key) {
IMCMethod method = null;
if (key instanceof IMCMethod) {
IMCMethod method = (IMCMethod) key;
method = (IMCMethod) key;
} else if (key instanceof IMCFrame) {
method = ((IMCFrame) key).getMethod();
}
if (method != null) {
if ((method.getModifier() & Modifier.PUBLIC) != 0) {
return publicMethodImage;
} else if ((method.getModifier() & Modifier.PROTECTED) != 0) {
@@ -395,6 +421,9 @@ public Image getImage(Object key) {

@Override
public String getText(Object key) {
if (key instanceof IMCFrame) {
key = ((IMCFrame) key).getMethod();
}
if (key instanceof IDisplayable) {
return ((IDisplayable) key).displayUsing(IDisplayable.EXACT);
}
@@ -357,6 +357,9 @@
public static String MemoryLeakPage_RELEVANCE_COLUMN_HEADER;
public static String MemoryLeakPage_STEPS_SKIPPED;
public static String MethodProfilingPage_CLASS_HISTOGRAM_SELECTION;
public static String MethodProfilingPage_METHOD_CONTENT_TYPE_DESCRIPTION;
public static String MethodProfilingPage_METHOD_DESCRIPTION;
public static String MethodProfilingPage_METHOD_TITLE;
public static String MethodProfilingPage_PACKAGE_HISTOGRAM_SELECTION;
public static String MethodProfilingPage_PAGE_NAME;
public static String MethodProfilingPage_PREDECESSORS_DESCRIPTION;
@@ -66,13 +66,17 @@
import org.openjdk.jmc.common.IState;
import org.openjdk.jmc.common.IWritableState;
import org.openjdk.jmc.common.item.Aggregators;
import org.openjdk.jmc.common.item.Attribute;
import org.openjdk.jmc.common.item.IAttribute;
import org.openjdk.jmc.common.item.IItem;
import org.openjdk.jmc.common.item.IItemCollection;
import org.openjdk.jmc.common.item.IItemFilter;
import org.openjdk.jmc.common.item.IItemIterable;
import org.openjdk.jmc.common.item.IMemberAccessor;
import org.openjdk.jmc.common.item.IType;
import org.openjdk.jmc.common.item.ItemFilters;
import org.openjdk.jmc.common.item.ItemToolkit;
import org.openjdk.jmc.common.unit.ContentType;
import org.openjdk.jmc.common.unit.IQuantity;
import org.openjdk.jmc.common.unit.IRange;
import org.openjdk.jmc.common.unit.UnitLookup;
@@ -108,6 +112,8 @@
import org.openjdk.jmc.flightrecorder.ui.common.ItemHistogram;
import org.openjdk.jmc.flightrecorder.ui.common.ItemHistogram.ItemHistogramBuilder;
import org.openjdk.jmc.flightrecorder.ui.messages.internal.Messages;
import org.openjdk.jmc.flightrecorder.ui.pages.internal.MethodWithFrameType;
import org.openjdk.jmc.flightrecorder.ui.pages.internal.MethodWithFrameTypeLabelProvider;
import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStoreActionToolkit;
import org.openjdk.jmc.ui.column.ColumnManager.SelectionState;
import org.openjdk.jmc.ui.column.ColumnMenusFactory;
@@ -128,6 +134,23 @@
private static final Color SIBLINGS_COUNT_COLOR = SWTColorToolkit.getColor(new RGB(170, 250, 170));
private static final Color COUNT_COLOR = SWTColorToolkit.getColor(new RGB(100, 200, 100));

// Same as STACK_TRACE_TOP_METHOD but includes information about the frame type for the sample (and will distinguish methods on this)
private static final IAttribute<MethodWithFrameType> STACK_TRACE_TOP_METHOD_WITH_FRAME_TYPE = new Attribute<MethodWithFrameType>(
"(stackTrace).topMethodOptimization", Messages.MethodProfilingPage_METHOD_TITLE, //$NON-NLS-1$
Messages.MethodProfilingPage_METHOD_DESCRIPTION, new ContentType<MethodWithFrameType>("methodwithframetype", //$NON-NLS-1$
Messages.MethodProfilingPage_METHOD_CONTENT_TYPE_DESCRIPTION)) {
@Override
public <U> IMemberAccessor<MethodWithFrameType, U> customAccessor(IType<U> type) {
final IMemberAccessor<IMCFrame, U> accessor = JdkAttributes.STACK_TRACE_TOP_FRAME.getAccessor(type);
return accessor == null ? null : new IMemberAccessor<MethodWithFrameType, U>() {
@Override
public MethodWithFrameType getMember(U i) {
IMCFrame frame = accessor.getMember(i);
return frame == null ? null : new MethodWithFrameType(frame.getMethod(), frame.getType());
}
};
}
};
private static final Listener PERCENTAGE_BACKGROUND_DRAWER = new Listener() {
@Override
public void handleEvent(Event event) {
@@ -228,8 +251,8 @@ public IDisplayablePage createPage(IPageDefinition dpd, StreamModel items, IPage
sash = new SashForm(form.getBody(), SWT.VERTICAL);
toolkit.adapt(sash);

table = HOT_METHODS_HISTOGRAM.buildWithoutBorder(sash, JdkAttributes.STACK_TRACE_TOP_METHOD,
getTableSettings(state.getChild(TABLE_ELEMENT)));
table = HOT_METHODS_HISTOGRAM.buildWithoutBorder(sash, STACK_TRACE_TOP_METHOD_WITH_FRAME_TYPE,
getTableSettings(state.getChild(TABLE_ELEMENT)), new MethodWithFrameTypeLabelProvider());
MCContextMenuManager mm = MCContextMenuManager.create(table.getManager().getViewer().getControl());
ColumnMenusFactory.addDefaultMenus(table.getManager(), mm);
SelectionStoreActionToolkit.addSelectionStoreActions(pageContainer.getSelectionStore(), table,
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 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.ui.pages.internal;

import org.openjdk.jmc.common.IMCFrame;
import org.openjdk.jmc.common.IMCMethod;

/**
* Simple wrapper type that captures an {@link IMCMethod} and the {@link Type} it had for the
* sample.
*/
public class MethodWithFrameType {
private final IMCMethod method;
private final IMCFrame.Type frameType;

public MethodWithFrameType(IMCMethod method, IMCFrame.Type frameType) {
this.method = method;
this.frameType = frameType;
}

public IMCMethod getMethod() {
return method;
}

public IMCFrame.Type getFrameType() {
return frameType;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((frameType == null) ? 0 : frameType.hashCode());
result = prime * result + ((method == null) ? 0 : method.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
MethodWithFrameType other = (MethodWithFrameType) obj;
if (frameType != other.frameType)
return false;
if (method == null) {
if (other.method != null)
return false;
} else if (!method.equals(other.method))
return false;
return true;
}
}

0 comments on commit 8bc1247

Please sign in to comment.