blob: ff8d2f49e1e3edd4b0bd7f7d25911ba1f3227550 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*******************************************************************************
* Copyright (c) 2011 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.views.statistics.model;
import java.util.HashMap;
import java.util.Map;
/**
* Factory class to create and store TMF statistic trees.
*
* Based on a given tree node ID a TMF statistic tree is stored internally. A
* root node is created for each tree. Using the tree node ID the statistics
* tree can be retrieved.
*
* @version 1.0
* @author Mathieu Denis
*
*/
public class TmfStatisticsTreeRootFactory {
/**
* Contains the experiment name as the key and the traces data
*/
private static final Map<String, AbsTmfStatisticsTree> fTreeInstances = new HashMap<String, AbsTmfStatisticsTree>();
/**
* Provide a statisticsTree instance per trace
*
* @param traceUniqueId
* Unique ID for the trace
* @return the corresponding trace statistics tree
*/
public static TmfStatisticsTreeNode getStatTreeRoot(String traceUniqueId) {
AbsTmfStatisticsTree tree = getStatTree(traceUniqueId);
if (tree == null) {
return null;
}
return tree.getOrCreate(AbsTmfStatisticsTree.ROOT);
}
/**
* Get the tree that's being used for statistics
*
* @param traceUniqueId
* Unique ID for the trace
* @return the corresponding trace statistics tree
*/
public static AbsTmfStatisticsTree getStatTree(String traceUniqueId) {
if (traceUniqueId == null) {
return null;
}
AbsTmfStatisticsTree tree = fTreeInstances.get(traceUniqueId);
return tree;
}
/**
* Add the new trace statistics data in the tree. Can be used later on if
* the same traces is selected back.
*
* @param traceUniqueId
* The name of the trace which will be used as a key to store the
* data. Must be different for each traces, otherwise the traces
* might be overwritten which would trigger a reload of the same
* trace.
* @param statsData
* The information about the trace
*/
public static void addStatsTreeRoot(String traceUniqueId, AbsTmfStatisticsTree statsData) {
if (traceUniqueId == null || statsData == null) {
return;
}
fTreeInstances.put(traceUniqueId, statsData);
// if called for the first time, create the root node
statsData.getOrCreate(AbsTmfStatisticsTree.ROOT);
}
/**
* Return if the given trace is currently known by the statistics manager.
*
* @param traceUniqueId
* The unique ID of the trace
* @return true if the trace id is known
*/
public static boolean containsTreeRoot(String traceUniqueId) {
return fTreeInstances.containsKey(traceUniqueId);
}
/**
* Remove previously registered statistics tree.
*
* @param traceUniqueId
* The unique ID of the trace
*/
public static void removeStatTreeRoot(String traceUniqueId) {
if (traceUniqueId != null && fTreeInstances.containsKey(traceUniqueId)) {
fTreeInstances.remove(traceUniqueId);
}
}
/**
* Remove all tree and root instances
*/
public static void removeAll() {
fTreeInstances.clear();
}
}
|