1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.analysis
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import java
.util
.HashSet
;
20 import org
.eclipse
.jdt
.annotation
.NonNull
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystemBuilder
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
25 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfStateProvider
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
33 * Stubs for experiment analysis. This analysis is a state system analysis that
34 * simply counts the number of traces for which events were received. The number
35 * of traces is the value of attribute
36 * {@link TestExperimentAnalysis#TRACE_QUARK_NAME}.
38 * @author Geneviève Bastien
40 public class TestExperimentAnalysis
extends TmfStateSystemAnalysisModule
{
43 * The quark counting the number of traces
45 public static final String TRACE_QUARK_NAME
= "Traces";
48 protected ITmfStateProvider
createStateProvider() {
49 return new TestExpStateSystemProvider(checkNotNull(getTrace()));
53 protected StateSystemBackendType
getBackendType() {
54 return StateSystemBackendType
.INMEM
;
57 private class TestExpStateSystemProvider
extends AbstractTmfStateProvider
{
59 private static final int VERSION
= 1;
60 private final Set
<ITmfTrace
> fTraces
= new HashSet
<>();
61 private int fCount
= 0;
67 * The LTTng 2.0 kernel trace directory
69 public TestExpStateSystemProvider(@NonNull ITmfTrace trace
) {
70 super(trace
, "Stub State System for Experiment");
74 public int getVersion() {
79 public ITmfStateProvider
getNewInstance() {
80 return new TestExpStateSystemProvider(this.getTrace());
84 protected void eventHandle(ITmfEvent event
) {
85 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
86 if (!fTraces
.contains(event
.getTrace())) {
88 int quarkId
= ss
.getQuarkAbsoluteAndAdd(TRACE_QUARK_NAME
);
89 ss
.modifyAttribute(event
.getTimestamp().getValue(), TmfStateValue
.newValueInt(++fCount
), quarkId
);
90 fTraces
.add(event
.getTrace());
91 } catch (TimeRangeException
| AttributeNotFoundException
| StateValueTypeException e
) {