1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Alvaro Sanchez-Leon - Initial API and implementation
11 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.controlflow
.model
;
15 import java
.util
.HashMap
;
16 import java
.util
.Iterator
;
18 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.TraceDebug
;
19 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.ItemContainer
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEventProcess
;
23 * Contains the processes in use by the Control flow view
28 public class FlowProcessContainer
implements ItemContainer
<TimeRangeEventProcess
> {
29 // ========================================================================
31 // ========================================================================
32 private final HashMap
<ProcessKey
, TimeRangeEventProcess
> allProcesses
= new HashMap
<ProcessKey
, TimeRangeEventProcess
>();
33 private static Integer uniqueId
= 0;
35 // ========================================================================
37 // ========================================================================
40 * Package level constructor
42 FlowProcessContainer() {
46 // ========================================================================
48 // ========================================================================
50 * Interface to add a new process.<p>
52 * Note : Process with the same key will be overwritten, it's calling function job to make sure the new process is unique.
54 * @param newProcess The process to add
57 public void addItem(TimeRangeEventProcess newItem
) {
58 if (newItem
!= null) {
59 allProcesses
.put(new ProcessKey(newItem
), newItem
);
69 public Integer
getUniqueId() {
74 * This method is intended for read only purposes in order to keep the
75 * internal data structure in synch
77 * @return TimeRangeEventProcess[]
80 public TimeRangeEventProcess
[] readItems() {
82 // This allow us to return an Array of the correct type of the exact correct dimension, without looping
83 return allProcesses
.values().toArray(new TimeRangeEventProcess
[allProcesses
.size()]);
87 * Clear the children information for processes e.g. just before refreshing
88 * data with a new time range
91 public void clearChildren() {
92 TimeRangeEventProcess process
= null;
93 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
95 while (iterator
.hasNext()) {
96 process
= allProcesses
.get(iterator
.next());
102 * Clear all process items
105 public void clearItems() {
106 allProcesses
.clear();
110 * Remove the process related to a specific trace e.g. during trace
113 * @param traceId The trace unique id (trace name?) on which we want to remove process
116 public void removeItems(String traceId
) {
117 ProcessKey iterKey
= null;
119 Iterator
<ProcessKey
> iterator
= allProcesses
.keySet().iterator();
120 while (iterator
.hasNext()) {
121 iterKey
= iterator
.next();
123 if (allProcesses
.get(iterKey
).getTraceID().equals(traceId
)) {
124 allProcesses
.remove(iterKey
);
130 * Search by keys (pid, cpuId, traceId and creationTime)<p>
132 * A match is returned if the four arguments received match an entry
133 * Otherwise null is returned
135 * @param searchedPid The processId (Pid) we are looking for
136 * @param searchedCpuId The cpu Id we are looking for
137 * @param searchedTraceID The traceId (trace name?) we are looking for
138 * @param searchedCreationtime The creation time we are looking for
140 * @return TimeRangeEventProcess
142 public TimeRangeEventProcess
findProcess(Long searchedPid
, Long searchedCpuId
, String searchedTraceID
, Long searchedCreationtime
) {
143 // Get the TimeRangeEventProcess associated to a key we create here
144 TimeRangeEventProcess foundProcess
= allProcesses
.get( new ProcessKey(searchedPid
, searchedCpuId
, searchedTraceID
, searchedCreationtime
) );
152 private TimeRangeEventProcess valueRef
= null;
154 private Long pid
= null;
155 private Long cpuId
= null;
156 private String traceId
= null;
157 private Long creationtime
= null;
159 @SuppressWarnings("unused")
160 private ProcessKey() { }
162 public ProcessKey(TimeRangeEventProcess newRef
) {
166 public ProcessKey(Long newPid
, Long newCpuId
, String newTraceId
, Long newCreationTime
) {
169 traceId
= newTraceId
;
170 creationtime
= newCreationTime
;
174 public boolean equals(Object obj
) {
180 boolean isSame
= false;
182 if ( obj
instanceof ProcessKey
) {
183 ProcessKey procKey
= (ProcessKey
) obj
;
185 if (valueRef
!= null) {
186 if ((procKey
.getPid().equals(valueRef
.getPid()))
187 && (procKey
.getTraceId().equals(valueRef
.getTraceID()))
188 && (procKey
.getCreationtime().equals(valueRef
.getCreationTime()))) {
189 // use the cpu value to validate pid 0
190 if (valueRef
.getPid().longValue() == 0L && !procKey
.getCpuId().equals(valueRef
.getCpu())) {
197 if ((procKey
.getPid().equals(this.pid
)) && (procKey
.getTraceId().equals(this.traceId
))
198 && (procKey
.getCreationtime().equals(this.creationtime
))) {
199 // use the cpu value to validate pid 0
200 if (this.pid
.longValue() == 0L && !procKey
.getCpuId().equals(this.cpuId
)) {
209 TraceDebug
.debug("ERROR : The given key is not of the type ProcessKey!" + obj
.getClass().toString()); //$NON-NLS-1$
215 // *** WARNING : Everything in there work because the check "valueRef != null" is the same for ALL getter
216 // Do NOT change this check without checking.
217 public Long
getPid() {
218 if ( valueRef
!= null ) {
219 return valueRef
.getPid();
226 public Long
getCpuId() {
227 if ( valueRef
!= null ) {
228 return valueRef
.getCpu();
235 public String
getTraceId() {
236 if ( valueRef
!= null ) {
237 return valueRef
.getTraceID();
244 public Long
getCreationtime() {
245 if ( valueRef
!= null ) {
246 return valueRef
.getCreationTime();
254 public int hashCode() {
255 return this.toString().hashCode();
260 @SuppressWarnings("nls")
261 public String
toString() {
262 if ( valueRef
!= null ) {
263 // return (valueRef.getPid().toString() + ":" +
264 // valueRef.getCpu().toString() + ":"
265 // + valueRef.getTraceID().toString() + ":" +
266 // valueRef.getCreationTime().toString());
267 return (valueRef
.getPid().toString() + ":" + valueRef
.getTraceID().toString() + ":" + valueRef
268 .getCreationTime().toString());
271 // return (pid.toString() + ":" + cpuId.toString() + ":" +
272 // traceId.toString() + ":" + creationtime.toString());
274 return (pid
.toString() + ":" + traceId
.toString() + ":" + creationtime
.toString());