Commit | Line | Data |
---|---|---|
8e364f8e | 1 | /******************************************************************************* |
ed48dc75 | 2 | * Copyright (c) 2013, 2016 Ericsson |
8e364f8e PT |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are made | |
5 | * 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 | * Jean-Christian Kouamé - Initial API and implementation | |
11 | * Patrick Tasse - Updates to mipmap feature | |
12 | *******************************************************************************/ | |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.internal.tmf.core.statesystem.mipmap; |
8e364f8e | 15 | |
d0c7e4ba AM |
16 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
17 | ||
8e364f8e PT |
18 | import java.util.HashMap; |
19 | import java.util.LinkedHashSet; | |
20 | import java.util.Map; | |
21 | import java.util.Set; | |
22 | ||
d0c7e4ba | 23 | import org.eclipse.jdt.annotation.NonNull; |
ee179c51 | 24 | import org.eclipse.tracecompass.internal.tmf.core.Activator; |
d0c7e4ba | 25 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; |
e894a508 AM |
26 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException; |
27 | import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException; | |
28 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; | |
e894a508 | 29 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type; |
e2bcc8a5 | 30 | import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; |
2bdf0193 AM |
31 | import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider; |
32 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
8e364f8e PT |
33 | |
34 | /** | |
35 | * This is an abstract state provider that allows attributes to be mipmapped | |
36 | * for one or more of the supported mipmap features (min, max, average). | |
37 | * | |
38 | * Extend this class for a specific implementation | |
39 | */ | |
40 | public abstract class AbstractTmfMipmapStateProvider extends AbstractTmfStateProvider { | |
41 | ||
42 | /** | |
43 | * Feature bit for the maximum mipmap feature (value is 1<<1). | |
44 | */ | |
45 | public static final int MAX = 1 << 1; | |
46 | ||
47 | /** | |
48 | * Feature bit for the minimum mipmap feature (value is 1<<2). | |
49 | */ | |
50 | public static final int MIN = 1 << 2; | |
51 | ||
52 | /** | |
53 | * Feature bit for the average mipmap feature (value is 1<<3). | |
54 | */ | |
55 | public static final int AVG = 1 << 3; | |
56 | ||
57 | /** | |
58 | * The string for maximum mipmap feature sub-attribute. | |
59 | * This attribute value is the mipmap number of levels. | |
60 | * It has sub-attributes for every level ("1", "2", etc.) | |
61 | */ | |
62 | public static final String MAX_STRING = "max"; //$NON-NLS-1$ | |
63 | ||
64 | /** | |
65 | * The string for minimum mipmap feature sub-attribute. | |
66 | * This attribute value is the mipmap number of levels. | |
67 | * It has sub-attributes for every level ("1", "2", etc.) | |
68 | */ | |
69 | public static final String MIN_STRING = "min"; //$NON-NLS-1$ | |
70 | ||
71 | /** | |
72 | * The string for average mipmap feature sub-attribute. | |
73 | * This attribute value is the mipmap number of levels. | |
74 | * It has sub-attributes for every level ("1", "2", etc.) | |
75 | */ | |
76 | public static final String AVG_STRING = "avg"; //$NON-NLS-1$ | |
77 | ||
78 | /** | |
79 | * Map of mipmap features per attribute. The map's key is the base attribute quark. | |
80 | */ | |
a4524c1b | 81 | private Map<Integer, Set<ITmfMipmapFeature>> featureMap = new HashMap<>(); |
8e364f8e PT |
82 | |
83 | // ------------------------------------------------------------------------ | |
84 | // Constructor | |
85 | // ------------------------------------------------------------------------ | |
86 | ||
87 | /** | |
88 | * Constructor | |
89 | * | |
90 | * @param trace | |
91 | * The trace directory | |
8e364f8e PT |
92 | * @param id |
93 | * The name given to this state change input. Only used | |
94 | * internally. | |
95 | */ | |
d0c7e4ba | 96 | public AbstractTmfMipmapStateProvider(@NonNull ITmfTrace trace, |
d0c7e4ba | 97 | @NonNull String id) { |
e2bcc8a5 | 98 | super(trace, id); |
8e364f8e PT |
99 | } |
100 | ||
101 | // ------------------------------------------------------------------------ | |
102 | // Public methods | |
103 | // ------------------------------------------------------------------------ | |
104 | ||
105 | @Override | |
106 | public void dispose() { | |
107 | waitForEmptyQueue(); | |
108 | for (Set<ITmfMipmapFeature> features : featureMap.values()) { | |
109 | for (ITmfMipmapFeature feature : features) { | |
110 | feature.updateAndCloseMipmap(); | |
111 | } | |
112 | } | |
113 | super.dispose(); | |
114 | } | |
115 | ||
116 | /** | |
117 | * Modify a mipmap attribute. The base attribute is modified and the mipmap | |
118 | * attributes for the feature(s) specified in the mipmap feature bitmap are | |
119 | * created and/or updated.<br> | |
120 | * Note: The mipmapFeatureBits and resolution are only used on the first | |
121 | * call of this method for a particular attribute, and the mipmap features | |
122 | * for this attribute are then activated until the end of the trace.<br> | |
123 | * Note: The base attribute should only be modified by calling this method. | |
124 | * | |
125 | * @param ts | |
126 | * The timestamp of the event | |
127 | * @param value | |
128 | * The value of the base attribute | |
129 | * @param baseQuark | |
130 | * The quark of the base attribute | |
131 | * @param mipmapFeatureBits | |
132 | * The mipmap feature bit(s) | |
133 | * @param resolution | |
134 | * The mipmap resolution (must be greater than 1) | |
135 | * @throws TimeRangeException | |
136 | * If the requested time is outside of the trace's range | |
8e364f8e PT |
137 | * @throws StateValueTypeException |
138 | * If the inserted state value's type does not match what is | |
139 | * already assigned to this attribute. | |
140 | * @see #MAX | |
141 | * @see #MIN | |
142 | * @see #AVG | |
143 | */ | |
144 | public void modifyMipmapAttribute(long ts, ITmfStateValue value, int baseQuark, int mipmapFeatureBits, int resolution) | |
ed48dc75 | 145 | throws TimeRangeException, StateValueTypeException { |
d0c7e4ba | 146 | ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder()); |
8e364f8e PT |
147 | ss.modifyAttribute(ts, value, baseQuark); |
148 | if (value.getType() == Type.LONG || value.getType() == Type.INTEGER || value.getType() == Type.DOUBLE || value.isNull()) { | |
149 | Set<ITmfMipmapFeature> features = getFeatureSet(baseQuark, ts, value, mipmapFeatureBits, resolution); | |
150 | for (ITmfMipmapFeature mf : features) { | |
151 | mf.updateMipmap(value, ts); | |
152 | } | |
153 | } | |
154 | } | |
155 | ||
156 | // ------------------------------------------------------------------------ | |
157 | // Private methods | |
158 | // ------------------------------------------------------------------------ | |
159 | ||
160 | private Set<ITmfMipmapFeature> getFeatureSet(int baseQuark, long ts, ITmfStateValue value, int mipmapFeatureBits, int resolution) { | |
d0c7e4ba AM |
161 | ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder()); |
162 | ||
8e364f8e PT |
163 | Set<ITmfMipmapFeature> features = featureMap.get(baseQuark); |
164 | if (features != null) { | |
165 | return features; | |
166 | } | |
a4524c1b | 167 | features = new LinkedHashSet<>(); |
8e364f8e PT |
168 | if (value.isNull()) { |
169 | return features; | |
170 | } | |
171 | featureMap.put(baseQuark, features); | |
172 | if (resolution > 1) { | |
173 | try { | |
174 | if ((mipmapFeatureBits & MAX) != 0) { | |
175 | int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, MAX_STRING); | |
176 | ss.modifyAttribute(ts, TmfStateValue.newValueInt(0), featureQuark); | |
177 | MaxMipmapFeature mf = new MaxMipmapFeature(baseQuark, featureQuark, resolution, ss); | |
178 | features.add(mf); | |
179 | } | |
180 | if ((mipmapFeatureBits & MIN) != 0) { | |
181 | int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, MIN_STRING); | |
182 | ss.modifyAttribute(ts, TmfStateValue.newValueInt(0), featureQuark); | |
183 | MinMipmapFeature mf = new MinMipmapFeature(baseQuark, featureQuark, resolution, ss); | |
184 | features.add(mf); | |
185 | } | |
186 | if ((mipmapFeatureBits & AVG) != 0) { | |
187 | int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, AVG_STRING); | |
188 | ss.modifyAttribute(ts, TmfStateValue.newValueInt(0), featureQuark); | |
189 | AvgMipmapFeature mf = new AvgMipmapFeature(baseQuark, featureQuark, resolution, ss); | |
190 | features.add(mf); | |
191 | } | |
192 | } catch (TimeRangeException e) { | |
ee179c51 | 193 | Activator.logError("MipMapProvider : Time stamp outside of time range of state system", e); //$NON-NLS-1$ |
8e364f8e | 194 | } catch (StateValueTypeException e) { |
ee179c51 | 195 | Activator.logError("MipMapProvider : Wrong state value type", e); //$NON-NLS-1$ |
8e364f8e PT |
196 | } |
197 | } | |
198 | return features; | |
199 | } | |
200 | } |