tmf: Correct the statistics partial event count
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / statistics / model / TmfBaseStatisticsTree.java
CommitLineData
79e08fd0 1/*******************************************************************************
b544077e 2 * Copyright (c) 2011, 2012 Ericsson
013a5f1c 3 *
79e08fd0
BH
4 * All rights reserved. This program and the accompanying materials are
5 * made 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
013a5f1c 8 *
79e08fd0 9 * Contributors:
09667aa4 10 * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API and Implementation
79e08fd0
BH
11 *******************************************************************************/
12
cfd22ad0 13package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
79e08fd0
BH
14
15import java.util.Collection;
16import java.util.HashSet;
17import java.util.LinkedList;
18import java.util.Map;
19import java.util.Set;
20
72f1e62a 21import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
6c13869b 22import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
cfd22ad0 23import org.eclipse.linuxtools.tmf.ui.viewers.statistics.ITmfExtraEventInfo;
79e08fd0
BH
24
25/**
b544077e 26 * Store information about base statistics data.
013a5f1c
AM
27 *
28 * This class provides a way to represent statistics data that is compatible
29 * with every type of trace.
30 *
25a042b3 31 * @version 2.0
b544077e 32 * @author Mathieu Denis
cfd22ad0 33 * @since 2.0
79e08fd0
BH
34 */
35public class TmfBaseStatisticsTree extends AbsTmfStatisticsTree {
36
37 /**
25a042b3 38 * Header for the event type categories.
79e08fd0 39 */
66711dc8 40 public static final String HEADER_EVENT_TYPES = Messages.TmfStatisticsData_EventTypes;
79e08fd0
BH
41
42 /**
09667aa4
MD
43 * Indicate that it's a value.
44 *
79e08fd0 45 * Used when checking the possible child node for a node.
09667aa4 46 *
79e08fd0 47 * It differentiate a category of a value by being appended to a value.
79e08fd0 48 */
66711dc8 49 protected static final String NODE = "z"; //$NON-NLS-1$
09667aa4 50
b544077e
BH
51 /**
52 * Root node key.
53 */
66711dc8 54 protected static final String ROOT_NODE_KEY = mergeString(ROOT.get(0), NODE);
79e08fd0 55
b544077e
BH
56 /**
57 * Default constructor. Creates base statistics tree for counting total
58 * number of events and number of events per event type.
59 */
79e08fd0
BH
60 public TmfBaseStatisticsTree() {
61 super();
62 Map<String, Set<String>> keys = getKeys();
63
64 // //////////// Adding category sets
65 // common
66 keys.put(HEADER_EVENT_TYPES, new HashSet<String>());
67
68 // /////////// Adding value sets
69 // Under a trace
70 Set<String> temp = new HashSet<String>(8);
71 temp.add(HEADER_EVENT_TYPES);
72 keys.put(ROOT_NODE_KEY, temp);
73 // Under an event type
74 temp = new HashSet<String>(16);
75 keys.put(mergeString(HEADER_EVENT_TYPES, NODE), temp);
76
77 // //////////// CREATE root
78 keys.put(ROOT.get(0), new HashSet<String>(2)); // 1 trace at the time
79 getOrCreate(ROOT);
80 }
81
82 /*
83 * (non-Javadoc)
09667aa4 84 *
cfd22ad0
MD
85 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#getChildren
86 * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
79e08fd0
BH
87 */
88 @Override
89 public Collection<TmfStatisticsTreeNode> getChildren(TmfFixedArray<String> path) {
90 LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
91
92 if (path.size() % 2 == 0) { // if we are at a Category
93 TmfStatisticsTreeNode current = null;
94 for (String value : getKeys().get(path.get(path.size() - 1))) {
95 current = get(path.append(value));
25a042b3 96 if (current != null && current.getValue().getTotal() != 0) {
79e08fd0 97 result.add(current);
013a5f1c 98 }
79e08fd0
BH
99 }
100 } else if (path.size() == 1) { // Special case.
013a5f1c
AM
101 if (path.equals(ROOT)) {
102 for (String value : getKeys().get(ROOT.get(0))) {
79e08fd0 103 result.add(getOrCreate(new TmfFixedArray<String>(value)));
013a5f1c
AM
104 }
105 } else {
79e08fd0 106 // Get value under the root
013a5f1c 107 for (String value : getKeys().get(ROOT_NODE_KEY)) {
79e08fd0 108 result.add(getOrCreate(path.append(value)));
013a5f1c
AM
109 }
110 }
79e08fd0 111 } else {// If we are at a value
013a5f1c 112 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
79e08fd0
BH
113 // Search the parent name + NODE
114 result.add(getOrCreate(path.append(value)));
013a5f1c 115 }
79e08fd0
BH
116 }
117
118 return result;
119 }
120
121 /*
122 * (non-Javadoc)
09667aa4 123 *
cfd22ad0
MD
124 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#getAllChildren
125 * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
79e08fd0
BH
126 */
127 @Override
128 public Collection<TmfStatisticsTreeNode> getAllChildren(TmfFixedArray<String> path) {
129 LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
130
131 if (path.size() % 2 == 0) { // if we are at a Category
132 TmfStatisticsTreeNode current = null;
133 for (String value : getKeys().get(path.get(path.size() - 1))) {
134 current = get(path.append(value));
013a5f1c 135 if (current != null) {
79e08fd0 136 result.add(current);
013a5f1c 137 }
79e08fd0
BH
138 }
139 } else if (path.size() == 1) { // Special case.
013a5f1c
AM
140 if (path.equals(ROOT)) {
141 for (String value : getKeys().get(ROOT.get(0))) {
79e08fd0 142 result.add(getOrCreate(new TmfFixedArray<String>(value)));
013a5f1c
AM
143 }
144 } else {
79e08fd0 145 // Get value under the root
013a5f1c 146 for (String value : getKeys().get(ROOT_NODE_KEY)) {
79e08fd0 147 result.add(getOrCreate(path.append(value)));
013a5f1c
AM
148 }
149 }
79e08fd0 150 } else {// If we are at a value
013a5f1c 151 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
79e08fd0
BH
152 // Search the parent name + NODE
153 result.add(getOrCreate(path.append(value)));
013a5f1c 154 }
79e08fd0
BH
155 }
156 return result;
157 }
158
25a042b3
MD
159 /*
160 * (non-Javadoc)
161 *
cfd22ad0
MD
162 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#increase
163 * (org.eclipse.linuxtools.tmf.core.event.ITmfEvent, org.eclipse.linuxtools.tmf.ui.viewers.statistics.ITmfExtraEventInfo, int)
25a042b3
MD
164 */
165 @Override
166 public void increase(ITmfEvent event, ITmfExtraEventInfo extraInfo, int values) {
167 // Do nothing
168 }
169
170 /*
171 * (non-Javadoc)
172 *
cfd22ad0
MD
173 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#registerEvent
174 * (org.eclipse.linuxtools.tmf.core.event.ITmfEvent, org.eclipse.linuxtools.tmf.ui.viewers.statistics.ITmfExtraEventInfo)
25a042b3
MD
175 */
176 @Override
177 public void registerEvent(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
178 TmfFixedArray<String>[] paths = getNormalPaths(event, extraInfo);
179 for (TmfFixedArray<String> path : paths) {
180 getOrCreate(path).getValue().incrementTotal();
181 }
182
183 paths = getTypePaths(event, extraInfo);
184 for (TmfFixedArray<String> path : paths) {
185 getOrCreate(path).getValue().incrementTotal();
186 }
187 }
188
189 /*
190 * (non-Javadoc)
191 *
cfd22ad0
MD
192 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#registerEventInTimeRange
193 * (org.eclipse.linuxtools.tmf.core.event.ITmfEvent, org.eclipse.linuxtools.tmf.ui.viewers.statistics.ITmfExtraEventInfo)
25a042b3
MD
194 */
195 @Override
196 public void registerEventInTimeRange(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
197 TmfFixedArray<String>[] paths = getNormalPaths(event, extraInfo);
198 for (TmfFixedArray<String> path : paths) {
199 getOrCreate(path).getValue().incrementPartial();
200 }
201
202 paths = getTypePaths(event, extraInfo);
203 for (TmfFixedArray<String> path : paths) {
204 getOrCreate(path).getValue().incrementPartial();
205 }
206 }
207
79e08fd0 208 /**
09667aa4 209 * Get the event types paths.
013a5f1c 210 *
79e08fd0
BH
211 * @param event
212 * Event to get the path for.
213 * @param extraInfo
214 * Extra information to pass along with the event
215 * @return Array of FixedArray representing the paths.
216 */
217 @SuppressWarnings({ "rawtypes", "unchecked" })
72f1e62a 218 protected TmfFixedArray<String>[] getTypePaths(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
79e08fd0 219 String trace = extraInfo.getTraceName();
79e08fd0
BH
220 String type = event.getType().toString();
221
222 TmfFixedArray[] paths = { new TmfFixedArray<String>(trace, HEADER_EVENT_TYPES, type) };
223
224 return paths;
225 }
226
227 /**
09667aa4 228 * Get the standard paths for an event.
013a5f1c 229 *
79e08fd0
BH
230 * @param event
231 * Event to get the path for.
232 * @param extraInfo
233 * Extra information to pass along with the event
234 * @return Array of FixedArray representing the paths.
235 */
236 @SuppressWarnings({ "rawtypes", "unchecked" })
72f1e62a 237 protected TmfFixedArray<String>[] getNormalPaths(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
79e08fd0
BH
238 String trace = extraInfo.getTraceName();
239
240 TmfFixedArray[] paths = { new TmfFixedArray<String>(trace) };
241 return paths;
242 }
013a5f1c 243
79e08fd0
BH
244 /*
245 * (non-Javadoc)
09667aa4 246 *
cfd22ad0
MD
247 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#registerName
248 * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
79e08fd0
BH
249 */
250 @Override
251 protected void registerName(TmfFixedArray<String> path) {
252 if (path.size() == 1) {
013a5f1c 253 if (!path.equals(ROOT)) {
79e08fd0 254 getKeys().get(ROOT.get(0)).add(path.get(0));
013a5f1c
AM
255 }
256 } else if (path.size() % 2 != 0) {
79e08fd0 257 getKeys().get(path.get(path.size() - 2)).add(path.get(path.size() - 1));
013a5f1c 258 }
79e08fd0
BH
259 }
260}
This page took 0.042126 seconds and 5 git commands to generate.