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
.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
) {
175 boolean isSame
= false;
177 if ( obj
instanceof ProcessKey
) {
178 ProcessKey procKey
= (ProcessKey
) obj
;
180 if (valueRef
!= null) {
181 if ((procKey
.getPid().equals(valueRef
.getPid()))
182 && (procKey
.getTraceId().equals(valueRef
.getTraceID()))
183 && (procKey
.getCreationtime().equals(valueRef
.getCreationTime()))) {
184 // use the cpu value to validate pid 0
185 if (valueRef
.getPid().longValue() == 0L && !procKey
.getCpuId().equals(valueRef
.getCpu())) {
192 if ((procKey
.getPid().equals(this.pid
)) && (procKey
.getTraceId().equals(this.traceId
))
193 && (procKey
.getCreationtime().equals(this.creationtime
))) {
194 // use the cpu value to validate pid 0
195 if (this.pid
.longValue() == 0L && !procKey
.getCpuId().equals(this.cpuId
)) {
204 TraceDebug
.debug("ERROR : The given key is not of the type ProcessKey!" + obj
.getClass().toString()); //$NON-NLS-1$
210 // *** WARNING : Everything in there work because the check "valueRef != null" is the same for ALL getter
211 // Do NOT change this check without checking.
212 public Long
getPid() {
213 if ( valueRef
!= null ) {
214 return valueRef
.getPid();
221 public Long
getCpuId() {
222 if ( valueRef
!= null ) {
223 return valueRef
.getCpu();
230 public String
getTraceId() {
231 if ( valueRef
!= null ) {
232 return valueRef
.getTraceID();
239 public Long
getCreationtime() {
240 if ( valueRef
!= null ) {
241 return valueRef
.getCreationTime();
249 public int hashCode() {
250 return this.toString().hashCode();
255 @SuppressWarnings("nls")
256 public String
toString() {
257 if ( valueRef
!= null ) {
258 // return (valueRef.getPid().toString() + ":" +
259 // valueRef.getCpu().toString() + ":"
260 // + valueRef.getTraceID().toString() + ":" +
261 // valueRef.getCreationTime().toString());
262 return (valueRef
.getPid().toString() + ":" + valueRef
.getTraceID().toString() + ":" + valueRef
263 .getCreationTime().toString());
266 // return (pid.toString() + ":" + cpuId.toString() + ":" +
267 // traceId.toString() + ":" + creationtime.toString());
269 return (pid
.toString() + ":" + traceId
.toString() + ":" + creationtime
.toString());