[292393] Revisited header search function
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / controlflow / model / FlowProcessContainer.java
CommitLineData
6e512b93
ASL
1/*******************************************************************************
2 * Copyright (c) 2009 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:
b513223f 10 * Alvaro Sanchez-Leon - Initial API and implementation
6e512b93
ASL
11 *******************************************************************************/
12package org.eclipse.linuxtools.lttng.ui.views.controlflow.model;
13
b513223f
FC
14import java.util.HashMap;
15import java.util.Iterator;
6e512b93 16
2211df66 17import org.eclipse.linuxtools.lttng.TraceDebug;
6e512b93
ASL
18import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess;
19
20/**
b513223f 21 * Contains the processes in use by the Control flow view
6e512b93
ASL
22 *
23 * @author alvaro
24 *
25 */
8035003b 26public class FlowProcessContainer {
6e512b93
ASL
27 // ========================================================================
28 // Data
29 // ========================================================================
b513223f
FC
30 private final HashMap<ProcessKey, TimeRangeEventProcess> allProcesses = new HashMap<ProcessKey, TimeRangeEventProcess>();
31 private static Integer uniqueId = 0;
32
6e512b93
ASL
33 // ========================================================================
34 // Constructor
35 // ========================================================================
36
37 /**
38 * Package level constructor
39 */
40 FlowProcessContainer() {
41
42 }
43
44 // ========================================================================
45 // Methods
46 // ========================================================================
47 /**
b513223f
FC
48 * Interface to add a new process.<p>
49 *
50 * Note : Process with the same key will be overwritten, it's calling function job to make sure the new process is unique.
6e512b93 51 *
b513223f 52 * @param newProcess The process to add
6e512b93 53 */
b513223f
FC
54 public void addProcess(TimeRangeEventProcess newProcess) {
55 if (newProcess != null) {
56 allProcesses.put(new ProcessKey(newProcess), newProcess);
6e512b93
ASL
57 }
58 }
b513223f 59
6e512b93 60 /**
b513223f
FC
61 * Request a unique ID
62 *
63 * @return Integer
64 */
65 public Integer getUniqueId() {
66 return uniqueId++;
67 }
68
69 /**
70 * This method is intended for read only purposes in order to keep the
71 * internal data structure in synch
72 *
73 * @return TimeRangeEventProcess[]
74 */
75 public TimeRangeEventProcess[] readProcesses() {
76 // This allow us to return an Array of the correct type of the exact correct dimension, without looping
77 return allProcesses.values().toArray(new TimeRangeEventProcess[allProcesses.size()]);
6e512b93 78 }
b513223f 79
6e512b93 80 /**
b513223f
FC
81 * Clear the children information for processes related to a specific trace
82 * e.g. just before refreshing data with a new time range
83 *
84 * @param traceId The trace unique id (trace name?) on which we need to eliminate children.
85 */
8035003b 86 public void clearChildren(String traceId) {
b513223f
FC
87 TimeRangeEventProcess process = null;
88 Iterator<ProcessKey> iterator = allProcesses.keySet().iterator();
89
90 while (iterator.hasNext()) {
91 process = allProcesses.get(iterator.next());
92
93 if (process.getTraceID().equals(traceId)) {
94 // Reset clear childEventComposites() and traceEvents()
95 // Also restore the nextGoodTime to the insertionTime for the drawing
96 process.reset();
97 }
98 }
6e512b93 99 }
b513223f 100
d712a5f3 101 /**
b513223f
FC
102 * Clear all process items
103 */
104 public void clearProcesses() {
105 allProcesses.clear();
106 }
107
108 /**
109 * Remove the process related to a specific trace e.g. during trace
110 * removal
111 *
112 * @param traceId The trace unique id (trace name?) on which we want to remove process
113 */
8035003b 114 public void removeProcesses(String traceId) {
b513223f
FC
115 ProcessKey iterKey = null;
116
117 Iterator<ProcessKey> iterator = allProcesses.keySet().iterator();
118 while (iterator.hasNext()) {
119 iterKey = iterator.next();
120
121 if (allProcesses.get(iterKey).getTraceID().equals(traceId)) {
122 allProcesses.remove(iterKey);
123 }
124 }
dfaf8391 125 }
b513223f
FC
126
127 /**
128 * Search by keys (pid, cpuId, traceId and creationTime)<p>
129 *
130 * A match is returned if the four arguments received match an entry
131 * Otherwise null is returned
132 *
133 * @param searchedPid The processId (Pid) we are looking for
134 * @param searchedCpuId The cpu Id we are looking for
135 * @param searchedTraceID The traceId (trace name?) we are looking for
136 * @param searchedCreationtime The creation time we are looking for
137 *
138 * @return TimeRangeEventProcess
139 */
140 public TimeRangeEventProcess findProcess(Long searchedPid, Long searchedCpuId, String searchedTraceID, Long searchedCreationtime) {
141 // Get the TimeRangeEventProcess associated to a key we create here
142 TimeRangeEventProcess foundProcess = allProcesses.get( new ProcessKey(searchedPid, searchedCpuId, searchedTraceID, searchedCreationtime) );
143
144 return foundProcess;
145 }
146}
dfaf8391 147
6e512b93 148
b513223f
FC
149class ProcessKey {
150 private TimeRangeEventProcess valueRef = null;
151
152 private Long pid = null;
153 private Long cpuId = null;
154 private String traceId = null;
155 private Long creationtime = null;
156
157 @SuppressWarnings("unused")
158 private ProcessKey() { }
159
160 public ProcessKey(TimeRangeEventProcess newRef) {
161 valueRef = newRef;
162 }
163
164 public ProcessKey(Long newPid, Long newCpuId, String newTraceId, Long newCreationTime) {
165 pid = newPid;
166 cpuId = newCpuId;
167 traceId = newTraceId;
168 creationtime = newCreationTime;
169 }
170
171 @Override
172 public boolean equals(Object obj) {
173 boolean isSame = false;
174
175 if ( obj instanceof ProcessKey ) {
176 ProcessKey procKey = (ProcessKey) obj;
2211df66
FC
177
178 if ( valueRef != null ) {
179 if ( (procKey.getPid().equals(valueRef.getPid()) ) &&
180 (procKey.getTraceId().equals(valueRef.getTraceID()) ) &&
181 (procKey.getCpuId().equals(valueRef.getCpu()) ) &&
182 (procKey.getCreationtime().equals(valueRef.getCreationTime()) ) )
183 {
184 isSame = true;
185 }
186 }
187 else {
188 if ( (procKey.getPid().equals(this.pid ) ) &&
189 (procKey.getTraceId().equals(this.traceId ) ) &&
190 (procKey.getCpuId().equals(this.cpuId ) ) &&
191 (procKey.getCreationtime().equals(this.creationtime ) ) )
192 {
193 isSame = true;
194 }
195 }
196 }
197 else {
198 TraceDebug.debug("ERROR : The given key is not of the type ProcessKey!" + obj.getClass().toString());
b513223f
FC
199 }
200
201 return isSame;
202 }
203
204 // *** WARNING : Everything in there work because the check "valueRef != null" is the same for ALL getter
205 // Do NOT change this check without checking.
206 public Long getPid() {
207 if ( valueRef != null ) {
208 return valueRef.getPid();
209 }
210 else {
211 return pid;
212 }
213 }
214
215 public Long getCpuId() {
216 if ( valueRef != null ) {
217 return valueRef.getCpu();
218 }
219 else {
220 return cpuId;
221 }
222 }
223
224 public String getTraceId() {
225 if ( valueRef != null ) {
226 return valueRef.getTraceID();
227 }
228 else {
229 return traceId;
230 }
231 }
232
233 public Long getCreationtime() {
234 if ( valueRef != null ) {
235 return valueRef.getCreationTime();
236 }
237 else {
238 return creationtime;
239 }
240 }
241
242 @Override
243 public int hashCode() {
244 return this.toString().hashCode();
245 }
246
247
248 @Override
249 public String toString() {
250 if ( valueRef != null ) {
251 return (valueRef.getPid().toString() + ":" + valueRef.getCpu().toString() + ":" + valueRef.getTraceID().toString() + ":" + valueRef.getCreationTime().toString());
252 }
253
254 return (pid + ":" + cpuId + ":" + traceId + ":" + creationtime);
255 }
6e512b93 256}
This page took 0.035889 seconds and 5 git commands to generate.