1 /*******************************************************************************
2 * Copyright (c) 2014 É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 java
.util
.HashSet
;
18 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
19 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
20 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfStateProvider
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
30 * Stubs for experiment analysis. This analysis is a state system analysis that
31 * simply counts the number of traces for which events were received. The number
32 * of traces is the value of attribute
33 * {@link TestExperimentAnalysis#TRACE_QUARK_NAME}.
35 * @author Geneviève Bastien
37 public class TestExperimentAnalysis
extends TmfStateSystemAnalysisModule
{
40 * The quark counting the number of traces
42 public static final String TRACE_QUARK_NAME
= "Traces";
45 protected ITmfStateProvider
createStateProvider() {
46 return new TestExpStateSystemProvider(getTrace());
50 protected StateSystemBackendType
getBackendType() {
51 return StateSystemBackendType
.INMEM
;
54 private class TestExpStateSystemProvider
extends AbstractTmfStateProvider
{
56 private static final int VERSION
= 1;
57 private final Set
<ITmfTrace
> fTraces
= new HashSet
<>();
58 private int fCount
= 0;
64 * The LTTng 2.0 kernel trace directory
66 public TestExpStateSystemProvider(ITmfTrace trace
) {
67 super(trace
, TmfEvent
.class, "Stub State System for Experiment");
71 public int getVersion() {
76 public ITmfStateProvider
getNewInstance() {
77 return new TestExpStateSystemProvider(this.getTrace());
81 protected void eventHandle(ITmfEvent event
) {
82 if (!fTraces
.contains(event
.getTrace())) {
84 int quarkId
= ss
.getQuarkAbsoluteAndAdd(TRACE_QUARK_NAME
);
85 ss
.modifyAttribute(event
.getTimestamp().getValue(), TmfStateValue
.newValueInt(++fCount
), quarkId
);
86 fTraces
.add(event
.getTrace());
87 } catch (TimeRangeException
| AttributeNotFoundException
| StateValueTypeException e
) {