Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 209727
Collapse All | Expand All

(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/messages.properties (-1 / +21 lines)
Lines 14-19 Link Here
14
# NLS_ENCODING=UTF-8
14
# NLS_ENCODING=UTF-8
15
15
16
THREAD_STATISTIC_TITLE = Thread Statistics
16
THREAD_STATISTIC_TITLE = Thread Statistics
17
MONITOR_STATISTIC_TITLE = Monitor Statistics
17
THREAD_STATES_TITLE = Threads Visualizer
18
THREAD_STATES_TITLE = Threads Visualizer
18
THREAD_ANALYSIS_TITLE = Threads Analysis
19
THREAD_ANALYSIS_TITLE = Threads Analysis
19
MEM_ANALYSIS_TITLE = Memory Analysis
20
MEM_ANALYSIS_TITLE = Memory Analysis
Lines 106-109 Link Here
106
_OBJECT_WAITING_FOR = Object Waiting For
107
_OBJECT_WAITING_FOR = Object Waiting For
107
_UNDEFINED_GROUP = <undefined>
108
_UNDEFINED_GROUP = <undefined>
108
_THREAD_GROUP_LABEL = Thread Group [{0}]
109
_THREAD_GROUP_LABEL = Thread Group [{0}]
109
_EDIT_PROFILING_OPTIONS = Edit Profiling Options
110
_EDIT_PROFILING_OPTIONS = Edit Profiling Options
111
112
113
#Monitor statistics view messages
114
_MONITOR_CLASS_NAME = Class Name:
115
_MONITOR_CALLER = Caller
116
_TOTAL_BLOCKED_TIME = Total Blocked Time
117
_TOTAL_WAITING_TIME = Total Waiting Time
118
_MAX_AVG_MIN_TIME = Max/Avg/Min Time
119
_OBJECT_NUMBER = Object Number
120
_THREAD_NUMBER = Thread Number
121
_BLOCKED_COUNT = Blocked Count
122
_WAITING_CONUT = Waited Count
123
_THREAD_ID_TITLE = Thread Id
124
_THREAD_NAME_TITLE = Thread Name
125
126
_MONITOR_THREADS_TAB = Threads Statistics
127
_MONITOR_CLASSES_TAB = Monitor Classes Statistics
128
_MONITOR_BLOCKED_TAB = Blocks Statistics
129
_MONITOR_WAITING_TAB = Waits Statistics
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/UIMessages.java (+18 lines)
Lines 18-23 Link Here
18
	private static final String BUNDLE_NAME = "org.eclipse.tptp.trace.jvmti.internal.client.views.messages"; //$NON-NLS-1$
18
	private static final String BUNDLE_NAME = "org.eclipse.tptp.trace.jvmti.internal.client.views.messages"; //$NON-NLS-1$
19
19
20
	public static String THREAD_STATISTIC_TITLE;
20
	public static String THREAD_STATISTIC_TITLE;
21
	public static String MONITOR_STATISTIC_TITLE;
21
	public static String THREAD_STATES_TITLE;
22
	public static String THREAD_STATES_TITLE;
22
	public static String THREAD_ANALYSIS_TITLE;
23
	public static String THREAD_ANALYSIS_TITLE;
23
	public static String MEM_ANALYSIS_TITLE;
24
	public static String MEM_ANALYSIS_TITLE;
Lines 112-117 Link Here
112
	public static String _THREAD_GROUP_LABEL;
113
	public static String _THREAD_GROUP_LABEL;
113
	public static String _EDIT_PROFILING_OPTIONS;
114
	public static String _EDIT_PROFILING_OPTIONS;
114
	
115
	
116
	//Monitor statistic view
117
	public static String _MONITOR_CLASS_NAME;
118
	public static String _MONITOR_CALLER;
119
	public static String _TOTAL_BLOCKED_TIME;
120
	public static String _TOTAL_WAITING_TIME;
121
	public static String _MAX_AVG_MIN_TIME;
122
	public static String _OBJECT_NUMBER;
123
	public static String _THREAD_NUMBER;
124
	public static String _BLOCKED_COUNT;
125
	public static String _WAITING_CONUT;
126
	public static String _THREAD_ID_TITLE;
127
	public static String _THREAD_NAME_TITLE;
128
	public static String _MONITOR_THREADS_TAB;
129
	public static String _MONITOR_CLASSES_TAB;
130
	public static String _MONITOR_BLOCKED_TAB;
131
	public static String _MONITOR_WAITING_TAB;	
132
	
115
	private UIMessages() {
133
	private UIMessages() {
116
		// Do not instantiate
134
		// Do not instantiate
117
	}
135
	}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/ThreadStatesView.java (-1 / +1 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    Intel Corporation - Initial API and implementation
9
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *    Alexander N. Alexeev, Intel - Add monitors statistics support
11
 *
12
 *
12
 * $Id: ThreadStatesView.java,v 1.3 2008/03/05 15:45:10 ewchan Exp $ 
13
 * $Id: ThreadStatesView.java,v 1.3 2008/03/05 15:45:10 ewchan Exp $ 
13
 *****************************************************************************/
14
 *****************************************************************************/
Lines 21-27 Link Here
21
import org.eclipse.hyades.trace.ui.internal.util.PerftraceUtil;
22
import org.eclipse.hyades.trace.ui.internal.util.PerftraceUtil;
22
import org.eclipse.hyades.trace.views.util.internal.ThreadDetails;
23
import org.eclipse.hyades.trace.views.util.internal.ThreadDetails;
23
import org.eclipse.hyades.ui.util.GridUtil;
24
import org.eclipse.hyades.ui.util.GridUtil;
24
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.jface.viewers.ISelection;
25
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.events.ControlAdapter;
27
import org.eclipse.swt.events.ControlAdapter;
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/ThreadAnalysisPage.java (-7 / +15 lines)
Lines 1-5 Link Here
1
/*****************************************************************************
1
/*****************************************************************************
2
 * Copyright (c) 2007 Intel Corporation.
2
 * Copyright (c) 2008 Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    Intel Corporation - Initial API and implementation
9
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *    Alexander N. Alexeev, Intel - Add monitors statistics support
11
 *
12
 *
12
 * $Id: ThreadAnalysisPage.java,v 1.1 2007/04/20 13:06:48 ewchan Exp $ 
13
 * $Id: ThreadAnalysisPage.java,v 1.1 2007/04/20 13:06:48 ewchan Exp $ 
13
 *****************************************************************************/
14
 *****************************************************************************/
Lines 31-38 Link Here
31
public class ThreadAnalysisPage extends TraceViewerPage {
32
public class ThreadAnalysisPage extends TraceViewerPage {
32
33
33
	static public final int TAB_THREAD_STATISTIC = 0;
34
	static public final int TAB_THREAD_STATISTIC = 0;
34
	static public final int TAB_THREAD_STATES = 1;
35
	static public final int TAB_MONITOR_STATISTIC = 1;
35
	static public final int TAB_NUM = 2;
36
	static public final int TAB_THREAD_STATES = 2;
37
	static public final int TAB_NUM = 3;
36
38
37
	CTabFolder _tabFolder;
39
	CTabFolder _tabFolder;
38
	BaseProfilerView _views[];
40
	BaseProfilerView _views[];
Lines 75-81 Link Here
75
			}
77
			}
76
		});
78
		});
77
79
78
		_views = new BaseProfilerView[2];
80
		_views = new BaseProfilerView[3];
79
		CTabItem tabItem;
81
		CTabItem tabItem;
80
82
81
		tabItem = new CTabItem(_tabFolder, SWT.NONE);
83
		tabItem = new CTabItem(_tabFolder, SWT.NONE);
Lines 85-95 Link Here
85
		tabItem.setControl(_views[0].getControl());
87
		tabItem.setControl(_views[0].getControl());
86
88
87
		tabItem = new CTabItem(_tabFolder, SWT.NONE);
89
		tabItem = new CTabItem(_tabFolder, SWT.NONE);
88
		tabItem.setText(UIMessages.THREAD_STATES_TITLE);
90
		tabItem.setText(UIMessages.MONITOR_STATISTIC_TITLE);
89
		ThreadStatesView view1 = new ThreadStatesView(_tabFolder, this);
91
		MonitorStatisticView view1 = new MonitorStatisticView(_tabFolder, this);
90
		_views[1] = view1;
92
		_views[1] = view1;
91
		tabItem.setControl(_views[1].getControl());
93
		tabItem.setControl(_views[1].getControl());		
92
94
95
		tabItem = new CTabItem(_tabFolder, SWT.NONE);
96
		tabItem.setText(UIMessages.THREAD_STATES_TITLE);
97
		ThreadStatesView view2 = new ThreadStatesView(_tabFolder, this);
98
		_views[2] = view2;
99
		tabItem.setControl(_views[2].getControl());
100
		
93
		_tabFolder.setSelection(selectedTab);
101
		_tabFolder.setSelection(selectedTab);
94
		setContextMenu(view0.getTree(), view0.getTreeViewer());
102
		setContextMenu(view0.getTree(), view0.getTreeViewer());
95
	}
103
	}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/MonitorThreadStatistics.java (+317 lines)
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
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/MonitorThreadDetails.java (+135 lines)
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 java.util.HashMap;
17
import java.util.Map;
18
19
import org.eclipse.emf.common.util.EList;
20
import org.eclipse.hyades.models.trace.TRCClass;
21
import org.eclipse.hyades.models.trace.TRCObject;
22
import org.eclipse.hyades.models.trace.TRCThread;
23
import org.eclipse.hyades.models.trace.TRCThreadEvent;
24
import org.eclipse.hyades.models.trace.TRCThreadSleepingEvent;
25
import org.eclipse.hyades.models.trace.TRCThreadWaitingForLockEvent;
26
import org.eclipse.hyades.models.trace.TRCThreadWaitingForObjectEvent;
27
import org.eclipse.hyades.trace.ui.internal.util.PerftraceUtil;
28
29
30
public class MonitorThreadDetails{
31
32
	protected HashMap _classMap = new HashMap(); 
33
	
34
	protected TRCThread _thread;
35
	
36
	protected double _lastUpdateTime = 0;
37
	
38
	protected double _sleepTime;
39
	protected int _sleepCount;
40
41
	protected double _waitTime;
42
	protected int _waitCount;
43
44
	protected double _blockTime;
45
	protected int _blockCount;
46
	
47
	public MonitorThreadDetails(TRCThread thread) {
48
		_thread = thread;
49
		recalculate();
50
	}
51
52
	public void recalculate() {
53
		EList events = _thread.getThreadEvents();
54
		int count = events.size();
55
		if (count > 0) {
56
			TRCThreadEvent event = (TRCThreadEvent)events.get(0);
57
			for (int i = 1; i < count; i++){
58
				TRCThreadEvent next = (TRCThreadEvent)events.get(i);
59
				double timeSpan = Math.max(next.getTime() - event.getTime(), 0);
60
				
61
				updateMonitorsData(event, timeSpan);
62
				MonitorClassDetails monObjectClass = getObjectClass(event);
63
				if (null != monObjectClass) {
64
					monObjectClass.updateMonitorsData(event, timeSpan);
65
				}
66
				
67
				event = next;
68
			}
69
			_lastUpdateTime = ((TRCThreadEvent)events.get(count - 1)).getTime();
70
		}
71
	}
72
73
	private void updateMonitorsData(TRCThreadEvent event, double timeSpan) {
74
		if(event instanceof TRCThreadSleepingEvent) {
75
			_sleepTime += timeSpan;
76
			_sleepCount++;
77
		} else if(event instanceof TRCThreadWaitingForObjectEvent) {
78
			_waitTime += timeSpan;
79
			_waitCount++;
80
		} else if(event instanceof TRCThreadWaitingForLockEvent) {
81
			_blockTime += timeSpan;
82
			_blockCount++;
83
		}
84
	}
85
86
	private MonitorClassDetails getObjectClass(TRCThreadEvent event) {
87
		TRCObject monObject = null;
88
		if(event instanceof TRCThreadWaitingForObjectEvent) {
89
			monObject = ((TRCThreadWaitingForObjectEvent)event).getObjectWaitingFor();
90
		} else if(event instanceof TRCThreadWaitingForLockEvent) {
91
			monObject = ((TRCThreadWaitingForLockEvent)event).getLockedObject();
92
		} else {
93
			return null;
94
		}
95
		TRCClass monObjClass =  PerftraceUtil.getClass(monObject);
96
		if (!_classMap.containsKey(monObjClass)) {
97
			MonitorClassDetails classDetails = new MonitorClassDetails(monObjClass);
98
			_classMap.put(monObjClass, classDetails);
99
			return classDetails;
100
		}
101
		return (MonitorClassDetails)_classMap.get(monObjClass);
102
	}
103
	
104
	public TRCThread getThread() {
105
		return _thread;
106
	}
107
	
108
	public int getBlockedCount() {
109
		return _blockCount;
110
	}
111
	
112
	public int getWaitCount() {
113
		return _waitCount;
114
	}
115
	
116
	public int getSleepCount() {
117
		return _sleepCount;
118
	}
119
	
120
	public double getBlockTime() {
121
		return _blockTime;
122
	}
123
124
	public double getSleepTime() {
125
		return _sleepTime;
126
	}
127
	
128
	public double getWaitingTime() {
129
		return _waitTime;
130
	}
131
	
132
	public Map getClassMap() {
133
		return _classMap;
134
	}
135
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/MonitorClassWaitingStatistics.java (+297 lines)
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.tptp.trace.jvmti.internal.client.widgets.Utils;
38
import org.eclipse.ui.forms.widgets.ColumnLayout;
39
import org.eclipse.ui.forms.widgets.Section;
40
41
public class MonitorClassWaitingStatistics  extends LabelProvider implements ITableLabelProvider, SelectionListener{
42
43
	private final static int MONSTAT_WAITTIME_COL_CALLER_NUM = 0;
44
	private final static int MONSTAT_WAITTIME_COL_CALLER_DEFW = 250;
45
	private final static int MONSTAT_WAITTIME_COL_TOTAL_TIME_NUM = 1;
46
	private final static int MONSTAT_WAITTIME_COL_TOTAL_TIME_DEFW = 100;
47
	private final static int MONSTAT_WAITTIME_COL_COUNT_NUM = 2;
48
	private final static int MONSTAT_WAITTIME_COL_COUNT_DEFW = 100;
49
	private final static int MONSTAT_WAITTIME_COL_STAT_NUM = 3;
50
	private final static int MONSTAT_WAITTIME_COL_STAT_DEFW = 200;
51
	private final static int MONSTAT_WAITTIME_COL_OBJECT_NUM_NUM = 4;
52
	private final static int MONSTAT_WAITTIME_COL_OBJECT_NUM_DEFW = 100;
53
	private final static int MONSTAT_WAITTIME_COL_THREAD_NUM_NUM = 5;
54
	private final static int MONSTAT_WAITTIME_COL_THREAD_NUM_DEFW = 100;
55
	
56
	//overall column number
57
	private final static int MONSTAT_WAITTIME_COL_NUM = 6;
58
	
59
	
60
	protected Composite _viewContainer;
61
	protected ViewForm _dataPane;
62
	protected StructuredViewer _viewer;
63
	protected Layout _layout = null;
64
	MonitorWaitingStatisticsSorter _sorter;
65
	
66
	protected HyadesFormToolkit _toolkit;
67
	
68
	MonitorStatisticController monViewCtrl;
69
	
70
	
71
	public MonitorClassWaitingStatistics(Section section, MonitorStatisticController monViewCtrl) {
72
		this.monViewCtrl = monViewCtrl;
73
		_toolkit = new HyadesFormToolkit(section.getDisplay());		
74
		_dataPane = _toolkit.createViewForm(section);
75
		_viewContainer = _dataPane;
76
		Control table = createTableViewer(_dataPane);
77
		_dataPane.setContent(table);	
78
	}
79
	
80
	public Layout getLayout() {
81
		if (_layout == null)
82
		{
83
			_layout = new ColumnLayout();
84
			((ColumnLayout)_layout).maxNumColumns = 100;
85
		}
86
		return _layout;
87
	}		
88
	
89
	private Control createTableViewer(ViewForm parent) {
90
		Tree tree = _toolkit.createTree(parent, SWT.MULTI | SWT.FULL_SELECTION | SWT.FLAT);
91
		
92
		tree.setLinesVisible(true);
93
		tree.setHeaderVisible(true);
94
		tree.setLayout(getLayout());
95
		tree.setLayoutData(new GridData(GridData.FILL_BOTH));
96
		tree.addSelectionListener(this);
97
		
98
		_viewer = new TreeViewer(tree);
99
		_viewer.setContentProvider(getContentProvider());
100
		_viewer.setLabelProvider(getTableLabelProvider());
101
		_sorter = new MonitorWaitingStatisticsSorter();
102
		_viewer.setSorter(_sorter);
103
				
104
		createColumns(tree);		
105
		_sorter.changeColumnSelection(0);
106
		
107
		monViewCtrl.setWaitTimeViewer(_viewer);
108
		return _viewer.getControl();
109
	}
110
111
	private void createColumns(Tree tree) {
112
113
		int colWidth[] = new int[MONSTAT_WAITTIME_COL_NUM];
114
		String colTitle[] = new String[MONSTAT_WAITTIME_COL_NUM];
115
		TreeColumn columns[] = new TreeColumn[MONSTAT_WAITTIME_COL_NUM];
116
		
117
		colTitle[MONSTAT_WAITTIME_COL_CALLER_NUM] = UIMessages._MONITOR_CALLER;
118
		colWidth[MONSTAT_WAITTIME_COL_CALLER_NUM] = MONSTAT_WAITTIME_COL_CALLER_DEFW;
119
		colTitle[MONSTAT_WAITTIME_COL_TOTAL_TIME_NUM] = UIMessages._TOTAL_WAITING_TIME;
120
		colWidth[MONSTAT_WAITTIME_COL_TOTAL_TIME_NUM] = MONSTAT_WAITTIME_COL_TOTAL_TIME_DEFW;
121
		colTitle[MONSTAT_WAITTIME_COL_COUNT_NUM] = UIMessages._WAITING_CONUT;
122
		colWidth[MONSTAT_WAITTIME_COL_COUNT_NUM] = MONSTAT_WAITTIME_COL_COUNT_DEFW;
123
		colTitle[MONSTAT_WAITTIME_COL_STAT_NUM] = UIMessages._MAX_AVG_MIN_TIME;
124
		colWidth[MONSTAT_WAITTIME_COL_STAT_NUM] = MONSTAT_WAITTIME_COL_STAT_DEFW;
125
		colTitle[MONSTAT_WAITTIME_COL_OBJECT_NUM_NUM] = UIMessages._OBJECT_NUMBER;
126
		colWidth[MONSTAT_WAITTIME_COL_OBJECT_NUM_NUM] = MONSTAT_WAITTIME_COL_OBJECT_NUM_DEFW;
127
		colTitle[MONSTAT_WAITTIME_COL_THREAD_NUM_NUM] = UIMessages._THREAD_NUMBER;
128
		colWidth[MONSTAT_WAITTIME_COL_THREAD_NUM_NUM] = MONSTAT_WAITTIME_COL_THREAD_NUM_DEFW;
129
		
130
		for (int i = 0; i < MONSTAT_WAITTIME_COL_NUM; i++) {
131
			columns[i] = new TreeColumn(tree, SWT.NULL | SWT.NO_BACKGROUND | SWT.LEFT);
132
			columns[i].setResizable(true);
133
			columns[i].setText(colTitle[i]);
134
			columns[i].setWidth(colWidth[i]);
135
			columns[i].addSelectionListener(getColumnSelectionListener(i));
136
		}
137
		
138
		_sorter.setColumns(columns);
139
	}
140
141
	SelectionListener getColumnSelectionListener(final int columnIndex) {
142
		return new SelectionListener(){
143
			public void widgetSelected(SelectionEvent e) {
144
				_sorter.changeColumnSelection(columnIndex);
145
				_viewer.refresh();
146
			}
147
			public void widgetDefaultSelected(SelectionEvent e) {
148
			}
149
		};
150
	}
151
	
152
	private IBaseLabelProvider getTableLabelProvider() {
153
		return this;
154
	}
155
156
	private IContentProvider getContentProvider() {
157
		return new MonitorWaitTimeStatisticContentProvider();
158
	}
159
160
	public Composite getViewContainer() {
161
		return _viewContainer;
162
	}
163
164
	public void widgetDefaultSelected(SelectionEvent e) {
165
	}
166
167
	public void widgetSelected(SelectionEvent e) {
168
	}
169
170
	public Image getColumnImage(Object element, int columnIndex) {
171
		return null;
172
	}
173
174
	public String getColumnText(Object element, int columnIndex) {
175
		if (!(element instanceof MonitorCallDetails)) {
176
			// TODO add assert
177
			return null;
178
		}
179
		MonitorCallDetails monCallDetails = (MonitorCallDetails)element;		
180
		
181
		switch (columnIndex) {
182
		case MONSTAT_WAITTIME_COL_CALLER_NUM:
183
			return monCallDetails.getCallTitle();
184
		case MONSTAT_WAITTIME_COL_TOTAL_TIME_NUM:
185
			return Utils.formatTime(monCallDetails.getWaitingTime());
186
		case MONSTAT_WAITTIME_COL_COUNT_NUM:
187
			return new Integer(monCallDetails.getWaitingCount()).toString();
188
		case MONSTAT_WAITTIME_COL_STAT_NUM:
189
			return Utils.formatTime(monCallDetails.getMaxWaitingTime()) + " / " + 
190
				Utils.formatTime(monCallDetails.getAvgWaitingTime()) + " / " +
191
				Utils.formatTime(monCallDetails.getMinWaitingTime());
192
		case MONSTAT_WAITTIME_COL_OBJECT_NUM_NUM:
193
			return new Integer(monCallDetails.getWaitingObjectsCount()).toString();
194
		case MONSTAT_WAITTIME_COL_THREAD_NUM_NUM:
195
			return new Integer(monCallDetails.getWaitingThreadsCount()).toString();
196
		default:
197
			break;
198
		}
199
		return null;		
200
		
201
	}	
202
203
	class MonitorWaitingStatisticsSorter extends ViewerSorter {
204
205
		private int sortedIdx = -1;
206
		private boolean ascOrder = true;
207
		//private TreeColumn columns[] = null;
208
		
209
		void changeColumnSelection(int idx) {
210
			// column isn't sortable 
211
			if (MONSTAT_WAITTIME_COL_STAT_NUM == idx)
212
				return;
213
			
214
			if (sortedIdx == idx) {
215
				ascOrder = !ascOrder;
216
			}
217
			else {
218
				ascOrder = true;
219
			} 
220
			sortedIdx = idx;
221
		}
222
		
223
		void setColumns(TreeColumn columns[]) {
224
			//this.columns = columns;
225
		}
226
		
227
		public int compare(Viewer viewer, Object e1, Object e2) {
228
			if (!(e1 instanceof MonitorCallDetails) ||
229
				!(e2 instanceof MonitorCallDetails)) {
230
				return 0;
231
			}
232
			
233
			MonitorCallDetails cd1 = (MonitorCallDetails)e1;
234
			MonitorCallDetails cd2 = (MonitorCallDetails)e2;
235
			int result = 0; 
236
			
237
			switch (sortedIdx) {
238
			case MONSTAT_WAITTIME_COL_CALLER_NUM:
239
				result = cd1.getCallTitle().compareTo(cd2.getCallTitle());
240
				break;
241
			case MONSTAT_WAITTIME_COL_COUNT_NUM:
242
				result = cd1.getWaitingCount() - cd2.getWaitingCount();
243
				break;
244
			case MONSTAT_WAITTIME_COL_TOTAL_TIME_NUM:
245
				result = new Double(cd1.getWaitingTime())
246
					.compareTo(new Double (cd2.getWaitingTime()));
247
				break;
248
			case MONSTAT_WAITTIME_COL_OBJECT_NUM_NUM:
249
				result = cd1.getWaitingObjectsCount() - cd2.getWaitingObjectsCount();
250
				break;
251
			case MONSTAT_WAITTIME_COL_THREAD_NUM_NUM:
252
				result = cd1.getWaitingThreadsCount() - cd2.getWaitingThreadsCount();
253
				break;
254
			default:
255
				break;		
256
			}
257
			
258
			return ascOrder ? result : -result;
259
		}
260
		
261
		public boolean isSorterProperty(Object element, String property) {
262
			 return true;
263
		}
264
		
265
	}	
266
}
267
268
class MonitorWaitTimeStatisticContentProvider implements ITreeContentProvider {
269
	
270
	Object[] calls;
271
	
272
	public Object[] getChildren(Object parentElement) {
273
		return null;
274
	}
275
276
	public Object getParent(Object element) {
277
		return null;
278
	}
279
280
	public boolean hasChildren(Object element) {
281
		return false;
282
	}
283
284
	public Object[] getElements(Object inputElement) {
285
		return calls;
286
	}
287
288
	public void dispose() {
289
	}
290
291
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
292
		if (newInput instanceof Object[]) {
293
			calls = (Object[])newInput;
294
		}
295
	}
296
	
297
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/MonitorStatisticController.java (+177 lines)
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 java.util.HashMap;
17
18
import org.eclipse.emf.common.util.EList;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.hyades.models.trace.TRCClass;
21
import org.eclipse.hyades.models.trace.TRCObject;
22
import org.eclipse.hyades.models.trace.TRCThread;
23
import org.eclipse.hyades.models.trace.TRCThreadEvent;
24
import org.eclipse.hyades.models.trace.TRCThreadWaitingForLockEvent;
25
import org.eclipse.hyades.models.trace.TRCThreadWaitingForObjectEvent;
26
import org.eclipse.hyades.trace.ui.internal.util.PerftraceUtil;
27
import org.eclipse.jface.viewers.StructuredViewer;
28
import org.eclipse.ui.forms.widgets.Form;
29
30
public class MonitorStatisticController {
31
32
	private EObject modelRoot;
33
	
34
	StructuredViewer _threadsViewer;
35
	StructuredViewer _classesViewer;
36
	StructuredViewer _blockTimeViewer;
37
	StructuredViewer _waitTimeViewer;
38
	Form             _classNameLable;
39
	
40
	HashMap _threads = new HashMap();
41
	
42
	public void setMOFObject(EObject object) {
43
		modelRoot = object;
44
		initialize();
45
	}
46
47
	public void setThreadsViewer(StructuredViewer _viewer) {
48
		_threadsViewer = _viewer;
49
	}
50
51
	public void setClassesTimeViewer(StructuredViewer _viewer) {
52
		_classesViewer = _viewer;
53
	}
54
	
55
	public void setClassLabel(Form _form) {
56
		_classNameLable = _form;
57
	}
58
	
59
	public void setBlockTimeViewer(StructuredViewer _viewer) {
60
		_blockTimeViewer = _viewer;
61
	}
62
63
	public void setWaitTimeViewer(StructuredViewer _viewer) {
64
		_waitTimeViewer = _viewer;
65
	}
66
	
67
	public void update() {
68
		//recalculate();
69
		_threadsViewer.setInput(_threads.values().toArray());
70
	}
71
72
	public void setSelectedThreads(MonitorThreadDetails[] threads) {
73
		_classNameLable.setText(UIMessages._MONITOR_CLASS_NAME); 
74
		_classesViewer.setInput(getMonitorClasses(threads));
75
		_blockTimeViewer.setInput(null);
76
		_waitTimeViewer.setInput(null);
77
	}
78
	
79
	private Object[] getMonitorClasses(MonitorThreadDetails[] threads) {
80
		return mergeClassDetails(threads);
81
	}
82
83
	private Object[] mergeClassDetails(MonitorThreadDetails[] threads){
84
		if (threads.length == 1) {
85
			return threads[0].getClassMap().values().toArray();
86
		}
87
		
88
		// TODO: VERY ineffective implementation, should be improved!!!  
89
		HashMap classMap = new HashMap();
90
		
91
		for (int t = 0; t < threads.length; t++) {
92
			TRCThread thread = threads[t].getThread();
93
			EList events = thread.getThreadEvents();
94
			int count = events.size();
95
			if (count > 0) {
96
				TRCThreadEvent event = (TRCThreadEvent)events.get(0);
97
				for (int i = 1; i < count; i++){
98
					TRCThreadEvent next = (TRCThreadEvent)events.get(i);
99
					double timeSpan = Math.max(next.getTime() - event.getTime(), 0);
100
					
101
					
102
					TRCObject monObject = null;
103
					MonitorClassDetails classDetails = null;
104
105
					if(event instanceof TRCThreadWaitingForObjectEvent) {
106
						monObject = ((TRCThreadWaitingForObjectEvent)event).getObjectWaitingFor();
107
					} else if(event instanceof TRCThreadWaitingForLockEvent) {
108
						monObject = ((TRCThreadWaitingForLockEvent)event).getLockedObject();
109
					}
110
					
111
					if (monObject != null) {
112
						TRCClass monObjClass =  PerftraceUtil.getClass(monObject);
113
						if (!classMap.containsKey(monObjClass)) {
114
							classDetails = new MonitorClassDetails(monObjClass);
115
							classMap.put(monObjClass, classDetails);
116
						} 
117
						else {
118
							classDetails = (MonitorClassDetails)classMap.get(monObjClass);
119
						}
120
					}
121
					
122
					if (null != classDetails) {
123
						classDetails.updateMonitorsData(event, timeSpan);
124
					}
125
					
126
					event = next;
127
				}
128
			}
129
		}
130
		
131
		return classMap.values().toArray();
132
	}
133
134
	
135
	public void setSelectedClass(Object classDesc) {
136
		_classNameLable.setText(UIMessages._MONITOR_CLASS_NAME + " "
137
				+ ((MonitorClassDetails)classDesc).getClassObj().getName());
138
		_blockTimeViewer.setInput(getBlockObjects(classDesc));
139
		_waitTimeViewer.setInput(getWaitObjects(classDesc));
140
	}
141
142
	private Object[] getWaitObjects(Object classDesc) {
143
		if (classDesc instanceof MonitorClassDetails) {
144
			return ((MonitorClassDetails)classDesc).getWaitCalls();
145
		}
146
		return null;
147
	}
148
149
	private Object[] getBlockObjects(Object classDesc) {
150
		if (classDesc instanceof MonitorClassDetails) {
151
			return ((MonitorClassDetails)classDesc).getBlockCalls();
152
		}
153
		return null;
154
	}
155
	
156
	private void initialize() {
157
		Object allThreads[] = PerftraceUtil.getAllThreads(modelRoot, false);
158
		for (int i = 0; i < allThreads.length; i++) {
159
			_threads.put(allThreads[i], new MonitorThreadDetails((TRCThread)allThreads[i]));
160
		}
161
	}	
162
163
//	private void recalculate() {
164
//		Object allThreads[] = PerftraceUtil.getAllThreads(modelRoot, false);
165
//		for (int i = 0; i < allThreads.length; i++) {
166
//			MonStatThreadDetails threadDetails = null;
167
//			if (!_threads.containsKey(allThreads[i])) {
168
//				threadDetails = new MonStatThreadDetails((TRCThread)allThreads[i]);
169
//				_threads.put(allThreads[i], threadDetails);
170
//			} else {
171
//				threadDetails = (MonStatThreadDetails)_threads.get(allThreads[i]);
172
//			}
173
//			threadDetails.recalculate();
174
//		}
175
//	}	
176
177
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/MonitorStatisticView.java (+116 lines)
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.trace.ui.TraceViewerPage;
17
import org.eclipse.hyades.ui.util.HyadesFormToolkit;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.layout.FillLayout;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.ui.forms.widgets.Form;
24
import org.eclipse.ui.forms.widgets.Section;
25
26
public class MonitorStatisticView  extends BaseProfilerView {
27
	
28
	private final static String TABLE_SECTION_THREAD_TITLE = UIMessages._MONITOR_THREADS_TAB;
29
	private final static String TABLE_SECTION_MON_CLASSES_TITLE = UIMessages._MONITOR_CLASSES_TAB;
30
	private final static String TABLE_SECTION_MON_BLOCKED_TITLE = UIMessages._MONITOR_BLOCKED_TAB;
31
	private final static String TABLE_SECTION_MON_WAITING_TITLE = UIMessages._MONITOR_WAITING_TAB;
32
	
33
	private HyadesFormToolkit _toolkit;
34
	private MonitorThreadStatistics _threadsStatistics;	
35
	private MonitorClassStatistics _monitorsStatistics;	
36
	private MonitorClassBlockedStatistics _classBlockTimeStatistics;
37
	private MonitorClassWaitingStatistics _classWaitTimeStatistics;
38
	private Form _form;
39
	private MonitorStatisticController monViewCtrl;
40
	
41
	public MonitorStatisticView(Composite parent, TraceViewerPage page) {
42
		super(parent, page);
43
	}
44
45
	protected Control createDataViewer(Composite parent) {
46
		_toolkit = new HyadesFormToolkit(parent.getDisplay());
47
		monViewCtrl = new MonitorStatisticController();
48
		monViewCtrl.setMOFObject(_page.getMOFObject());
49
		Composite monitorComposite = _toolkit.createComposite(parent);
50
		monitorComposite.setLayout(new FillLayout(SWT.VERTICAL));
51
		
52
		Composite sourceComposite = _toolkit.createComposite(monitorComposite);
53
		sourceComposite.setLayout(new FillLayout(SWT.VERTICAL));
54
		createThreadsSection(sourceComposite);
55
		createMonitorsSection(sourceComposite);
56
		
57
		_form = _toolkit.createForm(monitorComposite);
58
		_form.setText(UIMessages._MONITOR_CLASS_NAME);
59
		_form.getBody().setLayout(new FillLayout(SWT.VERTICAL));
60
		monViewCtrl.setClassLabel(_form);
61
62
		createClassBlockSection(_form.getBody());
63
		createClassWaitSection(_form.getBody());
64
		return monitorComposite;
65
	}
66
67
	protected String getViewTypeStr() {
68
		return "viewoption.monitors";
69
	}
70
71
	protected void update() {
72
		monViewCtrl.update();
73
	}
74
75
	private void createThreadsSection(Composite parent) {
76
		Section section = _toolkit.createSection(parent, Section.TITLE_BAR);
77
		section.setText(TABLE_SECTION_THREAD_TITLE); 
78
		section.marginWidth = 3;
79
		section.marginHeight = 3;
80
        section.setLayout(new GridLayout());	
81
        _threadsStatistics = new MonitorThreadStatistics (section, monViewCtrl);
82
    	section.setClient(_threadsStatistics.getViewContainer());
83
	}
84
	
85
	private void createMonitorsSection(Composite parent) {
86
		Section section = _toolkit.createSection(parent, Section.TITLE_BAR);
87
		section.setText(TABLE_SECTION_MON_CLASSES_TITLE); 
88
		section.marginWidth = 3;
89
		section.marginHeight = 3;
90
    	section.setLayout(new GridLayout());
91
		_monitorsStatistics = new MonitorClassStatistics (section, monViewCtrl);
92
    	section.setClient(_monitorsStatistics.getViewContainer());
93
	}
94
	
95
	private void createClassBlockSection(Composite parent) {
96
		Section section = _toolkit.createSection(parent, Section.TITLE_BAR);
97
		section.setText(TABLE_SECTION_MON_BLOCKED_TITLE); 
98
		section.marginWidth = 3;
99
		section.marginHeight = 3;
100
        section.setLayout(new GridLayout());
101
		_classBlockTimeStatistics = new MonitorClassBlockedStatistics (section, monViewCtrl);
102
    	section.setClient(_classBlockTimeStatistics.getViewContainer());
103
	}
104
	
105
	private void createClassWaitSection(Composite parent) {
106
		Section section = _toolkit.createSection(parent, Section.TITLE_BAR);
107
		section.setText(TABLE_SECTION_MON_WAITING_TITLE); 
108
		section.marginWidth = 3;
109
		section.marginHeight = 3;
110
        section.setLayout(new GridLayout());
111
		_classWaitTimeStatistics = new MonitorClassWaitingStatistics (section, monViewCtrl);
112
    	section.setClient(_classWaitTimeStatistics.getViewContainer());	
113
	}	
114
	
115
	
116
}
(-).settings/org.eclipse.jdt.core.prefs (+12 lines)
Added Link Here
1
#Mon Feb 18 18:56:17 MSK 2008
2
eclipse.preferences.version=1
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6
org.eclipse.jdt.core.compiler.compliance=1.4
7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
11
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
12
org.eclipse.jdt.core.compiler.source=1.3
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/MonitorClassDetails.java (+91 lines)
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 java.util.HashMap;
17
18
import org.eclipse.hyades.models.trace.TRCClass;
19
import org.eclipse.hyades.models.trace.TRCThreadEvent;
20
import org.eclipse.hyades.models.trace.TRCThreadWaitingForLockEvent;
21
import org.eclipse.hyades.models.trace.TRCThreadWaitingForObjectEvent;
22
23
public class MonitorClassDetails {
24
25
	protected HashMap _monWaitCallSites = new HashMap();
26
	protected HashMap _monBlockCallSites = new HashMap();
27
	
28
	protected TRCClass _monClass;
29
		
30
	protected double _blockTime;
31
	protected int _blockCount;
32
	protected double _waitTime;
33
	protected int _waitCount;
34
	
35
	MonitorClassDetails(TRCClass monClass) {
36
		this._monClass = monClass;
37
	}
38
	
39
	public int getWaitingCount() {
40
		return _waitCount;
41
	}
42
43
	public int getBlockedCount() {
44
		return _blockCount;
45
	}
46
47
	public TRCClass getClassObj() {
48
		return _monClass;
49
	}
50
	
51
	public double getBlockedTime() {
52
		return _blockTime;
53
	}
54
	
55
	public double getWaitingTime () {
56
		return _waitTime;
57
	}
58
59
	public void updateMonitorsData(TRCThreadEvent event, double timeSpan) {
60
		if(event instanceof TRCThreadWaitingForObjectEvent) {
61
			_waitCount++;
62
			_waitTime += timeSpan;		
63
			MonitorCallDetails callSite = new MonitorCallDetails(event);
64
			if (!_monWaitCallSites.containsKey(callSite)) {
65
				_monWaitCallSites.put(callSite, callSite);
66
			} else {
67
				callSite = (MonitorCallDetails)_monWaitCallSites.get(callSite);
68
			}
69
			callSite.updateCallData(event, timeSpan);
70
		} else if(event instanceof TRCThreadWaitingForLockEvent) {
71
			_blockCount++;
72
			_blockTime += timeSpan;		
73
			MonitorCallDetails callSite = new MonitorCallDetails(event);
74
			if (!_monBlockCallSites.containsKey(callSite)) {
75
				_monBlockCallSites.put(callSite, callSite);
76
			} else {
77
				callSite = (MonitorCallDetails)_monBlockCallSites.get(callSite);
78
			}
79
			callSite.updateCallData(event, timeSpan);
80
		}
81
	}
82
	
83
	public Object[] getWaitCalls() {
84
		return _monWaitCallSites.values().toArray();
85
	}
86
87
	public Object[] getBlockCalls() {
88
		return _monBlockCallSites.values().toArray();
89
	}
90
91
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/MonitorCallDetails.java (+229 lines)
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 java.util.ArrayList;
17
import java.util.HashSet;
18
import java.util.Iterator;
19
20
import org.eclipse.emf.common.util.EList;
21
import org.eclipse.hyades.models.hierarchy.TRCAnnotation;
22
import org.eclipse.hyades.models.trace.TRCThreadEvent;
23
import org.eclipse.hyades.models.trace.TRCThreadSleepingEvent;
24
import org.eclipse.hyades.models.trace.TRCThreadWaitingForLockEvent;
25
import org.eclipse.hyades.models.trace.TRCThreadWaitingForObjectEvent;
26
27
public class MonitorCallDetails {
28
	final static String ANNATATION_NAME_LINES = "callStackDumpLineNumbers";
29
	final static String ANNATATION_NAME_METHODS = "callStackDumpMethods";
30
	final static String WAIT_METHOD_STR_CONST = "java.lang.Object.wait"; 
31
32
	protected ArrayList _waitDeltas = new ArrayList();
33
	protected ArrayList _blockDeltas = new ArrayList();
34
	protected HashSet _waitThreadsSet = new HashSet(); 
35
	protected HashSet _waitObjectsSet = new HashSet();
36
	protected HashSet _blockThreadsSet = new HashSet(); 
37
	protected HashSet _blockObjectsSet = new HashSet();
38
	
39
	//private ArrayList _methods = new ArrayList(); 
40
	//private ArrayList _lines = new ArrayList();
41
	
42
	private String _idString = "";
43
	private String _callTitle = "";
44
	private boolean _isObjectWaiting;
45
46
	protected double _sleepingTime;
47
	protected int _sleepingCount;
48
49
	protected double _waitingTime;
50
	protected double _maxWaitingTime = 0;
51
	protected double _minWaitingTime = Double.MAX_VALUE;
52
	protected double _avgWaitingTime;
53
	protected int _waitCount;
54
55
	protected double _blockedTime;
56
	protected double _maxBlockedTime = 0;
57
	protected double _minBlockedTime = Double.MAX_VALUE;
58
	protected double _avgBlockedTime;
59
	protected int _blockedCount;
60
	
61
	public int hashCode() {
62
		final int prime = 31;
63
		int result = 1;
64
		result = prime * result
65
				+ ((_idString == null) ? 0 : _idString.hashCode());
66
		result = prime * result + (_isObjectWaiting ? 1231 : 1237);
67
		return result;
68
	}
69
70
	public boolean equals(Object obj) {
71
		if (this == obj)
72
			return true;
73
		if (obj == null)
74
			return false;
75
		if (getClass() != obj.getClass())
76
			return false;
77
		MonitorCallDetails other = (MonitorCallDetails) obj;
78
		if (_idString == null) {
79
			if (other._idString != null)
80
				return false;
81
		} else if (!_idString.equals(other._idString))
82
			return false;
83
		if (_isObjectWaiting != other._isObjectWaiting)
84
			return false;
85
		return true;
86
	}
87
88
	MonitorCallDetails(TRCThreadEvent event) {
89
		_isObjectWaiting = false;
90
		if (event instanceof TRCThreadWaitingForObjectEvent) {
91
			_isObjectWaiting = true;
92
		}
93
		
94
		TRCAnnotation methodsAnn = null;
95
		TRCAnnotation linesAnn = null;
96
	    for (Iterator it=event.getAnnotations().iterator(); it.hasNext(); ) {
97
	        Object element = it.next();
98
	        if (element instanceof TRCAnnotation) {
99
	        	TRCAnnotation ann = (TRCAnnotation)element;
100
	        	if (ann.getName().equals(ANNATATION_NAME_METHODS)) {
101
	        		methodsAnn = ann;
102
	        	} else if (ann.getName().equals(ANNATATION_NAME_LINES)) {
103
	        		linesAnn = ann;
104
	        	}
105
			}
106
	    }
107
	    
108
	    if (null != methodsAnn) {
109
	    	_idString = "";
110
	    	EList listMeth = methodsAnn.getValues();
111
	    	
112
	    	if (!_isObjectWaiting && listMeth.size() > 0) {
113
				_callTitle = listMeth.get(0).toString();
114
	    	}
115
	    	
116
	    	boolean titleFound = false;
117
			for (int i = 0; i < listMeth.size(); i++) {
118
				if (_isObjectWaiting) {
119
					if (!titleFound && 
120
						_callTitle.startsWith(WAIT_METHOD_STR_CONST) &&
121
						!listMeth.get(i).toString().startsWith(WAIT_METHOD_STR_CONST)) {
122
						_callTitle = listMeth.get(i).toString();
123
						titleFound = true;
124
					} else if (!titleFound){
125
						_callTitle = listMeth.get(i).toString();
126
					}
127
				}
128
				_idString += listMeth.get(i).toString();
129
			}
130
			if (null != linesAnn) {
131
		    	EList listLines = linesAnn.getValues();
132
				for (int i = 0; i < listMeth.size() && i < listLines.size(); i++) {
133
					_idString += listLines.get(i);
134
				}
135
			}
136
		}
137
    }
138
	
139
	public String getCallTitle() {
140
		return _callTitle;
141
	}
142
	
143
	public int getBlockedCount() {
144
		return _blockedCount;
145
	}
146
	
147
	public int getWaitingCount() {
148
		return _waitCount;
149
	}
150
	
151
	public int getSleepingCount() {
152
		return _sleepingCount;
153
	}
154
	
155
	public double getBlockedTime() {
156
		return _blockedTime;
157
	}
158
159
	public double getSleepingTime() {
160
		return _sleepingTime;
161
	}
162
	
163
	public double getWaitingTime() {
164
		return _waitingTime;
165
	}
166
	
167
	public double getMinBlockedTime() {
168
		return _minBlockedTime;
169
	}
170
	
171
	public double getAvgBlockedTime() {
172
		return _avgBlockedTime;
173
	}
174
175
	public double getMaxBlockedTime() {
176
		return _maxBlockedTime;
177
	}
178
179
	public double getMinWaitingTime() {
180
		return _minWaitingTime;
181
	}
182
	
183
	public double getAvgWaitingTime() {
184
		return _avgWaitingTime;
185
	}
186
187
	public double getMaxWaitingTime() {
188
		return _maxWaitingTime;
189
	}
190
191
	public int getWaitingObjectsCount() {
192
		return _waitObjectsSet.size();
193
	}
194
195
	public int getBlockedObjectsCount() {
196
		return _blockObjectsSet.size();
197
	}
198
199
	public int getWaitingThreadsCount() {
200
		return _waitThreadsSet.size();
201
	}
202
203
	public int getBlockedThreadsCount() {
204
		return _blockThreadsSet.size();
205
	}
206
	
207
	public void updateCallData(TRCThreadEvent event, double timeSpan) {
208
		if(event instanceof TRCThreadSleepingEvent) {
209
			_sleepingTime += timeSpan;
210
			_sleepingCount++;
211
		} else if(event instanceof TRCThreadWaitingForObjectEvent) {
212
			_waitingTime += timeSpan;
213
			_waitCount++;
214
			_avgWaitingTime = _waitingTime/_waitCount;
215
			if (timeSpan > _maxWaitingTime) _maxWaitingTime = timeSpan;
216
			if (timeSpan < _minWaitingTime) _minWaitingTime = timeSpan;
217
			_waitThreadsSet.add(event.getThread());
218
			_waitObjectsSet.add(((TRCThreadWaitingForObjectEvent)event).getObjectWaitingFor());
219
		} else if(event instanceof TRCThreadWaitingForLockEvent) {
220
			_blockedTime += timeSpan;
221
			_blockedCount++;
222
			_avgBlockedTime = _blockedTime/_blockedCount;
223
			if (timeSpan > _maxBlockedTime) _maxBlockedTime = timeSpan;
224
			if (timeSpan < _minBlockedTime) _minBlockedTime = timeSpan;
225
			_blockThreadsSet.add(event.getThread());
226
			_blockObjectsSet.add(((TRCThreadWaitingForLockEvent)event).getLockedObject());
227
		}
228
	}
229
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/MonitorClassStatistics.java (+307 lines)
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 MonitorClassStatistics extends LabelProvider implements ITableLabelProvider, SelectionListener{
43
44
	// MONSTAT_CLASSES_COL_CLASS_NAME
45
	private final static int MONSTAT_CLASSES_COL_CLASS_NAME_NUM = 0;
46
	private final static int MONSTAT_CLASSES_COL_CLASS_NAME_DEFW = 260;
47
	// MONSTAT_THREADS_COL_BLOCKED_COUNT
48
	private final static int MONSTAT_CLASSES_COL_BLOCKED_COUNT_NUM = 1;
49
	private final static int MONSTAT_CLASSES_COL_BLOCKED_COUNT_DEFW = 100;
50
	// MONSTAT_CLASSES_COL_BLOCKED_TIME
51
	private final static int MONSTAT_CLASSES_COL_BLOCKED_TIME_NUM = 2;
52
	private final static int MONSTAT_CLASSES_COL_BLOCKED_TIME_DEFW = 100;
53
	// MONSTAT_CLASSES_COL_WAITED_COUNT
54
	private final static int MONSTAT_CLASSES_COL_WAITED_COUNT_NUM = 3;
55
	private final static int MONSTAT_CLASSES_COL_WAITING_COUNT_DEFW = 100;
56
	// MONSTAT_CLASSES_COL_WAITED_TIME
57
	private final static int MONSTAT_CLASSES_COL_WAITED_TIME_NUM = 4;
58
	private final static int MONSTAT_CLASSES_COL_WAITING_TIME_DEFW = 100;
59
	
60
	//overall column number
61
	private final static int MONSTAT_CLASSES_COL_NUM = 5;
62
	
63
	
64
	protected Composite _viewContainer;
65
	protected ViewForm _dataPane;
66
	protected StructuredViewer _viewer;
67
	protected Layout _layout = null;
68
	
69
	protected HyadesFormToolkit _toolkit;
70
	protected ClassStatisticsSorter _sorter;
71
	
72
	MonitorStatisticController monViewCtrl;
73
	
74
	public MonitorClassStatistics(Section section, MonitorStatisticController monViewCtrl) {
75
		this.monViewCtrl = monViewCtrl;
76
		_toolkit = new HyadesFormToolkit(section.getDisplay());		
77
		_dataPane = _toolkit.createViewForm(section);
78
		_viewContainer = _dataPane;
79
		Control table = createTableViewer(_dataPane);
80
		_dataPane.setContent(table);	
81
	}
82
	
83
	public Layout getLayout() {
84
		if (_layout == null)
85
		{
86
			_layout = new ColumnLayout();
87
			((ColumnLayout)_layout).maxNumColumns = 100;
88
		}
89
		return _layout;
90
	}		
91
	
92
	private Control createTableViewer(ViewForm parent) {
93
		Tree tree = _toolkit.createTree(parent, SWT.FULL_SELECTION | SWT.FLAT);
94
		
95
		tree.setLinesVisible(true);
96
		tree.setHeaderVisible(true);
97
		tree.setLayout(getLayout());
98
		tree.setLayoutData(new GridData(GridData.FILL_BOTH));
99
		tree.addSelectionListener(this);
100
		
101
		_viewer = new TreeViewer(tree);
102
		
103
		_viewer.setContentProvider(getContentProvider());
104
		_viewer.setLabelProvider(getTableLabelProvider());
105
106
		_sorter = new ClassStatisticsSorter();
107
108
		_viewer.setSorter(_sorter);
109
				
110
		createColumns(tree);		
111
		_sorter.changeColumnSelection(0);
112
		
113
		monViewCtrl.setClassesTimeViewer(_viewer);
114
		return _viewer.getControl();
115
	}
116
117
	private void createColumns(Tree tree) {
118
119
		int colWidth[] = new int[MONSTAT_CLASSES_COL_NUM];
120
		String colTitle[] = new String[MONSTAT_CLASSES_COL_NUM];
121
		TreeColumn columns[] = new TreeColumn[MONSTAT_CLASSES_COL_NUM];
122
		
123
		colTitle[MONSTAT_CLASSES_COL_CLASS_NAME_NUM] = UIMessages._THREAD_CLASS_NAME;
124
		colWidth[MONSTAT_CLASSES_COL_CLASS_NAME_NUM] = MONSTAT_CLASSES_COL_CLASS_NAME_DEFW;
125
		colTitle[MONSTAT_CLASSES_COL_BLOCKED_COUNT_NUM] = UIMessages._BLOCKED_COUNT;
126
		colWidth[MONSTAT_CLASSES_COL_BLOCKED_COUNT_NUM] = MONSTAT_CLASSES_COL_BLOCKED_COUNT_DEFW;
127
		colTitle[MONSTAT_CLASSES_COL_BLOCKED_TIME_NUM] = UIMessages._THREAD_BLOCKED_TIME;
128
		colWidth[MONSTAT_CLASSES_COL_BLOCKED_TIME_NUM] = MONSTAT_CLASSES_COL_BLOCKED_TIME_DEFW;
129
		colTitle[MONSTAT_CLASSES_COL_WAITED_COUNT_NUM] = UIMessages._WAITING_CONUT;
130
		colWidth[MONSTAT_CLASSES_COL_WAITED_COUNT_NUM] = MONSTAT_CLASSES_COL_WAITING_COUNT_DEFW;
131
		colTitle[MONSTAT_CLASSES_COL_WAITED_TIME_NUM] = UIMessages._THREAD_WAITING_TIME;
132
		colWidth[MONSTAT_CLASSES_COL_WAITED_TIME_NUM] = MONSTAT_CLASSES_COL_WAITING_TIME_DEFW;
133
		
134
		for (int i = 0; i < MONSTAT_CLASSES_COL_NUM; i++) {
135
			columns[i] = new TreeColumn(tree, SWT.NULL | SWT.NO_BACKGROUND | SWT.LEFT);
136
			columns[i].setResizable(true);
137
			columns[i].setText(colTitle[i]);
138
			columns[i].setWidth(colWidth[i]);
139
			columns[i].addSelectionListener(getColumnSelectionListener(i));
140
		}
141
		
142
		_sorter.setColumns(columns);
143
	}
144
145
	SelectionListener getColumnSelectionListener(final int columnIndex) {
146
		return new SelectionListener(){
147
			public void widgetSelected(SelectionEvent e) {
148
				_sorter.changeColumnSelection(columnIndex);
149
				_viewer.refresh();
150
			}
151
			public void widgetDefaultSelected(SelectionEvent e) {
152
			}
153
		};
154
	}
155
	
156
	
157
	
158
	private IBaseLabelProvider getTableLabelProvider() {
159
		return this;
160
	}
161
162
	private IContentProvider getContentProvider() {
163
		return new MonitorClassesStatisticContentProvider();
164
	}
165
166
	public Composite getViewContainer() {
167
		return _viewContainer;
168
	}
169
170
	public void widgetDefaultSelected(SelectionEvent e) {
171
	}
172
 
173
	public void widgetSelected(SelectionEvent e) {
174
		if (!(e.widget instanceof Tree)) {
175
			// TODO add assert
176
			return;
177
		}
178
		
179
		Tree tree = (Tree)e.widget;
180
		TreeItem[] selectedItems = tree.getSelection();
181
		MonitorClassDetails[] classes = new MonitorClassDetails[selectedItems.length];
182
		for (int i = 0; i < selectedItems.length; i++) {
183
			classes[i] = (MonitorClassDetails)selectedItems[i].getData();
184
		}
185
		monViewCtrl.setSelectedClass(classes[0]);
186
	}	
187
	
188
	public Image getColumnImage(Object element, int columnIndex) {
189
		return null;
190
	}
191
192
	public String getColumnText(Object element, int columnIndex) {
193
		if (!(element instanceof MonitorClassDetails)) {
194
			return null;
195
		}
196
		MonitorClassDetails monClassDetails = (MonitorClassDetails)element;		
197
		
198
		switch (columnIndex) {
199
		case MONSTAT_CLASSES_COL_CLASS_NAME_NUM:
200
			return monClassDetails.getClassObj().getName();
201
		case MONSTAT_CLASSES_COL_BLOCKED_COUNT_NUM:
202
			return new Integer(monClassDetails.getBlockedCount()).toString();
203
		case MONSTAT_CLASSES_COL_BLOCKED_TIME_NUM:
204
			return Utils.formatTime(monClassDetails.getBlockedTime());
205
		case MONSTAT_CLASSES_COL_WAITED_COUNT_NUM:
206
			return new Integer(monClassDetails.getWaitingCount()).toString();
207
		case MONSTAT_CLASSES_COL_WAITED_TIME_NUM:
208
			return Utils.formatTime(monClassDetails.getWaitingTime());
209
		default:
210
			break;
211
		}
212
		return null;		
213
		
214
	}	
215
		
216
	class ClassStatisticsSorter extends ViewerSorter {
217
218
		private int sortedIdx = -1;
219
		private boolean ascOrder = true;
220
		//private TreeColumn columns[] = null;
221
		
222
		void changeColumnSelection(int idx) {
223
			if (sortedIdx == idx) {
224
				ascOrder = !ascOrder;
225
			}
226
			else {
227
				ascOrder = true;
228
			} 
229
			sortedIdx = idx;
230
		}
231
		
232
		void setColumns(TreeColumn columns[]) {
233
			//this.columns = columns;
234
		}
235
		
236
		public int compare(Viewer viewer, Object e1, Object e2) {
237
			if (!(e1 instanceof MonitorClassDetails) ||
238
				!(e2 instanceof MonitorClassDetails)) {
239
				return 0;
240
			}
241
			
242
			MonitorClassDetails cd1 = (MonitorClassDetails)e1;
243
			MonitorClassDetails cd2 = (MonitorClassDetails)e2;
244
			int result = 0; 
245
			
246
			switch (sortedIdx) {
247
			case MONSTAT_CLASSES_COL_CLASS_NAME_NUM:
248
				result = cd1.getClassObj().getName()
249
					.compareTo(cd2.getClassObj().getName());
250
				break;
251
			case MONSTAT_CLASSES_COL_BLOCKED_COUNT_NUM:
252
				result = cd1.getBlockedCount() - cd2.getBlockedCount();
253
				break;
254
			case MONSTAT_CLASSES_COL_BLOCKED_TIME_NUM:
255
				result = new Double(cd1.getBlockedTime())
256
					.compareTo(new Double (cd2.getBlockedTime()));
257
				break;
258
			case MONSTAT_CLASSES_COL_WAITED_COUNT_NUM:
259
				result = cd1.getWaitingCount() - cd2.getWaitingCount();
260
				break;
261
			case MONSTAT_CLASSES_COL_WAITED_TIME_NUM:
262
				result = new Double(cd1.getWaitingTime())
263
					.compareTo(new Double (cd2.getWaitingTime()));
264
				break;
265
			default:
266
				break;		
267
			}
268
			
269
			return ascOrder ? result : -result;
270
		}
271
		
272
		public boolean isSorterProperty(Object element, String property) {
273
			 return true;
274
		}
275
		
276
	}	
277
}
278
279
class MonitorClassesStatisticContentProvider implements ITreeContentProvider {
280
	Object[] classes = null;
281
	
282
	public Object[] getChildren(Object parentElement) {
283
		return null;
284
	}
285
286
	public Object getParent(Object element) {
287
		return null;
288
	}
289
290
	public boolean hasChildren(Object element) {
291
		return false;
292
	}
293
294
	public Object[] getElements(Object inputElement) {
295
		return classes;
296
	}
297
298
	public void dispose() {
299
	}
300
301
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
302
		if (newInput instanceof Object[]) {
303
			classes = (Object[])newInput;
304
		}
305
	}
306
	
307
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/MonitorClassBlockedStatistics.java (+296 lines)
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.tptp.trace.jvmti.internal.client.widgets.Utils;
38
import org.eclipse.ui.forms.widgets.ColumnLayout;
39
import org.eclipse.ui.forms.widgets.Section;
40
41
public class MonitorClassBlockedStatistics extends LabelProvider implements ITableLabelProvider, SelectionListener{
42
43
	private final static int MONSTAT_BLOCKTIME_COL_CALLER_NUM = 0;
44
	private final static int MONSTAT_BLOCKTIME_COL_CALLER_DEFW = 250;
45
	private final static int MONSTAT_BLOCKTIME_COL_TOTAL_TIME_NUM = 1;
46
	private final static int MONSTAT_BLOCKTIME_COL_TOTAL_TIME_DEFW = 100;
47
	private final static int MONSTAT_BLOCKTIME_COL_COUNT_NUM = 2;
48
	private final static int MONSTAT_BLOCKTIME_COL_COUNT_DEFW = 100;
49
	private final static int MONSTAT_BLOCKTIME_COL_STAT_NUM = 3;
50
	private final static int MONSTAT_BLOCKTIME_COL_STAT_DEFW = 200;
51
	private final static int MONSTAT_BLOCKTIME_COL_OBJECT_NUM_NUM = 4;
52
	private final static int MONSTAT_BLOCKTIME_COL_OBJECT_NUM_DEFW = 100;
53
	private final static int MONSTAT_BLOCKTIME_COL_THREAD_NUM_NUM = 5;
54
	private final static int MONSTAT_BLOCKTIME_COL_THREAD_NUM_DEFW = 100;
55
	
56
	//overall column number
57
	private final static int MONSTAT_BLOCKTIME_COL_NUM = 6;
58
	
59
	
60
	protected Composite _viewContainer;
61
	protected ViewForm _dataPane;
62
	protected StructuredViewer _viewer;
63
	protected Layout _layout = null;
64
	
65
	protected HyadesFormToolkit _toolkit;
66
	
67
	MonitorStatisticController monViewCtrl;
68
	
69
	MonitorBlockedStatisticsSorter _sorter;
70
	
71
	public MonitorClassBlockedStatistics(Section section, MonitorStatisticController monViewCtrl) {
72
		this.monViewCtrl = monViewCtrl;
73
		_toolkit = new HyadesFormToolkit(section.getDisplay());		
74
		_dataPane = _toolkit.createViewForm(section);
75
		_viewContainer = _dataPane;
76
		Control table = createTableViewer(_dataPane);
77
		_dataPane.setContent(table);	
78
	}
79
	
80
	public Layout getLayout() {
81
		if (_layout == null)
82
		{
83
			_layout = new ColumnLayout();
84
			((ColumnLayout)_layout).maxNumColumns = 100;
85
		}
86
		return _layout;
87
	}		
88
	
89
	private Control createTableViewer(ViewForm parent) {
90
		Tree tree = _toolkit.createTree(parent, SWT.MULTI | SWT.FULL_SELECTION | SWT.FLAT);
91
		
92
		tree.setLinesVisible(true);
93
		tree.setHeaderVisible(true);
94
		tree.setLayout(getLayout());
95
		tree.setLayoutData(new GridData(GridData.FILL_BOTH));
96
		tree.addSelectionListener(this);
97
		
98
		_viewer = new TreeViewer(tree);
99
		
100
		_viewer.setContentProvider(getContentProvider());
101
		_viewer.setLabelProvider(getTableLabelProvider());
102
		
103
		_sorter = new MonitorBlockedStatisticsSorter();
104
		_viewer.setSorter(_sorter);
105
				
106
		createColumns(tree);		
107
		_sorter.changeColumnSelection(0);
108
		
109
		monViewCtrl.setBlockTimeViewer(_viewer);		
110
		return _viewer.getControl();
111
	}
112
113
	private void createColumns(Tree tree) {
114
115
		int colWidth[] = new int[MONSTAT_BLOCKTIME_COL_NUM];
116
		String colTitle[] = new String[MONSTAT_BLOCKTIME_COL_NUM];
117
		TreeColumn columns[] = new TreeColumn[MONSTAT_BLOCKTIME_COL_NUM];
118
		
119
		colTitle[MONSTAT_BLOCKTIME_COL_CALLER_NUM] = UIMessages._MONITOR_CALLER;
120
		colWidth[MONSTAT_BLOCKTIME_COL_CALLER_NUM] = MONSTAT_BLOCKTIME_COL_CALLER_DEFW;
121
		colTitle[MONSTAT_BLOCKTIME_COL_TOTAL_TIME_NUM] = UIMessages._TOTAL_BLOCKED_TIME;
122
		colWidth[MONSTAT_BLOCKTIME_COL_TOTAL_TIME_NUM] = MONSTAT_BLOCKTIME_COL_TOTAL_TIME_DEFW;
123
		colTitle[MONSTAT_BLOCKTIME_COL_COUNT_NUM] = UIMessages._BLOCKED_COUNT;
124
		colWidth[MONSTAT_BLOCKTIME_COL_COUNT_NUM] = MONSTAT_BLOCKTIME_COL_COUNT_DEFW;
125
		colTitle[MONSTAT_BLOCKTIME_COL_STAT_NUM] = UIMessages._MAX_AVG_MIN_TIME;
126
		colWidth[MONSTAT_BLOCKTIME_COL_STAT_NUM] = MONSTAT_BLOCKTIME_COL_STAT_DEFW;
127
		colTitle[MONSTAT_BLOCKTIME_COL_OBJECT_NUM_NUM] = UIMessages._OBJECT_NUMBER;
128
		colWidth[MONSTAT_BLOCKTIME_COL_OBJECT_NUM_NUM] = MONSTAT_BLOCKTIME_COL_OBJECT_NUM_DEFW;
129
		colTitle[MONSTAT_BLOCKTIME_COL_THREAD_NUM_NUM] = UIMessages._THREAD_NUMBER;
130
		colWidth[MONSTAT_BLOCKTIME_COL_THREAD_NUM_NUM] = MONSTAT_BLOCKTIME_COL_THREAD_NUM_DEFW;
131
		
132
		for (int i = 0; i < MONSTAT_BLOCKTIME_COL_NUM; i++) {
133
			columns[i] = new TreeColumn(tree, SWT.NULL | SWT.NO_BACKGROUND | SWT.LEFT);
134
			columns[i].setResizable(true);
135
			columns[i].setText(colTitle[i]);
136
			columns[i].setWidth(colWidth[i]);
137
			columns[i].addSelectionListener(getColumnSelectionListener(i));
138
		}
139
		
140
		_sorter.setColumns(columns);
141
	}
142
143
	SelectionListener getColumnSelectionListener(final int columnIndex) {
144
		return new SelectionListener(){
145
			public void widgetSelected(SelectionEvent e) {
146
				_sorter.changeColumnSelection(columnIndex);
147
				_viewer.refresh();
148
			}
149
			public void widgetDefaultSelected(SelectionEvent e) {
150
			}
151
		};
152
	}
153
	
154
	private IBaseLabelProvider getTableLabelProvider() {
155
		return this;
156
	}
157
158
	private IContentProvider getContentProvider() {
159
		return new MonitorBlockTimeStatisticContentProvider();
160
	}
161
162
	public Composite getViewContainer() {
163
		return _viewContainer;
164
	}
165
166
	public void widgetDefaultSelected(SelectionEvent e) {
167
	}
168
169
	public void widgetSelected(SelectionEvent e) {
170
	}
171
172
	public Image getColumnImage(Object element, int columnIndex) {
173
		return null;
174
	}
175
176
	public String getColumnText(Object element, int columnIndex) {
177
		if (!(element instanceof MonitorCallDetails)) {
178
			return null;
179
		}
180
		MonitorCallDetails monCallDetails = (MonitorCallDetails)element;		
181
		
182
		switch (columnIndex) {
183
		case MONSTAT_BLOCKTIME_COL_CALLER_NUM:
184
			return monCallDetails.getCallTitle();
185
		case MONSTAT_BLOCKTIME_COL_TOTAL_TIME_NUM:
186
			return Utils.formatTime(monCallDetails.getBlockedTime());
187
		case MONSTAT_BLOCKTIME_COL_COUNT_NUM:
188
			return new Integer(monCallDetails.getBlockedCount()).toString();
189
		case MONSTAT_BLOCKTIME_COL_STAT_NUM:
190
			return Utils.formatTime(monCallDetails.getMaxBlockedTime()) + " / " + 
191
				Utils.formatTime(monCallDetails.getAvgBlockedTime()) + " / " +
192
				Utils.formatTime(monCallDetails.getMinBlockedTime());
193
		case MONSTAT_BLOCKTIME_COL_OBJECT_NUM_NUM:
194
			return new Integer(monCallDetails.getBlockedObjectsCount()).toString();
195
		case MONSTAT_BLOCKTIME_COL_THREAD_NUM_NUM:
196
			return new Integer(monCallDetails.getBlockedThreadsCount()).toString();
197
		default:
198
			break;
199
		}
200
		return null;		
201
		
202
	}	
203
	
204
	class MonitorBlockedStatisticsSorter extends ViewerSorter {
205
206
		private int sortedIdx = -1;
207
		private boolean ascOrder = true;
208
		//private TreeColumn columns[] = null;
209
		
210
		void changeColumnSelection(int idx) {
211
			// column isn't sortable 
212
			if (MONSTAT_BLOCKTIME_COL_STAT_NUM == idx)
213
				return;
214
			
215
			if (sortedIdx == idx) {
216
				ascOrder = !ascOrder;
217
			}
218
			else {
219
				ascOrder = true;
220
			} 
221
			sortedIdx = idx;
222
		}
223
		
224
		void setColumns(TreeColumn columns[]) {
225
			//this.columns = columns;
226
		}
227
		
228
		public int compare(Viewer viewer, Object e1, Object e2) {
229
			if (!(e1 instanceof MonitorCallDetails) ||
230
				!(e2 instanceof MonitorCallDetails)) {
231
				return 0;
232
			}
233
			
234
			MonitorCallDetails cd1 = (MonitorCallDetails)e1;
235
			MonitorCallDetails cd2 = (MonitorCallDetails)e2;
236
			int result = 0; 
237
			
238
			switch (sortedIdx) {
239
			case MONSTAT_BLOCKTIME_COL_CALLER_NUM:
240
				result = cd1.getCallTitle().compareTo(cd2.getCallTitle());
241
				break;
242
			case MONSTAT_BLOCKTIME_COL_TOTAL_TIME_NUM:
243
				result = new Double(cd1.getBlockedTime())
244
					.compareTo(new Double (cd2.getBlockedTime()));
245
				break;
246
			case MONSTAT_BLOCKTIME_COL_COUNT_NUM:
247
				result = cd1.getBlockedCount() - cd2.getBlockedCount();
248
				break;
249
			case MONSTAT_BLOCKTIME_COL_OBJECT_NUM_NUM:
250
				result = cd1.getBlockedObjectsCount() - cd2.getBlockedObjectsCount();
251
				break;
252
			case MONSTAT_BLOCKTIME_COL_THREAD_NUM_NUM:
253
				result = cd1.getBlockedThreadsCount() - cd2.getBlockedThreadsCount();
254
				break;
255
			default:
256
				break;		
257
			}
258
			
259
			return ascOrder ? result : -result;
260
		}
261
		
262
		public boolean isSorterProperty(Object element, String property) {
263
			 return true;
264
		}
265
		
266
	}		
267
}
268
269
class MonitorBlockTimeStatisticContentProvider implements ITreeContentProvider {
270
	Object[] calls;
271
272
	public Object[] getChildren(Object parentElement) {
273
		return null;
274
	}
275
276
	public Object getParent(Object element) {
277
		return null;
278
	}
279
280
	public boolean hasChildren(Object element) {
281
		return false;
282
	}
283
284
	public Object[] getElements(Object inputElement) {
285
		return calls;
286
	}
287
288
	public void dispose() {
289
	}
290
291
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
292
		if (newInput instanceof Object[]) {
293
			calls = (Object[])newInput;
294
		}
295
	}
296
}

Return to bug 209727