Commit | Line | Data |
---|---|---|
79e08fd0 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Mathieu Denis (mathieu.denis@polymtl.ca) - Initial API and Implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.statistics.model; | |
14 | ||
15 | import java.util.Collection; | |
16 | import java.util.HashSet; | |
17 | import java.util.LinkedList; | |
18 | import java.util.Map; | |
19 | import java.util.Set; | |
20 | ||
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; | |
24 | ||
25 | /** | |
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> | |
28 | */ | |
29 | public class TmfBaseStatisticsTree extends AbsTmfStatisticsTree { | |
30 | ||
31 | /** | |
32 | * <h4>Header for the event types categories.</h4> | |
33 | */ | |
66711dc8 | 34 | public static final String HEADER_EVENT_TYPES = Messages.TmfStatisticsData_EventTypes; |
79e08fd0 BH |
35 | |
36 | /** | |
37 | * <h4>Indicate that it's a value.</h4> | |
38 | * <p> | |
39 | * Used when checking the possible child node for a node. | |
40 | * </p> | |
41 | * * | |
42 | * <p> | |
43 | * It differentiate a category of a value by being appended to a value. | |
44 | * </p> | |
45 | */ | |
66711dc8 BH |
46 | protected static final String NODE = "z"; //$NON-NLS-1$ |
47 | protected static final String ROOT_NODE_KEY = mergeString(ROOT.get(0), NODE); | |
79e08fd0 BH |
48 | |
49 | public TmfBaseStatisticsTree() { | |
50 | super(); | |
51 | Map<String, Set<String>> keys = getKeys(); | |
52 | ||
53 | // //////////// Adding category sets | |
54 | // common | |
55 | keys.put(HEADER_EVENT_TYPES, new HashSet<String>()); | |
56 | ||
57 | // /////////// Adding value sets | |
58 | // Under a trace | |
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); | |
65 | ||
66 | // //////////// CREATE root | |
67 | keys.put(ROOT.get(0), new HashSet<String>(2)); // 1 trace at the time | |
68 | getOrCreate(ROOT); | |
69 | } | |
70 | ||
71 | /* | |
72 | * (non-Javadoc) | |
73 | * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray) | |
74 | */ | |
75 | @Override | |
76 | public Collection<TmfStatisticsTreeNode> getChildren(TmfFixedArray<String> path) { | |
77 | LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>(); | |
78 | ||
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) | |
84 | result.add(current); | |
85 | } | |
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))); | |
90 | else | |
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))); | |
98 | } | |
99 | ||
100 | return result; | |
101 | } | |
102 | ||
103 | /* | |
104 | * (non-Javadoc) | |
105 | * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getAllChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray) | |
106 | */ | |
107 | @Override | |
108 | public Collection<TmfStatisticsTreeNode> getAllChildren(TmfFixedArray<String> path) { | |
109 | LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>(); | |
110 | ||
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)); | |
115 | if (current != null) | |
116 | result.add(current); | |
117 | } | |
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))); | |
122 | else | |
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))); | |
130 | } | |
131 | return result; | |
132 | } | |
133 | ||
134 | /** | |
135 | * <h4>Get the event types paths.</h4> | |
136 | * | |
137 | * @param event | |
138 | * Event to get the path for. | |
139 | * @param extraInfo | |
140 | * Extra information to pass along with the event | |
141 | * @return Array of FixedArray representing the paths. | |
142 | */ | |
143 | @SuppressWarnings({ "rawtypes", "unchecked" }) | |
66711dc8 | 144 | protected TmfFixedArray<String>[] getTypePaths(TmfEvent event, ITmfExtraEventInfo extraInfo) { |
79e08fd0 BH |
145 | String trace = extraInfo.getTraceName(); |
146 | // String type = event.getType().getTypeId(); // Add too much | |
147 | // informations | |
148 | String type = event.getType().toString(); | |
149 | ||
150 | TmfFixedArray[] paths = { new TmfFixedArray<String>(trace, HEADER_EVENT_TYPES, type) }; | |
151 | ||
152 | return paths; | |
153 | } | |
154 | ||
155 | /** | |
156 | * <h4>Get the standard paths for an event.</h4> | |
157 | * | |
158 | * @param event | |
159 | * Event to get the path for. | |
160 | * @param extraInfo | |
161 | * Extra information to pass along with the event | |
162 | * @return Array of FixedArray representing the paths. | |
163 | */ | |
164 | @SuppressWarnings({ "rawtypes", "unchecked" }) | |
66711dc8 | 165 | protected TmfFixedArray<String>[] getNormalPaths(TmfEvent event, ITmfExtraEventInfo extraInfo) { |
79e08fd0 BH |
166 | String trace = extraInfo.getTraceName(); |
167 | ||
168 | TmfFixedArray[] paths = { new TmfFixedArray<String>(trace) }; | |
169 | return paths; | |
170 | } | |
171 | ||
172 | /* | |
173 | * (non-Javadoc) | |
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) | |
175 | */ | |
176 | @Override | |
177 | public void increase(TmfEvent event, ITmfExtraEventInfo extraInfo, int values) { | |
178 | // Do nothing | |
179 | } | |
180 | ||
181 | /* | |
182 | * (non-Javadoc) | |
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) | |
184 | */ | |
185 | @Override | |
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); | |
190 | ||
191 | paths = getTypePaths(event, extraInfo); | |
192 | for (TmfFixedArray<String> path : paths) | |
193 | ++(getOrCreate(path).getValue().nbEvents); | |
194 | } | |
195 | ||
196 | /* | |
197 | * (non-Javadoc) | |
198 | * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#registerName | |
199 | * (org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfFixedArray) | |
200 | */ | |
201 | @Override | |
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)); | |
208 | } | |
209 | } |