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