Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Khouzam2015-02-13 19:32:17 +0000
committerMarc Khouzam2015-03-20 14:07:28 +0000
commitb26c273112b7c67aba2a0e6676b07b8fb5fbbd7a (patch)
tree387486143bd30bb3be0e89b8ab7047ebb7b4f330 /dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui
parent0699f77da65f0e1e9d8d322a4faa7b5fcf43fb79 (diff)
downloadorg.eclipse.cdt-b26c273112b7c67aba2a0e6676b07b8fb5fbbd7a.tar.gz
org.eclipse.cdt-b26c273112b7c67aba2a0e6676b07b8fb5fbbd7a.tar.xz
org.eclipse.cdt-b26c273112b7c67aba2a0e6676b07b8fb5fbbd7a.zip
Bug 459114 - More cleanup of async handling for Multicore
Visualizer This commit migrates the MulticoreVisualizer class to use the standard DSF programming paradigm, which is to use RequestMonitors. It also renames some methods to better fit in that programming model. Change-Id: Ie00a5dcb810fb13a4ac526ff221cc10bd52a3fca Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com>
Diffstat (limited to 'dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui')
-rwxr-xr-xdsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/model/VisualizerModel.java32
-rwxr-xr-xdsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/MulticoreVisualizer.java210
2 files changed, 88 insertions, 154 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/model/VisualizerModel.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/model/VisualizerModel.java
index 820f9c102b8..2f59259e81a 100755
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/model/VisualizerModel.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/model/VisualizerModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2014 Tilera Corporation and others.
+ * Copyright (c) 2012, 2015 Tilera Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,8 +20,6 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.cdt.visualizer.ui.util.Todo;
-
/**
* Class representing the state of the data to display in the MulticoreVisualizer.
*/
@@ -38,12 +36,6 @@ public class VisualizerModel
/** List of threads */
protected ArrayList<VisualizerThread> m_threads;
- /** Completion state tracker. */
- protected Todo m_todo;
-
- /** Completion state tracker for load meters. */
- protected Todo m_loadTodo;
-
// Setting to remove exited threads, or keep them shown.
// If we are to support this, we should have a preference
// and a way to for the user to clean up old threads,
@@ -63,8 +55,6 @@ public class VisualizerModel
m_cpus = new ArrayList<VisualizerCPU>();
m_cpuMap = new Hashtable<Integer, VisualizerCPU>();
m_threads = new ArrayList<VisualizerThread>();
- m_todo = new Todo();
- m_loadTodo = new Todo();
}
/** Dispose method */
@@ -85,30 +75,12 @@ public class VisualizerModel
m_threads.clear();
m_threads = null;
}
- if (m_todo != null) {
- m_todo.dispose();
- m_todo = null;
- }
- if (m_loadTodo != null) {
- m_loadTodo.dispose();
- m_loadTodo = null;
- }
m_sessionId = null;
}
// --- accessors ---
-
- /** Gets completion state tracker. */
- public Todo getTodo() {
- return m_todo;
- }
-
- /** Gets completion state tracker. */
- public Todo getLoadTodo() {
- return m_loadTodo;
- }
-
+
public void setLoadMetersEnabled (boolean enable) {
m_loadMetersEnabled = enable;
}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/MulticoreVisualizer.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/MulticoreVisualizer.java
index 142cf168c2c..05aaeebf6f0 100755
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/MulticoreVisualizer.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/MulticoreVisualizer.java
@@ -26,6 +26,7 @@
* Marc Dumais (Ericsson) - Bug 460737
* Marc Dumais (Ericsson) - Bug 460837
* Marc Dumais (Ericsson) - Bug 460476
+ * Marc Khouzam (Ericsson) - Use DSF usual async pattern (Bug 459114)
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view;
@@ -37,10 +38,13 @@ import java.util.List;
import java.util.Set;
import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor;
-import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
+import org.eclipse.cdt.dsf.concurrent.ImmediateCountingRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
import org.eclipse.cdt.dsf.datamodel.DMContexts;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.debug.service.IProcesses.IThreadDMData;
@@ -1137,11 +1141,8 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
// clear CPU/core cache
m_cpuCoreContextsCache.clear();
- m_sessionState.execute(new DsfRunnable() { @Override public void run() {
- // get model asynchronously, and update canvas
- // in getVisualizerModelDone().
- getVisualizerModel();
- }});
+ fDataModel = new VisualizerModel(m_sessionState.getSessionID());
+ getVisualizerModel(fDataModel);
}
/** Sets canvas model. (Also updates canvas selection.) */
@@ -1199,54 +1200,44 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
// --- Visualizer model update methods ---
- /** Starts visualizer model request.
- * Calls getVisualizerModelDone() with the constructed model.
+ /**
+ * Starts visualizer model request.
*/
- @ConfinedToDsfExecutor("getSession().getExecutor()")
- public void getVisualizerModel() {
- String sessionId = m_sessionState.getSessionID();
- DsfSession session = DsfSession.getSession(sessionId);
-
- if (session != null) {
- final VisualizerModel model = new VisualizerModel(sessionId);
- fDataModel = model;
- fTargetData.getCPUs(m_sessionState, new DataRequestMonitor<ICPUDMContext[]>(session.getExecutor(), null) {
+ protected void getVisualizerModel(final VisualizerModel model) {
+ m_sessionState.execute(new DsfRunnable() { @Override public void run() {
+ // get model asynchronously starting at the top of the hierarchy
+ getCPUs(model, new ImmediateRequestMonitor() {
@Override
protected void handleCompleted() {
- ICPUDMContext[] cpuContexts = isSuccess() ? getData() : null;
- getCPUsDone(cpuContexts, model);
+ model.setLoadMetersEnabled(getLoadMetersEnabled());
+ updateLoads(model);
+ model.sort();
+ setCanvasModel(model);
}
});
- }
+ }});
}
- /** Invoked when getModel() request completes. */
@ConfinedToDsfExecutor("getSession().getExecutor()")
- public void getVisualizerModelDone(VisualizerModel model) {
- model.setLoadMetersEnabled(getLoadMetersEnabled());
- updateLoads(model);
- model.sort();
- setCanvasModel(model);
+ protected void getCPUs(final VisualizerModel model, final RequestMonitor rm) {
+ fTargetData.getCPUs(m_sessionState, new ImmediateDataRequestMonitor<ICPUDMContext[]>() {
+ @Override
+ protected void handleCompleted() {
+ ICPUDMContext[] cpuContexts = isSuccess() ? getData() : null;
+ getCores(cpuContexts, model, rm);
+ }
+ });
}
-
- // --- DSFDebugModelListener implementation ---
-
- /** Invoked when DSFDebugModel.getCPUs() completes. */
@ConfinedToDsfExecutor("getSession().getExecutor()")
- public void getCPUsDone(ICPUDMContext[] cpuContexts, final Object arg)
+ protected void getCores(ICPUDMContext[] cpuContexts, final VisualizerModel model, final RequestMonitor rm)
{
- VisualizerModel model = (VisualizerModel) arg;
-
if (cpuContexts == null || cpuContexts.length == 0) {
// Whoops, no CPU data.
// We'll fake a CPU and use it to contain any cores we find.
model.addCPU(new VisualizerCPU(0));
- // keep track of CPUs left to visit
- model.getTodo().add(1);
-
// Collect core data.
fTargetData.getCores(m_sessionState, new ImmediateDataRequestMonitor<ICoreDMContext[]>() {
@Override
@@ -1263,16 +1254,15 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
}
// Continue
- getCoresDone(cpu, coreContexts, arg);
+ getThreads(cpu, coreContexts, model, rm);
}
});
} else {
// save CPU contexts
m_cpuCoreContextsCache.addAll(Arrays.asList(cpuContexts));
- // keep track of CPUs left to visit
- int count = cpuContexts.length;
- model.getTodo().add(count);
+ final CountingRequestMonitor crm = new ImmediateCountingRequestMonitor(rm);
+ crm.setDoneCount(cpuContexts.length);
for (final ICPUDMContext cpuContext : cpuContexts) {
int cpuID = Integer.parseInt(cpuContext.getId());
@@ -1283,22 +1273,23 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
@Override
protected void handleCompleted() {
ICoreDMContext[] coreContexts = isSuccess() ? getData() : null;
- getCoresDone(cpuContext, coreContexts, arg);
+ getThreads(cpuContext, coreContexts, model, crm);
}
});
}
}
}
- /** Invoked when getCores() request completes. */
@ConfinedToDsfExecutor("getSession().getExecutor()")
- public void getCoresDone(final ICPUDMContext cpuContext, ICoreDMContext[] coreContexts, final Object arg)
+ protected void getThreads(final ICPUDMContext cpuContext,
+ ICoreDMContext[] coreContexts,
+ final VisualizerModel model,
+ RequestMonitor rm)
{
- VisualizerModel model = (VisualizerModel) arg;
-
if (coreContexts == null || coreContexts.length == 0) {
// no cores for this cpu context
// That's fine.
+ rm.done();
} else {
// save core contexts
m_cpuCoreContextsCache.addAll(Arrays.asList(coreContexts));
@@ -1306,10 +1297,9 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
int cpuID = Integer.parseInt(cpuContext.getId());
VisualizerCPU cpu = model.getCPU(cpuID);
- // keep track of Cores left to visit
- int count = coreContexts.length;
- model.getTodo().add(count);
-
+ final CountingRequestMonitor crm = new ImmediateCountingRequestMonitor(rm);
+ crm.setDoneCount(coreContexts.length);
+
for (final ICoreDMContext coreContext : coreContexts) {
int coreID = Integer.parseInt(coreContext.getId());
cpu.addCore(new VisualizerCore(cpu, coreID));
@@ -1319,35 +1309,27 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
@Override
protected void handleCompleted() {
IDMContext[] threadContexts = isSuccess() ? getData() : null;
-
- getThreadsDone(cpuContext, coreContext, threadContexts, arg);
+ getThreadData(cpuContext, coreContext, threadContexts, model, crm);
}
});
}
}
-
- // keep track of CPUs visited
- // note: do this _after_ incrementing for cores
- done(1, model);
}
-
- /** Invoked when getThreads() request completes. */
@ConfinedToDsfExecutor("getSession().getExecutor()")
- public void getThreadsDone(final ICPUDMContext cpuContext,
- final ICoreDMContext coreContext,
- IDMContext[] threadContexts,
- final Object arg)
+ protected void getThreadData(final ICPUDMContext cpuContext,
+ final ICoreDMContext coreContext,
+ IDMContext[] threadContexts,
+ final VisualizerModel model,
+ RequestMonitor rm)
{
- VisualizerModel model = (VisualizerModel) arg;
-
if (threadContexts == null || threadContexts.length == 0) {
// no threads for this core
// That's fine.
+ rm.done();
} else {
- // keep track of threads left to visit
- int count = threadContexts.length;
- model.getTodo().add(count);
+ final CountingRequestMonitor crm = new ImmediateCountingRequestMonitor(rm);
+ crm.setDoneCount(threadContexts.length);
for (IDMContext threadContext : threadContexts) {
final IMIExecutionDMContext execContext =
@@ -1358,24 +1340,21 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
@Override
protected void handleCompleted() {
IThreadDMData threadData = isSuccess() ? getData() : null;
- getThreadDataDone(cpuContext, coreContext, execContext, threadData, arg);
+ getThreadExecutionState(cpuContext, coreContext, execContext, threadData, model, crm);
}
});
}
}
-
- // keep track of cores visited
- // note: do this _after_ incrementing for threads
- done(1, model);
}
/** Invoked when getThreads() request completes. */
@ConfinedToDsfExecutor("getSession().getExecutor()")
- public void getThreadDataDone(final ICPUDMContext cpuContext,
- final ICoreDMContext coreContext,
- final IMIExecutionDMContext execContext,
- final IThreadDMData threadData,
- final Object arg)
+ protected void getThreadExecutionState(final ICPUDMContext cpuContext,
+ final ICoreDMContext coreContext,
+ final IMIExecutionDMContext execContext,
+ final IThreadDMData threadData,
+ final VisualizerModel model,
+ final RequestMonitor rm)
{
// Get the execution state
fTargetData.getThreadExecutionState(m_sessionState, cpuContext, coreContext, execContext,
@@ -1390,13 +1369,13 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
protected void handleCompleted() {
IFrameDMData frameData = isSuccess() ? getData() : null;
getThreadExecutionStateDone(cpuContext, coreContext, execContext, threadData,
- frameData, state, arg);
+ frameData, state, model, rm);
}
});
} else {
// frame data is not valid
getThreadExecutionStateDone(cpuContext, coreContext, execContext, threadData,
- null, state, arg);
+ null, state, model, rm);
}
}
});
@@ -1405,15 +1384,15 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
/** Invoked when getThreadExecutionState() request completes. */
@ConfinedToDsfExecutor("getSession().getExecutor()")
- public void getThreadExecutionStateDone(ICPUDMContext cpuContext,
- ICoreDMContext coreContext,
- IMIExecutionDMContext execContext,
- IThreadDMData threadData,
- IFrameDMData frame,
- VisualizerExecutionState state,
- Object arg)
+ protected void getThreadExecutionStateDone(ICPUDMContext cpuContext,
+ ICoreDMContext coreContext,
+ IMIExecutionDMContext execContext,
+ IThreadDMData threadData,
+ IFrameDMData frame,
+ VisualizerExecutionState state,
+ VisualizerModel model,
+ RequestMonitor rm)
{
- VisualizerModel model = (VisualizerModel) arg;
int cpuID = Integer.parseInt(cpuContext.getId());
VisualizerCPU cpu = model.getCPU(cpuID);
int coreID = Integer.parseInt(coreContext.getId());
@@ -1448,13 +1427,12 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
t.setLocationInfo(frame);
}
- // keep track of threads visited
- done(1, model);
+ rm.done();
}
/** Updates the loads for all cpus and cores */
@ConfinedToDsfExecutor("getSession().getExecutor()")
- public void updateLoads(final VisualizerModel model) {
+ protected void updateLoads(final VisualizerModel model) {
if (m_cpuCoreContextsCache.isEmpty()) {
// not ready to get load info yet
return;
@@ -1464,9 +1442,21 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
return;
}
- model.getLoadTodo().dispose();
- // keep track of how many loads we expect
- model.getLoadTodo().add(m_cpuCoreContextsCache.size());
+ final CountingRequestMonitor crm = new ImmediateCountingRequestMonitor() {
+ @Override
+ protected void handleSuccess() {
+ // canvas may have been disposed since the transaction has started
+ if (m_canvas != null) {
+ m_canvas.refreshLoadMeters();
+ m_canvas.requestUpdate();
+ }
+ if (m_updateLoadMeterTimer != null) {
+ // re-start timer
+ m_updateLoadMeterTimer.start();
+ }
+ }
+ };
+ crm.setDoneCount(m_cpuCoreContextsCache.size());
// ask load for each CPU and core
for (final IDMContext context : m_cpuCoreContextsCache) {
@@ -1474,7 +1464,7 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
@Override
protected void handleCompleted() {
ILoadInfo loadInfo = isSuccess() ? getData() : null;
- getLoadDone(context, loadInfo, model);
+ getLoadDone(context, loadInfo, model, crm);
}
});
}
@@ -1482,9 +1472,8 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
/** Invoked when a getLoad() request completes. */
@ConfinedToDsfExecutor("getSession().getExecutor()")
- public void getLoadDone(IDMContext context, ILoadInfo load, Object arg)
+ protected void getLoadDone(IDMContext context, ILoadInfo load, VisualizerModel model, RequestMonitor rm)
{
- VisualizerModel model = (VisualizerModel) arg;
Integer l = null;
if (load != null) {
@@ -1504,32 +1493,7 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
core.setLoadInfo(new VisualizerLoadInfo(l));
}
- loadDone(1, model);
- }
-
-
- /** Update "done" count for current visualizer model. */
- protected void done(int n, VisualizerModel model) {
- model.getTodo().done(n);
- if (model.getTodo().isDone()) {
- getVisualizerModelDone(model);
- }
- }
-
- /** Update "done" count for current visualizer model. */
- protected void loadDone(int n, VisualizerModel model) {
- model.getLoadTodo().done(n);
- if (model.getLoadTodo().isDone()) {
- // canvas may have been disposed since the transaction has started
- if (m_canvas != null) {
- m_canvas.refreshLoadMeters();
- m_canvas.requestUpdate();
- }
- if (m_updateLoadMeterTimer != null) {
- // re-start timer
- m_updateLoadMeterTimer.start();
- }
- }
+ rm.done();
}
private Timer getLoadTimer(final DSFSessionState sessionState, final int timeout) {
@@ -1544,8 +1508,7 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
executor.execute(new Runnable() {
@Override
public void run() {
- final VisualizerModel model = fDataModel;
- updateLoads(model);
+ updateLoads(fDataModel);
}
});
}
@@ -1556,6 +1519,5 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer implements IPin
return t;
}
-
}

Back to the top