[292397] Improve the search of Local UI model Process
authorFrancois Chouinard <fchouinard@gmail.com>
Tue, 20 Oct 2009 18:11:26 +0000 (18:11 +0000)
committerFrancois Chouinard <fchouinard@gmail.com>
Tue, 20 Oct 2009 18:11:26 +0000 (18:11 +0000)
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeComposite.java
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/model/trange/TimeRangeEventProcess.java
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/ControlFlowView.java
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/AbsFlowTRangeUpdate.java
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeAfterUpdateHandlers.java
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeBeforeUpdateHandlers.java
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeFinishUpdateHandler.java
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/model/FlowProcessContainer.java
org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/model/ResourceContainer.java

index 9bd391cf7c07db590b6f558c3d86cdd755b4066c..b9a728632bf3628eb68907b2f658ab87cd841c24 100644 (file)
@@ -186,7 +186,7 @@ ITmfTimeAnalysisEntry {
        }
 
        /**
-        * Reset this resource to the construction state except for
+        * Reset this resource to the construction state
         */
        public void reset() {
                getChildEventComposites().clear();
index 66dab7927e3777d7a30f77bfc97903c2b831c3d8..bceef5f6cd326a7a1281e750fa0daa392d1f4500 100644 (file)
@@ -51,6 +51,19 @@ public class TimeRangeEventProcess extends TimeRangeComposite implements
        // ========================================================================\r
        // Methods\r
        // =======================================================================\r
+       \r
+       \r
+       /**\r
+     * Interface to add children to this process\r
+     * \r
+     * @param newEvent\r
+     */\r
+    public void addChildren(TimeRangeEvent newEvent) {\r
+        if ((newEvent != null)) {\r
+            this.ChildEventLeafs.add(newEvent);\r
+        }\r
+    }\r
+       \r
        /**\r
         * @return\r
         */\r
index cbf3df9cfa87d1e85bf4b97d3bc8079b455f8103..e3c3fd13d807267597fc2ceb88cf6a1409656f33 100644 (file)
@@ -1146,12 +1146,10 @@ public class ControlFlowView extends AbsTimeUpdateView implements
                        TmfTimeRange trange) {
                if (clearAllData) {
                        FlowModelFactory.getProcContainer().clearProcesses();
-                       // Obtain the current process list
-                       Vector<TimeRangeEventProcess> processList = FlowModelFactory
+                       // Obtain the current process array
+                       TimeRangeEventProcess[] processArr = FlowModelFactory
                                        .getProcContainer().readProcesses();
-                       // convert it to an Array as expected by the widget
-                       TimeRangeEventProcess[] processArr = processList
-                                       .toArray(new TimeRangeEventProcess[processList.size()]);
+                       
 
                        // initialise to an empty model
                        flowModelUpdates(processArr, -1, -1, false);
@@ -1186,12 +1184,9 @@ public class ControlFlowView extends AbsTimeUpdateView implements
                        experimentStartTime = experimentTimeRange.getStartTime().getValue();
                        experimentEndTime = experimentTimeRange.getEndTime().getValue();
                }
-               // Obtain the current process list
-               Vector<TimeRangeEventProcess> processList = FlowModelFactory
+               // Obtain the current process array
+               TimeRangeEventProcess[] processArr = FlowModelFactory
                                .getProcContainer().readProcesses();
-               // convert it to an Array as expected by the widget
-               TimeRangeEventProcess[] processArr = processList
-                               .toArray(new TimeRangeEventProcess[processList.size()]);
                // Sort the array by pid
                Arrays.sort(processArr);
 
@@ -1214,8 +1209,8 @@ public class ControlFlowView extends AbsTimeUpdateView implements
                if (TraceDebug.isDEBUG()) {
                        int eventCount = 0;
                        Long count = smanager.getEventCount();
-                       for (TimeRangeEventProcess process : processList) {
-                               eventCount += process.getTraceEvents().size();
+                       for ( int pos = 0; pos<processArr.length; pos++ ) {
+                               eventCount += processArr[pos].getTraceEvents().size();
                        }
 
                        int discarded = FlowModelFactory.getParamsUpdater()
index eeec2ee04390725813c9879f94ddea51f8966e62..f4879b4fdbbfd2b6c5c3e9f4fa0cb1d83133c979 100644 (file)
@@ -42,7 +42,7 @@ public abstract class AbsFlowTRangeUpdate extends AbsTRangeUpdate implements IEv
        protected TimeRangeEventProcess addLocalProcess(LttngProcessState stateProcess, long traceStartTime, long traceEndTime, String traceId) {
                // TimeRangeEventProcess localProcess = new TimeRangeEventProcess(id, name, startTime, stopTime, groupName, className)
                TimeRangeEventProcess localProcess = new TimeRangeEventProcess(
-                               procContainer.bookProcId(), stateProcess.getName(),
+                               procContainer.getUniqueId(), stateProcess.getName(),
                                traceStartTime, traceEndTime, "", stateProcess.getType()
                                                .getInName(), stateProcess.getCpu(), stateProcess
                                                .getInsertion_time().getValue());
@@ -54,7 +54,7 @@ public abstract class AbsFlowTRangeUpdate extends AbsTRangeUpdate implements IEv
                localProcess.setBrand(stateProcess.getBrand());
                localProcess.setTraceID(traceId);
                localProcess.setProcessType(stateProcess.getType().getInName());
-               procContainer.addProcesse(localProcess);
+               procContainer.addProcess(localProcess);
                return localProcess;
        }
        
index 514f7a7c9360e7828894013d732c08da2c22e41d..8ca30915a0254d6f65a8223862a3732580900149 100644 (file)
@@ -60,7 +60,7 @@ class FlowTRangeAfterUpdateHandlers {
                 }
                                
                                //hashed_process_data = processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
-                               TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCreation_time().getValue(), traceSt.getTraceId() );
+                               TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCpu(), traceSt.getTraceId(),process_in.getCreation_time().getValue() );
                                
                                if ( localProcess == null ) {
                                        if ( (pid_in == 0) || (pid_in != process_in.getPpid()) ) {
@@ -139,7 +139,7 @@ class FlowTRangeAfterUpdateHandlers {
                 LttngProcessState process_child = lttv_state_find_process(traceSt, trcEvent.getCpuId(), child_pid );
                            
                            if ( process_child != null ) {
-                               TimeRangeEventProcess localProcess = procContainer.findProcess(process_child.getPid(), process_child.getCreation_time().getValue(), traceSt.getTraceId() );
+                               TimeRangeEventProcess localProcess = procContainer.findProcess(process_child.getPid(), process_child.getCpu(), traceSt.getTraceId(), process_child.getCreation_time().getValue() );
                                
                                if ( localProcess == null ) {
                                    if ( (child_pid == 0) || (child_pid != process_child.getPpid()) ) {            
@@ -198,7 +198,7 @@ class FlowTRangeAfterUpdateHandlers {
                                //   if(likely(process_list->current_hash_data[trace_num][cpu] != NULL) ){
                            //        hashed_process_data = process_list->current_hash_data[trace_num][cpu];
                            //   }
-                               TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCreation_time().getValue(), traceSt.getTraceId());
+                               TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(),  process.getCreation_time().getValue());
                                
                                if ( localProcess == null ) {
                                    if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) {                                 
@@ -246,7 +246,7 @@ class FlowTRangeAfterUpdateHandlers {
 
                 if ( process != null ) {
                     
-                    TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCreation_time().getValue(), traceSt.getTraceId());
+                    TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(),  process.getCpu(), traceSt.getTraceId(), process.getCreation_time().getValue());
                     
                     if ( localProcess == null ) {
                         if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) {
@@ -302,7 +302,7 @@ class FlowTRangeAfterUpdateHandlers {
                     //   if(likely(process_list->current_hash_data[trace_num][cpu] != NULL) ){
                     //        hashed_process_data = process_list->current_hash_data[trace_num][cpu];
                     //   }
-                    TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCreation_time().getValue(), traceSt.getTraceId());
+                    TimeRangeEventProcess localProcess = procContainer.findProcess(process.getPid(), process.getCpu(), traceSt.getTraceId(), process.getCreation_time().getValue());
                     
                     if ( localProcess == null ) {
                         if ( (process.getPid() == 0) || (process.getPid() != process.getPpid()) ) {                         
@@ -382,7 +382,7 @@ class FlowTRangeAfterUpdateHandlers {
                                LttngProcessState process_in = lttv_state_find_process(traceSt, trcEvent.getCpuId(), pid_in );
                                
                                if ( process_in != null ) {
-                                   TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCreation_time().getValue(), traceSt.getTraceId());
+                                   TimeRangeEventProcess localProcess = procContainer.findProcess(process_in.getPid(), process_in.getCpu(), traceSt.getTraceId(), process_in.getCreation_time().getValue());
                            
                                    if (localProcess == null) {
                                            if ( (process_in.getPid() == 0) || (process_in.getPid() != process_in.getPpid()) ) {
index c381ea6006e0c5abebe6d5fdde2ce032de44cd2c..cec3cc7ea1ecab199fba4179278e884a32eba95a 100644 (file)
@@ -64,8 +64,8 @@ class FlowTRangeBeforeUpdateHandlers {
                                        // it
                                        // may change
                                        TimeRangeEventProcess localProcess = procContainer
-                                                       .findProcess(stateProcess.getPid(), stateProcess
-                                                                       .getCreation_time().getValue(), traceId);
+                                                       .findProcess(stateProcess.getPid(), stateProcess.getCpu(), traceId, stateProcess
+                                    .getCreation_time().getValue());
 
                                        // Add process to process list if not present
                                        if (localProcess == null) {
@@ -147,9 +147,8 @@ class FlowTRangeBeforeUpdateHandlers {
                                                // hashed_process_data =
                                                // processlist_get_process_data(process_list,pid_out,process->cpu,&birth,trace_num);
                                                TimeRangeEventProcess localProcess = procContainer
-                                                               .findProcess(process.getPid(), process
-                                                                               .getCreation_time().getValue(), traceSt
-                                                                               .getTraceId());
+                                                               .findProcess(process.getPid(), process.getCpu(), traceSt
+                                                                               .getTraceId(), process.getCreation_time().getValue());
 
                                                // Add process to process list if not present
                                                // Replace C Call :
@@ -183,9 +182,8 @@ class FlowTRangeBeforeUpdateHandlers {
                                                // processlist_get_process_data(process_list, pid_in,
                                                // tfs->cpu, &birth, trace_num);
                                                TimeRangeEventProcess localProcess = procContainer
-                                                               .findProcess(process.getPid(), process
-                                                                               .getCreation_time().getValue(), traceSt
-                                                                               .getTraceId());
+                                                               .findProcess(process.getPid(), process.getCpu(), traceSt
+                                                                               .getTraceId(), process.getCreation_time().getValue());
 
                                                // Add process to process list if not present
                                                // Replace C Call :
@@ -258,9 +256,8 @@ class FlowTRangeBeforeUpdateHandlers {
                                        // processlist_get_process_data(process_list, pid,
                                        // process->cpu, &birth,trace_num);
                                        TimeRangeEventProcess localProcess = procContainer
-                                                       .findProcess(process.getPid(), process
-                                                                       .getCreation_time().getValue(), traceSt
-                                                                       .getTraceId());
+                                                       .findProcess(process.getPid(), process.getCpu(), traceSt
+                                                                       .getTraceId(), process.getCreation_time().getValue());
 
                                        // Add process to process list if not present
                                        // Replace C Call :
@@ -327,9 +324,9 @@ class FlowTRangeBeforeUpdateHandlers {
                                                // hashed_process_data =
                                                // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
                                                TimeRangeEventProcess localProcess = procContainer
-                                                               .findProcess(process.getPid(), process
-                                                                               .getCreation_time().getValue(), traceSt
-                                                                               .getTraceId());
+                                                               .findProcess(process.getPid(), process.getCpu(), traceSt
+                                                                               .getTraceId(), process
+                                        .getCreation_time().getValue());
 
                                                // This is as it was in the C ... ?
                                                if (localProcess == null) {
@@ -396,9 +393,9 @@ class FlowTRangeBeforeUpdateHandlers {
                                        // hashed_process_data =
                                        // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num);
                                        TimeRangeEventProcess localProcess = procContainer
-                                                       .findProcess(process.getPid(), process
-                                                                       .getCreation_time().getValue(), traceSt
-                                                                       .getTraceId());
+                                                       .findProcess(process.getPid(), process.getCpu(), traceSt
+                                                                       .getTraceId(), process
+                                    .getCreation_time().getValue());
 
                                        // Add process to process list if not present
                                        if (localProcess == null) {
index f759c9173add130da9d07246c1800b376d5a6770..dbaeb542df247b9a60a3a9da000d04ad81383fe8 100644 (file)
@@ -41,7 +41,7 @@ public class FlowTRangeFinishUpdateHandler extends AbsFlowTRangeUpdate
                long endReqTime = traceSt.getInputDataRef().getTraceTimeWindow()
                                .getEndTime().getValue();
                TraceDebug.debug("Number of localProcesses: "
-                               + procContainer.readProcesses().size());
+                               + procContainer.readProcesses().length);
                // to identify the process relevant to the traceState
                String traceId = traceSt.getTraceId();
                int numLocalFound = 0;
index 3b04c8dfa52a0dc3eeb7a307cac06ae063038bba..535b88958c5087a70d788026fa224c9e8d081b33 100644 (file)
@@ -7,16 +7,17 @@
  * http://www.eclipse.org/legal/epl-v10.html
  * 
  * Contributors:
- *   Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
+ *   Alvaro Sanchez-Leon - Initial API and implementation
  *******************************************************************************/
 package org.eclipse.linuxtools.lttng.ui.views.controlflow.model;
 
-import java.util.Vector;
+import java.util.HashMap;
+import java.util.Iterator;
 
 import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess;
 
 /**
- * Common location to allocate the processes in use by the Control flow view
+ * Contains the processes in use by the Control flow view
  * 
  * @author alvaro
  * 
@@ -25,9 +26,9 @@ public class FlowProcessContainer {
        // ========================================================================
        // Data
        // ========================================================================
-       private final Vector<TimeRangeEventProcess> processes = new Vector<TimeRangeEventProcess>();
-       private int idgen = 0;
-
+       private final HashMap<ProcessKey, TimeRangeEventProcess> allProcesses = new HashMap<ProcessKey, TimeRangeEventProcess>();
+       private static Integer uniqueId = 0;
+       
        // ========================================================================
        // Constructor
        // ========================================================================
@@ -43,103 +44,197 @@ public class FlowProcessContainer {
        // Methods
        // ========================================================================
        /**
-        * Interface to add processes.
+        * Interface to add a new process.<p>
+        * 
+        * Note : Process with the same key will be overwritten, it's calling function job to make sure the new process is unique.
         * 
-        * @param process
+        * @param newProcess   The process to add
         */
-       public void addProcesse(TimeRangeEventProcess process) {
-               if (process != null) {
-                       processes.add(process);
+       public void addProcess(TimeRangeEventProcess newProcess) {
+               if (newProcess != null) {
+                       allProcesses.put(new ProcessKey(newProcess), newProcess);
                }
        }
-
+       
        /**
-        * This method is intended for ready only purposes in order to keep the
-        * internal data structure in Synch
-        * 
-        * @return
-        */
-       public Vector<TimeRangeEventProcess> readProcesses() {
-               return processes;
+     * Request a unique ID
+     * 
+     * @return Integer
+     */
+    public Integer getUniqueId() {
+        return uniqueId++;
+    }
+    
+    /**
+     * This method is intended for read only purposes in order to keep the
+     * internal data structure in synch
+     * 
+     * @return TimeRangeEventProcess[]
+     */
+       public TimeRangeEventProcess[] readProcesses() {
+           // This allow us to return an Array of the correct type of the exact correct dimension, without looping
+               return allProcesses.values().toArray(new TimeRangeEventProcess[allProcesses.size()]);
        }
-
+       
        /**
-        * Clear the children information for processes related to a specific trace
-        * e.g. just before refreshing data with a new time range
-        
-        * @param traceId
-        */
+     * Clear the children information for processes related to a specific trace
+     * e.g. just before refreshing data with a new time range
+     * 
+     * @param traceId   The trace unique id (trace name?) on which we need to eliminate children.
+     */
        public void clearChildren(String traceId) {
-               String procTraceId;
-               for (TimeRangeEventProcess process : processes) {
-                       procTraceId = process.getTraceID();
-                       if (procTraceId.equals(traceId)) {
-                               process.reset();
-                       }
-               }
+           TimeRangeEventProcess process = null;
+        Iterator<ProcessKey> iterator = allProcesses.keySet().iterator();
+        
+        while (iterator.hasNext()) {
+            process = allProcesses.get(iterator.next());
+            
+            if (process.getTraceID().equals(traceId)) {
+                // Reset clear childEventComposites() and traceEvents()
+                // Also restore the nextGoodTime to the insertionTime for the drawing
+                process.reset();
+            }
+        }
        }
-
+       
        /**
-        * Clear all process items
-        */
-       public void clearProcesses() {
-               processes.clear();
-       }
-
-       /**
-        * remove the processes related to a specific trace e.g. during trace
-        * removal
-        
-        * @param traceId
-        */
+     * Clear all process items
+     */
+    public void clearProcesses() {
+        allProcesses.clear();
+    }
+       
+    /**
+     * Remove the process related to a specific trace e.g. during trace
+     * removal
+     * 
+     * @param traceId   The trace unique id (trace name?) on which we want to remove process
+     */
        public void removeProcesses(String traceId) {
-               String procTraceId;
-               for (TimeRangeEventProcess process : processes) {
-                       procTraceId = process.getTraceID();
-                       if (procTraceId.equals(traceId)) {
-                           // Children and traceEvent will get claimed by the garbage collector when process is unreferenced
-                           // Therefore, we don't need to removed them
-                               processes.remove(process);
-                       }
-               }
-       }
-
-       /**
-        * A match is returned if the three arguments received match an entry in the
-        * Map, otherwise null is returned
-        * 
-        * @param pid
-        * @param creationtime
-        * @param traceID
-        * @return
-        */
-       public TimeRangeEventProcess findProcess(Long pid, Long creationtime,
-                       String traceID) {
-               TimeRangeEventProcess rprocess = null;
-
-               // TODO: This needs a more efficient way to find, e.g. use class with
-               // hash code base on the keys trace, pid and creation time the class
-               // should also override the equals to valid the search via the hashcode
-               for (TimeRangeEventProcess process : processes) {
-                       if (process.getPid().equals(pid)) {
-                               if (process.getCreationTime().equals(creationtime)) {
-                                       if (process.getTraceID().equals(traceID)) {
-                                               return process;
-                                       }
-                               }
-                       }
-               }
-
-               return rprocess;
+           ProcessKey iterKey = null;
+
+        Iterator<ProcessKey> iterator = allProcesses.keySet().iterator();
+        while (iterator.hasNext()) {
+            iterKey = iterator.next();
+            
+            if (allProcesses.get(iterKey).getTraceID().equals(traceId)) {
+                allProcesses.remove(iterKey);
+            }
+        }
        }
+       
+    /**
+     * Search by keys (pid, cpuId, traceId and creationTime)<p>
+     * 
+     * A match is returned if the four arguments received match an entry
+     *  Otherwise null is returned
+     *  
+     * @param searchedPid       The processId (Pid) we are looking for
+     * @param searchedCpuId     The cpu Id we are looking for
+     * @param searchedTraceID   The traceId (trace name?) we are looking for
+     * @param searchedCreationtime The creation time we are looking for
+     * 
+     * @return TimeRangeEventProcess
+     */
+    public TimeRangeEventProcess findProcess(Long searchedPid, Long searchedCpuId, String searchedTraceID, Long searchedCreationtime) {
+        // Get the TimeRangeEventProcess associated to a key we create here
+        TimeRangeEventProcess foundProcess = allProcesses.get( new ProcessKey(searchedPid, searchedCpuId, searchedTraceID, searchedCreationtime) );
+        
+        return foundProcess;
+    }
+}
 
-       /**
-        * Generate a unique process id while building the process list
-        * 
-        * @return
-        */
-       public int bookProcId() {
-               return idgen++;
-       }
 
+class ProcessKey {
+    private TimeRangeEventProcess valueRef = null;
+    
+    private Long    pid = null;
+    private Long    cpuId = null;
+    private String  traceId = null;
+    private Long    creationtime = null;
+    
+    @SuppressWarnings("unused")
+    private ProcessKey() { }
+    
+    public ProcessKey(TimeRangeEventProcess newRef) {
+        valueRef = newRef;
+    }
+    
+    public ProcessKey(Long newPid, Long newCpuId, String newTraceId, Long newCreationTime) {
+        pid = newPid;
+        cpuId = newCpuId;
+        traceId = newTraceId;
+        creationtime = newCreationTime;
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        boolean isSame = false;
+        
+        if ( obj instanceof ProcessKey ) {
+               ProcessKey procKey = (ProcessKey) obj;
+            if ( (procKey.getPid().equals(this.getPid()) ) &&
+                 (procKey.getTraceId().equals(this.getTraceId()) ) &&
+                 (procKey.getCpuId().equals(this.getCpuId()) ) &&
+                 (procKey.getCreationtime().equals(this.getCreationtime()) )  )
+            {
+                isSame = true;
+            }
+        }
+        
+        return isSame;
+    }
+    
+    // *** WARNING : Everything in there work because the check "valueRef != null" is the same for ALL getter
+    // Do NOT change this check without checking.
+    public Long getPid() {
+       if ( valueRef != null ) {
+            return valueRef.getPid();
+        }
+        else {
+            return pid;
+        }
+    }
+
+    public Long getCpuId() {
+        if ( valueRef != null ) {
+            return valueRef.getCpu();
+        }
+        else {
+            return cpuId;
+        }
+    }
+    
+    public String getTraceId() {
+        if ( valueRef != null ) {
+            return valueRef.getTraceID();
+        }
+        else {
+            return traceId;
+        }
+    }
+    
+    public Long getCreationtime() {
+        if ( valueRef != null ) {
+            return valueRef.getCreationTime();
+        }
+        else {
+            return creationtime;
+        }
+    }
+    
+    @Override
+    public int hashCode() {
+       return this.toString().hashCode();
+    }
+    
+    
+    @Override
+    public String toString() {
+        if ( valueRef != null ) {
+            return (valueRef.getPid().toString() + ":" + valueRef.getCpu().toString() + ":" + valueRef.getTraceID().toString() + ":" + valueRef.getCreationTime().toString());
+        } 
+        
+        return (pid + ":" + cpuId + ":" + traceId + ":" + creationtime);
+    }
 }
index ff2e6dcc34e66cba2de1c4ea8bd857e9fd025e0c..74ba240b419973d20353a39c64a3a25e0dfc845b 100644 (file)
@@ -7,7 +7,7 @@
  * http://www.eclipse.org/legal/epl-v10.html
  * 
  * Contributors:
- *   Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
+ *   Alvaro Sanchez-Leon - Initial API and implementation
  *******************************************************************************/
 package org.eclipse.linuxtools.lttng.ui.views.resources.model;
 
@@ -25,10 +25,16 @@ import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource.Resou
  * 
  */
 public class ResourceContainer {
-    
+       // ========================================================================
+       // Data
+       // ========================================================================
        private final HashMap<ResourceKey, TimeRangeEventResource> resources = new HashMap<ResourceKey, TimeRangeEventResource>();
        private static Integer uniqueId = 0;
        
+       
+       // ========================================================================
+       // Constructor
+       // ========================================================================
        /**
         * Package level constructor
         */
@@ -45,7 +51,9 @@ public class ResourceContainer {
                }
        }
        
-       
+       // ========================================================================
+       // Methods
+       // ========================================================================
        /**
      * Request a unique ID
      * 
@@ -73,7 +81,6 @@ public class ResourceContainer {
         * @param traceId
         */
        public void clearChildren(String traceId) {
-           
            TimeRangeEventResource newRes = null;
         Iterator<ResourceKey> iterator = resources.keySet().iterator();
         
@@ -94,7 +101,7 @@ public class ResourceContainer {
        }
 
        /**
-        * remove the resources related to a specific trace e.g. during trace
+        * Remove the resources related to a specific trace e.g. during trace
         * removal
         * 
         * @param traceId
@@ -114,82 +121,24 @@ public class ResourceContainer {
        
        
        /**
-     * Obtain a resource id from resource attributes<br>
-     * <br>
-     * Note : Slow as hell and defeat the purpose of the map. 
-     *        This function probably shouldn't be used, except for testing.
-     * 
-     */
-    public Long findUniqueIdOfresource(Long startTime, Long endTime, String name, String groupName, String className, ResourceTypes type, String traceId) {
-        
-        Long foundId = null;
-        
-        ResourceKey newKey = null;
-        TimeRangeEventResource newContent = null;
-        
-        Iterator<ResourceKey> iterator = resources.keySet().iterator();
-        while ( (iterator.hasNext()) && (foundId == null) ) {
-            newKey = iterator.next();
-            newContent = resources.get(newKey);
-            
-            if ( ( newContent.getStartTime() == startTime ) && ( newContent.getStopTime() == endTime ) && ( newContent.getName() == name ) &&
-                 ( newContent.getGroupName() == groupName ) && ( newContent.getClassName() == className ) && ( newContent.getType() == type ) &&
-                 ( newContent.getTraceId() == traceId ) ) 
-            {
-                foundId = newKey.getResourceId();
-            }
-        }
-        
-        return foundId;
-        
-    }
-       
-       /**
-        * Search by keys (resourceId, traceId and type)<br>
-        * <br>
+        * Search by keys (resourceId, traceId and type)<p>
+        * 
      * A match is returned if the three arguments received match an entry
      *  Otherwise null is returned
+     *  
+     * @param searchedId        The ressourceId we are looking for
+     * @param searchedType      The ressourceType we are looking for
+     * @param searchedTraceId   The traceId (trace name?) we are looking for
      * 
-     * @return
+     * @return TimeRangeEventResource
      */
     public TimeRangeEventResource findResource(Long searchedId, ResourceTypes searchedType, String searchedTraceId) {
-        
-        TimeRangeEventResource foundResource = null;
-        
                // Get the EventResource associated to a key we create here
-        TimeRangeEventResource tmpRes = resources.get( new ResourceKey(searchedId, searchedTraceId, searchedType) );
-        
-        if ( tmpRes != null ) {
-            foundResource = tmpRes;
-        }
+        TimeRangeEventResource foundResource = resources.get( new ResourceKey(searchedId, searchedTraceId, searchedType) );
         
         return foundResource;
     }
        
-       /**
-        * Search by name<br>
-        * <br>
-        * A match is returned if the four arguments received match an entry in the
-        *     Otherwise null is returned
-        * 
-        * @return
-        */
-       public TimeRangeEventResource findResourceFilterByName(Long searchedId, ResourceTypes searchedType, String searchedTraceId, String searchedName) {
-           
-           TimeRangeEventResource foundResource = null;
-           
-           // Get the EventResource asociated to a key we create here
-           TimeRangeEventResource tmpRes = resources.get( new ResourceKey(searchedId, searchedTraceId, searchedType) );
-           
-           if ( tmpRes != null ) {
-            if ( tmpRes.getName().equals(searchedName) ) {
-                foundResource = tmpRes;
-            }
-           }
-           
-               return foundResource;
-       }
-       
        /* 
      *  MAIN : For testing only!
      */
@@ -313,8 +262,9 @@ class ResourceKey {
     
     @Override
     public String toString() {
-        return (getResourceId().toString() + ":" + getTraceId().toString() + ":" + getType().toString());
-        
+        if ( valueRef != null ) {
+            return (valueRef.getResourceId().toString() + ":" + valueRef.getTraceId().toString() + ":" + valueRef.getType().toString());
+        }
+        return (resourceId + ":" + traceId + ":" + type);
     }
 }
-
This page took 0.037843 seconds and 5 git commands to generate.