}
/**
- * Reset this resource to the construction state except for
+ * Reset this resource to the construction state
*/
public void reset() {
getChildEventComposites().clear();
// ========================================================================\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
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);
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);
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()
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());
localProcess.setBrand(stateProcess.getBrand());
localProcess.setTraceID(traceId);
localProcess.setProcessType(stateProcess.getType().getInName());
- procContainer.addProcesse(localProcess);
+ procContainer.addProcess(localProcess);
return localProcess;
}
}
//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()) ) {
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()) ) {
// 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()) ) {
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()) ) {
// 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()) ) {
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()) ) {
// 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) {
// 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 :
// 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 :
// 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 :
// 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) {
// 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) {
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;
* 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
*
// ========================================================================
// 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
// ========================================================================
// 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);
+ }
}
* 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;
*
*/
public class ResourceContainer {
-
+ // ========================================================================
+ // Data
+ // ========================================================================
private final HashMap<ResourceKey, TimeRangeEventResource> resources = new HashMap<ResourceKey, TimeRangeEventResource>();
private static Integer uniqueId = 0;
+
+ // ========================================================================
+ // Constructor
+ // ========================================================================
/**
* Package level constructor
*/
}
}
-
+ // ========================================================================
+ // Methods
+ // ========================================================================
/**
* Request a unique ID
*
* @param traceId
*/
public void clearChildren(String traceId) {
-
TimeRangeEventResource newRes = null;
Iterator<ResourceKey> iterator = resources.keySet().iterator();
}
/**
- * 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
/**
- * 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!
*/
@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);
}
}
-