Move alltests plugin to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core.tests / stubs / org / eclipse / linuxtools / tmf / tests / stubs / analysis / TestExperimentAnalysis.java
CommitLineData
6a6adab9
GB
1/*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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
13package org.eclipse.linuxtools.tmf.tests.stubs.analysis;
14
2d208fb7
GB
15import java.util.HashSet;
16import java.util.Set;
17
18import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException;
19import org.eclipse.linuxtools.statesystem.core.exceptions.StateValueTypeException;
20import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
21import org.eclipse.linuxtools.statesystem.core.statevalue.TmfStateValue;
22import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
23import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
24import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
25import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
26import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
27import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
6a6adab9
GB
28
29/**
2d208fb7
GB
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}.
6a6adab9
GB
34 *
35 * @author Geneviève Bastien
36 */
2d208fb7
GB
37public class TestExperimentAnalysis extends TmfStateSystemAnalysisModule {
38
39 /**
40 * The quark counting the number of traces
41 */
42 public static final String TRACE_QUARK_NAME = "Traces";
6a6adab9
GB
43
44 @Override
2d208fb7
GB
45 protected ITmfStateProvider createStateProvider() {
46 return new TestExpStateSystemProvider(getTrace());
6a6adab9
GB
47 }
48
49 @Override
2d208fb7
GB
50 protected StateSystemBackendType getBackendType() {
51 return StateSystemBackendType.INMEM;
6a6adab9
GB
52 }
53
2d208fb7
GB
54 private class TestExpStateSystemProvider extends AbstractTmfStateProvider {
55
56 private static final int VERSION = 1;
57 private final Set<ITmfTrace> fTraces = new HashSet<>();
58 private int fCount = 0;
59
60 /**
61 * Constructor
62 *
63 * @param trace
64 * The LTTng 2.0 kernel trace directory
65 */
66 public TestExpStateSystemProvider(ITmfTrace trace) {
67 super(trace, TmfEvent.class, "Stub State System for Experiment");
68 }
69
70 @Override
71 public int getVersion() {
72 return VERSION;
73 }
74
75 @Override
76 public ITmfStateProvider getNewInstance() {
77 return new TestExpStateSystemProvider(this.getTrace());
78 }
79
80 @Override
81 protected void eventHandle(ITmfEvent event) {
82 if (!fTraces.contains(event.getTrace())) {
83 try {
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) {
88
89 }
90 }
91 }
92 }
6a6adab9 93}
This page took 0.037978 seconds and 5 git commands to generate.