Skip to content

Commit

Permalink
7031: Build a constant pool explorer page
Browse files Browse the repository at this point in the history
Reviewed-by: hirt, hdafgard
  • Loading branch information
jpbempel authored and thegreystone committed Apr 6, 2021
1 parent b46be35 commit f25df12
Show file tree
Hide file tree
Showing 20 changed files with 522 additions and 15 deletions.
18 changes: 17 additions & 1 deletion application/org.openjdk.jmc.flightrecorder.ui/defaultPages.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
Expand Down Expand Up @@ -985,6 +985,22 @@
</eventSettings>
<eventSettingsFilter showFilter="false" showSearch="true" />
</state>
<page factory="org.openjdk.jmc.flightrecorder.ui.constantpools" id="org.openjdk.jmc.flightrecorder.ui.constantpools">
<state>
<table sortColumn="count">
<column id="itemhistogram.key" width="420" />
<column id="count" hidden="false" sortAscending="false" width="100" />
<column id="size" hidden="false" width="100" />
<column id="percentPools" width="100" />
</table>
<constantTable>
<column id="itemhistogram.key" width="420" />
<column id="itemhistogram.count" hidden="true" width="100" sortAscending="false" />
</constantTable>
<typeFilter showFilter="false" showSearch="true" />
<valueFilter showFilter="false" showSearch="true" />
</state>
</page>
</page>
</page>
<page factory="org.openjdk.jmc.flightrecorder.ui.eventbrowser" id="org.openjdk.jmc.flightrecorder.ui.eventbrowser">
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion application/org.openjdk.jmc.flightrecorder.ui/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
Expand Down Expand Up @@ -306,6 +306,10 @@
class="org.openjdk.jmc.flightrecorder.ui.pages.RecordingPage$RecordingPageFactory"
id="org.openjdk.jmc.flightrecorder.ui.recording">
</factory>
<factory
class="org.openjdk.jmc.flightrecorder.ui.pages.ConstantPoolsPage$ConstantPoolsPageFactory"
id="org.openjdk.jmc.flightrecorder.ui.constantpools">
</factory>
<factory
class="org.openjdk.jmc.flightrecorder.ui.pages.EventBrowserPage$Factory"
id="org.openjdk.jmc.flightrecorder.ui.eventbrowser">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -62,10 +62,22 @@ public class StreamModel {

private final EventArray[] eventsByType;
private final Set<IRange<IQuantity>> chunkRanges;
private final IItemCollection constantPools;
private final IItemCollection constants;

StreamModel(EventArrays eventsByType) {
this.eventsByType = eventsByType.getArrays();
this.chunkRanges = eventsByType.getChunkTimeranges();
this.constantPools = eventsByType.getConstantPools();
this.constants = eventsByType.getConstants();
}

public IItemCollection getConstantPools() {
return constantPools;
}

public IItemCollection getConstants() {
return constants;
}

public IItemCollection getItems(IRange<IQuantity> range, IItemFilter filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class ImageConstants {

public static final String ICON_MAGNIFIER = "magnifier.png"; //$NON-NLS-1$

public static final String PAGE_CONSTANT_POOL = "pages/cpool.png"; //$NON-NLS-1$
public static final String PAGE_JAVA_APPLICATION = "pages/methodprofiling.png"; //$NON-NLS-1$
public static final String PAGE_METHOD = "pages/method.png"; //$NON-NLS-1$
public static final String PAGE_HEAP = "pages/objectstatistics.png"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -99,6 +99,9 @@ public class Messages extends NLS {
public static String CompilationsPage_ROW_DURATIONS;
public static String CompilationsPage_TAB_COMPILATIONS;
public static String CompilationsPage_TAB_COMPILATIONS_FAILED;
public static String ConstantPoolsPage_PAGE_NAME;
public static String ConstantPoolsPage_SIZE_TOTAL_PERCENTAGE;
public static String ConstantPoolsPage_SIZE_TOTAL_PERCENTAGE_DESC;
public static String DropdownLaneFilter_QUICK_FILTER;
public static String DropdownLaneFilter_THREAD_STATE_SELECTION;
public static String DUMP_RECORDING_DEFAULT_TIMESPAN_TO_DUMP;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/*
* 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;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
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.IItemCollection;
import org.openjdk.jmc.common.item.IItemFilter;
import org.openjdk.jmc.common.item.ItemFilters;
import org.openjdk.jmc.common.item.ItemToolkit;
import org.openjdk.jmc.flightrecorder.jdk.JdkAttributes;
import org.openjdk.jmc.flightrecorder.rules.util.JfrRuleTopics;
import org.openjdk.jmc.flightrecorder.ui.FlightRecorderUI;
import org.openjdk.jmc.flightrecorder.ui.IDataPageFactory;
import org.openjdk.jmc.flightrecorder.ui.IDisplayablePage;
import org.openjdk.jmc.flightrecorder.ui.IPageContainer;
import org.openjdk.jmc.flightrecorder.ui.IPageDefinition;
import org.openjdk.jmc.flightrecorder.ui.IPageUI;
import org.openjdk.jmc.flightrecorder.ui.StreamModel;
import org.openjdk.jmc.flightrecorder.ui.common.AbstractDataPage;
import org.openjdk.jmc.flightrecorder.ui.common.DataPageToolkit;
import org.openjdk.jmc.flightrecorder.ui.common.FilterComponent;
import org.openjdk.jmc.flightrecorder.ui.common.ImageConstants;
import org.openjdk.jmc.flightrecorder.ui.common.ItemHistogram;
import org.openjdk.jmc.flightrecorder.ui.common.ItemHistogramWithInput;
import org.openjdk.jmc.flightrecorder.ui.common.ItemHistogram.ItemHistogramBuilder;
import org.openjdk.jmc.flightrecorder.ui.messages.internal.Messages;
import org.openjdk.jmc.ui.column.ColumnMenusFactory;
import org.openjdk.jmc.ui.column.TableSettings;
import org.openjdk.jmc.ui.handlers.MCContextMenuManager;
import org.openjdk.jmc.ui.misc.PersistableSashForm;

public class ConstantPoolsPage extends AbstractDataPage {
public static class ConstantPoolsPageFactory implements IDataPageFactory {

@Override
public String getName(IState state) {
return Messages.ConstantPoolsPage_PAGE_NAME;
}

@Override
public ImageDescriptor getImageDescriptor(IState state) {
return FlightRecorderUI.getDefault().getMCImageDescriptor(ImageConstants.PAGE_CONSTANT_POOL);
}

@Override
public String[] getTopics(IState state) {
return new String[] {JfrRuleTopics.RECORDING};
}

@Override
public IDisplayablePage createPage(IPageDefinition dpd, StreamModel items, IPageContainer editor) {
return new ConstantPoolsPage(dpd, items, editor);
}
}

private static final String TABLE = "table"; //$NON-NLS-1$
private static final String CONSTANT_TABLE = "constantTable"; //$NON-NLS-1$
private static final String TYPE_FILTER = "typeFilter"; //$NON-NLS-1$
private static final String PERCENT_POOLS = "percentPools"; //$NON-NLS-1$
private static final String VALUE_FILTER = "valueFilter"; //$NON-NLS-1$

private static final ItemHistogramBuilder BY_TYPE_CONSTANT_POOLS_HISTOGRAM = new ItemHistogramBuilder();
private static final ItemHistogramBuilder CONSTANT_HISTOGRAM = new ItemHistogramBuilder();
static {
BY_TYPE_CONSTANT_POOLS_HISTOGRAM.addColumn(JdkAttributes.CONSTANT_POOLS_COUNT);
BY_TYPE_CONSTANT_POOLS_HISTOGRAM.addColumn(JdkAttributes.CONSTANT_POOLS_SIZE);
BY_TYPE_CONSTANT_POOLS_HISTOGRAM.addPercentageColumn(PERCENT_POOLS,
Aggregators.sum(JdkAttributes.CONSTANT_POOLS_SIZE), Messages.ConstantPoolsPage_SIZE_TOTAL_PERCENTAGE,
Messages.ConstantPoolsPage_SIZE_TOTAL_PERCENTAGE_DESC);
CONSTANT_HISTOGRAM.addCountColumn();
}

private class ConstantPoolsPageUi implements IPageUI {
private static final String SASH_ELEMENT = "sash"; //$NON-NLS-1$

private final IItemCollection constPoolItems;
private final SashForm sash;
private final ItemHistogram byTypeTable;
private final ItemHistogram constantValueTable;
private FilterComponent byTypeFilter;
private FilterComponent constantValueFilter;
private IItemCollection selectionConstPoolItems;
private IItemCollection selectionConstantItems;
private ItemHistogramWithInput byTypeHistogram;
private ItemHistogramWithInput constantHistogram;

ConstantPoolsPageUi(Composite parent, FormToolkit toolkit, IPageContainer pageContainer, IState state) {
constPoolItems = getDataSource().getConstantPools();
selectionConstPoolItems = constPoolItems;
selectionConstantItems = getDataSource().getConstants();
Form form = DataPageToolkit.createForm(parent, toolkit, getName(), getIcon());
sash = new SashForm(form.getBody(), SWT.VERTICAL);
toolkit.adapt(sash);
byTypeTable = BY_TYPE_CONSTANT_POOLS_HISTOGRAM.buildWithoutBorder(sash, JdkAttributes.CONSTANT_POOLS_NAME,
new TableSettings(state.getChild(TABLE)));
MCContextMenuManager mm = MCContextMenuManager.create(byTypeTable.getManager().getViewer().getControl());
ColumnMenusFactory.addDefaultMenus(byTypeTable.getManager(), mm);
byTypeFilter = FilterComponent.createFilterComponent(byTypeTable, null, constPoolItems,
pageContainer.getSelectionStore()::getSelections, this::onTypeFilterChange);
//mm.add(byTypeFilter.getShowFilterAction());
mm.add(byTypeFilter.getShowSearchAction());

constantValueTable = CONSTANT_HISTOGRAM.buildWithoutBorder(sash, JdkAttributes.CONSTANT_VALUE,
new TableSettings(state.getChild(CONSTANT_TABLE)));
mm = MCContextMenuManager.create(constantValueTable.getManager().getViewer().getControl());
ColumnMenusFactory.addDefaultMenus(constantValueTable.getManager(), mm);
constantValueFilter = FilterComponent.createFilterComponent(constantValueTable, null,
getDataSource().getConstants(), pageContainer.getSelectionStore()::getSelections,
this::onValueFilterChange);
//mm.add(constantValueFilter.getShowFilterAction());
mm.add(constantValueFilter.getShowSearchAction());

// chains the 2 tables
byTypeHistogram = new ItemHistogramWithInput(byTypeTable);
constantHistogram = new ItemHistogramWithInput(constantValueTable);
byTypeHistogram.addListener(this::typeHistogramListener);

PersistableSashForm.loadState(sash, state.getChild(SASH_ELEMENT));
byTypeFilter.loadState(state.getChild(TYPE_FILTER));
constantValueFilter.loadState(state.getChild(VALUE_FILTER));
}

private void typeHistogramListener(IItemCollection constantPoolType) {
String poolName = ItemToolkit.getFirstFound(constantPoolType, JdkAttributes.CONSTANT_POOLS_NAME);
IItemCollection filteredItems = getDataSource().getConstants()
.apply(ItemFilters.equals(JdkAttributes.CONSTANT_TYPE, poolName));
constantHistogram.setInput(filteredItems);
}

private void onTypeFilterChange(IItemFilter filter) {
byTypeFilter.filterChangeHelper(filter, byTypeTable, selectionConstPoolItems);
}

private void onValueFilterChange(IItemFilter filter) {
constantValueFilter.filterChangeHelper(filter, constantValueTable, selectionConstantItems);
}

@Override
public void saveTo(IWritableState writableState) {
PersistableSashForm.saveState(sash, writableState.createChild(SASH_ELEMENT));
byTypeTable.getManager().getSettings().saveState(writableState.createChild(TABLE));
byTypeFilter.saveState(writableState.createChild(TYPE_FILTER));
constantValueTable.getManager().getSettings().saveState(writableState.createChild(CONSTANT_TABLE));
constantValueFilter.saveState(writableState.createChild(VALUE_FILTER));
}
}

public ConstantPoolsPage(IPageDefinition dpd, StreamModel items, IPageContainer editor) {
super(dpd, items, editor);
}

@Override
public IPageUI display(Composite parent, FormToolkit toolkit, IPageContainer pageContainer, IState state) {
return new ConstantPoolsPageUi(parent, toolkit, pageContainer, state);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
Expand Down Expand Up @@ -102,6 +102,9 @@ CompilationsPage_ROW_DURATIONS=Compilation Durations
CompilationsPage_TAB_COMPILATIONS=Compilations
CompilationsPage_TAB_COMPILATIONS_FAILED=Failed Compilations
CONFIGURATION_EDIT_ACTION=Edit Configuration
ConstantPoolsPage_PAGE_NAME=Constant Pools
ConstantPoolsPage_SIZE_TOTAL_PERCENTAGE=Total Size (%)
ConstantPoolsPage_SIZE_TOTAL_PERCENTAGE_DESC=Size over total constant pool size
COUNT_COLUMN_NAME=Count

DropdownLaneFilter_QUICK_FILTER=Quick Filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,14 @@ public long getEventCountByType(String eventTypeName) {
public long getEventTotalSizeByType(String eventTypeName) {
return parserStats.getTotalSize(eventTypeName);
}

@Override
public IItemCollection getConstantPools() {
return parserStats.getConstantPools();
}

@Override
public IItemCollection getConstants() {
return parserStats.getConstants();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

import java.util.function.Consumer;

import org.openjdk.jmc.common.item.IItemCollection;

public interface IParserStats {

public interface IEventStats {
Expand All @@ -58,4 +60,8 @@ public interface IEventStats {
long getEventCountByType(String eventTypeName);

long getEventTotalSizeByType(String eventTypeName);

IItemCollection getConstantPools();

IItemCollection getConstants();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import java.util.Set;

import org.openjdk.jmc.common.item.IItemCollection;
import org.openjdk.jmc.common.unit.IQuantity;
import org.openjdk.jmc.common.unit.IRange;
import org.openjdk.jmc.flightrecorder.internal.parser.ParserStats;
Expand Down Expand Up @@ -62,4 +63,11 @@ public ParserStats getParserStats() {
return parserStats;
}

public IItemCollection getConstantPools() {
return parserStats.getConstantPools();
}

public IItemCollection getConstants() {
return parserStats.getConstants();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.openjdk.jmc.common.collection.FastAccessNumberMap;
import org.openjdk.jmc.common.item.IAttribute;
import org.openjdk.jmc.common.item.IItem;
import org.openjdk.jmc.common.unit.IQuantity;
Expand Down Expand Up @@ -147,6 +148,10 @@ public void updateEventStats(String eventTypeName, long size) {
parserStats.updateEventStats(eventTypeName, size);
}

public void addTypeConstantPool(long id, String name, FastAccessNumberMap<Object> constantPool) {
parserStats.addConstantPool(id, name, constantPool);
}

public ParserStats getParserStats() {
return parserStats;
}
Expand All @@ -158,4 +163,8 @@ public void setVersion(short majorVersion, short minorVersion) {
public void setSkippedEventCount(long skippedEventCount) {
parserStats.setSkippedEventCount(skippedEventCount);
}

public void addEntryPoolSize(String typeIdentifier, long size) {
parserStats.addEntryPoolSize(typeIdentifier, size);
}
}
Loading

0 comments on commit f25df12

Please sign in to comment.