Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Johnson2018-11-18 17:46:11 -0500
committerAndrew Johnson2018-11-18 17:51:15 -0500
commit8b23f214fd0e7b27ef542411ad98868af88c83b2 (patch)
treef992ece26502326622ac84c508ebeaf92645d0b5
parentd6dfde22ff326ebad0eb3aac56dfb2859bb012af (diff)
downloadorg.eclipse.mat-8b23f214fd0e7b27ef542411ad98868af88c83b2.tar.gz
org.eclipse.mat-8b23f214fd0e7b27ef542411ad98868af88c83b2.tar.xz
org.eclipse.mat-8b23f214fd0e7b27ef542411ad98868af88c83b2.zip
[541286] Missing shallow heap size values in comparison tables
Allow for Bytes as well as Long Change-Id: Icbeb10856b11d83fd9c560bc4408fa891ca42089
-rw-r--r--plugins/org.eclipse.mat.api/src/org/eclipse/mat/internal/snapshot/inspections/CompareTablesQuery.java40
-rw-r--r--plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/TotalsCalculator.java5
-rw-r--r--plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueryLookupTest.java109
3 files changed, 147 insertions, 7 deletions
diff --git a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/internal/snapshot/inspections/CompareTablesQuery.java b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/internal/snapshot/inspections/CompareTablesQuery.java
index 6aa13108..28d53af2 100644
--- a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/internal/snapshot/inspections/CompareTablesQuery.java
+++ b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/internal/snapshot/inspections/CompareTablesQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 SAP AG and IBM Corporation.
+ * 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
@@ -21,6 +21,8 @@ import java.util.Map;
import org.eclipse.mat.collect.ArrayInt;
import org.eclipse.mat.internal.Messages;
+import org.eclipse.mat.query.Bytes;
+import org.eclipse.mat.query.BytesFormat;
import org.eclipse.mat.query.Column;
import org.eclipse.mat.query.ContextProvider;
import org.eclipse.mat.query.IContextObject;
@@ -983,13 +985,20 @@ public class CompareTablesQuery implements IQuery
if (value == null && firstTableValue == null) return null;
- if (value == null && firstTableValue instanceof Number) return null;
+ if (value == null && (firstTableValue instanceof Number || firstTableValue instanceof Bytes)) return null;
- if (value instanceof Number && firstTableValue == null)
+ if ((value instanceof Number || value instanceof Bytes) && firstTableValue == null)
{
return ratio ? null : value;
}
+ boolean returnBytes = value instanceof Bytes && firstTableValue instanceof Bytes;
+ if (value instanceof Bytes)
+ value = Long.valueOf(((Bytes)value).getValue());
+
+ if (firstTableValue instanceof Bytes)
+ firstTableValue = Long.valueOf(((Bytes)firstTableValue).getValue());
+
if (value instanceof Number && firstTableValue instanceof Number)
{
Object ret = computeDiff((Number) firstTableValue, (Number) value);
@@ -999,6 +1008,8 @@ public class CompareTablesQuery implements IQuery
}
else
{
+ if (returnBytes)
+ return new Bytes(((Number)ret).longValue());
return ret;
}
}
@@ -1018,13 +1029,20 @@ public class CompareTablesQuery implements IQuery
if (value == null && previousTableValue == null) return null;
- if (value == null && previousTableValue instanceof Number) return null;
+ if (value == null && (previousTableValue instanceof Number || previousTableValue instanceof Bytes)) return null;
- if (value instanceof Number && previousTableValue == null)
+ if ((value instanceof Number || value instanceof Bytes) && previousTableValue == null)
{
return ratio ? null : value;
}
+ boolean returnBytes = value instanceof Bytes && previousTableValue instanceof Bytes;
+ if (value instanceof Bytes)
+ value = Long.valueOf(((Bytes)value).getValue());
+
+ if (previousTableValue instanceof Bytes)
+ previousTableValue = Long.valueOf(((Bytes)previousTableValue).getValue());
+
if (value instanceof Number && previousTableValue instanceof Number)
{
Object ret = computeDiff((Number) previousTableValue, (Number) value);
@@ -1034,6 +1052,8 @@ public class CompareTablesQuery implements IQuery
}
else
{
+ if (returnBytes)
+ return new Bytes(((Number)ret).longValue());
return ret;
}
}
@@ -1124,6 +1144,10 @@ public class CompareTablesQuery implements IQuery
{
((DecimalFormat)formatterPercent).setPositivePrefix("+"); //$NON-NLS-1$
}
+ // Force the sign for Bytes formatting
+ String detailed1 = "+"+BytesFormat.DETAILED_DECIMAL_FORMAT+";-"+BytesFormat.DETAILED_DECIMAL_FORMAT; //$NON-NLS-1$ //$NON-NLS-2$
+ DecimalFormat bcf = new DecimalFormat(detailed1);
+ BytesFormat bfm = new BytesFormat(formatter, bcf);
for (ComparedColumn comparedColumn : displayedColumns)
{
@@ -1145,6 +1169,12 @@ public class CompareTablesQuery implements IQuery
fm.setPositivePrefix("+"); //$NON-NLS-1$
columns[i].formatting(fm);
}
+ else if (c.getFormatter() instanceof BytesFormat)
+ {
+ //BytesFormat fm = ((BytesFormat) c.getFormatter().clone());
+ // Force the sign - can't retrieve information from existing formatter
+ columns[i].formatting(bfm);
+ }
else
{
columns[i].formatting(formatter);
diff --git a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/TotalsCalculator.java b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/TotalsCalculator.java
index 04e1cac6..0e236847 100644
--- a/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/TotalsCalculator.java
+++ b/plugins/org.eclipse.mat.report/src/org/eclipse/mat/query/refined/TotalsCalculator.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 - also total sizes (Bytes)
*******************************************************************************/
package org.eclipse.mat.query.refined;
@@ -93,6 +94,8 @@ import org.eclipse.mat.util.IProgressListener;
{
v = ((Number) o).doubleValue();
}
+ else if (o instanceof Bytes)
+ v = ((Bytes) o).getValue();
else
{
try
diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueryLookupTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueryLookupTest.java
index 3d3bb624..24f334d1 100644
--- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueryLookupTest.java
+++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueryLookupTest.java
@@ -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,14 +7,18 @@
*
* Contributors:
* SAP AG - initial API and implementation
+ * Andrew Johnson/IBM Corporation - comparison queries
*******************************************************************************/
package org.eclipse.mat.tests.snapshot;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.number.OrderingComparison.greaterThan;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -103,6 +107,109 @@ public class QueryLookupTest
assertTrue(r2 != null);
}
+
+ /**
+ * Test that subtraction comparisons are done, even for sizes.
+ */
+ @Test
+ public void testCompareDiffPrevious() throws SnapshotException
+ {
+ String queryId = "comparetablesquery";
+ ISnapshot snapshot1 = TestSnapshots.getSnapshot(TestSnapshots.SUN_JDK6_18_32BIT, false);
+ ISnapshot snapshot2 = TestSnapshots.getSnapshot(TestSnapshots.SUN_JDK6_18_64BIT, false);
+
+ SnapshotQuery query1 = SnapshotQuery.lookup("histogram", snapshot1);
+ IResult result1 = query1.execute(new VoidProgressListener());
+
+ SnapshotQuery query2 = SnapshotQuery.lookup("histogram", snapshot2);
+ IResult result2 = query2.execute(new VoidProgressListener());
+
+ SnapshotQuery query3 = SnapshotQuery.parse(queryId+" -mode DIFF_TO_PREVIOUS", snapshot1);
+
+ List<IResultTable> r = new ArrayList<IResultTable>();
+ r.add((IResultTable) result1);
+ r.add((IResultTable) result2);
+ query3.setArgument("tables", r);
+ ArrayList<ISnapshot> snapshots = new ArrayList<ISnapshot>();
+ snapshots.add(snapshot1);
+ snapshots.add(snapshot2);
+ query3.setArgument("snapshots", snapshots);
+ IResultTable r2 = (IResultTable) query3.execute(new VoidProgressListener());
+ assertTrue(r2 != null);
+ System.out.println(Arrays.toString(r2.getColumns()));
+ int count = 0;
+ for (int i = 0; i < r2.getRowCount(); ++i)
+ {
+ Object v0 = r2.getColumnValue(r2.getRow(i), 1);
+ for (int j = 1; j < r2.getColumns().length - 1; j += 2)
+ {
+ Object v1 = r2.getColumnValue(r2.getRow(i), j);
+ Object v2 = r2.getColumnValue(r2.getRow(i), j + 1);
+ // With a difference, if there is a value from table 1 then the difference has a value
+ if (v1 != null)
+ {
+ if (v2 != null)
+ ++count;
+ }
+ }
+ }
+ assertThat(count, greaterThan(0));
+ }
+
+ /**
+ * Test that subtraction comparisons are done, even for sizes.
+ */
+ @Test
+ public void testCompareDiffRatioFirst() throws SnapshotException
+ {
+ String queryId = "comparetablesquery";
+ ISnapshot snapshot1 = TestSnapshots.getSnapshot(TestSnapshots.SUN_JDK6_18_32BIT, false);
+ ISnapshot snapshot2 = TestSnapshots.getSnapshot(TestSnapshots.SUN_JDK6_18_64BIT, false);
+
+ SnapshotQuery query1 = SnapshotQuery.lookup("histogram", snapshot1);
+ IResult result1 = query1.execute(new VoidProgressListener());
+
+ SnapshotQuery query2 = SnapshotQuery.lookup("histogram", snapshot2);
+ IResult result2 = query2.execute(new VoidProgressListener());
+
+ SnapshotQuery query3 = SnapshotQuery.parse(queryId+" -mode DIFF_RATIO_TO_FIRST", snapshot1);
+
+
+ List<IResultTable> r = new ArrayList<IResultTable>();
+ r.add((IResultTable) result1);
+ r.add((IResultTable) result2);
+ query3.setArgument("tables", r);
+ ArrayList<ISnapshot> snapshots = new ArrayList<ISnapshot>();
+ snapshots.add(snapshot1);
+ snapshots.add(snapshot2);
+ query3.setArgument("snapshots", snapshots);
+ IResultTable r2 = (IResultTable) query3.execute(new VoidProgressListener());
+ assertTrue(r2 != null);
+ System.out.println(Arrays.toString(r2.getColumns()));
+ int count1 = 0;
+ int count2 = 0;
+ for (int i = 0; i < r2.getRowCount(); ++i)
+ {
+ Object v0 = r2.getColumnValue(r2.getRow(i), 1);
+ for (int j = 1; j < r2.getColumns().length - 2; j += 3)
+ {
+ Object v1 = r2.getColumnValue(r2.getRow(i), j);
+ Object v2 = r2.getColumnValue(r2.getRow(i), j + 1);
+ Object v3 = r2.getColumnValue(r2.getRow(i), j + 2);
+ // With a difference, if there is a value from table 1 then the difference has a value
+ if (v1 != null)
+ {
+ if (v2 != null)
+ ++count1;
+ if (v3 != null)
+ ++count2;
+ }
+ }
+ }
+ assertThat(count1, greaterThan(0));
+ assertThat(count2, greaterThan(0));
+ }
+
@Test()
public void testParse() throws SnapshotException
{

Back to the top