|
Added
Link Here
|
| 1 |
/********************************************************************** |
| 2 |
* Copyright (c) 2008, Intel Corporation. |
| 3 |
* All rights reserved. This content is made available under |
| 4 |
* the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* $Id$ |
| 8 |
* |
| 9 |
* Contributors: |
| 10 |
* Intel Corporation - Initial API and implementation |
| 11 |
* Alexander N. Alexeev, Intel - Initial API and implementation |
| 12 |
**********************************************************************/ |
| 13 |
|
| 14 |
package org.eclipse.tptp.trace.jvmti.internal.client.views; |
| 15 |
|
| 16 |
import org.eclipse.hyades.ui.util.HyadesFormToolkit; |
| 17 |
import org.eclipse.jface.viewers.IBaseLabelProvider; |
| 18 |
import org.eclipse.jface.viewers.IContentProvider; |
| 19 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
| 20 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
| 21 |
import org.eclipse.jface.viewers.LabelProvider; |
| 22 |
import org.eclipse.jface.viewers.StructuredViewer; |
| 23 |
import org.eclipse.jface.viewers.TreeViewer; |
| 24 |
import org.eclipse.jface.viewers.Viewer; |
| 25 |
import org.eclipse.jface.viewers.ViewerSorter; |
| 26 |
import org.eclipse.swt.SWT; |
| 27 |
import org.eclipse.swt.custom.ViewForm; |
| 28 |
import org.eclipse.swt.events.SelectionEvent; |
| 29 |
import org.eclipse.swt.events.SelectionListener; |
| 30 |
import org.eclipse.swt.graphics.Image; |
| 31 |
import org.eclipse.swt.layout.GridData; |
| 32 |
import org.eclipse.swt.widgets.Composite; |
| 33 |
import org.eclipse.swt.widgets.Control; |
| 34 |
import org.eclipse.swt.widgets.Layout; |
| 35 |
import org.eclipse.swt.widgets.Tree; |
| 36 |
import org.eclipse.swt.widgets.TreeColumn; |
| 37 |
import org.eclipse.swt.widgets.TreeItem; |
| 38 |
import org.eclipse.tptp.trace.jvmti.internal.client.widgets.Utils; |
| 39 |
import org.eclipse.ui.forms.widgets.ColumnLayout; |
| 40 |
import org.eclipse.ui.forms.widgets.Section; |
| 41 |
|
| 42 |
public class MonitorThreadStatistics extends LabelProvider implements ITableLabelProvider, SelectionListener{ |
| 43 |
|
| 44 |
// MONSTAT_THREADS_COL_THREAD_ID |
| 45 |
private final static int MONSTAT_THREADS_COL_THREAD_ID_NUM = 0; |
| 46 |
private final static int MONSTAT_THREADS_COL_THREAD_ID_DEFW = 60; |
| 47 |
// MONSTAT_THREADS_COL_THREAD_NAME |
| 48 |
private final static int MONSTAT_THREADS_COL_THREAD_NAME_NUM = 1; |
| 49 |
private final static int MONSTAT_THREADS_COL_THREAD_NAME_DEFW = 200; |
| 50 |
// MONSTAT_THREADS_COL_BLOCKED_COUNT |
| 51 |
private final static int MONSTAT_THREADS_COL_BLOCKED_COUNT_NUM = 2; |
| 52 |
private final static int MONSTAT_THREADS_COL_BLOCKED_COUNT_DEFW = 100; |
| 53 |
// MONSTAT_THREADS_COL_BLOCKED_TIME |
| 54 |
private final static int MONSTAT_THREADS_COL_BLOCKED_TIME_NUM = 3; |
| 55 |
private final static int MONSTAT_THREADS_COL_BLOCKED_TIME_DEFW = 100; |
| 56 |
// MONSTAT_THREADS_COL_WAITED_COUNT |
| 57 |
private final static int MONSTAT_THREADS_COL_WAITING_COUNT_NUM = 4; |
| 58 |
private final static int MONSTAT_THREADS_COL_WAITING_COUNT_DEFW = 100; |
| 59 |
// MONSTAT_THREADS_COL_WAITED_TIME |
| 60 |
private final static int MONSTAT_THREADS_COL_WAITING_TIME_NUM = 5; |
| 61 |
private final static int MONSTAT_THREADS_COL_WAITING_TIME_DEFW = 100; |
| 62 |
|
| 63 |
//overall column number |
| 64 |
private final static int MONSTAT_THREADS_COL_NUM = 6; |
| 65 |
|
| 66 |
|
| 67 |
protected Composite _viewContainer; |
| 68 |
protected ViewForm _dataPane; |
| 69 |
protected StructuredViewer _viewer; |
| 70 |
protected ThreadStatisticsSorter _sorter; |
| 71 |
protected Layout _layout = null; |
| 72 |
|
| 73 |
protected HyadesFormToolkit _toolkit; |
| 74 |
|
| 75 |
MonitorStatisticController monViewCtrl; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public MonitorThreadStatistics(Section section, MonitorStatisticController monViewCtrl) { |
| 80 |
this.monViewCtrl = monViewCtrl; |
| 81 |
_toolkit = new HyadesFormToolkit(section.getDisplay()); |
| 82 |
_dataPane = _toolkit.createViewForm(section); |
| 83 |
_viewContainer = _dataPane; |
| 84 |
Control table = createTableViewer(_dataPane); |
| 85 |
_dataPane.setContent(table); |
| 86 |
} |
| 87 |
|
| 88 |
public Layout getLayout() { |
| 89 |
if (_layout == null) |
| 90 |
{ |
| 91 |
_layout = new ColumnLayout(); |
| 92 |
((ColumnLayout)_layout).maxNumColumns = 100; |
| 93 |
} |
| 94 |
return _layout; |
| 95 |
} |
| 96 |
|
| 97 |
private Control createTableViewer(ViewForm parent) { |
| 98 |
Tree tree = _toolkit.createTree(parent, SWT.MULTI | SWT.FULL_SELECTION | SWT.FLAT); |
| 99 |
tree.setLinesVisible(true); |
| 100 |
tree.setHeaderVisible(true); |
| 101 |
tree.setLayout(getLayout()); |
| 102 |
tree.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 103 |
tree.addSelectionListener(this); |
| 104 |
|
| 105 |
_viewer = new TreeViewer(tree); |
| 106 |
_viewer.setContentProvider(getContentProvider()); |
| 107 |
_viewer.setLabelProvider(getTableLabelProvider()); |
| 108 |
|
| 109 |
_sorter = new ThreadStatisticsSorter(); |
| 110 |
|
| 111 |
_viewer.setSorter(_sorter); |
| 112 |
|
| 113 |
createColumns(tree); |
| 114 |
_sorter.changeColumnSelection(0); |
| 115 |
|
| 116 |
monViewCtrl.setThreadsViewer(_viewer); |
| 117 |
return _viewer.getControl(); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
private void createColumns(Tree tree) { |
| 122 |
|
| 123 |
int colWidth[] = new int[MONSTAT_THREADS_COL_NUM]; |
| 124 |
String colTitle[] = new String[MONSTAT_THREADS_COL_NUM]; |
| 125 |
TreeColumn columns[] = new TreeColumn[MONSTAT_THREADS_COL_NUM]; |
| 126 |
|
| 127 |
colTitle[MONSTAT_THREADS_COL_THREAD_ID_NUM] = UIMessages._THREAD_ID_TITLE; |
| 128 |
colWidth[MONSTAT_THREADS_COL_THREAD_ID_NUM] = MONSTAT_THREADS_COL_THREAD_ID_DEFW; |
| 129 |
colTitle[MONSTAT_THREADS_COL_THREAD_NAME_NUM] = UIMessages._THREAD_NAME_TITLE; |
| 130 |
colWidth[MONSTAT_THREADS_COL_THREAD_NAME_NUM] = MONSTAT_THREADS_COL_THREAD_NAME_DEFW; |
| 131 |
colTitle[MONSTAT_THREADS_COL_BLOCKED_COUNT_NUM] = UIMessages._BLOCKED_COUNT; |
| 132 |
colWidth[MONSTAT_THREADS_COL_BLOCKED_COUNT_NUM] = MONSTAT_THREADS_COL_BLOCKED_COUNT_DEFW; |
| 133 |
colTitle[MONSTAT_THREADS_COL_BLOCKED_TIME_NUM] = UIMessages._THREAD_BLOCKED_TIME; |
| 134 |
colWidth[MONSTAT_THREADS_COL_BLOCKED_TIME_NUM] = MONSTAT_THREADS_COL_BLOCKED_TIME_DEFW; |
| 135 |
colTitle[MONSTAT_THREADS_COL_WAITING_COUNT_NUM] = UIMessages._WAITING_CONUT; |
| 136 |
colWidth[MONSTAT_THREADS_COL_WAITING_COUNT_NUM] = MONSTAT_THREADS_COL_WAITING_COUNT_DEFW; |
| 137 |
colTitle[MONSTAT_THREADS_COL_WAITING_TIME_NUM] = UIMessages._THREAD_WAITING_TIME; |
| 138 |
colWidth[MONSTAT_THREADS_COL_WAITING_TIME_NUM] = MONSTAT_THREADS_COL_WAITING_TIME_DEFW; |
| 139 |
|
| 140 |
|
| 141 |
for (int i = 0; i < MONSTAT_THREADS_COL_NUM; i++) { |
| 142 |
columns[i] = new TreeColumn(tree, SWT.NULL | SWT.NO_BACKGROUND | SWT.LEFT); |
| 143 |
columns[i].setResizable(true); |
| 144 |
columns[i].setText(colTitle[i]); |
| 145 |
columns[i].setWidth(colWidth[i]); |
| 146 |
columns[i].addSelectionListener(getColumnSelectionListener(i)); |
| 147 |
} |
| 148 |
|
| 149 |
_sorter.setColumns(columns); |
| 150 |
} |
| 151 |
|
| 152 |
SelectionListener getColumnSelectionListener(final int columnIndex) { |
| 153 |
return new SelectionListener(){ |
| 154 |
public void widgetSelected(SelectionEvent e) { |
| 155 |
_sorter.changeColumnSelection(columnIndex); |
| 156 |
_viewer.refresh(); |
| 157 |
} |
| 158 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 159 |
} |
| 160 |
}; |
| 161 |
} |
| 162 |
|
| 163 |
private IBaseLabelProvider getTableLabelProvider() { |
| 164 |
return this; |
| 165 |
} |
| 166 |
|
| 167 |
private IContentProvider getContentProvider() { |
| 168 |
return new MonitorThreadStatisticContentProvider(); |
| 169 |
} |
| 170 |
|
| 171 |
public Composite getViewContainer() { |
| 172 |
return _viewContainer; |
| 173 |
} |
| 174 |
|
| 175 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 176 |
// TODO Auto-generated method stub |
| 177 |
|
| 178 |
} |
| 179 |
|
| 180 |
public void widgetSelected(SelectionEvent e) { |
| 181 |
if (!(e.widget instanceof Tree)) { |
| 182 |
// TODO add assert |
| 183 |
return; |
| 184 |
} |
| 185 |
|
| 186 |
Tree tree = (Tree)e.widget; |
| 187 |
TreeItem[] selectedItems = tree.getSelection(); |
| 188 |
MonitorThreadDetails[] threads = new MonitorThreadDetails[selectedItems.length]; |
| 189 |
for (int i = 0; i < selectedItems.length; i++) { |
| 190 |
threads[i] = (MonitorThreadDetails)selectedItems[i].getData(); |
| 191 |
} |
| 192 |
monViewCtrl.setSelectedThreads(threads); |
| 193 |
} |
| 194 |
|
| 195 |
public Image getColumnImage(Object element, int columnIndex) { |
| 196 |
// TODO Auto-generated method stub |
| 197 |
return null; |
| 198 |
} |
| 199 |
|
| 200 |
public String getColumnText(Object element, int columnIndex) { |
| 201 |
if (!(element instanceof MonitorThreadDetails)) { |
| 202 |
// TODO add assert |
| 203 |
return null; |
| 204 |
} |
| 205 |
|
| 206 |
MonitorThreadDetails threadDetails = (MonitorThreadDetails)element; |
| 207 |
switch (columnIndex) { |
| 208 |
case MONSTAT_THREADS_COL_THREAD_ID_NUM: |
| 209 |
return new Integer(threadDetails.getThread().getId()).toString(); |
| 210 |
case MONSTAT_THREADS_COL_THREAD_NAME_NUM: |
| 211 |
return (threadDetails.getThread().getName()); |
| 212 |
case MONSTAT_THREADS_COL_BLOCKED_COUNT_NUM: |
| 213 |
return new Integer(threadDetails.getBlockedCount()).toString(); |
| 214 |
case MONSTAT_THREADS_COL_BLOCKED_TIME_NUM: |
| 215 |
return Utils.formatTime(threadDetails.getBlockTime()).toString(); |
| 216 |
case MONSTAT_THREADS_COL_WAITING_COUNT_NUM: |
| 217 |
return new Integer(threadDetails.getWaitCount()).toString(); |
| 218 |
case MONSTAT_THREADS_COL_WAITING_TIME_NUM: |
| 219 |
return Utils.formatTime(threadDetails.getWaitingTime()).toString(); |
| 220 |
default: |
| 221 |
break; |
| 222 |
} |
| 223 |
return null; |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
class ThreadStatisticsSorter extends ViewerSorter { |
| 228 |
|
| 229 |
private int sortedIdx = -1; |
| 230 |
private boolean ascOrder = true; |
| 231 |
//private TreeColumn columns[] = null; |
| 232 |
|
| 233 |
void changeColumnSelection(int idx) { |
| 234 |
if (sortedIdx == idx) { |
| 235 |
ascOrder = !ascOrder; |
| 236 |
} |
| 237 |
else { |
| 238 |
ascOrder = true; |
| 239 |
} |
| 240 |
sortedIdx = idx; |
| 241 |
} |
| 242 |
|
| 243 |
void setColumns(TreeColumn columns[]) { |
| 244 |
//this.columns = columns; |
| 245 |
} |
| 246 |
|
| 247 |
public int compare(Viewer viewer, Object e1, Object e2) { |
| 248 |
if (!(e1 instanceof MonitorThreadDetails) || |
| 249 |
!(e2 instanceof MonitorThreadDetails)) { |
| 250 |
return 0; |
| 251 |
} |
| 252 |
MonitorThreadDetails td1 = (MonitorThreadDetails)e1; |
| 253 |
MonitorThreadDetails td2 = (MonitorThreadDetails)e2; |
| 254 |
int result = 0; |
| 255 |
|
| 256 |
switch (sortedIdx) { |
| 257 |
case MONSTAT_THREADS_COL_THREAD_ID_NUM: |
| 258 |
result = td1.getThread().getId() - td2.getThread().getId(); |
| 259 |
break; |
| 260 |
case MONSTAT_THREADS_COL_THREAD_NAME_NUM: |
| 261 |
result = td1.getThread().getName().compareTo(td2.getThread().getName()); |
| 262 |
break; |
| 263 |
case MONSTAT_THREADS_COL_BLOCKED_COUNT_NUM: |
| 264 |
result = td1.getBlockedCount() - td2.getBlockedCount(); |
| 265 |
break; |
| 266 |
case MONSTAT_THREADS_COL_BLOCKED_TIME_NUM: |
| 267 |
result = new Double(td1.getBlockTime()).compareTo(new Double (td2.getBlockTime())); |
| 268 |
break; |
| 269 |
case MONSTAT_THREADS_COL_WAITING_COUNT_NUM: |
| 270 |
result = td1.getWaitCount() - td2.getWaitCount(); |
| 271 |
break; |
| 272 |
case MONSTAT_THREADS_COL_WAITING_TIME_NUM: |
| 273 |
result = new Double(td1.getWaitingTime()).compareTo(new Double (td2.getWaitingTime())); |
| 274 |
break; |
| 275 |
default: |
| 276 |
break; |
| 277 |
} |
| 278 |
return ascOrder ? result : -result; |
| 279 |
} |
| 280 |
|
| 281 |
public boolean isSorterProperty(Object element, String property) { |
| 282 |
return true; |
| 283 |
} |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
class MonitorThreadStatisticContentProvider implements ITreeContentProvider { |
| 288 |
|
| 289 |
Object[] threads; |
| 290 |
|
| 291 |
public Object[] getChildren(Object parentElement) { |
| 292 |
return null; |
| 293 |
} |
| 294 |
|
| 295 |
public Object getParent(Object element) { |
| 296 |
return null; |
| 297 |
} |
| 298 |
|
| 299 |
public boolean hasChildren(Object element) { |
| 300 |
return false; |
| 301 |
} |
| 302 |
|
| 303 |
public Object[] getElements(Object inputElement) { |
| 304 |
return threads; |
| 305 |
} |
| 306 |
|
| 307 |
public void dispose() { |
| 308 |
} |
| 309 |
|
| 310 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
| 311 |
if (newInput instanceof Object[]) { |
| 312 |
threads = (Object[])newInput; |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
} |
| 317 |
|