use of org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics in project tracecompass by tracecompass.
the class AbstractSegmentStatisticsAnalysis method calculateTotalPerType.
private Map<@NonNull String, IStatistics<@NonNull ISegment>> calculateTotalPerType(Iterable<ISegment> segments, IProgressMonitor monitor) {
Map<String, IStatistics<ISegment>> perSegmentTypeStats = new HashMap<>();
for (ISegment segment : segments) {
if (monitor.isCanceled()) {
return Collections.emptyMap();
}
String segmentType = getSegmentType(segment);
if (segmentType != null) {
IStatistics<ISegment> values = perSegmentTypeStats.getOrDefault(segmentType, new Statistics<>(getMapper()));
values.update(segment);
perSegmentTypeStats.put(segmentType, values);
}
}
return perSegmentTypeStats;
}
use of org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics in project tracecompass by tracecompass.
the class SegmentStoreStatisticsDataProvider method fetchTree.
@Override
public TmfModelResponse<TmfTreeModel<SegmentStoreStatisticsModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
IAnalysisModule module = fModule;
if (module != null) {
if (monitor != null) {
module.waitForCompletion(monitor);
if (monitor.isCanceled()) {
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
} else {
module.waitForCompletion();
}
}
IStatistics<ISegment> statsTotal = fProvider.getStatsTotal();
if (statsTotal == null) {
return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
}
List<SegmentStoreStatisticsModel> list = new ArrayList<>();
String rootName = getRootEntryName();
if (rootName == null) {
rootName = getTrace().getName();
}
list.add(new SegmentStoreStatisticsModel(fTraceId, -1, getCellLabels(NonNullUtils.nullToEmptyString(rootName), statsTotal), statsTotal));
/*
* Add statistics for full duration.
*/
long totalId = getUniqueId(TOTAL_PREFIX);
list.add(new SegmentStoreStatisticsModel(totalId, fTraceId, getCellLabels(Objects.requireNonNull(Messages.SegmentStoreStatisticsDataProvider_Total), statsTotal), statsTotal));
Map<String, IStatistics<ISegment>> totalStats = fProvider.getStatsPerType();
for (Entry<String, IStatistics<ISegment>> entry : totalStats.entrySet()) {
IStatistics<ISegment> statistics = entry.getValue();
list.add(new SegmentStoreStatisticsModel(getUniqueId(TOTAL_PREFIX + entry.getKey()), totalId, getCellLabels(entry.getKey(), statistics), statistics));
}
/*
* Add statistics for selection if any.
*/
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
Boolean isFiltered = DataProviderParameterUtils.extractIsFiltered(fetchParameters);
if (filter != null && isFiltered != null && isFiltered) {
long start = filter.getStart();
long end = filter.getEnd();
IProgressMonitor nonNullMonitor = monitor != null ? monitor : new NullProgressMonitor();
IStatistics<ISegment> statsForRange = fProvider.getStatsForRange(start, end, nonNullMonitor);
if (statsForRange == null) {
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
long selectionId = getUniqueId(SELECTION_PREFIX);
if (statsForRange.getNbElements() > 0) {
list.add(new SegmentStoreStatisticsModel(selectionId, fTraceId, getCellLabels(Objects.requireNonNull(Messages.SegmentStoreStatisticsDataProvider_Selection), statsForRange), statsForRange));
Map<String, IStatistics<ISegment>> selectionStats = fProvider.getStatsPerTypeForRange(start, end, nonNullMonitor);
for (Entry<String, IStatistics<ISegment>> entry : selectionStats.entrySet()) {
IStatistics<ISegment> statistics = entry.getValue();
list.add(new SegmentStoreStatisticsModel(getUniqueId(SELECTION_PREFIX + entry.getKey()), selectionId, getCellLabels(entry.getKey(), statistics), statistics));
}
}
}
TmfTreeModel.Builder<SegmentStoreStatisticsModel> treeModelBuilder = new TmfTreeModel.Builder();
treeModelBuilder.setColumnDescriptors(getColumnDescriptors());
treeModelBuilder.setEntries(Collections.unmodifiableList(list));
return new TmfModelResponse<>(treeModelBuilder.build(), Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
use of org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics in project tracecompass by tracecompass.
the class AbstractStatsAnalysisTest method testPartialPerTypeStatsCancel.
/**
* Test the cancel operation
*
* @throws TmfAnalysisException
* should not happen
*/
@Test
public void testPartialPerTypeStatsCancel() throws TmfAnalysisException {
TmfXmlTraceStub trace = new TmfXmlTraceStubNs();
StubSegmentStatisticsAnalysis fixture = getValidSegmentStats(trace);
NullProgressMonitor monitor = new NullProgressMonitor();
monitor.setCanceled(true);
Map<@NonNull String, IStatistics<@NonNull ISegment>> perTypeStats = fixture.getStatsPerTypeForRange(100, 1100, monitor);
assertEquals(Collections.emptyMap(), perTypeStats);
trace.dispose();
fixture.dispose();
}
use of org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics in project tracecompass by tracecompass.
the class AbstractStatsAnalysisTest method testPartialPerTypeStats.
/**
* Test the partial per type statistic
*
* @throws TmfAnalysisException
* should not happen
*/
@Test
public void testPartialPerTypeStats() throws TmfAnalysisException {
TmfXmlTraceStub trace = new TmfXmlTraceStubNs();
StubSegmentStatisticsAnalysis fixture = getValidSegmentStats(trace);
Map<@NonNull String, IStatistics<@NonNull ISegment>> perTypeStats = fixture.getStatsPerTypeForRange(100, 1100, new NullProgressMonitor());
assertNotNull(perTypeStats);
// no need to test the content much as it is tested in the other test.
assertEquals(2, perTypeStats.size());
assertEquals(ImmutableSet.<String>of("odd", "even"), perTypeStats.keySet());
IStatistics<@NonNull ISegment> segmentStoreStatistics = perTypeStats.get("even");
assertNotNull(segmentStoreStatistics);
// 526 = 1051/2+1 = see explanation of 1051 in #testPartialStats
assertEquals(526, segmentStoreStatistics.getNbElements());
trace.dispose();
fixture.dispose();
}
use of org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics in project tracecompass by tracecompass.
the class AbstractStatsAnalysisTest method testPerTypeStats.
/**
* Test per-type statistics
*
* @throws TmfAnalysisException
* should not happen
*/
@Test
public void testPerTypeStats() throws TmfAnalysisException {
TmfXmlTraceStub trace = new TmfXmlTraceStubNs();
StubSegmentStatisticsAnalysis fixture = getValidSegmentStats(trace);
Map<@NonNull String, IStatistics<@NonNull ISegment>> perTypeStats = fixture.getStatsPerType();
assertNotNull(perTypeStats);
// no need to test the content much as it is tested in the other test.
assertEquals(2, perTypeStats.size());
assertEquals(ImmutableSet.<String>of("odd", "even"), perTypeStats.keySet());
IStatistics<@NonNull ISegment> segmentStoreStatistics = perTypeStats.get("even");
assertNotNull(segmentStoreStatistics);
// starts with 0 so size + 1
assertEquals(StubSegmentStatisticsAnalysis.SIZE / 2 + 1, segmentStoreStatistics.getNbElements());
trace.dispose();
fixture.dispose();
}
Aggregations