import java.util.Map;
import java.util.Map.Entry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.ui.viewers.tree.AbstractTmfTreeViewer;
private static final Format FORMATTER = new SubSecondTimeWithUnitFormat();
- @Nullable
- private TmfAbstractAnalysisModule fModule;
+ private @Nullable TmfAbstractAnalysisModule fModule;
private MenuManager fTablePopupMenuManager;
private static final String[] COLUMN_NAMES = new String[] {
long start = segment.getEntry().getMinSegment().getStart();
long end = segment.getEntry().getMinSegment().getEnd();
broadcast(new TmfSelectionRangeUpdatedSignal(AbstractSegmentStoreStatisticsViewer.this, TmfTimestamp.fromNanos(start), TmfTimestamp.fromNanos(end)));
+ updateContent(start, end, true);
}
};
long start = segment.getEntry().getMaxSegment().getStart();
long end = segment.getEntry().getMaxSegment().getEnd();
broadcast(new TmfSelectionRangeUpdatedSignal(AbstractSegmentStoreStatisticsViewer.this, TmfTimestamp.fromNanos(start), TmfTimestamp.fromNanos(end)));
+ updateContent(start, end, true);
}
};
@Override
protected @Nullable ITmfTreeViewerEntry updateElements(long start, long end, boolean isSelection) {
- if (isSelection || (start == end)) {
- return null;
- }
TmfAbstractAnalysisModule analysisModule = getStatisticsAnalysisModule();
module.waitForCompletion();
TmfTreeViewerEntry root = new TmfTreeViewerEntry(""); //$NON-NLS-1$
- final SegmentStoreStatistics entry = module.getTotalStats();
- if (entry != null) {
+ List<ITmfTreeViewerEntry> entryList = root.getChildren();
- List<ITmfTreeViewerEntry> entryList = root.getChildren();
+ if (isSelection) {
+ setStats(start, end, entryList, module, true, new NullProgressMonitor());
+ }
+ setStats(start, end, entryList, module, false, new NullProgressMonitor());
+ return root;
+ }
+
+ private void setStats(long start, long end, List<ITmfTreeViewerEntry> entryList, AbstractSegmentStatisticsAnalysis module, boolean isSelection, IProgressMonitor monitor) {
+ String label = isSelection ? getSelectionLabel() : getTotalLabel();
+ final SegmentStoreStatistics entry = isSelection ? module.getTotalStatsForRange(start, end, monitor) : module.getTotalStats();
+ if (entry != null) {
- TmfTreeViewerEntry aggregateEntry = new SegmentStoreStatisticsEntry(getTotalLabel(), entry);
- entryList.add(aggregateEntry);
- HiddenTreeViewerEntry category = new HiddenTreeViewerEntry(getTypeLabel());
- aggregateEntry.addChild(category);
+ if (entry.getNbSegments() == 0) {
+ return;
+ }
+ TmfTreeViewerEntry child = new SegmentStoreStatisticsEntry(checkNotNull(label), entry);
+ entryList.add(child);
- Map<String, SegmentStoreStatistics> perSegmentStats = module.getPerSegmentTypeStats();
- if (perSegmentStats != null) {
- for (Entry<String, SegmentStoreStatistics> statsEntry : perSegmentStats.entrySet()) {
- category.addChild(new SegmentStoreStatisticsEntry(statsEntry.getKey(), statsEntry.getValue()));
+ final Map<@NonNull String, @NonNull SegmentStoreStatistics> perTypeStats = isSelection? module.getPerSegmentTypeStatsForRange(start, end, monitor) : module.getPerSegmentTypeStats();
+ if (perTypeStats != null) {
+ for (Entry<@NonNull String, @NonNull SegmentStoreStatistics> statsEntry : perTypeStats.entrySet()) {
+ child.addChild(new SegmentStoreStatisticsEntry(statsEntry.getKey(), statsEntry.getValue()));
}
}
}
- return root;
+ }
+
+ @Override
+ @TmfSignalHandler
+ public void windowRangeUpdated(@Nullable TmfWindowRangeUpdatedSignal signal) {
+ // Do nothing. We do not want to update the view and lose the selection
+ // if the window range is updated with current selection outside of this
+ // new range.
}
/**
return checkNotNull(Messages.AbstractSegmentStoreStatisticsViewer_total);
}
+ /**
+ * Get the selection column label
+ *
+ * @return The selection column label
+ * @since 1.2
+ */
+ protected String getSelectionLabel() {
+ return checkNotNull(Messages.AbstractSegmentStoreStatisticsViewer_selection);
+ }
+
/**
* Class to define a level in the tree that doesn't have any values.
*/