Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Johnson2018-11-15 06:44:28 -0500
committerAndrew Johnson2018-11-15 09:07:39 -0500
commite241739475e4a71ea574d781f959227c3ec1ec55 (patch)
tree046a274468c03fa70cc40848be6804888623b8e9
parent5c8a351e457f9363712c660d5f3d38680c509a2d (diff)
downloadorg.eclipse.mat-e241739475e4a71ea574d781f959227c3ec1ec55.tar.gz
org.eclipse.mat-e241739475e4a71ea574d781f959227c3ec1ec55.tar.xz
org.eclipse.mat-e241739475e4a71ea574d781f959227c3ec1ec55.zip
[380600] Resave Heap Dump without Unreachable Objects
Allow export HPROF to be run as a command line report. Change-Id: Ib33531d6165890aa4634b14afcbdf70fa38027fd
-rw-r--r--plugins/org.eclipse.mat.api/src/org/eclipse/mat/internal/apps/ParseSnapshotApp.java4
-rw-r--r--plugins/org.eclipse.mat.hprof/plugin.properties9
-rw-r--r--plugins/org.eclipse.mat.hprof/plugin.xml11
-rw-r--r--plugins/org.eclipse.mat.hprof/reports/exporthprof.xml23
-rw-r--r--plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/ExportHprof.java2
-rw-r--r--plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/annotations.properties2
-rw-r--r--plugins/org.eclipse.mat.report/schema/report.xsd110
-rw-r--r--plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/SpecFactory.java10
-rw-r--r--plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/RunExternalTest.java45
-rw-r--r--plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/RunRegisterdReport.java27
-rw-r--r--plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/annotations.properties11
-rw-r--r--plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java99
-rw-r--r--plugins/org.eclipse.mat.ui/src/org/eclipse/mat/ui/actions/RunReportsDropDownAction.java35
13 files changed, 368 insertions, 20 deletions
diff --git a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/internal/apps/ParseSnapshotApp.java b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/internal/apps/ParseSnapshotApp.java
index 7e23f493..388dbf4a 100644
--- a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/internal/apps/ParseSnapshotApp.java
+++ b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/internal/apps/ParseSnapshotApp.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 SAP AG and IBM Corporation.
+ * Copyright (c) 2008, 2018 SAP AG and IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -90,6 +90,8 @@ public class ParseSnapshotApp implements IApplication
if (spec != null)
{
+ // Allow command line options to control reports
+ spec.putAll(options);
factory.resolve(spec);
reports.add(spec);
}
diff --git a/plugins/org.eclipse.mat.hprof/plugin.properties b/plugins/org.eclipse.mat.hprof/plugin.properties
index c368d9f8..2dda33d0 100644
--- a/plugins/org.eclipse.mat.hprof/plugin.properties
+++ b/plugins/org.eclipse.mat.hprof/plugin.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2010 SAP AG.
+# Copyright (c) 2010, 2018 SAP AG and IBM Corporation.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
#
# Contributors:
# SAP AG - initial API and implementation
+# Andrew Johnson/IBM Corporation - export HPROF report
###############################################################################
#Properties file for org.eclipse.mat.hprof
Bundle-Vendor = Eclipse Memory Analyzer
@@ -16,4 +17,8 @@ content-type.name.Hprof_Heap_Dump = Hprof Heap Dump
parser.name = HPROF Formatted Dumps
parser.filetype.name = HPROF binary heap dumps
extension-point.enhancer.name = HPROF Enhancement
-hprofPreferencesTitle = HPROF Parser \ No newline at end of file
+hprofPreferencesTitle = HPROF Parser
+report.exporthprof.title=Export HPROF
+report.export.desc = Export a HPROF file from the command line
+report.export.name = __hidden__/Export HPROF
+report.exporthprof.defaultavoid = .*ae.*|.*oe.*|.*uu.*|.*kr.*|.*kw.*|.*[cC]ie.*|.*[^c]ei.*
diff --git a/plugins/org.eclipse.mat.hprof/plugin.xml b/plugins/org.eclipse.mat.hprof/plugin.xml
index bedfdd69..24e061bf 100644
--- a/plugins/org.eclipse.mat.hprof/plugin.xml
+++ b/plugins/org.eclipse.mat.hprof/plugin.xml
@@ -59,5 +59,14 @@
impl="org.eclipse.mat.hprof.ExportHprof">
</query>
</extension>
-
+ <extension
+ id="export"
+ point="org.eclipse.mat.report.report">
+ <report
+ description="%report.export.desc Export a HPROF file from the command line"
+ file="reports/exporthprof.xml"
+ id="export"
+ name="%report.export.name __hidden__/Export HPROF">
+ </report>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.mat.hprof/reports/exporthprof.xml b/plugins/org.eclipse.mat.hprof/reports/exporthprof.xml
new file mode 100644
index 00000000..aa857a7b
--- /dev/null
+++ b/plugins/org.eclipse.mat.hprof/reports/exporthprof.xml
@@ -0,0 +1,23 @@
+<!--
+ Copyright (c) 2018 IBM Corporation.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ Andrew Johnson - initial creation
+ -->
+<query name="%report.exporthprof.title Export HPROF" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://www.eclipse.org/mat/report.xsd"
+ xsi:schemaLocation="http://www.eclipse.org/mat/report.xsd platform:/resource/org.eclipse.mat.report/schema/report.xsd">
+
+ <param key="output" value=""></param>
+ <param key="redact" value="NONE"></param>
+ <param key="map" value="&quot;&quot;"></param>
+ <param key="skip" value="java\\..*|boolean|byte|char|short|int|long|float|double|void"></param>
+ <param key="avoid" value="%report.exporthprof.defaultavoid .*ae.*|.*oe.*|.*uu.*|.*kr.*|.*kw.*|.*[cC]ie.*|.*[^c]ei.*"></param>
+ <param key="options" value=""></param>
+
+ <command>export_hprof -output ${output} -map ${map} -redact ${redact} -skip ${skip} -avoid ${avoid} ${options}</command>
+</query>
diff --git a/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/ExportHprof.java b/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/ExportHprof.java
index 1254ded4..95c6520d 100644
--- a/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/ExportHprof.java
+++ b/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/ExportHprof.java
@@ -493,7 +493,7 @@ public class ExportHprof implements IQuery
name = name.substring(0, dot);
}
String prefix = (new File(output.getParentFile(), name)).getPath();
- SnapshotInfo si = new SnapshotInfo(output.getPath(), prefix, null, idsize, new Date(startTime), nobjects, nroots, nclasses, nclassloaders, nused);
+ SnapshotInfo si = new SnapshotInfo(output.getAbsolutePath(), prefix, null, idsize, new Date(startTime), nobjects, nroots, nclasses, nclassloaders, nused);
String format = (new HprofContentDescriber()).getSupportedOptions()[0].getLocalName();
si.setProperty("$heapFormat", format); //$NON-NLS-1$
sq.setArgument("info", si); //$NON-NLS-1$
diff --git a/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/annotations.properties b/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/annotations.properties
index 6c004fb7..6fe38443 100644
--- a/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/annotations.properties
+++ b/plugins/org.eclipse.mat.hprof/src/org/eclipse/mat/hprof/annotations.properties
@@ -35,4 +35,4 @@ ExportHprof.undo.help = Whether to reverse the obfuscation process using the sup
mapping file.
ExportHprof.objects.help = Only export selected objects. See the help for how this \
could be used to remove unreachable objects retained by the 'keep unreachable objects' option.
-ExportHprof.classInst = Also export classes as object instances. Experimental, for class fields and types of classes.
+ExportHprof.classInst.help = Also export classes as object instances. Experimental, for class fields and types of classes.
diff --git a/plugins/org.eclipse.mat.report/schema/report.xsd b/plugins/org.eclipse.mat.report/schema/report.xsd
index 0ab1233f..bdab4a05 100644
--- a/plugins/org.eclipse.mat.report/schema/report.xsd
+++ b/plugins/org.eclipse.mat.report/schema/report.xsd
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2011 IBM Corporation.
+ Copyright (c) 2011, 2018 IBM Corporation.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
@@ -12,24 +12,54 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.eclipse.org/mat/report.xsd"
targetNamespace="http://www.eclipse.org/mat/report.xsd">
+ <xs:annotation>
+ <xs:documentation>This defines how reports for Eclipse Memory Analyzer should be constructed.</xs:documentation>
+ </xs:annotation>
<xs:element name="param">
<xs:annotation>
<xs:documentation>This allows output of a query to be controlled.
+ Parameters are substituted in certain elements and attributes when ${keyname} is seen.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="key" type="paramkey" use="required"></xs:attribute>
- <xs:attribute name="value" type="translatablestring"
+ <xs:attribute name="value" type="paramvalue"
use="required"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:simpleType name="paramkey">
<xs:annotation>
+ <xs:documentation>A parameter - either one of a fixed set of known
+ types, or anything for an adopter defined type.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:union memberTypes="paramkeyfixed paramkeyany" />
+ </xs:simpleType>
+
+ <xs:simpleType name="paramkeyany">
+ <xs:annotation>
+ <xs:documentation>A general parameter key
+ </xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:pattern value="[A-Za-z0-9_.]+" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:simpleType name="paramkeyfixed">
+ <xs:annotation>
<xs:documentation>The name of a parameter to control a report.
+ See org.eclipse.mat.report.Params
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
+ <xs:enumeration value="timestamp" />
+ <!--
+ <xs:enumeration value="snapshot" />
+ <xs:enumeration value="snapshot_prefix" />
+ -->
+
<xs:enumeration value="format" />
<xs:enumeration value="filename" />
<xs:enumeration value="filename_suffix" />
@@ -53,14 +83,77 @@
</xs:restriction>
</xs:simpleType>
+ <xs:simpleType name="paramvalue">
+ <xs:annotation>
+ <xs:documentation>A value for a parameter - either one of a fixed set of known
+ types, or anything as a translatable string.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:union memberTypes="booleanvalue patternvalue derived_data_columnvalue decimalstring columnnumber translatablestring" />
+ </xs:simpleType>
+
+ <xs:simpleType name="booleanvalue">
+ <xs:annotation>
+ <xs:documentation>Choices for a boolean value.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="true" />
+ <xs:enumeration value="false" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:simpleType name="patternvalue">
+ <xs:annotation>
+ <xs:documentation>Choices for a pattern.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="overview_details" />
+ <xs:enumeration value="sequential" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:simpleType name="derived_data_columnvalue">
+ <xs:annotation>
+ <xs:documentation>Choices for a pattern.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="_default_=PRECISE" />
+ <xs:enumeration value="_default_=APPROXIMATE" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:simpleType name="decimalstring">
+ <xs:annotation>
+ <xs:documentation>A number as text
+ </xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:pattern value="[1-9][0-9]*" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:simpleType name="columnnumber">
+ <xs:annotation>
+ <xs:documentation>A number preceded by # as text
+ </xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:string">
+ <xs:pattern value="#[0-9]+" />
+ </xs:restriction>
+ </xs:simpleType>
+
<xs:simpleType name="translatedstring">
<xs:annotation>
<xs:documentation>A string with a leading % to be used as key into
the plugin properties file to provided translated text.
+ Default text to be used for a missing translation can be provided after the key and a space.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
- <xs:pattern value="%[A-Za-z0-9_.]*" />
+ <xs:pattern value="%[A-Za-z0-9_.]+( .*)?" />
</xs:restriction>
</xs:simpleType>
@@ -70,13 +163,19 @@
</xs:restriction>
</xs:simpleType>
+ <xs:simpleType name="literalpercentuntranslatedstring">
+ <xs:restriction base="xs:string">
+ <xs:pattern value="%%.*" />
+ </xs:restriction>
+ </xs:simpleType>
+
<xs:simpleType name="translatablestring">
<xs:annotation>
<xs:documentation>A readable string or a string that will be
translated according to the plugin.properties file.
</xs:documentation>
</xs:annotation>
- <xs:union memberTypes="translatedstring untranslatedstring" />
+ <xs:union memberTypes="translatedstring untranslatedstring literalpercentuntranslatedstring" />
</xs:simpleType>
<xs:element name="query">
@@ -109,11 +208,12 @@
<xs:annotation>
<xs:documentation>
This specifies a query command to be executed.
+ The command can have arguments, and parameter substitution with ${} can be used to inject text.
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
- <xs:pattern value="\S.*"></xs:pattern>
+ <xs:pattern value="\S+(\s+\S+)*"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>
diff --git a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/SpecFactory.java b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/SpecFactory.java
index a7117b7a..c4b0b8cc 100644
--- a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/SpecFactory.java
+++ b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/SpecFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 SAP AG.
+ * Copyright (c) 2008, 2018 SAP AG and IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* SAP AG - initial API and implementation
+ * Andrew Johnson - improved translation of reports
*******************************************************************************/
package org.eclipse.mat.report;
@@ -245,12 +246,15 @@ public final class SpecFactory extends RegistryReader<SpecFactory.Report>
/**
* Some values are translatable using % prefix and a translation
* in the plugin.properties file.
+ * %key.part default value
+ * 'key.part' is looked up, if missing then
+ * 'default value' is returned (without quotes).
* @param n
- * @return
+ * @return the translated string, or the default if present, or the key
*/
private String translate(String n)
{
- if (bundle != null && n != null && n.length() > 0 && n.charAt(0) == '%')
+ if (n != null && n.length() > 0 && n.charAt(0) == '%')
n = Platform.getResourceString(bundle, n);
return n;
}
diff --git a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/RunExternalTest.java b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/RunExternalTest.java
index 97052d28..9b857eeb 100644
--- a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/RunExternalTest.java
+++ b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/RunExternalTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 SAP AG.
+ * Copyright (c) 2008, 2018 SAP AG and IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,11 +7,15 @@
*
* Contributors:
* SAP AG - initial API and implementation
+ * Andrew Johnson/IBM Corporation - add parameters
*******************************************************************************/
package org.eclipse.mat.report.internal;
import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.mat.SnapshotException;
import org.eclipse.mat.query.IQuery;
import org.eclipse.mat.query.IQueryContext;
import org.eclipse.mat.query.IResult;
@@ -19,6 +23,8 @@ import org.eclipse.mat.query.annotations.Argument;
import org.eclipse.mat.query.annotations.Category;
import org.eclipse.mat.query.annotations.CommandName;
import org.eclipse.mat.query.results.DisplayFileResult;
+import org.eclipse.mat.report.Spec;
+import org.eclipse.mat.report.SpecFactory;
import org.eclipse.mat.report.TestSuite;
import org.eclipse.mat.util.IProgressListener;
@@ -32,9 +38,29 @@ public class RunExternalTest implements IQuery
@Argument(flag = Argument.UNFLAGGED)
public File testSuite;
+ @Argument(isMandatory = false)
+ public String params[];
+
public IResult execute(IProgressListener listener) throws Exception
{
- TestSuite suite = new TestSuite.Builder(testSuite).build(context);
+ Spec template;
+ try
+ {
+ SpecFactory factory = SpecFactory.instance();
+ template = factory.create(testSuite);
+
+ // Add options
+ Map<String, String> opts = parseOptions(params);
+ template.putAll(opts);
+
+ factory.resolve(template);
+ }
+ catch (Exception e)
+ {
+ throw new SnapshotException(e);
+ }
+
+ TestSuite suite = new TestSuite.Builder(template).build(context);
suite.execute(listener);
@@ -47,4 +73,19 @@ public class RunExternalTest implements IQuery
return null;
}
+ Map<String,String>parseOptions(String opts[])
+ {
+ Map<String,String>m = new HashMap<String,String>();
+ if (opts != null)
+ {
+ for (String opt : opts)
+ {
+ int i = opt.indexOf('=');
+ if (i < 0)
+ throw new IllegalArgumentException(opt);
+ m.put(opt.substring(0, i), opt.substring(i + 1));
+ }
+ }
+ return m;
+ }
}
diff --git a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/RunRegisterdReport.java b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/RunRegisterdReport.java
index 7de23a2a..5e40bab3 100644
--- a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/RunRegisterdReport.java
+++ b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/RunRegisterdReport.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 SAP AG.
+ * Copyright (c) 2008, 2010 SAP AG and IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,13 @@
*
* Contributors:
* SAP AG - initial API and implementation
+ * Andrew Johnson/IBM Corporation - add parameters
*******************************************************************************/
package org.eclipse.mat.report.internal;
import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
import org.eclipse.mat.query.IQuery;
import org.eclipse.mat.query.IQueryContext;
@@ -35,6 +38,9 @@ public class RunRegisterdReport implements IQuery
@Argument(flag = Argument.UNFLAGGED)
public String extensionIdentifier;
+ @Argument(isMandatory = false)
+ public String params[];
+
public IResult execute(IProgressListener listener) throws Exception
{
SpecFactory factory = SpecFactory.instance();
@@ -43,6 +49,10 @@ public class RunRegisterdReport implements IQuery
throw new Exception(MessageUtil
.format(Messages.RunRegisterdReport_Error_UnknownReport, extensionIdentifier));
+ // Add options
+ Map<String, String> opts = parseOptions(params);
+ spec.putAll(opts);
+
factory.resolve(spec);
TestSuite suite = new TestSuite.Builder(spec).build(queryContext);
@@ -58,4 +68,19 @@ public class RunRegisterdReport implements IQuery
return null;
}
+ Map<String,String>parseOptions(String opts[])
+ {
+ Map<String,String>m = new HashMap<String,String>();
+ if (opts != null)
+ {
+ for (String opt : opts)
+ {
+ int i = opt.indexOf('=');
+ if (i < 0)
+ throw new IllegalArgumentException(opt);
+ m.put(opt.substring(0, i), opt.substring(i + 1));
+ }
+ }
+ return m;
+ }
}
diff --git a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/annotations.properties b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/annotations.properties
index cc0c4edd..a227dba9 100644
--- a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/annotations.properties
+++ b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/report/internal/annotations.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2008, 2010 SAP AG.
+# Copyright (c) 2008, 2018 SAP AG and IBM Corporation.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -7,6 +7,15 @@
#
# Contributors:
# SAP AG - initial API and implementation
+# Andrew Johnson/IBM Corporation - additional details for the reports
###############################################################################
RunExternalTest.name = Run Expert System Test
+RunExternalTest.help = Hidden query to run a report defined in an external file.
+RunExternalTest.testSuite.help = The file path of the report to be run.
+RunExternalTest.params.help = Additional parameters for the report, as 'key=value'.
+RunRegisterdReport.name = Run Registered Report
+RunRegisterdReport.help = Hidden query to run a report already register in a plugin.
+RunRegisterdReport.extensionIdentifier.help = The bundle name and report extension identifier to find the report.\n\
+The format is like: my.bundle.name:reportid
+RunRegisterdReport.params.help = Additional parameters for the report, as 'key=value'.
diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java
index ea6cc353..370155b5 100644
--- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java
+++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java
@@ -16,15 +16,26 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.Collections;
+
+import org.eclipse.core.runtime.Platform;
import org.eclipse.mat.SnapshotException;
import org.eclipse.mat.query.Column;
import org.eclipse.mat.query.IContextObject;
+import org.eclipse.mat.query.IResult;
import org.eclipse.mat.query.IResultTree;
import org.eclipse.mat.query.refined.RefinedResultBuilder;
import org.eclipse.mat.query.refined.RefinedTable;
import org.eclipse.mat.snapshot.ClassHistogramRecord;
import org.eclipse.mat.snapshot.Histogram;
import org.eclipse.mat.snapshot.ISnapshot;
+import org.eclipse.mat.snapshot.SnapshotFactory;
import org.eclipse.mat.snapshot.model.IClass;
import org.eclipse.mat.snapshot.model.IClassLoader;
import org.eclipse.mat.snapshot.model.IObject;
@@ -34,6 +45,7 @@ import org.eclipse.mat.util.VoidProgressListener;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.osgi.framework.Bundle;
public class QueriesTest
{
@@ -252,4 +264,91 @@ public class QueriesTest
}
assertEquals("Number of objects", objs, snapshot.getSnapshotInfo().getNumberOfObjects());
}
+
+ /**
+ * Test running a report defined in a plugin, with parameters.
+ * @throws SnapshotException
+ * @throws IOException
+ */
+ @Test
+ public void testExportHprofReport() throws SnapshotException, IOException
+ {
+ File samp = new File(snapshot.getSnapshotInfo().getPrefix());
+ File fn = File.createTempFile(samp.getName(), ".hprof");
+ try
+ {
+ SnapshotQuery query = SnapshotQuery.parse("default_report org.eclipse.mat.hprof:export -params output="+fn.getPath(), snapshot);
+ IResult t = query.execute(new VoidProgressListener());
+ assertNotNull(t);
+ ISnapshot newSnapshot = SnapshotFactory.openSnapshot(fn, Collections.<String,String>emptyMap(), new VoidProgressListener());
+ assertNotNull(newSnapshot);
+ newSnapshot.dispose();
+ }
+ finally
+ {
+ fn.delete();
+ }
+ }
+
+ /**
+ * Test running an external report from a report file, with parameters.
+ * @throws SnapshotException
+ * @throws IOException
+ */
+ @Test
+ public void testExportHprofReportFile() throws SnapshotException, IOException
+ {
+ // Create a temporary report file
+ File rep = File.createTempFile("exporthprof", ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
+ try
+ {
+ // We happen to know where the exporthprof report lives, so copy it
+ Bundle bundle = Platform.getBundle("org.eclipse.mat.hprof"); //$NON-NLS-1$
+ URL url = bundle.getResource("reports/exporthprof.xml"); //$NON-NLS-1$
+ InputStream is = url.openStream();
+ OutputStream os = new FileOutputStream(rep);
+ try
+ {
+ try
+ {
+ int r;
+ while ((r = is.read()) != -1)
+ {
+ os.write(r);
+ }
+ }
+ finally
+ {
+ os.close();
+ }
+ }
+ finally
+ {
+ is.close();
+ }
+
+ // Run the report
+ File samp = new File(snapshot.getSnapshotInfo().getPrefix());
+ File fn = File.createTempFile(samp.getName(), ".hprof");
+ try
+ {
+ SnapshotQuery query = SnapshotQuery.parse(
+ "create_report "+rep.getPath()+" -params output=" + fn.getPath(), snapshot);
+ IResult t = query.execute(new VoidProgressListener());
+ assertNotNull(t);
+ ISnapshot newSnapshot = SnapshotFactory.openSnapshot(fn, Collections.<String, String> emptyMap(),
+ new VoidProgressListener());
+ assertNotNull(newSnapshot);
+ newSnapshot.dispose();
+ }
+ finally
+ {
+ fn.delete();
+ }
+ }
+ finally
+ {
+ rep.delete();
+ }
+ }
}
diff --git a/plugins/org.eclipse.mat.ui/src/org/eclipse/mat/ui/actions/RunReportsDropDownAction.java b/plugins/org.eclipse.mat.ui/src/org/eclipse/mat/ui/actions/RunReportsDropDownAction.java
index feb66a0a..b21c130c 100644
--- a/plugins/org.eclipse.mat.ui/src/org/eclipse/mat/ui/actions/RunReportsDropDownAction.java
+++ b/plugins/org.eclipse.mat.ui/src/org/eclipse/mat/ui/actions/RunReportsDropDownAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 SAP AG.
+ * Copyright (c) 2008, 2018 SAP AG and IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* SAP AG - initial API and implementation
+ * Andrew Johnson/IBM Corporation - submenus/hidden reports
*******************************************************************************/
package org.eclipse.mat.ui.actions;
@@ -16,6 +17,7 @@ import java.util.Comparator;
import java.util.List;
import org.eclipse.jface.action.Action;
+import org.eclipse.mat.query.annotations.Category;
import org.eclipse.mat.report.SpecFactory;
import org.eclipse.mat.ui.MemoryAnalyserPlugin;
import org.eclipse.mat.ui.Messages;
@@ -48,6 +50,7 @@ public class RunReportsDropDownAction extends EasyToolBarDropDown
{
Action action = new ExecuteQueryAction(editor, "default_report " + report.getExtensionIdentifier());//$NON-NLS-1$
action.setText(report.getName());
+ action.setDescription(report.getDescription());
reportActions.add(action);
}
@@ -60,7 +63,35 @@ public class RunReportsDropDownAction extends EasyToolBarDropDown
});
for (Action action : reportActions)
- menu.add(action);
+ {
+ String name[] = action.getText().split("/"); //$NON-NLS-1$
+ for (int i = 0; i < name.length; ++i)
+ {
+ // Strip off ordering e.g. 1|Name
+ name[i] = name[i].replaceFirst("^\\d\\|", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ // Create sub-menus
+ PopupMenu m1 = menu;
+ int i;
+ for (i = 0; i < name.length - 1; ++i)
+ {
+ if (name[i].equals(Category.HIDDEN))
+ break;
+ PopupMenu m2 = m1.getChildMenu(name[i]);
+ if (m2 == null)
+ {
+ m2 = new PopupMenu(name[i]);
+ m1.add(m2);
+ }
+ m1 = m2;
+ }
+ if (i >= name.length - 1)
+ {
+ // Finally, add the action
+ action.setText(name[name.length - 1]);
+ m1.add(action);
+ }
+ }
menu.addSeparator();
menu.add(importReportAction);

Back to the top