1 /*******************************************************************************
2 * Copyright (c) 2013 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.core
.statesystem
.mipmap
;
15 import java
.util
.List
;
17 import org
.eclipse
.linuxtools
.statesystem
.core
.ITmfStateSystemBuilder
;
18 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.StateValueTypeException
;
19 import org
.eclipse
.linuxtools
.statesystem
.core
.interval
.ITmfStateInterval
;
20 import org
.eclipse
.linuxtools
.statesystem
.core
.statevalue
.ITmfStateValue
;
21 import org
.eclipse
.linuxtools
.statesystem
.core
.statevalue
.TmfStateValue
;
22 import org
.eclipse
.linuxtools
.statesystem
.core
.statevalue
.ITmfStateValue
.Type
;
25 * The average mipmap feature.
27 * Each mipmap state value is the weighted average by time duration of all the
28 * lower-level state values it covers. Null state values count as zero in the
29 * weighted average. The state value is a Double.
31 public class AvgMipmapFeature
extends TmfMipmapFeature
{
37 * The quark for the attribute we want to mipmap
39 * The quark of the mipmap feature attribute
40 * @param mipmapResolution
41 * The resolution that will be use in the mipmap
43 * The state system in which to insert the state changes
45 public AvgMipmapFeature(final int baseQuark
, final int mipmapQuark
, final int mipmapResolution
, final ITmfStateSystemBuilder ss
) {
46 super(baseQuark
, mipmapQuark
, mipmapResolution
, ss
);
50 protected ITmfStateValue
computeMipmapValue(List
<ITmfStateInterval
> lowerIntervals
, long startTime
, long endTime
) {
51 long range
= endTime
- startTime
;
53 return TmfStateValue
.newValueDouble(0.0);
57 for (ITmfStateInterval interval
: lowerIntervals
) {
58 ITmfStateValue value
= interval
.getStateValue();
59 long duration
= interval
.getEndTime() - interval
.getStartTime();
60 if (value
.getType() == Type
.DOUBLE
) {
61 sum
+= value
.unboxDouble() * duration
;
63 sum
+= (double) value
.unboxLong() * duration
;
66 } catch (StateValueTypeException e
) {
69 double average
= sum
/ range
;
70 ITmfStateValue avgValue
= TmfStateValue
.newValueDouble(average
);