use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.
the class AbstractStatsAnalysisTest method testPartialStats.
/**
* Test the partial statistics
*
* @throws TmfAnalysisException
* should not happen
*/
@Test
public void testPartialStats() throws TmfAnalysisException {
TmfXmlTraceStub trace = new TmfXmlTraceStubNs();
StubSegmentStatisticsAnalysis fixture = getValidSegmentStats(trace);
IStatistics<@NonNull ISegment> totalStats = fixture.getStatsForRange(100, 1100, new NullProgressMonitor());
assertNotNull(totalStats);
// no need to test the content much as it is tested in the other test.
// 1051 = 1001 where start is between start and end + 50 overlapping
// start
assertEquals(1051, totalStats.getNbElements());
trace.dispose();
fixture.dispose();
}
use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.
the class AbstractSegmentStoreAnalysisModule method executeAnalysis.
@Override
protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException {
SegmentStoreType type = getSegmentStoreType();
ISegmentStore<ISegment> store = null;
switch(type) {
case Distinct:
// Fall-through
case Fast:
// Fall-through
case Stable:
store = buildInMemorySegmentStore(type, monitor);
break;
case OnDisk:
@Nullable final String dataFileName = getDataFileName();
store = buildOnDiskSegmentStore(dataFileName, monitor);
break;
default:
// $NON-NLS-1$
Activator.getInstance().logError("Unknown segment store type: " + type);
break;
}
if (store == null) {
return false;
}
fSegmentStore = store;
sendUpdate(store);
return true;
}
use of org.eclipse.tracecompass.segmentstore.core.ISegment 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.segmentstore.core.ISegment in project tracecompass by tracecompass.
the class AbstractSegmentStatisticsAnalysis method getSegmentStore.
/**
* Get the segment store from which we want the statistics
*
* @return The segment store
*/
@Nullable
private Iterable<@NonNull ISegment> getSegmentStore(long start, long end) {
ISegmentStoreProvider segmentStoreProviderModule = fSegmentStoreProviderModule;
if (segmentStoreProviderModule == null) {
return null;
}
if (segmentStoreProviderModule instanceof IAnalysisModule) {
((IAnalysisModule) segmentStoreProviderModule).waitForCompletion();
}
long t0 = Long.min(start, end);
long t1 = Long.max(start, end);
ISegmentStore<@NonNull ISegment> segmentStore = segmentStoreProviderModule.getSegmentStore();
return segmentStore != null ? isEternity(t0, t1) ? segmentStore : segmentStore.getIntersectingElements(t0, t1) : Collections.emptyList();
}
use of org.eclipse.tracecompass.segmentstore.core.ISegment 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);
}
Aggregations