Commit | Line | Data |
---|---|---|
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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.tests.stubs.analysis; |
6a6adab9 | 14 | |
d0c7e4ba AM |
15 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
16 | ||
2d208fb7 GB |
17 | import java.util.HashSet; |
18 | import java.util.Set; | |
19 | ||
d0c7e4ba AM |
20 | import org.eclipse.jdt.annotation.NonNull; |
21 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; | |
e894a508 AM |
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; | |
2bdf0193 AM |
26 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
27 | import org.eclipse.tracecompass.tmf.core.event.TmfEvent; | |
28 | import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider; | |
29 | import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider; | |
30 | import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule; | |
31 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
6a6adab9 GB |
32 | |
33 | /** | |
2d208fb7 GB |
34 | * Stubs for experiment analysis. This analysis is a state system analysis that |
35 | * simply counts the number of traces for which events were received. The number | |
36 | * of traces is the value of attribute | |
37 | * {@link TestExperimentAnalysis#TRACE_QUARK_NAME}. | |
6a6adab9 GB |
38 | * |
39 | * @author Geneviève Bastien | |
40 | */ | |
2d208fb7 GB |
41 | public class TestExperimentAnalysis extends TmfStateSystemAnalysisModule { |
42 | ||
43 | /** | |
44 | * The quark counting the number of traces | |
45 | */ | |
46 | public static final String TRACE_QUARK_NAME = "Traces"; | |
6a6adab9 GB |
47 | |
48 | @Override | |
2d208fb7 | 49 | protected ITmfStateProvider createStateProvider() { |
d0c7e4ba | 50 | return new TestExpStateSystemProvider(checkNotNull(getTrace())); |
6a6adab9 GB |
51 | } |
52 | ||
53 | @Override | |
2d208fb7 GB |
54 | protected StateSystemBackendType getBackendType() { |
55 | return StateSystemBackendType.INMEM; | |
6a6adab9 GB |
56 | } |
57 | ||
2d208fb7 GB |
58 | private class TestExpStateSystemProvider extends AbstractTmfStateProvider { |
59 | ||
60 | private static final int VERSION = 1; | |
61 | private final Set<ITmfTrace> fTraces = new HashSet<>(); | |
62 | private int fCount = 0; | |
63 | ||
64 | /** | |
65 | * Constructor | |
66 | * | |
67 | * @param trace | |
68 | * The LTTng 2.0 kernel trace directory | |
69 | */ | |
d0c7e4ba | 70 | public TestExpStateSystemProvider(@NonNull ITmfTrace trace) { |
2d208fb7 GB |
71 | super(trace, TmfEvent.class, "Stub State System for Experiment"); |
72 | } | |
73 | ||
74 | @Override | |
75 | public int getVersion() { | |
76 | return VERSION; | |
77 | } | |
78 | ||
79 | @Override | |
80 | public ITmfStateProvider getNewInstance() { | |
81 | return new TestExpStateSystemProvider(this.getTrace()); | |
82 | } | |
83 | ||
84 | @Override | |
85 | protected void eventHandle(ITmfEvent event) { | |
d0c7e4ba | 86 | ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder()); |
2d208fb7 GB |
87 | if (!fTraces.contains(event.getTrace())) { |
88 | try { | |
89 | int quarkId = ss.getQuarkAbsoluteAndAdd(TRACE_QUARK_NAME); | |
90 | ss.modifyAttribute(event.getTimestamp().getValue(), TmfStateValue.newValueInt(++fCount), quarkId); | |
91 | fTraces.add(event.getTrace()); | |
92 | } catch (TimeRangeException | AttributeNotFoundException | StateValueTypeException e) { | |
93 | ||
94 | } | |
95 | } | |
96 | } | |
97 | } | |
6a6adab9 | 98 | } |