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

Bug 404894 - [visualizer] Make CPUs and cores selectable in multicore

visualizer

Change-Id: I842df73a2718ac82bb392e7e82652b4b056c254b
Reviewed-on: https://git.eclipse.org/r/11824
Reviewed-by: William Swanson <traveler@tilera.com>
IP-Clean: William Swanson <traveler@tilera.com>
Tested-by: William Swanson <traveler@tilera.com>
This commit is contained in:
Marc Dumais 2013-04-16 10:28:54 -04:00 committed by William Swanson
parent 08a62c3e85
commit 12b229dec0
3 changed files with 185 additions and 125 deletions

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* William R. Swanson (Tilera Corporation) - initial API and implementation * William R. Swanson (Tilera Corporation) - initial API and implementation
* Marc Dumais (Ericsson) - Add CPU/core load information to the multicore visualizer (Bug 396268) * Marc Dumais (Ericsson) - Add CPU/core load information to the multicore visualizer (Bug 396268)
* Marc Dumais (Ericsson) - Bug 404894
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view; package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view;
@ -118,12 +119,20 @@ public class MulticoreVisualizerCPU extends MulticoreVisualizerGraphicObject
/** Invoked to allow element to paint itself on the viewer canvas */ /** Invoked to allow element to paint itself on the viewer canvas */
@Override @Override
public void paintContent(GC gc) { public void paintContent(GC gc) {
gc.setForeground(FG_COLOR);
gc.setBackground(BG_COLOR); gc.setBackground(BG_COLOR);
// We want the load meter to share the same BG color // We want the load meter to share the same BG color
m_loadMeter.setParentBgColor(BG_COLOR); m_loadMeter.setParentBgColor(BG_COLOR);
// highlight in a different color if selected
if (m_selected)
{
gc.setForeground(IMulticoreVisualizerConstants.COLOR_SELECTED);
}
else {
gc.setForeground(FG_COLOR);
}
gc.fillRectangle(m_bounds); gc.fillRectangle(m_bounds);
gc.drawRectangle(m_bounds); gc.drawRectangle(m_bounds);
} }
@ -141,8 +150,8 @@ public class MulticoreVisualizerCPU extends MulticoreVisualizerGraphicObject
gc.setForeground(IMulticoreVisualizerConstants.COLOR_CPU_FG); gc.setForeground(IMulticoreVisualizerConstants.COLOR_CPU_FG);
gc.setBackground(IMulticoreVisualizerConstants.COLOR_CPU_BG); gc.setBackground(IMulticoreVisualizerConstants.COLOR_CPU_BG);
int text_indent_x = 6; int text_indent_x = 2;
int text_indent_y = 2; int text_indent_y = 0;
int tx = m_bounds.x + m_bounds.width - text_indent_x; int tx = m_bounds.x + m_bounds.width - text_indent_x;
int ty = m_bounds.y + m_bounds.height - text_indent_y; int ty = m_bounds.y + m_bounds.height - text_indent_y;
GUIUtils.drawTextAligned(gc, Integer.toString(m_id), tx, ty, false, false); GUIUtils.drawTextAligned(gc, Integer.toString(m_id), tx, ty, false, false);

View file

@ -14,6 +14,7 @@
* Marc Dumais (Ericsson) - Bug 399281 * Marc Dumais (Ericsson) - Bug 399281
* Marc Dumais (Ericsson) - Add CPU/core load information to the multicore visualizer (Bug 396268) * Marc Dumais (Ericsson) - Add CPU/core load information to the multicore visualizer (Bug 396268)
* Marc Dumais (Ericsson) - Bug 399419 * Marc Dumais (Ericsson) - Bug 399419
* Marc Dumais (Ericsson) - Bug 404894
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view; package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view;
@ -60,6 +61,8 @@ public class MulticoreVisualizerCanvas extends GraphicCanvas
/** Spacing to allow between threads, when many are displayed on same tile. */ /** Spacing to allow between threads, when many are displayed on same tile. */
protected static final int THREAD_SPACING = 8; protected static final int THREAD_SPACING = 8;
protected static final int SELECTION_SLOP = 20;
// --- members --- // --- members ---
@ -160,7 +163,7 @@ public class MulticoreVisualizerCanvas extends GraphicCanvas
// perform any initialization here // perform any initialization here
// text font // text font
m_textFont = CDTVisualizerUIPlugin.getResources().getFont("Luxi Sans", 8); //$NON-NLS-1$ m_textFont = CDTVisualizerUIPlugin.getResources().getFont("Luxi Sans", 6); //$NON-NLS-1$
setFont(m_textFont); setFont(m_textFont);
// initialize cached state storage // initialize cached state storage
@ -473,8 +476,8 @@ public class MulticoreVisualizerCanvas extends GraphicCanvas
int cpu_separation = 6; // spacing between CPUS int cpu_separation = 6; // spacing between CPUS
// make room when load meters are present, else use a more compact layout // make room when load meters are present, else use a more compact layout
int core_margin = m_model.getLoadMetersEnabled() ? 20 : 4; // margin around cores in a CPU int core_margin = m_model.getLoadMetersEnabled() ? 20 : 12; // margin around cores in a CPU
int core_separation = m_model.getLoadMetersEnabled() ? 4 : 2; // spacing between cores int core_separation = 4; // spacing between cores
int loadMeterWidth = core_margin*3/5; int loadMeterWidth = core_margin*3/5;
int loadMeterHMargin = core_margin/5; int loadMeterHMargin = core_margin/5;
@ -724,41 +727,39 @@ public class MulticoreVisualizerCanvas extends GraphicCanvas
public void selectRegion(Rectangle region, public void selectRegion(Rectangle region,
boolean addToSelection, boolean toggleSelection) boolean addToSelection, boolean toggleSelection)
{ {
// currently, we select/deselect threads, not processes or tiles boolean changed = false;
if (m_threads != null) {
boolean changed = false; List<MulticoreVisualizerGraphicObject> selectableObjects = getSelectableObjects();
for (MulticoreVisualizerThread tobj : m_threads) {
boolean within = tobj.isWithin(region);
if (addToSelection && toggleSelection) { for (MulticoreVisualizerGraphicObject gobj : selectableObjects) {
if (within) { boolean within = gobj.isWithin(region);
tobj.setSelected(false);
changed = true; if (addToSelection && toggleSelection) {
} if (within) {
} gobj.setSelected(false);
else if (addToSelection) {
if (within) {
tobj.setSelected(true);
changed = true;
}
}
else if (toggleSelection) {
if (within) {
tobj.setSelected(! tobj.isSelected());
changed = true;
}
}
else {
tobj.setSelected(within);
changed = true; changed = true;
} }
} }
else if (addToSelection) {
if (changed) if (within) {
selectionChanged(); gobj.setSelected(true);
changed = true;
}
}
else if (toggleSelection) {
if (within) {
gobj.setSelected(! gobj.isSelected());
changed = true;
}
}
else {
gobj.setSelected(within);
changed = true;
}
} }
if (changed)
selectionChanged();
} }
/** /**
@ -776,88 +777,82 @@ public class MulticoreVisualizerCanvas extends GraphicCanvas
* Otherwise, selects item(s) and deselects other items. * Otherwise, selects item(s) and deselects other items.
*/ */
public void selectPoint(int x, int y, public void selectPoint(int x, int y,
boolean addToSelection, boolean toggleSelection) boolean addToSelection, boolean toggleSelection)
{ {
// Currently we only allow selection of threads. List<MulticoreVisualizerGraphicObject> selectedObjects = new ArrayList<MulticoreVisualizerGraphicObject>();
if (m_threads != null) { List<MulticoreVisualizerGraphicObject> selectableObjects = getSelectableObjects();
List<MulticoreVisualizerThread> threads = new ArrayList<MulticoreVisualizerThread>(); // the list of selectable objects is ordered to have contained objects
// before container objects, so the first match we find is the specific
// first see if selection click landed on a thread dot. // one we want.
for (MulticoreVisualizerThread tobj : m_threads) { for (MulticoreVisualizerGraphicObject gobj : selectableObjects) {
if (tobj.contains(x,y)) { if (gobj.contains(x,y)) {
threads.add(tobj); selectedObjects.add(gobj);
break; break;
}
}
// else we assume it landed outside any CPU; de-select everything
if (selectedObjects.isEmpty()) {
clearSelection();
}
// in addToSelection case, include any object in region
// bracketed by last selection click and current click
// (with some extra slop added so we pick up objects that
// overlap the edge of this region)
if (addToSelection) {
int slop = SELECTION_SLOP;
Rectangle r1 = new Rectangle(m_lastSelectionClick.x - slop/2,
m_lastSelectionClick.y - slop/2,
slop, slop);
Rectangle r2 = new Rectangle(x - slop/2, y - slop/2, slop, slop);
Rectangle region = r1.union(r2);
for (MulticoreVisualizerGraphicObject gobj : selectableObjects) {
if (gobj.isWithin(region)) {
selectedObjects.add(gobj);
} }
} }
}
// if not, see if it landed on a core; if so, select its threads
if (threads.isEmpty()) {
for (MulticoreVisualizerCore tobj : m_cores) {
if (tobj.contains(x,y)) {
List<MulticoreVisualizerThread> corethreads = tobj.getThreads();
threads.addAll(corethreads);
break;
}
}
}
// in addToSelection case, include any threads in region
// bracketed by last selection click and current click
// (with some extra slop added so we pick up threads that
// overlap the edge of this region)
if (addToSelection) {
int spotSize = MulticoreVisualizerThread.THREAD_SPOT_SIZE * 3;
Rectangle r1 = new Rectangle(m_lastSelectionClick.x - spotSize/2,
m_lastSelectionClick.y - spotSize/2,
spotSize, spotSize);
Rectangle r2 = new Rectangle(x - spotSize/2, y - spotSize/2, spotSize, spotSize);
Rectangle region = r1.union(r2);
for (MulticoreVisualizerThread tobj : m_threads) {
if (tobj.isWithin(region)) {
threads.add(tobj);
}
}
}
boolean changed = false;
for (MulticoreVisualizerThread tobj : m_threads) { boolean changed = false;
boolean within = threads.contains(tobj);
if (addToSelection && toggleSelection) { for (MulticoreVisualizerGraphicObject gobj : selectableObjects) {
if (within) { boolean within = selectedObjects.contains(gobj);
tobj.setSelected(false);
changed = true; if (addToSelection && toggleSelection) {
} if (within) {
} gobj.setSelected(false);
else if (addToSelection) {
if (within) {
tobj.setSelected(true);
changed = true;
}
}
else if (toggleSelection) {
if (within) {
tobj.setSelected(! tobj.isSelected());
changed = true;
}
}
else {
tobj.setSelected(within);
changed = true; changed = true;
} }
} }
else if (addToSelection) {
if (changed) if (within) {
selectionChanged(); gobj.setSelected(true);
changed = true;
}
}
else if (toggleSelection) {
if (within) {
gobj.setSelected(! gobj.isSelected());
changed = true;
}
}
else {
gobj.setSelected(within);
changed = true;
}
} }
if (changed)
selectionChanged();
// remember last mouse-up point for shift-click selection // remember last mouse-up point for shift-click selection
m_lastSelectionClick.x = x; m_lastSelectionClick.x = x;
m_lastSelectionClick.y = y; m_lastSelectionClick.y = y;
} }
// --- selection management methods --- // --- selection management methods ---
@ -865,28 +860,25 @@ public class MulticoreVisualizerCanvas extends GraphicCanvas
/** Selects all items in the canvas. */ /** Selects all items in the canvas. */
public void selectAll() public void selectAll()
{ {
// currently, we select/deselect threads, not processes or tiles List<MulticoreVisualizerGraphicObject> selectableObjects = getSelectableObjects();
if (m_threads != null) {
for (MulticoreVisualizerThread tobj : m_threads) { for (MulticoreVisualizerGraphicObject gobj : selectableObjects) {
tobj.setSelected(true); gobj.setSelected(true);
}
selectionChanged();
} }
selectionChanged();
} }
/** Clears selection. */ /** Clears selection. */
public void clearSelection() { public void clearSelection() {
// currently, we select/deselect threads, not processes or tiles
if (m_threads != null) {
for (MulticoreVisualizerThread tobj : m_threads) { List<MulticoreVisualizerGraphicObject> selectableObjects = getSelectableObjects();
tobj.setSelected(false);
} for (MulticoreVisualizerGraphicObject gobj : selectableObjects) {
gobj.setSelected(false);
selectionChanged();
} }
selectionChanged();
} }
/** Things to do whenever the selection changes. */ /** Things to do whenever the selection changes. */
@ -905,31 +897,79 @@ public class MulticoreVisualizerCanvas extends GraphicCanvas
/** Saves current canvas selection as list of model objects. */ /** Saves current canvas selection as list of model objects. */
protected void updateSelection(boolean raiseEvent) { protected void updateSelection(boolean raiseEvent) {
// get model objects (if any) corresponding to canvas selection // get model objects (if any) corresponding to canvas selection
HashSet<VisualizerThread> selectedThreads = new HashSet<VisualizerThread>(); HashSet<Object> selectedObjects = new HashSet<Object>();
// threads
if (m_threads != null) { if (m_threads != null) {
for (MulticoreVisualizerThread tobj : m_threads) { for (MulticoreVisualizerThread tobj : m_threads) {
if (tobj.isSelected()) { if (tobj.isSelected()) {
selectedThreads.add(tobj.getThread()); selectedObjects.add(tobj.getThread());
}
}
}
// cpus and cores
if (m_model != null) {
for (VisualizerCPU modelCpu : m_model.getCPUs()) {
MulticoreVisualizerCPU cpu = m_cpuMap.get(modelCpu);
if (cpu != null && cpu.isSelected()) {
selectedObjects.add(modelCpu);
}
for (VisualizerCore modelCore : modelCpu.getCores()) {
MulticoreVisualizerCore core = m_coreMap.get(modelCore);
if (core != null && core.isSelected()) {
selectedObjects.add(modelCore);
}
} }
} }
} }
// update model object selection // update model object selection
ISelection selection = SelectionUtils.toSelection(selectedThreads); ISelection selection = SelectionUtils.toSelection(selectedObjects);
setSelection(selection, raiseEvent); setSelection(selection, raiseEvent);
} }
/** Restores current selection from saved list of model objects. */ /** Restores current selection from saved list of model objects. */
protected void restoreSelection() { protected void restoreSelection() {
ISelection selection = getSelection(); ISelection selection = getSelection();
List<Object> selectedThreads = SelectionUtils.getSelectedObjects(selection); List<Object> selectedObjects = SelectionUtils.getSelectedObjects(selection);
if (m_threads != null) {
for (MulticoreVisualizerThread tobj : m_threads) { for (Object modelObj : selectedObjects) {
tobj.setSelected(selectedThreads.contains(tobj.getThread())); if (modelObj instanceof VisualizerThread) {
MulticoreVisualizerThread thread = m_threadMap.get(modelObj);
if (thread != null) {
thread.setSelected(true);
}
}
else if (modelObj instanceof VisualizerCore) {
MulticoreVisualizerCore core = m_coreMap.get(modelObj);
if (core != null) {
core.setSelected(true);
}
}
else if (modelObj instanceof VisualizerCPU) {
MulticoreVisualizerCPU cpu = m_cpuMap.get(modelObj);
if (cpu != null) {
cpu.setSelected(true);
}
} }
} }
} }
/**
* Gets the current list of selectable objects. The list is ordered by object type,
* so that more specific objects will appear first, followed by enclosing objects.
* For instance, threads are before cores and cores before CPUs.
*/
protected List<MulticoreVisualizerGraphicObject> getSelectableObjects () {
List<MulticoreVisualizerGraphicObject> selectableObjects = new ArrayList<MulticoreVisualizerGraphicObject>();
selectableObjects.addAll(m_threads);
selectableObjects.addAll(m_cores);
selectableObjects.addAll(m_cpus);
return selectableObjects;
}
// --- ISelectionProvider implementation --- // --- ISelectionProvider implementation ---

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* William R. Swanson (Tilera Corporation) - initial API and implementation * William R. Swanson (Tilera Corporation) - initial API and implementation
* Marc Dumais (Ericsson) - Add CPU/core load information to the multicore visualizer (Bug 396268) * Marc Dumais (Ericsson) - Add CPU/core load information to the multicore visualizer (Bug 396268)
* Marc Dumais (Ericsson) - Bug 404894
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view; package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view;
@ -178,11 +179,19 @@ public class MulticoreVisualizerCore extends MulticoreVisualizerGraphicObject
public void paintContent(GC gc) { public void paintContent(GC gc) {
Color bg = getCoreStateColor(false); Color bg = getCoreStateColor(false);
gc.setForeground(getCoreStateColor(true));
gc.setBackground(bg); gc.setBackground(bg);
// We want the load meter to share the same BG color // We want the load meter to share the same BG color
m_loadMeter.setParentBgColor(bg); m_loadMeter.setParentBgColor(bg);
// highlight in a different color if selected
if (m_selected)
{
gc.setForeground(IMulticoreVisualizerConstants.COLOR_SELECTED);
}
else {
gc.setForeground(getCoreStateColor(true));
}
gc.fillRectangle(m_bounds); gc.fillRectangle(m_bounds);
gc.drawRectangle(m_bounds); gc.drawRectangle(m_bounds);
@ -190,6 +199,8 @@ public class MulticoreVisualizerCore extends MulticoreVisualizerGraphicObject
int text_indent = 3; int text_indent = 3;
int tx = m_bounds.x + m_bounds.width - text_indent; int tx = m_bounds.x + m_bounds.width - text_indent;
int ty = m_bounds.y + text_indent; int ty = m_bounds.y + text_indent;
// make sure we use the right color for core number, even if selected.
gc.setForeground(getCoreStateColor(true));
GUIUtils.drawTextAligned(gc, Integer.toString(m_id), tx, ty, false, true); GUIUtils.drawTextAligned(gc, Integer.toString(m_id), tx, ty, false, true);
} }
} }