1 /*******************************************************************************
2 * Copyright (c) 2013, 2016 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
.StateValueTypeException
;
27 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
28 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
29 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
.Type
;
30 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
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).
38 * Extend this class for a specific implementation
40 public abstract class AbstractTmfMipmapStateProvider
extends AbstractTmfStateProvider
{
43 * Feature bit for the maximum mipmap feature (value is 1<<1).
45 public static final int MAX
= 1 << 1;
48 * Feature bit for the minimum mipmap feature (value is 1<<2).
50 public static final int MIN
= 1 << 2;
53 * Feature bit for the average mipmap feature (value is 1<<3).
55 public static final int AVG
= 1 << 3;
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.)
62 public static final String MAX_STRING
= "max"; //$NON-NLS-1$
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.)
69 public static final String MIN_STRING
= "min"; //$NON-NLS-1$
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.)
76 public static final String AVG_STRING
= "avg"; //$NON-NLS-1$
79 * Map of mipmap features per attribute. The map's key is the base attribute quark.
81 private Map
<Integer
, Set
<ITmfMipmapFeature
>> featureMap
= new HashMap
<>();
83 // ------------------------------------------------------------------------
85 // ------------------------------------------------------------------------
93 * The name given to this state change input. Only used
96 public AbstractTmfMipmapStateProvider(@NonNull ITmfTrace trace
,
101 // ------------------------------------------------------------------------
103 // ------------------------------------------------------------------------
106 public void dispose() {
108 for (Set
<ITmfMipmapFeature
> features
: featureMap
.values()) {
109 for (ITmfMipmapFeature feature
: features
) {
110 feature
.updateAndCloseMipmap();
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.
126 * The timestamp of the event
128 * The value of the base attribute
130 * The quark of the base attribute
131 * @param mipmapFeatureBits
132 * The mipmap feature bit(s)
134 * The mipmap resolution (must be greater than 1)
135 * @throws TimeRangeException
136 * If the requested time is outside of the trace's range
137 * @throws StateValueTypeException
138 * If the inserted state value's type does not match what is
139 * already assigned to this attribute.
144 public void modifyMipmapAttribute(long ts
, ITmfStateValue value
, int baseQuark
, int mipmapFeatureBits
, int resolution
)
145 throws TimeRangeException
, StateValueTypeException
{
146 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
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
);
156 // ------------------------------------------------------------------------
158 // ------------------------------------------------------------------------
160 private Set
<ITmfMipmapFeature
> getFeatureSet(int baseQuark
, long ts
, ITmfStateValue value
, int mipmapFeatureBits
, int resolution
) {
161 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
163 Set
<ITmfMipmapFeature
> features
= featureMap
.get(baseQuark
);
164 if (features
!= null) {
167 features
= new LinkedHashSet
<>();
168 if (value
.isNull()) {
171 featureMap
.put(baseQuark
, features
);
172 if (resolution
> 1) {
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
);
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
);
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
);
192 } catch (TimeRangeException e
) {
193 Activator
.logError("MipMapProvider : Time stamp outside of time range of state system", e
); //$NON-NLS-1$
194 } catch (StateValueTypeException e
) {
195 Activator
.logError("MipMapProvider : Wrong state value type", e
); //$NON-NLS-1$