1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
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
10 * Mathieu Denis (mathieu.denis@polymtl.ca) - Initial API and Implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
;
15 import java
.util
.Collection
;
16 import java
.util
.HashSet
;
17 import java
.util
.LinkedList
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.util
.TmfFixedArray
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.ITmfExtraEventInfo
;
26 * Store information about base statistics data.
28 * This class provides a way to represent statistics data that is compatible
29 * with every type of trace.
32 * @author Mathieu Denis
34 public class TmfBaseStatisticsTree
extends AbsTmfStatisticsTree
{
37 * <h4>Header for the event types categories.</h4>
39 public static final String HEADER_EVENT_TYPES
= Messages
.TmfStatisticsData_EventTypes
;
42 * <h4>Indicate that it's a value.</h4>
44 * Used when checking the possible child node for a node.
48 * It differentiate a category of a value by being appended to a value.
51 protected static final String NODE
= "z"; //$NON-NLS-1$
55 protected static final String ROOT_NODE_KEY
= mergeString(ROOT
.get(0), NODE
);
58 * Default constructor. Creates base statistics tree for counting total
59 * number of events and number of events per event type.
61 public TmfBaseStatisticsTree() {
63 Map
<String
, Set
<String
>> keys
= getKeys();
65 // //////////// Adding category sets
67 keys
.put(HEADER_EVENT_TYPES
, new HashSet
<String
>());
69 // /////////// Adding value sets
71 Set
<String
> temp
= new HashSet
<String
>(8);
72 temp
.add(HEADER_EVENT_TYPES
);
73 keys
.put(ROOT_NODE_KEY
, temp
);
74 // Under an event type
75 temp
= new HashSet
<String
>(16);
76 keys
.put(mergeString(HEADER_EVENT_TYPES
, NODE
), temp
);
78 // //////////// CREATE root
79 keys
.put(ROOT
.get(0), new HashSet
<String
>(2)); // 1 trace at the time
85 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray)
88 public Collection
<TmfStatisticsTreeNode
> getChildren(TmfFixedArray
<String
> path
) {
89 LinkedList
<TmfStatisticsTreeNode
> result
= new LinkedList
<TmfStatisticsTreeNode
>();
91 if (path
.size() % 2 == 0) { // if we are at a Category
92 TmfStatisticsTreeNode current
= null;
93 for (String value
: getKeys().get(path
.get(path
.size() - 1))) {
94 current
= get(path
.append(value
));
95 if (current
!= null && current
.getValue().nbEvents
!= 0) {
99 } else if (path
.size() == 1) { // Special case.
100 if (path
.equals(ROOT
)) {
101 for (String value
: getKeys().get(ROOT
.get(0))) {
102 result
.add(getOrCreate(new TmfFixedArray
<String
>(value
)));
105 // Get value under the root
106 for (String value
: getKeys().get(ROOT_NODE_KEY
)) {
107 result
.add(getOrCreate(path
.append(value
)));
110 } else {// If we are at a value
111 for (String value
: getKeys().get(mergeString(path
.get(path
.size() - 2), NODE
))) {
112 // Search the parent name + NODE
113 result
.add(getOrCreate(path
.append(value
)));
122 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getAllChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray)
125 public Collection
<TmfStatisticsTreeNode
> getAllChildren(TmfFixedArray
<String
> path
) {
126 LinkedList
<TmfStatisticsTreeNode
> result
= new LinkedList
<TmfStatisticsTreeNode
>();
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
));
132 if (current
!= null) {
136 } else if (path
.size() == 1) { // Special case.
137 if (path
.equals(ROOT
)) {
138 for (String value
: getKeys().get(ROOT
.get(0))) {
139 result
.add(getOrCreate(new TmfFixedArray
<String
>(value
)));
142 // Get value under the root
143 for (String value
: getKeys().get(ROOT_NODE_KEY
)) {
144 result
.add(getOrCreate(path
.append(value
)));
147 } else {// If we are at a value
148 for (String value
: getKeys().get(mergeString(path
.get(path
.size() - 2), NODE
))) {
149 // Search the parent name + NODE
150 result
.add(getOrCreate(path
.append(value
)));
157 * <h4>Get the event types paths.</h4>
160 * Event to get the path for.
162 * Extra information to pass along with the event
163 * @return Array of FixedArray representing the paths.
165 @SuppressWarnings({ "rawtypes", "unchecked" })
166 protected TmfFixedArray
<String
>[] getTypePaths(ITmfEvent event
, ITmfExtraEventInfo extraInfo
) {
167 String trace
= extraInfo
.getTraceName();
168 // String type = event.getType().getTypeId(); // Add too much
170 String type
= event
.getType().toString();
172 TmfFixedArray
[] paths
= { new TmfFixedArray
<String
>(trace
, HEADER_EVENT_TYPES
, type
) };
178 * <h4>Get the standard paths for an event.</h4>
181 * Event to get the path for.
183 * Extra information to pass along with the event
184 * @return Array of FixedArray representing the paths.
186 @SuppressWarnings({ "rawtypes", "unchecked" })
187 protected TmfFixedArray
<String
>[] getNormalPaths(ITmfEvent event
, ITmfExtraEventInfo extraInfo
) {
188 String trace
= extraInfo
.getTraceName();
190 TmfFixedArray
[] paths
= { new TmfFixedArray
<String
>(trace
) };
196 * @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)
199 public void increase(ITmfEvent event
, ITmfExtraEventInfo extraInfo
, int values
) {
205 * @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 public void registerEvent(ITmfEvent event
, ITmfExtraEventInfo extraInfo
) {
209 TmfFixedArray
<String
>[] paths
= getNormalPaths(event
, extraInfo
);
210 for (TmfFixedArray
<String
> path
: paths
) {
211 ++(getOrCreate(path
).getValue().nbEvents
);
214 paths
= getTypePaths(event
, extraInfo
);
215 for (TmfFixedArray
<String
> path
: paths
) {
216 ++(getOrCreate(path
).getValue().nbEvents
);
222 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#registerName
223 * (org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfFixedArray)
226 protected void registerName(TmfFixedArray
<String
> path
) {
227 if (path
.size() == 1) {
228 if (!path
.equals(ROOT
)) {
229 getKeys().get(ROOT
.get(0)).add(path
.get(0));
231 } else if (path
.size() % 2 != 0) {
232 getKeys().get(path
.get(path
.size() - 2)).add(path
.get(path
.size() - 1));