tmf: Do not define base aspects in the interface
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / stubs / org / eclipse / tracecompass / tmf / tests / stubs / analysis / TestExperimentAnalysis.java
CommitLineData
6a6adab9 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2014, 2015 École Polytechnique de Montréal
6a6adab9
GB
3 *
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 *
9 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
2bdf0193 13package org.eclipse.tracecompass.tmf.tests.stubs.analysis;
6a6adab9 14
d0c7e4ba
AM
15import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
2d208fb7
GB
17import java.util.HashSet;
18import java.util.Set;
19
d0c7e4ba
AM
20import org.eclipse.jdt.annotation.NonNull;
21import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
e894a508
AM
22import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
23import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
24import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
25import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
2bdf0193 26import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
2bdf0193
AM
27import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
28import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
29import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
30import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
6a6adab9
GB
31
32/**
2d208fb7
GB
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}.
6a6adab9
GB
37 *
38 * @author Geneviève Bastien
39 */
2d208fb7
GB
40public class TestExperimentAnalysis extends TmfStateSystemAnalysisModule {
41
42 /**
43 * The quark counting the number of traces
44 */
45 public static final String TRACE_QUARK_NAME = "Traces";
6a6adab9
GB
46
47 @Override
2d208fb7 48 protected ITmfStateProvider createStateProvider() {
d0c7e4ba 49 return new TestExpStateSystemProvider(checkNotNull(getTrace()));
6a6adab9
GB
50 }
51
52 @Override
2d208fb7
GB
53 protected StateSystemBackendType getBackendType() {
54 return StateSystemBackendType.INMEM;
6a6adab9
GB
55 }
56
2d208fb7
GB
57 private class TestExpStateSystemProvider extends AbstractTmfStateProvider {
58
59 private static final int VERSION = 1;
60 private final Set<ITmfTrace> fTraces = new HashSet<>();
61 private int fCount = 0;
62
63 /**
64 * Constructor
65 *
66 * @param trace
67 * The LTTng 2.0 kernel trace directory
68 */
d0c7e4ba 69 public TestExpStateSystemProvider(@NonNull ITmfTrace trace) {
e2bcc8a5 70 super(trace, "Stub State System for Experiment");
2d208fb7
GB
71 }
72
73 @Override
74 public int getVersion() {
75 return VERSION;
76 }
77
78 @Override
79 public ITmfStateProvider getNewInstance() {
80 return new TestExpStateSystemProvider(this.getTrace());
81 }
82
83 @Override
84 protected void eventHandle(ITmfEvent event) {
d0c7e4ba 85 ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
2d208fb7
GB
86 if (!fTraces.contains(event.getTrace())) {
87 try {
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) {
92
93 }
94 }
95 }
96 }
6a6adab9 97}
This page took 0.073918 seconds and 5 git commands to generate.