From 2211df66ad6ceb930bed077c8f76dc663cde0901 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Fri, 6 Nov 2009 21:48:22 +0000 Subject: [PATCH] [292393] Revisited header search function --- .../FlowTRangeBeforeUpdateHandlers.java | 8 +- .../model/FlowProcessContainer.java | 30 ++- .../resources/model/ResourceContainer.java | 75 ++---- .../linuxtools/lttng/state/StateManager.java | 69 +----- .../evProcessor/state/AbsStateProcessing.java | 26 +- .../evProcessor/state/AbsStateUpdate.java | 6 +- .../state/StateUpdateHandlers.java | 11 +- .../lttng/state/model/LttngProcessState.java | 86 ++----- .../lttng/state/model/LttngTraceState.java | 227 +++++++++++++++--- 9 files changed, 263 insertions(+), 275 deletions(-) diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeBeforeUpdateHandlers.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeBeforeUpdateHandlers.java index cec3cc7ea1..20362e3f8a 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeBeforeUpdateHandlers.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/evProcessor/FlowTRangeBeforeUpdateHandlers.java @@ -11,8 +11,6 @@ *******************************************************************************/ package org.eclipse.linuxtools.lttng.ui.views.controlflow.evProcessor; -import java.util.List; - import org.eclipse.linuxtools.lttng.event.LttngEvent; import org.eclipse.linuxtools.lttng.state.StateStrings.Events; import org.eclipse.linuxtools.lttng.state.StateStrings.Fields; @@ -387,8 +385,10 @@ class FlowTRangeBeforeUpdateHandlers { // present in the state provider? // This seems more direct. and makes sure all processes are // reflected in the control flow view. - List processes = traceSt.getProcesses(); - for (LttngProcessState process : processes) { + LttngProcessState[] processes = traceSt.getProcesses(); + for (int pos=0; pos < processes.length; pos++) { + LttngProcessState process = processes[pos]; + // Replace the C call : // hashed_process_data = // processlist_get_process_data(process_list,pid,process->cpu,&birth,trace_num); diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/model/FlowProcessContainer.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/model/FlowProcessContainer.java index 535b88958c..64be7332b4 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/model/FlowProcessContainer.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/controlflow/model/FlowProcessContainer.java @@ -14,6 +14,7 @@ package org.eclipse.linuxtools.lttng.ui.views.controlflow.model; import java.util.HashMap; import java.util.Iterator; +import org.eclipse.linuxtools.lttng.TraceDebug; import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess; /** @@ -173,13 +174,28 @@ class ProcessKey { 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; - } + + if ( valueRef != null ) { + if ( (procKey.getPid().equals(valueRef.getPid()) ) && + (procKey.getTraceId().equals(valueRef.getTraceID()) ) && + (procKey.getCpuId().equals(valueRef.getCpu()) ) && + (procKey.getCreationtime().equals(valueRef.getCreationTime()) ) ) + { + isSame = true; + } + } + else { + if ( (procKey.getPid().equals(this.pid ) ) && + (procKey.getTraceId().equals(this.traceId ) ) && + (procKey.getCpuId().equals(this.cpuId ) ) && + (procKey.getCreationtime().equals(this.creationtime ) ) ) + { + isSame = true; + } + } + } + else { + TraceDebug.debug("ERROR : The given key is not of the type ProcessKey!" + obj.getClass().toString()); } return isSame; diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/model/ResourceContainer.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/model/ResourceContainer.java index 74ba240b41..23082c9207 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/model/ResourceContainer.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/resources/model/ResourceContainer.java @@ -14,8 +14,8 @@ package org.eclipse.linuxtools.lttng.ui.views.resources.model; import java.util.HashMap; import java.util.Iterator; +import org.eclipse.linuxtools.lttng.TraceDebug; import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource; -import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeResourceFactory; import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource.ResourceTypes; /** @@ -138,56 +138,8 @@ public class ResourceContainer { return foundResource; } - - /* - * MAIN : For testing only! - */ - public static void main(String[] args) { - - System.out.println("**** TEST PART 1 WITH STANDALONE *** "); - HashMap newMap = new HashMap(); - - ResourceKey test1 = new ResourceKey(0L,"trace1", ResourceTypes.CPU); - ResourceKey test2 = new ResourceKey(0L, "trace1", ResourceTypes.CPU); - newMap.put(test2, "BUG BUG BUG"); - newMap.put(test1, "JOY JOY JOY"); - - // Test1 and TestKey return the same value! - ResourceKey testKey = new ResourceKey(0L, "trace1", ResourceTypes.CPU); - System.out.println( newMap.get(testKey) + " == " + newMap.get(test1) ); - - // Test2 should return the same as Test1 - System.out.println( "JOY JOY JOY == " + newMap.get(test2) ); - - - - - System.out.println("**** TEST PART 2 WITH TimeRangeEventResource *** "); - newMap.clear(); - TimeRangeResourceFactory rfactory = TimeRangeResourceFactory - .getInstance(); - TimeRangeEventResource tmpRes1 = rfactory.createResource(0, 0, 0, - "name1", "trace1", "classname1", ResourceTypes.CPU, 0L, 0l); - TimeRangeEventResource tmpRes2 = rfactory.createResource(0, 0, 0, - "name2", "trace1", "classname2", ResourceTypes.CPU, 0L, 0l); - - ResourceKey test3 = new ResourceKey(tmpRes1); - ResourceKey test4 = new ResourceKey(tmpRes2); - - newMap.put(test3, "BUG BUG BUG"); - newMap.put(test4, "JOY JOY JOY"); - - // Test3 and Test4 return the same value! - System.out.println( newMap.get(test3) + " == " + newMap.get(test4) ); - - - ResourceKey testKey2 = new ResourceKey(0L, "trace1", ResourceTypes.CPU); - // TestKey2 should return the same as Test3 AND Test4 - System.out.println( newMap.get(test4) + " == " + newMap.get(test4) + " == " + newMap.get(testKey2) ); - } } - class ResourceKey { private TimeRangeEventResource valueRef = null; @@ -214,12 +166,25 @@ class ResourceKey { boolean isSame = false; if ( obj instanceof ResourceKey ) { - if ( ( ((ResourceKey)obj).getResourceId().equals(this.getResourceId()) ) && - ( ((ResourceKey)obj).getTraceId().equals(this.getTraceId()) ) && - ( ((ResourceKey)obj).getType().equals(this.getType()) ) ) - { - isSame = true; - } + if ( valueRef != null ) { + if ( ( ((ResourceKey)obj).getResourceId().equals(valueRef.getResourceId()) ) && + ( ((ResourceKey)obj).getTraceId().equals(valueRef.getTraceId()) ) && + ( ((ResourceKey)obj).getType().equals(valueRef.getType()) ) ) + { + isSame = true; + } + } + else { + if ( ( ((ResourceKey)obj).getResourceId().equals(this.resourceId)) && + ( ((ResourceKey)obj).getTraceId().equals(this.traceId)) && + ( ((ResourceKey)obj).getType().equals(this.traceId)) ) + { + isSame = true; + } + } + } + else { + TraceDebug.debug("ERROR : The given key is not of the type ProcessKey!" + obj.getClass().toString()); } return isSame; diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateManager.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateManager.java index 0663458a48..5cd47bf380 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateManager.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateManager.java @@ -15,7 +15,6 @@ package org.eclipse.linuxtools.lttng.state; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Observable; import java.util.Set; import java.util.Vector; @@ -26,9 +25,7 @@ import org.eclipse.linuxtools.lttng.jni.JniTrace; import org.eclipse.linuxtools.lttng.state.evProcessor.AbsEventProcessorFactory; import org.eclipse.linuxtools.lttng.state.evProcessor.EventProcessorProxy; import org.eclipse.linuxtools.lttng.state.evProcessor.IEventProcessing; -import org.eclipse.linuxtools.lttng.state.experiment.StateManagerFactory; import org.eclipse.linuxtools.lttng.state.model.ILttngStateInputRef; -import org.eclipse.linuxtools.lttng.state.model.LttngProcessState; import org.eclipse.linuxtools.lttng.state.model.LttngTraceState; import org.eclipse.linuxtools.lttng.state.model.StateModelFactory; import org.eclipse.linuxtools.lttng.trace.LTTngTrace; @@ -154,11 +151,9 @@ public class StateManager extends Observable { request.startRequestInd(fExperiment, true, true); if (TraceDebug.isDEBUG()) { - List processes = stateIn - .getTraceStateModel().getProcesses(); StringBuilder sb = new StringBuilder( "Total number of processes in the State provider: " - + processes.size()); + + stateIn.getTraceStateModel().getProcesses().length); TmfTimeRange logTimes = fEventLog.getTimeRange(); sb.append("\n\tLog file times " @@ -201,14 +196,12 @@ public class StateManager extends Observable { request.startRequestInd(fExperiment, false, false); if (TraceDebug.isDEBUG()) { - List processes = stateIn.getTraceStateModel() - .getProcesses(); TraceDebug .debug(" Time Window requested, (start adjusted to checkpoint): " + trange.getStartTime() + "-" + trange.getEndTime() + " Total number of processes in the State provider: " - + processes.size() + " Completed"); + + stateIn.getTraceStateModel().getProcesses().length + " Completed"); } } @@ -596,62 +589,4 @@ public class StateManager extends Observable { } } } - - // *** MAIN : For testing only *** - public static void main(String[] args) { - - // Timestamp for the "197500th" events - long timefor197500 = 953098902827L; - - // A new StateManager - StateManager stateManagerTest = StateManagerFactory.getManager("test"); - - LTTngTrace[] testStream = new LTTngTrace[1]; - try { - // The stream is needed by the eventLog, which is needed by the - // StateManager - // testStream[0] = new LttngEventStream("/home/william/trace1", - // true); - testStream[0] = new LTTngTrace( - "/home/william/runtime-EclipseApplication/TEST_JOIE/Traces/trace3", - true); - - TmfExperiment newExpt = new TmfExperiment("trace1", testStream); - - // This will create all the checkpoint - stateManagerTest.setTraceSelection(newExpt, false); - System.out.println("JOIE JOIE FIN DE LA CREATION DES CHECKPOINTS"); - - // *** Restore some checkpoint to test - - // Test the restoration from position - // stateManagerTest.restoreCheckPointByPosition(197500); - - if (testStream[0].getCurrentEvent().getTimestamp().getValue() == timefor197500) { - System.out.println("Successfully restored by Position!"); - } else { - System.out.println("FAILED : " - + testStream[0].getCurrentEvent().getTimestamp() - .getValue() + " != " + timefor197500); - } - - // Test the restoration from Timestamp - TmfTimestamp newTimestamp = new TmfTimestamp(timefor197500, - (byte) -9); - stateManagerTest.restoreCheckPointByTimestamp(newTimestamp); - // test the timestamp - if (testStream[0].getCurrentEvent().getTimestamp().getValue() == timefor197500) { - System.out.println("Successfully restored by Timestamp!"); - } else { - System.out.println("FAILED : " - + testStream[0].getCurrentEvent().getTimestamp() - .getValue() + " != " + timefor197500); - } - - } catch (Exception e) { - e.printStackTrace(); - } - - } - } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateProcessing.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateProcessing.java index 30b66d65ac..b6cb14ecf4 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateProcessing.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateProcessing.java @@ -3,8 +3,6 @@ */ package org.eclipse.linuxtools.lttng.state.evProcessor.state; -import java.util.List; - import org.eclipse.linuxtools.lttng.TraceDebug; import org.eclipse.linuxtools.lttng.event.LttngEvent; import org.eclipse.linuxtools.lttng.event.LttngEventContent; @@ -146,29 +144,9 @@ public abstract class AbsStateProcessing { * @return */ protected LttngProcessState lttv_state_find_process( - LttngTraceState traceState, Long cpu, Long pid) { - // Define the return value - LttngProcessState returnedProcess = null; - - // Obtain the list of available processes - List processList = traceState.getProcesses(); - - // FIXME: This needs be more efficient e.g. introduce a class with a - // overriden hash and equals to consider the key values pid, cpu and - // traceid and iterate over a collection of this new type. - int pos = 0; - while ((pos < processList.size()) && (returnedProcess == null)) { - if (processList.get(pos).getPid().equals(pid)) { - if ((processList.get(pos).getCpu().equals(cpu)) - || (cpu.longValue() == 0L)) { - returnedProcess = processList.get(pos); - } - } - - pos++; - } + LttngTraceState traceState, Long cpu, Long pid) { - return returnedProcess; + return traceState.findProcessState(pid, cpu, traceState.getTraceId()); } protected void sendNoFieldFoundMsg(TmfEventField[] fields, diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateUpdate.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateUpdate.java index 2a7eb8695b..f2a6340325 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateUpdate.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/AbsStateUpdate.java @@ -184,7 +184,7 @@ public abstract class AbsStateUpdate extends AbsStateProcessing implements process.clearExecutionStack(); process.clearUserStack(); - ts.getProcesses().remove(process); + ts.removeProcessState(process); return true; } @@ -217,8 +217,8 @@ public abstract class AbsStateUpdate extends AbsStateProcessing implements Long cpu, Long pid, Long tgid, String name, final TmfTimestamp timestamp) { LttngProcessState process; - process = new LttngProcessState(cpu, pid, tgid, name, timestamp); - traceSt.getProcesses().add(process); + process = new LttngProcessState(cpu, pid, tgid, name, timestamp, traceSt.getTraceId()); + traceSt.addProcessState(process); return process; } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/StateUpdateHandlers.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/StateUpdateHandlers.java index b36af501c6..f5297cfb9d 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/StateUpdateHandlers.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/evProcessor/state/StateUpdateHandlers.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.eclipse.linuxtools.lttng.state.evProcessor.state; -import java.util.List; import java.util.Map; import org.eclipse.linuxtools.lttng.TraceDebug; @@ -1417,13 +1416,13 @@ class StateUpdateHandlers { * mode, wait */ /* else, if stack[0] is unknown, set to user mode, running */ - List processes = traceSt.getProcesses(); + LttngProcessState[] processes = traceSt.getProcesses(); TmfTimestamp time = trcEvent.getTimestamp(); - - for (LttngProcessState process : processes) { - fix_process(process, time); + + for (int pos = 0; pos < processes.length; pos++) { + fix_process(processes[pos], time); } - + return false; } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngProcessState.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngProcessState.java index 3081ef892f..d0a556ee85 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngProcessState.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngProcessState.java @@ -48,7 +48,8 @@ public class LttngProcessState implements Cloneable { private String userTrace = null; /* Associated file trace */ private Long target_pid = null; /* target PID of the current event. */ - + private String trace_id = null; + // ======================================================================== // Constructor // ======================================================================= @@ -58,16 +59,18 @@ public class LttngProcessState implements Cloneable { this.tgid = 0L; this.name = StateStrings.ProcessStatus.LTTV_STATE_UNNAMED.getInName(); this.insertion_time = startTime; + this.trace_id = ""; init(); } public LttngProcessState(Long cpu, Long pid, Long tgid, - String name, TmfTimestamp startTime) { + String name, TmfTimestamp startTime, String traceId) { this.cpu = cpu; this.pid = pid; this.tgid = tgid; this.name = name; this.insertion_time = startTime; + this.trace_id = traceId; init(); } @@ -134,6 +137,7 @@ public class LttngProcessState implements Cloneable { newState.free_events = this.free_events; newState.userTrace = this.userTrace; newState.target_pid = this.target_pid; + newState.trace_id = this.trace_id; // No clonable implemented in TMF, we will use copy constructor // NOTE : we GOT to check for null to avoid crashing on null pointer here! @@ -364,7 +368,15 @@ public class LttngProcessState implements Cloneable { public void setTarget_pid(Long targetPid) { target_pid = targetPid; } + + public String getTrace_id() { + return trace_id; + } + public void setTrace_id(String traceId) { + trace_id = traceId; + } + /** * @return the free_events */ @@ -468,7 +480,7 @@ public class LttngProcessState implements Cloneable { public LttngExecutionState popFromExecutionStack() { if (execution_stack.size() <= 1) { - TraceDebug.debug("Removing last item from execution stack is not allowed! (popFromExecutionStack)"); + TraceDebug.debug("Removing last item from execution stack is not allowed! (popFromExecutionStack)"); return null; } else { @@ -486,72 +498,4 @@ public class LttngProcessState implements Cloneable { public LttngExecutionState getFirstElementFromExecutionStack() { return execution_stack.firstElement(); } - - /* - * MAIN : For testing only! - */ - public static void main(String[] args) { - - // !!! TESTING CLONE HERE !!! - - // *** New object with some args set to "123" - LttngProcessState joie = new LttngProcessState(new TmfTimestamp(123L, (byte) -9)); - - // Stack not empty by default?? - System.out.println("Emptying stack... Trashing empty instance of : " + joie.popFromExecutionStack() ); - - joie.setCpu(123L); - joie.setName("123"); - - LttngExecutionState testEx1 = new LttngExecutionState(); - testEx1.setCum_cpu_time(123L); - testEx1.setChange_Time(new TmfTimestamp(123L, (byte) -9)); - testEx1.setEntry_Time(new TmfTimestamp(123L, (byte) -9)); - - // Print testEx1 reference - System.out.println("testEx1 reference : " + testEx1); - - joie.pushToExecutionStack(testEx1); - joie.pushToUserStack(123L); - - - - // *** New object cloned from the first one - LttngProcessState joie2 = (LttngProcessState)joie.clone(); - - - // *** Modification of the FIRST object : Everything to "456" - joie.setCpu(456L); - joie.setName("456"); - testEx1.setCum_cpu_time(456L); - testEx1.setChange_Time(new TmfTimestamp(456L, (byte) -9)); - testEx1.setEntry_Time(new TmfTimestamp(456L, (byte) -9)); - - // Push new object on stack of the FIRST object - LttngExecutionState testEx2 = new LttngExecutionState(); - testEx2.setCum_cpu_time(456L); - joie.pushToExecutionStack(testEx2); - joie.pushToUserStack(456L); - - - // *** TEST : Everything should be "123L" stil - System.out.println("123 == " + joie2.getCpu() ); - System.out.println("123 == " + joie2.getName() ); - - LttngExecutionState newtestEx1 = joie2.popFromExecutionStack(); - // Print newtestEx1 reference - System.out.println("testEx1 reference : " + newtestEx1); - - System.out.println("123 == " + newtestEx1.getCum_cpu_time() ); - System.out.println("123 == " + joie2.popFromUserStack() ); - - // *** LAST TEST : The joie2 stack should be empty, only joie1 stack contains more than 1 object - try { - System.out.println("123 == " + joie2.popFromExecutionStack().getCum_cpu_time() ); - } - catch ( Exception e) { - System.out.println("All fine"); - } - } - } diff --git a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngTraceState.java b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngTraceState.java index 62d3094298..ca2cece640 100644 --- a/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngTraceState.java +++ b/org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/model/LttngTraceState.java @@ -11,12 +11,11 @@ *******************************************************************************/ package org.eclipse.linuxtools.lttng.state.model; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; +import org.eclipse.linuxtools.lttng.TraceDebug; import org.eclipse.linuxtools.lttng.state.LttngStateException; import org.eclipse.linuxtools.lttng.state.StateStrings; import org.eclipse.linuxtools.lttng.state.StateStrings.ExecutionMode; @@ -45,10 +44,7 @@ public class LttngTraceState implements Cloneable { private TmfTimestamp max_time_state_recomputed_in_seek = null; private boolean has_precomputed_states = false; - // TODO: check if this can be used as a map, but consider that the key - // shall be composed by Pid, TimeStamp, and CPU, this combination may not - // always be available and the cpu value may change over time. - private List processes = new ArrayList(); + private HashMap processes = new HashMap(); // by cpu private Map running_process = new HashMap(); @@ -150,58 +146,62 @@ public class LttngTraceState implements Cloneable { // *** TODO *** // In the future, implement something better here... serialization // perhaps? Or copy the array chunk of memory in C? - newState.processes = new ArrayList(); - for (int pos = 0; pos < this.processes.size(); pos++) { - newState.processes.add(this.processes.get(pos).clone()); - } - - Iterator iterator = null; + + Iterator iteratorL = null; + Iterator iteratorP = null; Long mapKey = null; + ProcessStateKey processKey = null; + + newState.processes = new HashMap(); + iteratorP = this.processes.keySet().iterator(); + while (iteratorP.hasNext()) { + processKey = iteratorP.next(); + newState.processes.put(processKey, this.processes.get(processKey).clone()); + } newState.running_process = new HashMap(); - iterator = this.running_process.keySet().iterator(); - while (iterator.hasNext()) { - mapKey = iterator.next(); - newState.running_process.put(mapKey, this.running_process.get( - mapKey).clone()); + iteratorL = this.running_process.keySet().iterator(); + while (iteratorL.hasNext()) { + mapKey = iteratorL.next(); + newState.running_process.put(mapKey, this.running_process.get(mapKey).clone()); } newState.cpu_states = new HashMap(); - iterator = this.cpu_states.keySet().iterator(); - while (iterator.hasNext()) { - mapKey = iterator.next(); + iteratorL = this.cpu_states.keySet().iterator(); + while (iteratorL.hasNext()) { + mapKey = iteratorL.next(); newState.cpu_states.put(mapKey, this.cpu_states.get(mapKey) .clone()); } newState.irq_states = new HashMap(); - iterator = this.irq_states.keySet().iterator(); - while (iterator.hasNext()) { - mapKey = iterator.next(); + iteratorL = this.irq_states.keySet().iterator(); + while (iteratorL.hasNext()) { + mapKey = iteratorL.next(); newState.irq_states.put(mapKey, this.irq_states.get(mapKey) .clone()); } newState.soft_irq_states = new HashMap(); - iterator = this.soft_irq_states.keySet().iterator(); - while (iterator.hasNext()) { - mapKey = iterator.next(); + iteratorL = this.soft_irq_states.keySet().iterator(); + while (iteratorL.hasNext()) { + mapKey = iteratorL.next(); newState.soft_irq_states.put(mapKey, this.soft_irq_states.get( mapKey).clone()); } newState.trap_states = new HashMap(); - iterator = this.trap_states.keySet().iterator(); - while (iterator.hasNext()) { - mapKey = iterator.next(); + iteratorL = this.trap_states.keySet().iterator(); + while (iteratorL.hasNext()) { + mapKey = iteratorL.next(); newState.trap_states.put(mapKey, this.trap_states.get(mapKey) .clone()); } newState.bdev_states = new HashMap(); - iterator = this.bdev_states.keySet().iterator(); - while (iterator.hasNext()) { - mapKey = iterator.next(); + iteratorL = this.bdev_states.keySet().iterator(); + while (iteratorL.hasNext()) { + mapKey = iteratorL.next(); newState.bdev_states.put(mapKey, this.bdev_states.get(mapKey) .clone()); } @@ -300,7 +300,7 @@ public class LttngTraceState implements Cloneable { LTTngCPUState cpuState = cpu_states.get(i); cpuState.reset(); // Add the new process to the list - processes.add(process); + processes.put(new ProcessStateKey(process), process); } // reset irq_states @@ -369,11 +369,6 @@ public class LttngTraceState implements Cloneable { public void setHas_precomputed_states(boolean hasPrecomputedStates) { has_precomputed_states = hasPrecomputedStates; } - - - public List getProcesses() { - return processes; - } public Map getRunning_process() { return running_process; @@ -425,5 +420,161 @@ public class LttngTraceState implements Cloneable { public String getTraceId() { return traceId; } + + /** + * Return an array of Processes + * + * @return LttngProcessState + */ + public LttngProcessState[] getProcesses() { + return processes.values().toArray(new LttngProcessState[processes.size()]); + } + + /** + * Clear all process state items e.g. when a new experiment is selected + */ + public void clearProcessState() { + processes.clear(); + } + + /** + * Interface to add process state. + * + * @param newProcessState + */ + public void addProcessState(LttngProcessState newProcessState) { + if (newProcessState != null) { + processes.put( new ProcessStateKey(newProcessState), newProcessState); + } + } + + /** + * Interface to remove process state. + * + * @param oldProcessState + */ + public void removeProcessState(LttngProcessState oldProcessState) { + if (oldProcessState != null) { + processes.remove(new ProcessStateKey(oldProcessState)); + } + } + + /** + * Search by keys (pid, cpuId and traceId)

+ * + * A match is returned if the three 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 + * + * @return LttngProcessState + */ + public LttngProcessState findProcessState(Long searchedPid, Long searchedCpuId, String searchedTraceID) { + // Get the TimeRangeEventProcess associated to a key we create here + LttngProcessState foundProcess = processes.get( new ProcessStateKey(searchedPid, searchedCpuId, searchedTraceID) ); + + return foundProcess; + } + + +} +class ProcessStateKey { + private LttngProcessState valueRef = null; + + private Long pid = null; + private Long cpuId = null; + private String traceId = null; + + @SuppressWarnings("unused") + private ProcessStateKey() { } + + public ProcessStateKey(LttngProcessState newRef) { + valueRef = newRef; + } + + public ProcessStateKey(Long newPid, Long newCpuId, String newTraceId) { + pid = newPid; + cpuId = newCpuId; + traceId = newTraceId; + } + + @Override + public boolean equals(Object obj) { + boolean isSame = false; + + if ( obj instanceof ProcessStateKey ) { + ProcessStateKey procKey = (ProcessStateKey) obj; + + if ( valueRef != null ) { + if ( (procKey.getPid().equals(valueRef.getPid()) ) && + (procKey.getTraceId().equals(valueRef.getTrace_id()) ) && + ( (procKey.getCpuId().longValue() == 0L ) || (procKey.getCpuId().equals(valueRef.getCpu())) ) ) + { + isSame = true; + } + } + else { + if ( (procKey.getPid().equals(this.pid) ) && + (procKey.getTraceId().equals(this.traceId) ) && + ( (procKey.getCpuId().longValue() == 0L ) || (procKey.getCpuId().equals(this.cpuId)) ) ) + { + isSame = true; + } + } + } + else { + TraceDebug + .debug("ERROR : The received Key is not of the type ProcessStateKey! but " + + obj.getClass().toString()); + } + + 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.getTrace_id(); + } + else { + return traceId; + } + } + + @Override + public int hashCode() { + return this.toString().hashCode(); + } + + + @Override + public String toString() { + if ( valueRef != null ) { + return (valueRef.getPid().toString() + ":" + valueRef.getCpu().toString() + ":" + valueRef.getTrace_id().toString() ); + } + + return (pid.toString() + ":" + cpuId.toString() + ":" + traceId.toString()); + } } -- 2.34.1