1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
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
10 * Jean-Christian Kouamé - Initial API and implementation
11 * Patrick Tasse - Updates to mipmap feature
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.tmf
.core
.statesystem
.mipmap
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
18 import java
.util
.HashMap
;
19 import java
.util
.LinkedHashSet
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.Activator
;
25 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystemBuilder
;
26 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
27 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
28 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
29 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
30 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
.Type
;
31 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
36 * This is an abstract state provider that allows attributes to be mipmapped
37 * for one or more of the supported mipmap features (min, max, average).
39 * Extend this class for a specific implementation
41 public abstract class AbstractTmfMipmapStateProvider
extends AbstractTmfStateProvider
{
44 * Feature bit for the maximum mipmap feature (value is 1<<1).
46 public static final int MAX
= 1 << 1;
49 * Feature bit for the minimum mipmap feature (value is 1<<2).
51 public static final int MIN
= 1 << 2;
54 * Feature bit for the average mipmap feature (value is 1<<3).
56 public static final int AVG
= 1 << 3;
59 * The string for maximum mipmap feature sub-attribute.
60 * This attribute value is the mipmap number of levels.
61 * It has sub-attributes for every level ("1", "2", etc.)
63 public static final String MAX_STRING
= "max"; //$NON-NLS-1$
66 * The string for minimum mipmap feature sub-attribute.
67 * This attribute value is the mipmap number of levels.
68 * It has sub-attributes for every level ("1", "2", etc.)
70 public static final String MIN_STRING
= "min"; //$NON-NLS-1$
73 * The string for average mipmap feature sub-attribute.
74 * This attribute value is the mipmap number of levels.
75 * It has sub-attributes for every level ("1", "2", etc.)
77 public static final String AVG_STRING
= "avg"; //$NON-NLS-1$
80 * Map of mipmap features per attribute. The map's key is the base attribute quark.
82 private Map
<Integer
, Set
<ITmfMipmapFeature
>> featureMap
= new HashMap
<>();
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
94 * The name given to this state change input. Only used
97 public AbstractTmfMipmapStateProvider(@NonNull ITmfTrace trace
,
102 // ------------------------------------------------------------------------
104 // ------------------------------------------------------------------------
107 public void dispose() {
109 for (Set
<ITmfMipmapFeature
> features
: featureMap
.values()) {
110 for (ITmfMipmapFeature feature
: features
) {
111 feature
.updateAndCloseMipmap();
118 * Modify a mipmap attribute. The base attribute is modified and the mipmap
119 * attributes for the feature(s) specified in the mipmap feature bitmap are
120 * created and/or updated.<br>
121 * Note: The mipmapFeatureBits and resolution are only used on the first
122 * call of this method for a particular attribute, and the mipmap features
123 * for this attribute are then activated until the end of the trace.<br>
124 * Note: The base attribute should only be modified by calling this method.
127 * The timestamp of the event
129 * The value of the base attribute
131 * The quark of the base attribute
132 * @param mipmapFeatureBits
133 * The mipmap feature bit(s)
135 * The mipmap resolution (must be greater than 1)
136 * @throws TimeRangeException
137 * If the requested time is outside of the trace's range
138 * @throws AttributeNotFoundException
139 * If the requested attribute quark is invalid
140 * @throws StateValueTypeException
141 * If the inserted state value's type does not match what is
142 * already assigned to this attribute.
147 public void modifyMipmapAttribute(long ts
, ITmfStateValue value
, int baseQuark
, int mipmapFeatureBits
, int resolution
)
148 throws TimeRangeException
, AttributeNotFoundException
, StateValueTypeException
{
149 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
150 ss
.modifyAttribute(ts
, value
, baseQuark
);
151 if (value
.getType() == Type
.LONG
|| value
.getType() == Type
.INTEGER
|| value
.getType() == Type
.DOUBLE
|| value
.isNull()) {
152 Set
<ITmfMipmapFeature
> features
= getFeatureSet(baseQuark
, ts
, value
, mipmapFeatureBits
, resolution
);
153 for (ITmfMipmapFeature mf
: features
) {
154 mf
.updateMipmap(value
, ts
);
159 // ------------------------------------------------------------------------
161 // ------------------------------------------------------------------------
163 private Set
<ITmfMipmapFeature
> getFeatureSet(int baseQuark
, long ts
, ITmfStateValue value
, int mipmapFeatureBits
, int resolution
) {
164 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
166 Set
<ITmfMipmapFeature
> features
= featureMap
.get(baseQuark
);
167 if (features
!= null) {
170 features
= new LinkedHashSet
<>();
171 if (value
.isNull()) {
174 featureMap
.put(baseQuark
, features
);
175 if (resolution
> 1) {
177 if ((mipmapFeatureBits
& MAX
) != 0) {
178 int featureQuark
= ss
.getQuarkRelativeAndAdd(baseQuark
, MAX_STRING
);
179 ss
.modifyAttribute(ts
, TmfStateValue
.newValueInt(0), featureQuark
);
180 MaxMipmapFeature mf
= new MaxMipmapFeature(baseQuark
, featureQuark
, resolution
, ss
);
183 if ((mipmapFeatureBits
& MIN
) != 0) {
184 int featureQuark
= ss
.getQuarkRelativeAndAdd(baseQuark
, MIN_STRING
);
185 ss
.modifyAttribute(ts
, TmfStateValue
.newValueInt(0), featureQuark
);
186 MinMipmapFeature mf
= new MinMipmapFeature(baseQuark
, featureQuark
, resolution
, ss
);
189 if ((mipmapFeatureBits
& AVG
) != 0) {
190 int featureQuark
= ss
.getQuarkRelativeAndAdd(baseQuark
, AVG_STRING
);
191 ss
.modifyAttribute(ts
, TmfStateValue
.newValueInt(0), featureQuark
);
192 AvgMipmapFeature mf
= new AvgMipmapFeature(baseQuark
, featureQuark
, resolution
, ss
);
195 } catch (TimeRangeException e
) {
196 Activator
.logError("MipMapProvider : Time stamp outside of time range of state system", e
); //$NON-NLS-1$
197 } catch (AttributeNotFoundException e
) {
198 Activator
.logError("MipMapProvider : Attribute not found", e
); //$NON-NLS-1$
199 } catch (StateValueTypeException e
) {
200 Activator
.logError("MipMapProvider : Wrong state value type", e
); //$NON-NLS-1$