Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / 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
13package org.eclipse.linuxtools.tmf.ui.views.statistics.model;
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;
79e08fd0 23import org.eclipse.linuxtools.tmf.ui.views.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 *
b544077e
BH
31 * @version 1.0
32 * @author Mathieu Denis
79e08fd0
BH
33 */
34public class TmfBaseStatisticsTree extends AbsTmfStatisticsTree {
35
36 /**
09667aa4 37 * Header for the event types categories.
79e08fd0 38 */
66711dc8 39 public static final String HEADER_EVENT_TYPES = Messages.TmfStatisticsData_EventTypes;
79e08fd0
BH
40
41 /**
09667aa4
MD
42 * Indicate that it's a value.
43 *
79e08fd0 44 * Used when checking the possible child node for a node.
09667aa4 45 *
79e08fd0 46 * It differentiate a category of a value by being appended to a value.
79e08fd0 47 */
66711dc8 48 protected static final String NODE = "z"; //$NON-NLS-1$
09667aa4 49
b544077e
BH
50 /**
51 * Root node key.
52 */
66711dc8 53 protected static final String ROOT_NODE_KEY = mergeString(ROOT.get(0), NODE);
79e08fd0 54
b544077e
BH
55 /**
56 * Default constructor. Creates base statistics tree for counting total
57 * number of events and number of events per event type.
58 */
79e08fd0
BH
59 public TmfBaseStatisticsTree() {
60 super();
61 Map<String, Set<String>> keys = getKeys();
62
63 // //////////// Adding category sets
64 // common
65 keys.put(HEADER_EVENT_TYPES, new HashSet<String>());
66
67 // /////////// Adding value sets
68 // Under a trace
69 Set<String> temp = new HashSet<String>(8);
70 temp.add(HEADER_EVENT_TYPES);
71 keys.put(ROOT_NODE_KEY, temp);
72 // Under an event type
73 temp = new HashSet<String>(16);
74 keys.put(mergeString(HEADER_EVENT_TYPES, NODE), temp);
75
76 // //////////// CREATE root
77 keys.put(ROOT.get(0), new HashSet<String>(2)); // 1 trace at the time
78 getOrCreate(ROOT);
79 }
80
81 /*
82 * (non-Javadoc)
09667aa4 83 *
79e08fd0
BH
84 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray)
85 */
86 @Override
87 public Collection<TmfStatisticsTreeNode> getChildren(TmfFixedArray<String> path) {
88 LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
89
90 if (path.size() % 2 == 0) { // if we are at a Category
91 TmfStatisticsTreeNode current = null;
92 for (String value : getKeys().get(path.get(path.size() - 1))) {
93 current = get(path.append(value));
013a5f1c 94 if (current != null && current.getValue().nbEvents != 0) {
79e08fd0 95 result.add(current);
013a5f1c 96 }
79e08fd0
BH
97 }
98 } else if (path.size() == 1) { // Special case.
013a5f1c
AM
99 if (path.equals(ROOT)) {
100 for (String value : getKeys().get(ROOT.get(0))) {
79e08fd0 101 result.add(getOrCreate(new TmfFixedArray<String>(value)));
013a5f1c
AM
102 }
103 } else {
79e08fd0 104 // Get value under the root
013a5f1c 105 for (String value : getKeys().get(ROOT_NODE_KEY)) {
79e08fd0 106 result.add(getOrCreate(path.append(value)));
013a5f1c
AM
107 }
108 }
79e08fd0 109 } else {// If we are at a value
013a5f1c 110 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
79e08fd0
BH
111 // Search the parent name + NODE
112 result.add(getOrCreate(path.append(value)));
013a5f1c 113 }
79e08fd0
BH
114 }
115
116 return result;
117 }
118
119 /*
120 * (non-Javadoc)
09667aa4 121 *
79e08fd0
BH
122 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getAllChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray)
123 */
124 @Override
125 public Collection<TmfStatisticsTreeNode> getAllChildren(TmfFixedArray<String> path) {
126 LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
127
128 if (path.size() % 2 == 0) { // if we are at a Category
129 TmfStatisticsTreeNode current = null;
130 for (String value : getKeys().get(path.get(path.size() - 1))) {
131 current = get(path.append(value));
013a5f1c 132 if (current != null) {
79e08fd0 133 result.add(current);
013a5f1c 134 }
79e08fd0
BH
135 }
136 } else if (path.size() == 1) { // Special case.
013a5f1c
AM
137 if (path.equals(ROOT)) {
138 for (String value : getKeys().get(ROOT.get(0))) {
79e08fd0 139 result.add(getOrCreate(new TmfFixedArray<String>(value)));
013a5f1c
AM
140 }
141 } else {
79e08fd0 142 // Get value under the root
013a5f1c 143 for (String value : getKeys().get(ROOT_NODE_KEY)) {
79e08fd0 144 result.add(getOrCreate(path.append(value)));
013a5f1c
AM
145 }
146 }
79e08fd0 147 } else {// If we are at a value
013a5f1c 148 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
79e08fd0
BH
149 // Search the parent name + NODE
150 result.add(getOrCreate(path.append(value)));
013a5f1c 151 }
79e08fd0
BH
152 }
153 return result;
154 }
155
156 /**
09667aa4 157 * Get the event types paths.
013a5f1c 158 *
79e08fd0
BH
159 * @param event
160 * Event to get the path for.
161 * @param extraInfo
162 * Extra information to pass along with the event
163 * @return Array of FixedArray representing the paths.
164 */
165 @SuppressWarnings({ "rawtypes", "unchecked" })
72f1e62a 166 protected TmfFixedArray<String>[] getTypePaths(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
79e08fd0
BH
167 String trace = extraInfo.getTraceName();
168 // String type = event.getType().getTypeId(); // Add too much
169 // informations
170 String type = event.getType().toString();
171
172 TmfFixedArray[] paths = { new TmfFixedArray<String>(trace, HEADER_EVENT_TYPES, type) };
173
174 return paths;
175 }
176
177 /**
09667aa4 178 * Get the standard paths for an event.
013a5f1c 179 *
79e08fd0
BH
180 * @param event
181 * Event to get the path for.
182 * @param extraInfo
183 * Extra information to pass along with the event
184 * @return Array of FixedArray representing the paths.
185 */
186 @SuppressWarnings({ "rawtypes", "unchecked" })
72f1e62a 187 protected TmfFixedArray<String>[] getNormalPaths(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
79e08fd0
BH
188 String trace = extraInfo.getTraceName();
189
190 TmfFixedArray[] paths = { new TmfFixedArray<String>(trace) };
191 return paths;
192 }
013a5f1c 193
79e08fd0
BH
194 /*
195 * (non-Javadoc)
09667aa4 196 *
79e08fd0
BH
197 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#increase(org.eclipse.linuxtools.tmf.event.TmfEvent, org.eclipse.linuxtools.tmf.ui.views.statistics.ITmfEventInfo, int)
198 */
199 @Override
72f1e62a 200 public void increase(ITmfEvent event, ITmfExtraEventInfo extraInfo, int values) {
79e08fd0
BH
201 // Do nothing
202 }
203
204 /*
205 * (non-Javadoc)
09667aa4 206 *
79e08fd0
BH
207 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#registerEvent(org.eclipse.linuxtools.tmf.event.TmfEvent, org.eclipse.linuxtools.tmf.ui.views.statistics.ITmfEventInfo)
208 */
209 @Override
72f1e62a 210 public void registerEvent(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
79e08fd0 211 TmfFixedArray<String>[] paths = getNormalPaths(event, extraInfo);
013a5f1c 212 for (TmfFixedArray<String> path : paths) {
79e08fd0 213 ++(getOrCreate(path).getValue().nbEvents);
013a5f1c 214 }
79e08fd0
BH
215
216 paths = getTypePaths(event, extraInfo);
013a5f1c 217 for (TmfFixedArray<String> path : paths) {
79e08fd0 218 ++(getOrCreate(path).getValue().nbEvents);
013a5f1c 219 }
79e08fd0
BH
220 }
221
222 /*
223 * (non-Javadoc)
09667aa4
MD
224 *
225 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.AbsTmfStatisticsTree#registerName(org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
79e08fd0
BH
226 */
227 @Override
228 protected void registerName(TmfFixedArray<String> path) {
229 if (path.size() == 1) {
013a5f1c 230 if (!path.equals(ROOT)) {
79e08fd0 231 getKeys().get(ROOT.get(0)).add(path.get(0));
013a5f1c
AM
232 }
233 } else if (path.size() % 2 != 0) {
79e08fd0 234 getKeys().get(path.get(path.size() - 2)).add(path.get(path.size() - 1));
013a5f1c 235 }
79e08fd0
BH
236 }
237}
This page took 0.043724 seconds and 5 git commands to generate.