Commit | Line | Data |
---|---|---|
8e364f8e PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 Ericsson | |
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 | *******************************************************************************/ | |
2bdf0193 | 13 | package org.eclipse.tracecompass.internal.tmf.core.statesystem.mipmap; |
8e364f8e PT |
14 | |
15 | import java.util.List; | |
16 | ||
e894a508 AM |
17 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; |
18 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException; | |
19 | import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; | |
20 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; | |
21 | import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; | |
22 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type; | |
8e364f8e PT |
23 | |
24 | /** | |
25 | * The average mipmap feature. | |
26 | * | |
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. | |
30 | */ | |
31 | public class AvgMipmapFeature extends TmfMipmapFeature { | |
32 | ||
33 | /** | |
34 | * Constructor | |
35 | * | |
36 | * @param baseQuark | |
37 | * The quark for the attribute we want to mipmap | |
38 | * @param mipmapQuark | |
39 | * The quark of the mipmap feature attribute | |
40 | * @param mipmapResolution | |
41 | * The resolution that will be use in the mipmap | |
42 | * @param ss | |
43 | * The state system in which to insert the state changes | |
44 | */ | |
45 | public AvgMipmapFeature(final int baseQuark, final int mipmapQuark, final int mipmapResolution, final ITmfStateSystemBuilder ss) { | |
46 | super(baseQuark, mipmapQuark, mipmapResolution, ss); | |
47 | } | |
48 | ||
49 | @Override | |
50 | protected ITmfStateValue computeMipmapValue(List<ITmfStateInterval> lowerIntervals, long startTime, long endTime) { | |
51 | long range = endTime - startTime; | |
52 | if (range <= 0) { | |
53 | return TmfStateValue.newValueDouble(0.0); | |
54 | } | |
55 | double sum = 0.0; | |
56 | try { | |
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; | |
62 | } else { | |
63 | sum += (double) value.unboxLong() * duration; | |
64 | } | |
65 | } | |
66 | } catch (StateValueTypeException e) { | |
67 | e.printStackTrace(); | |
68 | } | |
69 | double average = sum / range; | |
70 | ITmfStateValue avgValue = TmfStateValue.newValueDouble(average); | |
71 | return avgValue; | |
72 | } | |
73 | } |