1 /*******************************************************************************
2 * Copyright (c) 2011 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
.event
.TmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.ITmfExtraEventInfo
;
23 import org
.eclipse
.linuxtools
.tmf
.util
.TmfFixedArray
;
26 * <h4>Store information about base statistics data</h4>
27 * <p>This class provides a way to represent statistics data that is compatible to every kind of traces</p>
29 public class TmfBaseStatisticsTree
extends AbsTmfStatisticsTree
{
32 * <h4>Header for the event types categories.</h4>
34 private static final String HEADER_EVENT_TYPES
= Messages
.TmfStatisticsData_EventTypes
;
37 * <h4>Indicate that it's a value.</h4>
39 * Used when checking the possible child node for a node.
43 * It differentiate a category of a value by being appended to a value.
46 private static final String NODE
= "z"; //$NON-NLS-1$
47 private static final String ROOT_NODE_KEY
= mergeString(ROOT
.get(0), NODE
);
49 public TmfBaseStatisticsTree() {
51 Map
<String
, Set
<String
>> keys
= getKeys();
53 // //////////// Adding category sets
55 keys
.put(HEADER_EVENT_TYPES
, new HashSet
<String
>());
57 // /////////// Adding value sets
59 Set
<String
> temp
= new HashSet
<String
>(8);
60 temp
.add(HEADER_EVENT_TYPES
);
61 keys
.put(ROOT_NODE_KEY
, temp
);
62 // Under an event type
63 temp
= new HashSet
<String
>(16);
64 keys
.put(mergeString(HEADER_EVENT_TYPES
, NODE
), temp
);
66 // //////////// CREATE root
67 keys
.put(ROOT
.get(0), new HashSet
<String
>(2)); // 1 trace at the time
73 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray)
76 public Collection
<TmfStatisticsTreeNode
> getChildren(TmfFixedArray
<String
> path
) {
77 LinkedList
<TmfStatisticsTreeNode
> result
= new LinkedList
<TmfStatisticsTreeNode
>();
79 if (path
.size() % 2 == 0) { // if we are at a Category
80 TmfStatisticsTreeNode current
= null;
81 for (String value
: getKeys().get(path
.get(path
.size() - 1))) {
82 current
= get(path
.append(value
));
83 if (current
!= null && current
.getValue().nbEvents
!= 0)
86 } else if (path
.size() == 1) { // Special case.
87 if (path
.equals(ROOT
)) // Asking for the root.
88 for (String value
: getKeys().get(ROOT
.get(0)))
89 result
.add(getOrCreate(new TmfFixedArray
<String
>(value
)));
91 // Get value under the root
92 for (String value
: getKeys().get(ROOT_NODE_KEY
))
93 result
.add(getOrCreate(path
.append(value
)));
94 } else {// If we are at a value
95 for (String value
: getKeys().get(mergeString(path
.get(path
.size() - 2), NODE
)))
96 // Search the parent name + NODE
97 result
.add(getOrCreate(path
.append(value
)));
105 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getAllChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray)
108 public Collection
<TmfStatisticsTreeNode
> getAllChildren(TmfFixedArray
<String
> path
) {
109 LinkedList
<TmfStatisticsTreeNode
> result
= new LinkedList
<TmfStatisticsTreeNode
>();
111 if (path
.size() % 2 == 0) { // if we are at a Category
112 TmfStatisticsTreeNode current
= null;
113 for (String value
: getKeys().get(path
.get(path
.size() - 1))) {
114 current
= get(path
.append(value
));
118 } else if (path
.size() == 1) { // Special case.
119 if (path
.equals(ROOT
)) // Asking for the root.
120 for (String value
: getKeys().get(ROOT
.get(0)))
121 result
.add(getOrCreate(new TmfFixedArray
<String
>(value
)));
123 // Get value under the root
124 for (String value
: getKeys().get(ROOT_NODE_KEY
))
125 result
.add(getOrCreate(path
.append(value
)));
126 } else {// If we are at a value
127 for (String value
: getKeys().get(mergeString(path
.get(path
.size() - 2), NODE
)))
128 // Search the parent name + NODE
129 result
.add(getOrCreate(path
.append(value
)));
135 * <h4>Get the event types paths.</h4>
138 * Event to get the path for.
140 * Extra information to pass along with the event
141 * @return Array of FixedArray representing the paths.
143 @SuppressWarnings({ "rawtypes", "unchecked" })
144 private TmfFixedArray
<String
>[] getTypePaths(TmfEvent event
, ITmfExtraEventInfo extraInfo
) {
145 String trace
= extraInfo
.getTraceName();
146 // String type = event.getType().getTypeId(); // Add too much
148 String type
= event
.getType().toString();
150 TmfFixedArray
[] paths
= { new TmfFixedArray
<String
>(trace
, HEADER_EVENT_TYPES
, type
) };
156 * <h4>Get the standard paths for an event.</h4>
159 * Event to get the path for.
161 * Extra information to pass along with the event
162 * @return Array of FixedArray representing the paths.
164 @SuppressWarnings({ "rawtypes", "unchecked" })
165 private TmfFixedArray
<String
>[] getNormalPaths(TmfEvent event
, ITmfExtraEventInfo extraInfo
) {
166 String trace
= extraInfo
.getTraceName();
168 TmfFixedArray
[] paths
= { new TmfFixedArray
<String
>(trace
) };
174 * @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)
177 public void increase(TmfEvent event
, ITmfExtraEventInfo extraInfo
, int values
) {
183 * @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)
186 public void registerEvent(TmfEvent event
, ITmfExtraEventInfo extraInfo
) {
187 TmfFixedArray
<String
>[] paths
= getNormalPaths(event
, extraInfo
);
188 for (TmfFixedArray
<String
> path
: paths
)
189 ++(getOrCreate(path
).getValue().nbEvents
);
191 paths
= getTypePaths(event
, extraInfo
);
192 for (TmfFixedArray
<String
> path
: paths
)
193 ++(getOrCreate(path
).getValue().nbEvents
);
198 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#registerName
199 * (org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfFixedArray)
202 protected void registerName(TmfFixedArray
<String
> path
) {
203 if (path
.size() == 1) {
204 if (!path
.equals(ROOT
))
205 getKeys().get(ROOT
.get(0)).add(path
.get(0));
206 } else if (path
.size() % 2 != 0)
207 getKeys().get(path
.get(path
.size() - 2)).add(path
.get(path
.size() - 1));