Search in sources :

Example 1 with IStatistics

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;
}
Also used : HashMap(java.util.HashMap) IStatistics(org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment)

Example 2 with IStatistics

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);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SegmentStoreStatisticsModel(org.eclipse.tracecompass.analysis.timing.core.segmentstore.SegmentStoreStatisticsModel) ArrayList(java.util.ArrayList) IStatistics(org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) FilterTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.FilterTimeQueryFilter) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)

Example 3 with IStatistics

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();
}
Also used : TmfXmlTraceStubNs(org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStubNs) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TmfXmlTraceStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub) NonNull(org.eclipse.jdt.annotation.NonNull) IStatistics(org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics) Test(org.junit.Test)

Example 4 with IStatistics

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();
}
Also used : TmfXmlTraceStubNs(org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStubNs) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TmfXmlTraceStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub) NonNull(org.eclipse.jdt.annotation.NonNull) IStatistics(org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) Test(org.junit.Test)

Example 5 with IStatistics

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();
}
Also used : TmfXmlTraceStubNs(org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStubNs) TmfXmlTraceStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub) NonNull(org.eclipse.jdt.annotation.NonNull) IStatistics(org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) Test(org.junit.Test)

Aggregations

IStatistics (org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics)5 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 NonNull (org.eclipse.jdt.annotation.NonNull)3 TmfXmlTraceStub (org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub)3 TmfXmlTraceStubNs (org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStubNs)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SegmentStoreStatisticsModel (org.eclipse.tracecompass.analysis.timing.core.segmentstore.SegmentStoreStatisticsModel)1 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)1 FilterTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.FilterTimeQueryFilter)1 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)1 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)1 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)1