1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 399419 - [visualizer] Minimize visualizer model (re-)creation

Change-Id: I74bddda8a2eb814c04b93089d10bbb0683e747f5
Reviewed-on: https://git.eclipse.org/r/11601
IP-Clean: Marc Khouzam <marc.khouzam@ericsson.com>
Tested-by: Marc Khouzam <marc.khouzam@ericsson.com>
Reviewed-by: William Swanson <traveler@tilera.com>
Reviewed-by: Marc Khouzam <marc.khouzam@ericsson.com>
This commit is contained in:
Marc Dumais 2013-04-12 12:08:54 -04:00 committed by Marc Khouzam
parent 482e736a08
commit 76b5dde840
3 changed files with 105 additions and 44 deletions

View file

@ -10,6 +10,7 @@
* IBM Corporation
* Marc Dumais (Ericsson) - Bug 399281
* Marc Dumais (Ericsson) - Add CPU/core load information to the multicore visualizer (Bug 396268)
* Marc Dumais (Ericsson) - Bug 399419
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view;
@ -665,7 +666,8 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer
{
// Execute a refresh after any pending UI updates.
GUIUtils.exec( new Runnable() { @Override public void run() {
MulticoreVisualizer.this.refresh();
// check if we need to update the debug context
updateDebugContext();
}});
}
};
@ -692,8 +694,20 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer
@Override
public void workbenchSelectionChanged(ISelection selection)
{
refresh();
// See if we need to update our debug info from
// the workbench selection. This will be done asynchronously.
boolean changed = updateDebugContext();
if (changed) {
update();
}
else {
// Even if debug info doesn't change, we still want to
// check whether the canvas selection needs to change
// to reflect the current workbench selection.
updateCanvasSelection();
}
// Also check whether we need to attach debug view listener.
updateDebugViewListener();
}
@ -701,14 +715,8 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer
/** Refreshes visualizer content from model. */
public void refresh()
{
// See if we need to update our debug info from
// the workbench selection. This will be done asynchronously.
boolean changed = updateDebugContext();
// Even if debug info doesn't change, we still want to
// check whether the canvas selection needs to change
// to reflect the current workbench selection.
if (!changed) updateCanvasSelection();
m_canvas.requestRecache();
m_canvas.requestUpdate();
}
@ -829,7 +837,7 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer
* Returns true if canvas context actually changes, false if not.
*/
public boolean setDebugSession(String sessionId) {
boolean changed = true;
boolean changed = false;
if (m_sessionState != null &&
! m_sessionState.getSessionID().equals(sessionId))
@ -854,8 +862,6 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer
initializeLoadMeterTimer();
changed = true;
}
if (changed) update();
return changed;
}
@ -1102,7 +1108,12 @@ public class MulticoreVisualizer extends GraphicCanvasVisualizer
// If we can't get the real Linux OS tid, fallback to using the gdb thread id
int osTid = (osTIDValue == null) ? tid : Integer.parseInt(osTIDValue);
model.addThread(new VisualizerThread(core, pid, osTid, tid, state));
// add thread if not already there - there is a potential race condition where a
// thread can be added twice to the model: once at model creation and once more
// through the listener. Checking at both places to prevent this.
if (model.getThread(tid) == null) {
model.addThread(new VisualizerThread(core, pid, osTid, tid, state));
}
// keep track of threads visited
done(1, model);

View file

@ -13,6 +13,7 @@
* Marc Dumais (Ericsson) - Bug 396293
* Marc Dumais (Ericsson) - Bug 399281
* Marc Dumais (Ericsson) - Add CPU/core load information to the multicore visualizer (Bug 396268)
* Marc Dumais (Ericsson) - Bug 399419
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view;
@ -970,13 +971,14 @@ public class MulticoreVisualizerCanvas extends GraphicCanvas
@Override
public void setSelection(ISelection selection)
{
m_selectionManager.setSelection(selection);
setSelection(selection, true);
}
/** Sets externally-visible selection. */
public void setSelection(ISelection selection, boolean raiseEvent)
{
m_selectionManager.setSelection(selection, raiseEvent);
requestUpdate();
}
/** Sets whether selection events are enabled. */

View file

@ -8,12 +8,14 @@
* Contributors:
* Marc Khouzam (Ericsson) - initial API and implementation
* Marc Dumais (Ericsson) - Bug 400231
* Marc Dumais (Ericsson) - Bug 399419
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view;
import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor;
import org.eclipse.cdt.dsf.datamodel.DMContexts;
import org.eclipse.cdt.dsf.datamodel.DataModelInitializedEvent;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.debug.service.IProcesses;
import org.eclipse.cdt.dsf.debug.service.IProcesses.IThreadDMContext;
@ -61,39 +63,72 @@ public class MulticoreVisualizerEventListener {
// --- event handlers ---
/** Invoked when a thread or process is suspended. */
/**
* Invoked when a thread or process is suspended.
* Updates both state of the thread and the core it's running on
*/
@DsfServiceEventHandler
public void handleEvent(ISuspendedDMEvent event) {
public void handleEvent(final ISuspendedDMEvent event) {
IDMContext context = event.getDMContext();
if (context instanceof IContainerDMContext) {
// We don't deal with processes
} else if (context instanceof IMIExecutionDMContext) {
// Thread suspended
int tid = ((IMIExecutionDMContext)context).getThreadId();
VisualizerThread thread = fVisualizer.getModel().getThread(tid);
if (thread != null) {
assert thread.getState() == VisualizerExecutionState.RUNNING;
VisualizerExecutionState newState = VisualizerExecutionState.SUSPENDED;
final IMIExecutionDMContext execDmc = (IMIExecutionDMContext)context;
IThreadDMContext threadContext =
DMContexts.getAncestorOfType(execDmc, IThreadDMContext.class);
if (event.getReason() == StateChangeReason.SIGNAL) {
if (event instanceof IMIDMEvent) {
Object miEvent = ((IMIDMEvent)event).getMIEvent();
if (miEvent instanceof MISignalEvent) {
String signalName = ((MISignalEvent)miEvent).getName();
if (DSFDebugModel.isCrashSignal(signalName)) {
newState = VisualizerExecutionState.CRASHED;
}
}
}
}
DsfServicesTracker tracker =
new DsfServicesTracker(MulticoreVisualizerUIPlugin.getBundleContext(),
execDmc.getSessionId());
IProcesses procService = tracker.getService(IProcesses.class);
tracker.dispose();
procService.getExecutionData(threadContext,
new ImmediateDataRequestMonitor<IThreadDMData>() {
@Override
protected void handleSuccess() {
IThreadDMData data = getData();
// Check whether we know about cores
if (data instanceof IGdbThreadDMData) {
String[] cores = ((IGdbThreadDMData)data).getCores();
if (cores != null) {
assert cores.length == 1; // A thread belongs to a single core
int coreId = Integer.parseInt(cores[0]);
VisualizerCore vCore = fVisualizer.getModel().getCore(coreId);
int tid = execDmc.getThreadId();
VisualizerThread thread = fVisualizer.getModel().getThread(tid);
if (thread != null) {
assert thread.getState() == VisualizerExecutionState.RUNNING;
VisualizerExecutionState newState = VisualizerExecutionState.SUSPENDED;
thread.setState(newState);
fVisualizer.getMulticoreVisualizerCanvas().requestUpdate();
}
if (event.getReason() == StateChangeReason.SIGNAL) {
if (event instanceof IMIDMEvent) {
Object miEvent = ((IMIDMEvent)event).getMIEvent();
if (miEvent instanceof MISignalEvent) {
String signalName = ((MISignalEvent)miEvent).getName();
if (DSFDebugModel.isCrashSignal(signalName)) {
newState = VisualizerExecutionState.CRASHED;
}
}
}
}
thread.setState(newState);
thread.setCore(vCore);
fVisualizer.getMulticoreVisualizerCanvas().requestUpdate();
}
}
}
}
}
);
}
}
@ -165,9 +200,13 @@ public class MulticoreVisualizerEventListener {
// That is ok, we'll be refreshing right away at startup
}
fVisualizer.getModel().addThread(new VisualizerThread(vCore, pid, osTid, tid, VisualizerExecutionState.RUNNING));
fVisualizer.getMulticoreVisualizerCanvas().requestUpdate();
// add thread if not already there - there is a potential race condition where a
// thread can be added twice to the model: once at model creation and once more
// through the listener. Checking at both places to prevent this.
if (fVisualizer.getModel().getThread(tid) == null ) {
fVisualizer.getModel().addThread(new VisualizerThread(vCore, pid, osTid, tid, VisualizerExecutionState.RUNNING));
fVisualizer.getMulticoreVisualizerCanvas().requestUpdate();
}
}
}
}
@ -193,6 +232,15 @@ public class MulticoreVisualizerEventListener {
canvas.requestUpdate();
}
}
}
}
/** Invoked when the debug data model is ready */
@DsfServiceEventHandler
public void handleEvent(DataModelInitializedEvent event) {
// re-create the visualizer model now that CPU and core info is available
fVisualizer.update();
}
}