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 * Header for the event types categories.
39 public static final String HEADER_EVENT_TYPES
= Messages
.TmfStatisticsData_EventTypes
;
42 * Indicate that it's a value.
44 * Used when checking the possible child node for a node.
46 * It differentiate a category of a value by being appended to a value.
48 protected static final String NODE
= "z"; //$NON-NLS-1$
53 protected static final String ROOT_NODE_KEY
= mergeString(ROOT
.get(0), NODE
);
56 * Default constructor. Creates base statistics tree for counting total
57 * number of events and number of events per event type.
59 public TmfBaseStatisticsTree() {
61 Map
<String
, Set
<String
>> keys
= getKeys();
63 // //////////// Adding category sets
65 keys
.put(HEADER_EVENT_TYPES
, new HashSet
<String
>());
67 // /////////// Adding value sets
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
);
76 // //////////// CREATE root
77 keys
.put(ROOT
.get(0), new HashSet
<String
>(2)); // 1 trace at the time
84 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray)
87 public Collection
<TmfStatisticsTreeNode
> getChildren(TmfFixedArray
<String
> path
) {
88 LinkedList
<TmfStatisticsTreeNode
> result
= new LinkedList
<TmfStatisticsTreeNode
>();
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
));
94 if (current
!= null && current
.getValue().nbEvents
!= 0) {
98 } else if (path
.size() == 1) { // Special case.
99 if (path
.equals(ROOT
)) {
100 for (String value
: getKeys().get(ROOT
.get(0))) {
101 result
.add(getOrCreate(new TmfFixedArray
<String
>(value
)));
104 // Get value under the root
105 for (String value
: getKeys().get(ROOT_NODE_KEY
)) {
106 result
.add(getOrCreate(path
.append(value
)));
109 } else {// If we are at a value
110 for (String value
: getKeys().get(mergeString(path
.get(path
.size() - 2), NODE
))) {
111 // Search the parent name + NODE
112 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 * Get the event types paths.
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 * Get the standard paths for an event.
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
) };
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)
200 public void increase(ITmfEvent event
, ITmfExtraEventInfo extraInfo
, int values
) {
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)
210 public void registerEvent(ITmfEvent event
, ITmfExtraEventInfo extraInfo
) {
211 TmfFixedArray
<String
>[] paths
= getNormalPaths(event
, extraInfo
);
212 for (TmfFixedArray
<String
> path
: paths
) {
213 ++(getOrCreate(path
).getValue().nbEvents
);
216 paths
= getTypePaths(event
, extraInfo
);
217 for (TmfFixedArray
<String
> path
: paths
) {
218 ++(getOrCreate(path
).getValue().nbEvents
);
225 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.AbsTmfStatisticsTree#registerName(org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
228 protected void registerName(TmfFixedArray
<String
> path
) {
229 if (path
.size() == 1) {
230 if (!path
.equals(ROOT
)) {
231 getKeys().get(ROOT
.get(0)).add(path
.get(0));
233 } else if (path
.size() % 2 != 0) {
234 getKeys().get(path
.get(path
.size() - 2)).add(path
.get(path
.size() - 1));