Skip to content

Commit

Permalink
Bug 582520 beginTask should only be called once per instance.
Browse files Browse the repository at this point in the history
Use SimpleMonitor to split tasks.

Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=582520
Change-Id: I3c18bbc38744a86aebd7bf1c4a35d51a70c3bed6
  • Loading branch information
ajohnson1 committed Oct 14, 2023
1 parent ee4d644 commit f6a3983
Show file tree
Hide file tree
Showing 36 changed files with 459 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.mat.snapshot.query.IHeapObjectArgument;
import org.eclipse.mat.util.IProgressListener;
import org.eclipse.mat.util.MessageUtil;
import org.eclipse.mat.util.SimpleMonitor;

@CommandName("customized_retained_set")
@Icon("/META-INF/icons/show_retained_set.gif")
Expand All @@ -65,12 +66,15 @@ public class CustomizedRetainedSetQuery implements IQuery

public IResult execute(IProgressListener listener) throws Exception
{
SimpleMonitor monitor = new SimpleMonitor(MessageUtil.format(Messages.CustomizedRetainedSetQuery_QueryName, objects.getLabel()),
listener, new int[] { 10, 950, 50 });
int[] retainedSet;

if (excludedReferences == null && excludedReferencesListFile == null)
{
// normal retained set
retainedSet = snapshot.getRetainedSet(objects.getIds(listener), listener);
int objs[] = objects.getIds(monitor.nextMonitor());
retainedSet = snapshot.getRetainedSet(objs, monitor.nextMonitor());
}
else
{
Expand All @@ -93,18 +97,20 @@ public IResult execute(IProgressListener listener) throws Exception
}
}
ExcludedReferencesDescriptor[] excludedRefDescriptors = getExcludedReferenceDescriptors(excludedReferences);
retainedSet = snapshot.getRetainedSet(objects.getIds(listener), excludedRefDescriptors, listener);
int objs[] = objects.getIds(monitor.nextMonitor());
retainedSet = snapshot.getRetainedSet(objs, excludedRefDescriptors, monitor.nextMonitor());
}

if (listener.isCanceled())
throw new IProgressListener.OperationCanceledException();

Histogram histogram = snapshot.getHistogram(retainedSet, listener);
Histogram histogram = snapshot.getHistogram(retainedSet, monitor.nextMonitor());

if (listener.isCanceled())
throw new IProgressListener.OperationCanceledException();

histogram.setLabel(MessageUtil.format(Messages.CustomizedRetainedSetQuery_RetainedBy, objects.getLabel()));
listener.done();
return histogram;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2020 SAP AG and IBM Corporation.
* Copyright (c) 2008, 2023 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 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -64,7 +64,8 @@ public IResult execute(IProgressListener listener) throws Exception
{
IClass[] allClasses = snapshot.getClasses().toArray(new IClass[0]);
int length = allClasses.length;
listener.beginTask(Messages.DuplicatedClassesQuery_Checking, length / 100);
int taskScale = 100;
listener.beginTask(Messages.DuplicatedClassesQuery_Checking, (length + taskScale - 1) / taskScale);

Arrays.sort(allClasses, ObjectComparators.getComparatorForTechnicalNameAscending());

Expand All @@ -88,13 +89,14 @@ public IResult execute(IProgressListener listener) throws Exception
if (ii < length)
previousName = allClasses[ii].getName();

if (ii % 100 == 0)
if (ii % taskScale == 0)
listener.worked(1);

if (listener.isCanceled())
throw new IProgressListener.OperationCanceledException();
}

listener.done();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
import java.util.Random;
import java.util.Set;

import org.eclipse.core.runtime.Status;
import org.eclipse.mat.SnapshotException;
import org.eclipse.mat.collect.ArrayInt;
import org.eclipse.mat.collect.ArrayIntBig;
import org.eclipse.mat.collect.BitField;
import org.eclipse.mat.internal.MATPlugin;
import org.eclipse.mat.internal.Messages;
import org.eclipse.mat.internal.snapshot.inspections.Path2GCRootsQuery;
import org.eclipse.mat.query.Bytes;
Expand Down Expand Up @@ -56,6 +54,7 @@
import org.eclipse.mat.snapshot.model.IObject;
import org.eclipse.mat.util.IProgressListener;
import org.eclipse.mat.util.MessageUtil;
import org.eclipse.mat.util.SilentProgressListener;

import com.ibm.icu.text.NumberFormat;

Expand Down Expand Up @@ -130,7 +129,7 @@ public IResult execute(IProgressListener listener) throws Exception
*/
listener.subTask(Messages.FindLeaksQuery_SearchingGroupsOfObjects);

Histogram histogram = groupByClasses(topDominators, listener);
Histogram histogram = groupByClasses(topDominators, new SilentProgressListener(listener));
ArrayList<ClassHistogramRecord> suspiciousClasses = new ArrayList<ClassHistogramRecord>();

ClassHistogramRecord[] classRecords = histogram.getClassHistogramRecords().toArray(new ClassHistogramRecord[0]);
Expand All @@ -154,7 +153,8 @@ public IResult execute(IProgressListener listener) throws Exception
/*
* build the results
*/
return buildResult(suspiciousObjects, suspiciousClasses, totalHeap, listener);
IResult result = buildResult(suspiciousObjects, suspiciousClasses, totalHeap, listener);
return result;

}

Expand Down Expand Up @@ -344,6 +344,7 @@ private IResult buildResult(ArrayInt suspiciousObjects, ArrayList<ClassHistogram
long totalHeap, IProgressListener listener) throws SnapshotException
{
SuspectRecord[] allSuspects = new SuspectRecord[suspiciousObjects.size() + suspiciousClasses.size()];
listener.beginTask(Messages.FindLeaksQuery_BuildResult, allSuspects.length);
int j = 0;
int[] suspectObjIds = suspiciousObjects.toArray();
for (int objectId : suspectObjIds)
Expand All @@ -356,6 +357,7 @@ private IResult buildResult(ArrayInt suspiciousObjects, ArrayList<ClassHistogram
SuspectRecord r = new SuspectRecord(suspectObject, suspectObject.getRetainedHeapSize(), accPoint);

allSuspects[j++] = r;
listener.worked(1);
}

for (ClassHistogramRecord record : suspiciousClasses)
Expand All @@ -368,10 +370,12 @@ private IResult buildResult(ArrayInt suspiciousObjects, ArrayList<ClassHistogram
* (
* threshold
* 0.7),
*/listener);
*/new SilentProgressListener(listener));
allSuspects[j++] = r;
listener.worked(1);
}

listener.done();
return new SuspectsResultTable(allSuspects, totalHeap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.eclipse.mat.snapshot.query.SnapshotQuery;
import org.eclipse.mat.util.IProgressListener;
import org.eclipse.mat.util.MessageUtil;
import org.eclipse.mat.util.SimpleMonitor;

import com.ibm.icu.text.NumberFormat;

Expand Down Expand Up @@ -132,13 +133,14 @@ public class FindLeaksQuery2 implements IQuery

public IResult execute(IProgressListener listener) throws Exception
{
SimpleMonitor monitor = new SimpleMonitor(Messages.FindLeaksQuery2_ProgressName, listener, new int[] { 5, 5, 30, 5, 5, 50 });
long totalHeap;

totalHeap = baseline.getSnapshotInfo().getUsedHeapSize();
long threshold = threshold_percent * totalHeap / 100;

IResultTree baseTree = callDominatorTree(listener, baseline);
IResultTree currTree = callDominatorTree(listener, snapshot);
IResultTree baseTree = callDominatorTree(monitor.nextMonitor(), baseline);
IResultTree currTree = callDominatorTree(monitor.nextMonitor(), snapshot);

String queryId = "comparetablesquery -mode DIFF_RATIO_TO_FIRST"; //$NON-NLS-1$
if (options != null && options.length() > 0)
Expand All @@ -162,15 +164,16 @@ public IResult execute(IProgressListener listener) throws Exception
if (extraReferencesListFile != null)
queryc.setArgument("extraReferencesListFile", extraReferencesListFile); //$NON-NLS-1$

RefinedResultBuilder rbc = queryc.refine(listener);
RefinedResultBuilder rbc = queryc.refine(monitor.nextMonitor());
rbc.setSortOrder(retainedDiffCol, SortDirection.DESC);
final RefinedTree compTree = (RefinedTree)rbc.build();
List<?>topDominators = compTree.getElements();

/*
* find suspect single objects
*/
listener.subTask(Messages.FindLeaksQuery_SearchingSingleObjects);
IProgressListener single = monitor.nextMonitor();
single.beginTask(Messages.FindLeaksQuery_SearchingSingleObjects, topDominators.size());

List<ContextProvider> provs = compTree.getResultMetaData().getContextProviders();
// Get the last - in case the first is also this snapshot, so has a context provider
Expand Down Expand Up @@ -211,15 +214,18 @@ public IResult execute(IProgressListener listener) throws Exception
}
}
i++;
single.worked(1);
}
single.done();

if (listener.isCanceled())
throw new IProgressListener.OperationCanceledException();

/*
* Find suspect classes
*/
listener.subTask(Messages.FindLeaksQuery_SearchingGroupsOfObjects);
IProgressListener group = monitor.nextMonitor();
group.beginTask(Messages.FindLeaksQuery_SearchingGroupsOfObjects, map.size());

ArrayList<ClassHistogramRecord> suspiciousClasses = new ArrayList<ClassHistogramRecord>();

Expand All @@ -231,15 +237,17 @@ public IResult execute(IProgressListener listener) throws Exception
ClassHistogramRecord chr = new ClassHistogramRecord(cr.name, cr.clsId, cr.objs.toArray(), cr.simple, cr.retained);
suspiciousClasses.add(chr);
}
group.worked(1);
}
group.done();

if (listener.isCanceled())
throw new IProgressListener.OperationCanceledException();

/*
* build the results
*/
final SuspectsResultTable ret = buildResult(suspiciousObjects, suspiciousClasses, totalHeap, compTree, rowmap, listener);
final SuspectsResultTable ret = buildResult(suspiciousObjects, suspiciousClasses, totalHeap, compTree, rowmap, monitor.nextMonitor());

// Indicate some interesting rows
compTree.setSelectionProvider(new ISelectionProvider() {
Expand Down Expand Up @@ -325,6 +333,7 @@ public boolean isExpanded(Object row)
CompositeResult cr = new CompositeResult();
cr.addResult(Messages.FindLeaksQuery2_ComparedDominatorTrees, compTree);
cr.addResult(Messages.FindLeaksQuery2_Leaks, ret);
listener.done();
return cr;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2020 SAP AG and IBM Corporation.
* Copyright (c) 2008, 2023 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 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.eclipse.mat.snapshot.query.Icons;
import org.eclipse.mat.util.IProgressListener;
import org.eclipse.mat.util.MessageUtil;
import org.eclipse.mat.util.SimpleMonitor;

@CommandName("histogram")
@Icon("/META-INF/icons/show_histogram.gif")
Expand Down Expand Up @@ -72,15 +73,26 @@ public String toString()

public IResult execute(IProgressListener listener) throws Exception
{
Histogram histogram = objects == null ? snapshot.getHistogram(listener) //
: snapshot.getHistogram(objects.getIds(listener), listener);
Histogram histogram;
if (objects == null)
{
histogram = snapshot.getHistogram(listener);
}
else
{
SimpleMonitor monitor = new SimpleMonitor(
MessageUtil.format(Messages.HistogramQuery_ProgressName, objects.getLabel()), listener,
new int[] { 100, 200 });
histogram = snapshot.getHistogram(objects.getIds(monitor.nextMonitor()), monitor.nextMonitor());
}

if (listener.isCanceled())
throw new IProgressListener.OperationCanceledException();

if (objects != null)
histogram.setLabel(MessageUtil.format(Messages.HistogramQuery_HistogramOf, objects.getLabel()));

listener.done();
switch (groupBy)
{
case BY_CLASS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.eclipse.mat.snapshot.query.IHeapObjectArgument;
import org.eclipse.mat.snapshot.query.Icons;
import org.eclipse.mat.util.IProgressListener;
import org.eclipse.mat.util.MessageUtil;
import org.eclipse.mat.util.SimpleMonitor;

@CommandName("immediate_dominators")
@Icon("/META-INF/icons/immediate_dominators.gif")
Expand All @@ -56,7 +58,10 @@ public class ImmediateDominatorsQuery implements IQuery

public IResult execute(IProgressListener listener) throws Exception
{
DominatorsSummary summary = snapshot.getDominatorsOf(objects.getIds(listener), skipPattern, listener);
SimpleMonitor monitor = new SimpleMonitor(
MessageUtil.format(Messages.ImmediateDominatorsQuery_ProgressName, objects.getLabel()), listener,
new int[] { 10, 100 });
DominatorsSummary summary = snapshot.getDominatorsOf(objects.getIds(monitor.nextMonitor()), skipPattern, monitor.nextMonitor());

return new ResultImpl(summary);
}
Expand Down

0 comments on commit f6a3983

Please sign in to comment.