tmf: Store the generic statistics timestamps in nanoseconds
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / 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
cfd22ad0 13package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
79e08fd0
BH
14
15import java.util.Collection;
16import java.util.HashSet;
17import java.util.LinkedList;
18import java.util.Map;
19import java.util.Set;
20
6c13869b 21import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
79e08fd0
BH
22
23/**
b544077e 24 * Store information about base statistics data.
013a5f1c
AM
25 *
26 * This class provides a way to represent statistics data that is compatible
27 * with every type of trace.
28 *
25a042b3 29 * @version 2.0
b544077e 30 * @author Mathieu Denis
cfd22ad0 31 * @since 2.0
79e08fd0
BH
32 */
33public class TmfBaseStatisticsTree extends AbsTmfStatisticsTree {
34
35 /**
25a042b3 36 * Header for the event type categories.
79e08fd0 37 */
66711dc8 38 public static final String HEADER_EVENT_TYPES = Messages.TmfStatisticsData_EventTypes;
79e08fd0
BH
39
40 /**
09667aa4
MD
41 * Indicate that it's a value.
42 *
79e08fd0 43 * Used when checking the possible child node for a node.
09667aa4 44 *
79e08fd0 45 * It differentiate a category of a value by being appended to a value.
79e08fd0 46 */
66711dc8 47 protected static final String NODE = "z"; //$NON-NLS-1$
09667aa4 48
b544077e
BH
49 /**
50 * Root node key.
51 */
66711dc8 52 protected static final String ROOT_NODE_KEY = mergeString(ROOT.get(0), NODE);
79e08fd0 53
b544077e
BH
54 /**
55 * Default constructor. Creates base statistics tree for counting total
56 * number of events and number of events per event type.
57 */
79e08fd0
BH
58 public TmfBaseStatisticsTree() {
59 super();
60 Map<String, Set<String>> keys = getKeys();
61
62 // //////////// Adding category sets
63 // common
64 keys.put(HEADER_EVENT_TYPES, new HashSet<String>());
65
66 // /////////// Adding value sets
67 // Under a trace
68 Set<String> temp = new HashSet<String>(8);
69 temp.add(HEADER_EVENT_TYPES);
70 keys.put(ROOT_NODE_KEY, temp);
71 // Under an event type
72 temp = new HashSet<String>(16);
73 keys.put(mergeString(HEADER_EVENT_TYPES, NODE), temp);
74
75 // //////////// CREATE root
76 keys.put(ROOT.get(0), new HashSet<String>(2)); // 1 trace at the time
77 getOrCreate(ROOT);
78 }
79
80 /*
81 * (non-Javadoc)
09667aa4 82 *
cfd22ad0
MD
83 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#getChildren
84 * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
79e08fd0
BH
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));
89c06060 94 if (current != null && current.getValues().getTotal() != 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 *
cfd22ad0
MD
122 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#getAllChildren
123 * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
79e08fd0
BH
124 */
125 @Override
126 public Collection<TmfStatisticsTreeNode> getAllChildren(TmfFixedArray<String> path) {
127 LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
128
129 if (path.size() % 2 == 0) { // if we are at a Category
130 TmfStatisticsTreeNode current = null;
131 for (String value : getKeys().get(path.get(path.size() - 1))) {
132 current = get(path.append(value));
013a5f1c 133 if (current != null) {
79e08fd0 134 result.add(current);
013a5f1c 135 }
79e08fd0
BH
136 }
137 } else if (path.size() == 1) { // Special case.
013a5f1c
AM
138 if (path.equals(ROOT)) {
139 for (String value : getKeys().get(ROOT.get(0))) {
79e08fd0 140 result.add(getOrCreate(new TmfFixedArray<String>(value)));
013a5f1c
AM
141 }
142 } else {
79e08fd0 143 // Get value under the root
013a5f1c 144 for (String value : getKeys().get(ROOT_NODE_KEY)) {
79e08fd0 145 result.add(getOrCreate(path.append(value)));
013a5f1c
AM
146 }
147 }
79e08fd0 148 } else {// If we are at a value
013a5f1c 149 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
79e08fd0
BH
150 // Search the parent name + NODE
151 result.add(getOrCreate(path.append(value)));
013a5f1c 152 }
79e08fd0
BH
153 }
154 return result;
155 }
156
25a042b3 157 @Override
89c06060
AM
158 public void setTotal(String traceName, boolean isGlobal, long qty) {
159 TmfFixedArray<String>[] paths = getNormalPaths(traceName);
73fbf6be 160 for (TmfFixedArray<String> path : paths) {
89c06060 161 getOrCreate(path).getValues().setValue(isGlobal, qty);
73fbf6be 162 }
25a042b3
MD
163 }
164
25a042b3 165 @Override
89c06060
AM
166 public void setTypeCount(String traceName, String type, boolean isGlobal, long qty) {
167 TmfFixedArray<String>[] paths = getTypePaths(traceName, type);
25a042b3 168 for (TmfFixedArray<String> path : paths) {
89c06060 169 getOrCreate(path).getValues().setValue(isGlobal, qty);
25a042b3
MD
170 }
171 }
172
79e08fd0 173 /**
09667aa4 174 * Get the event types paths.
013a5f1c 175 *
79e08fd0
BH
176 * @param event
177 * Event to get the path for.
178 * @param extraInfo
179 * Extra information to pass along with the event
180 * @return Array of FixedArray representing the paths.
181 */
182 @SuppressWarnings({ "rawtypes", "unchecked" })
89c06060
AM
183 protected TmfFixedArray<String>[] getTypePaths(String traceName, String type) {
184 TmfFixedArray[] paths = { new TmfFixedArray<String>(traceName, HEADER_EVENT_TYPES, type) };
79e08fd0
BH
185 return paths;
186 }
187
188 /**
09667aa4 189 * Get the standard paths for an event.
013a5f1c 190 *
79e08fd0
BH
191 * @param event
192 * Event to get the path for.
193 * @param extraInfo
194 * Extra information to pass along with the event
195 * @return Array of FixedArray representing the paths.
196 */
197 @SuppressWarnings({ "rawtypes", "unchecked" })
89c06060
AM
198 protected TmfFixedArray<String>[] getNormalPaths(String traceName) {
199 TmfFixedArray[] paths = { new TmfFixedArray<String>(traceName) };
79e08fd0
BH
200 return paths;
201 }
013a5f1c 202
79e08fd0
BH
203 /*
204 * (non-Javadoc)
09667aa4 205 *
cfd22ad0
MD
206 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#registerName
207 * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
79e08fd0
BH
208 */
209 @Override
210 protected void registerName(TmfFixedArray<String> path) {
211 if (path.size() == 1) {
013a5f1c 212 if (!path.equals(ROOT)) {
79e08fd0 213 getKeys().get(ROOT.get(0)).add(path.get(0));
013a5f1c
AM
214 }
215 } else if (path.size() % 2 != 0) {
79e08fd0 216 getKeys().get(path.get(path.size() - 2)).add(path.get(path.size() - 1));
013a5f1c 217 }
79e08fd0
BH
218 }
219}
This page took 0.042346 seconds and 5 git commands to generate.