1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.timing
.core
.tests
.segmentstore
.statistics
;
12 import java
.util
.Collections
;
13 import java
.util
.List
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.jdt
.annotation
.NonNull
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.analysis
.timing
.core
.segmentstore
.IAnalysisProgressListener
;
19 import org
.eclipse
.tracecompass
.analysis
.timing
.core
.segmentstore
.ISegmentStoreProvider
;
20 import org
.eclipse
.tracecompass
.analysis
.timing
.core
.segmentstore
.statistics
.AbstractSegmentStatisticsAnalysis
;
21 import org
.eclipse
.tracecompass
.segmentstore
.core
.BasicSegment
;
22 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
23 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegmentStore
;
24 import org
.eclipse
.tracecompass
.segmentstore
.core
.SegmentStoreFactory
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.segment
.ISegmentAspect
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
29 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.analysis
.TestAnalysis
;
30 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.xml
.TmfXmlTraceStub
;
32 import com
.google
.common
.collect
.ImmutableList
;
33 import com
.google
.common
.collect
.ImmutableList
.Builder
;
36 * Test stuf for statistics analysis
38 * @author Matthew Khouzam
41 class StubSegmentStatisticsAnalysis
extends AbstractSegmentStatisticsAnalysis
{
43 private final class StubProvider
extends TestAnalysis
implements ISegmentStoreProvider
{
44 private final ISegmentStore
<@NonNull ISegment
> ifFixture
;
46 public StubProvider(ISegmentStore
<@NonNull ISegment
> fixture
) {
51 public void removeListener(@NonNull IAnalysisProgressListener listener
) {
56 public @Nullable ISegmentStore
<@NonNull ISegment
> getSegmentStore() {
61 public @NonNull Iterable
<@NonNull ISegmentAspect
> getSegmentAspects() {
62 return Collections
.emptyList();
66 public void addListener(@NonNull IAnalysisProgressListener listener
) {
71 public static final int SIZE
= 65535;
73 private final List
<@NonNull ISegment
> fPreFixture
;
74 private final ISegmentStore
<@NonNull ISegment
> fFixture
= SegmentStoreFactory
.createSegmentStore();
75 private StubProvider fSegmentStoreProvider
;
77 public StubSegmentStatisticsAnalysis() {
78 ImmutableList
.Builder
<@NonNull ISegment
> builder
= new Builder
<>();
79 for (int i
= 0; i
< SIZE
; i
++) {
80 ISegment seg
= new BasicSegment(i
, i
+ i
);
83 fPreFixture
= builder
.build();
84 fFixture
.addAll(fPreFixture
);
85 fSegmentStoreProvider
= new StubProvider(fFixture
);
89 public boolean setTrace(@NonNull ITmfTrace trace
) throws TmfAnalysisException
{
90 if (trace
instanceof TmfXmlTraceStub
) {
91 TmfXmlTraceStub tmfXmlTraceStub
= (TmfXmlTraceStub
) trace
;
92 tmfXmlTraceStub
.addAnalysisModule(this);
93 tmfXmlTraceStub
.addAnalysisModule(fSegmentStoreProvider
);
96 return super.setTrace(trace
);
99 protected @Nullable String
getSegmentType(@NonNull ISegment segment
) {
100 return segment
.getLength() % 2 == 0 ?
"even" : "odd";
104 protected @Nullable ISegmentStoreProvider
getSegmentProviderAnalysis(@NonNull ITmfTrace trace
) {
105 return fSegmentStoreProvider
;
110 public boolean executeAnalysis(@NonNull IProgressMonitor monitor
) throws TmfAnalysisException
{
111 return super.executeAnalysis(monitor
);
116 public @NonNull Iterable
<@NonNull IAnalysisModule
> getDependentAnalyses() {
117 return super.getDependentAnalyses();