|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 * |
|
20 */ |
|
21 package com.nokia.carbide.cpp.pi.graphicsmemory; |
|
22 |
|
23 import java.text.DecimalFormat; |
|
24 |
|
25 import org.eclipse.swt.SWT; |
|
26 import org.eclipse.swt.events.SelectionEvent; |
|
27 import org.eclipse.swt.events.SelectionListener; |
|
28 import org.eclipse.swt.layout.GridData; |
|
29 import org.eclipse.swt.layout.GridLayout; |
|
30 import org.eclipse.swt.widgets.Button; |
|
31 import org.eclipse.swt.widgets.Composite; |
|
32 import org.eclipse.swt.widgets.Display; |
|
33 import org.eclipse.swt.widgets.Group; |
|
34 import org.eclipse.swt.widgets.Label; |
|
35 import org.eclipse.swt.widgets.Shell; |
|
36 |
|
37 import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository; |
|
38 import com.nokia.carbide.cpp.internal.pi.analyser.ProfileVisualiser; |
|
39 import com.nokia.carbide.cpp.pi.editors.PIPageEditor; |
|
40 |
|
41 public class GraphicsMemoryStatisticsDialog { |
|
42 |
|
43 private Shell shell; |
|
44 private GridData gridData; |
|
45 private DecimalFormat formatKBytes = new DecimalFormat(Messages |
|
46 .getString("GraphicsMemoryStatisticsDialog.KBformat")); //$NON-NLS-1$ |
|
47 private DecimalFormat formatBytes = new DecimalFormat(Messages |
|
48 .getString("GraphicsMemoryStatisticsDialog.BytesFormat")); //$NON-NLS-1$ |
|
49 private GraphicsMemoryTrace trace; |
|
50 private double startTime; |
|
51 private double endTime; |
|
52 |
|
53 public GraphicsMemoryStatisticsDialog(Display display) { |
|
54 Group group; |
|
55 |
|
56 shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM | SWT.RESIZE); |
|
57 shell.setText(Messages |
|
58 .getString("GraphicsMemoryStatisticsDialog.statistics")); //$NON-NLS-1$ |
|
59 shell.setLayout(new GridLayout(3, false)); |
|
60 |
|
61 startTime = PIPageEditor.currentPageEditor().getStartTime(); |
|
62 endTime = PIPageEditor.currentPageEditor().getEndTime(); |
|
63 |
|
64 trace = (GraphicsMemoryTrace) NpiInstanceRepository.getInstance() |
|
65 .activeUidGetTrace(GraphicsMemoryPlugin.PLUGIN_ID); //$NON-NLS-1$ |
|
66 |
|
67 group = new Group(shell, SWT.SHADOW_NONE); |
|
68 group.setText(Messages |
|
69 .getString("GraphicsMemoryStatisticsDialog.interval")); //$NON-NLS-1$ |
|
70 group.setFont(PIPageEditor.helvetica_9); |
|
71 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
72 gridData.horizontalSpan = 3; |
|
73 group.setLayoutData(gridData); |
|
74 group.setLayout(new GridLayout(3, false));// new FillLayout()); |
|
75 textGrid(group, showTimeInterval(startTime, endTime), SWT.CENTER, |
|
76 SWT.CENTER, 3); |
|
77 |
|
78 int pageIndex = PIPageEditor.currentPageIndex(); |
|
79 |
|
80 GraphicsMemoryTraceGraph graph = (GraphicsMemoryTraceGraph) trace |
|
81 .getTraceGraph(pageIndex); // since graph intervals are in |
|
82 // lockstep, any pageIndex will do |
|
83 GraphicsMemoryProcessTable table = graph.getGraphicsMemoryProcessTable(); |
|
84 |
|
85 MaxGraphicsMemoryItem systemUseByInterval = trace |
|
86 .getSystemUseByInterval((long) (startTime * 1000.0), |
|
87 (long) (endTime * 1000.0)); |
|
88 |
|
89 group = new Group(shell, SWT.NONE); |
|
90 group.setText(Messages |
|
91 .getString("GraphicsMemoryStatisticsDialog.onDevice")); //$NON-NLS-1$ |
|
92 group.setFont(PIPageEditor.helvetica_9); |
|
93 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
94 gridData.horizontalSpan = 3; |
|
95 group.setLayoutData(gridData); |
|
96 group.setLayout(new GridLayout(3, false));// new FillLayout()); |
|
97 |
|
98 String usedKB = Messages |
|
99 .getString("GraphicsMemoryStatisticsDialog.notRecorded"); //$NON-NLS-1$ |
|
100 String usedBytes = ""; //$NON-NLS-1$ |
|
101 String freeKB = usedKB; |
|
102 String freeBytes = usedBytes; |
|
103 String totalKB = usedKB; |
|
104 String totalBytes = usedBytes; |
|
105 |
|
106 if ((long) (endTime * 1000.0 + 0.5) >= trace.getFirstSampleNumber()) { |
|
107 long deviceTotalMemory = systemUseByInterval.maxTotal; |
|
108 long deviceUsedMemory = systemUseByInterval.maxPrivate; |
|
109 |
|
110 usedKB = formatKBytes.format(deviceUsedMemory / 1024.0); |
|
111 usedBytes = formatBytes.format(deviceUsedMemory); |
|
112 freeKB = formatKBytes |
|
113 .format((deviceTotalMemory - deviceUsedMemory) / 1024.0); |
|
114 freeBytes = formatBytes |
|
115 .format(deviceTotalMemory - deviceUsedMemory); |
|
116 totalKB = formatKBytes.format(deviceTotalMemory / 1024.0); |
|
117 totalBytes = formatBytes.format(deviceTotalMemory); |
|
118 } |
|
119 textGrid( |
|
120 group, |
|
121 Messages.getString("GraphicsMemoryStatisticsDialog.used"), SWT.LEFT, SWT.CENTER, 1); //$NON-NLS-1$ |
|
122 textGrid(group, usedKB, SWT.RIGHT, SWT.CENTER, 1); |
|
123 textGrid(group, usedBytes, SWT.RIGHT, SWT.CENTER, 1); |
|
124 textGrid( |
|
125 group, |
|
126 Messages.getString("GraphicsMemoryStatisticsDialog.free"), SWT.LEFT, SWT.CENTER, 1); //$NON-NLS-1$ |
|
127 textGrid(group, freeKB, SWT.RIGHT, SWT.CENTER, 1); |
|
128 textGrid(group, freeBytes, SWT.RIGHT, SWT.CENTER, 1); |
|
129 textGrid( |
|
130 group, |
|
131 Messages.getString("GraphicsMemoryStatisticsDialog.total"), SWT.LEFT, SWT.CENTER, 1); //$NON-NLS-1$ |
|
132 textGrid(group, totalKB, SWT.RIGHT, SWT.CENTER, 1); |
|
133 textGrid(group, totalBytes, SWT.RIGHT, SWT.CENTER, 1); |
|
134 |
|
135 group = new Group(shell, SWT.NONE); |
|
136 group.setText(Messages |
|
137 .getString("GraphicsMemoryStatisticsDialog.currentSelection")); //$NON-NLS-1$ |
|
138 group.setFont(PIPageEditor.helvetica_9); |
|
139 gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
|
140 gridData.horizontalSpan = 3; |
|
141 group.setLayoutData(gridData); |
|
142 group.setLayout(new GridLayout(3, false));// new FillLayout()); |
|
143 |
|
144 String privateKB = Messages |
|
145 .getString("GraphicsMemoryStatisticsDialog.notRecorded"); //$NON-NLS-1$ |
|
146 String privateBytes = ""; //$NON-NLS-1$ |
|
147 String sharedKB = privateKB; |
|
148 String sharedBytes = privateBytes; |
|
149 |
|
150 if ((long) (endTime * 1000.0 + 0.5) >= trace.getFirstSampleNumber()) { |
|
151 float selectedMaxPrivate = 0; |
|
152 float selectedMaxShared = 0; |
|
153 |
|
154 Object[] selected = table.getTableViewer().getCheckedElements(); |
|
155 |
|
156 for (int i = 0; i < selected.length; i++) { |
|
157 if (selected[i] instanceof GraphicsMemoryProcess) { |
|
158 GraphicsMemoryProcess checked = (GraphicsMemoryProcess) selected[i]; |
|
159 selectedMaxPrivate += checked.maxMemoryItem.maxPrivate; |
|
160 selectedMaxShared += checked.maxMemoryItem.maxShared; |
|
161 } |
|
162 } |
|
163 |
|
164 privateKB = formatKBytes.format(selectedMaxPrivate / 1024.0); |
|
165 privateBytes = formatBytes.format((long) selectedMaxPrivate); |
|
166 sharedKB = formatKBytes.format(selectedMaxShared / 1024.0); |
|
167 sharedBytes = formatBytes.format((long) selectedMaxShared); |
|
168 } |
|
169 |
|
170 textGrid( |
|
171 group, |
|
172 Messages.getString("GraphicsMemoryStatisticsDialog.private"), SWT.LEFT, SWT.CENTER, 1); //$NON-NLS-1$ |
|
173 textGrid(group, privateKB, SWT.RIGHT, SWT.CENTER, 1); |
|
174 textGrid(group, privateBytes, SWT.RIGHT, SWT.CENTER, 1); |
|
175 textGrid( |
|
176 group, |
|
177 Messages.getString("GraphicsMemoryStatisticsDialog.shared"), SWT.LEFT, SWT.CENTER, 1); //$NON-NLS-1$ |
|
178 textGrid(group, sharedKB, SWT.RIGHT, SWT.CENTER, 1); |
|
179 textGrid(group, sharedBytes, SWT.RIGHT, SWT.CENTER, 1); |
|
180 |
|
181 // create the Close button |
|
182 Button close = new Button(shell, SWT.NONE); |
|
183 close.setText(Messages |
|
184 .getString("GraphicsMemoryStatisticsDialog.close")); //$NON-NLS-1$ |
|
185 gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true); |
|
186 gridData.minimumWidth = 60; |
|
187 gridData.horizontalSpan = 3; |
|
188 close.setLayoutData(gridData); |
|
189 close.addSelectionListener(new SelectionListener() { |
|
190 |
|
191 public void widgetSelected(SelectionEvent e) { |
|
192 shell.close(); |
|
193 } |
|
194 |
|
195 public void widgetDefaultSelected(SelectionEvent e) { |
|
196 widgetSelected(e); |
|
197 } |
|
198 }); |
|
199 |
|
200 shell.pack(); |
|
201 shell.open(); |
|
202 |
|
203 while (!shell.isDisposed()) { |
|
204 if (!shell.getDisplay().readAndDispatch()) { |
|
205 shell.getDisplay().sleep(); |
|
206 } |
|
207 } |
|
208 } |
|
209 |
|
210 private void textGrid(Composite parent, String text, int labelStyle, |
|
211 int gridStyle, int gridSpan) { |
|
212 Label label = new Label(parent, labelStyle); |
|
213 label.setFont(PIPageEditor.helvetica_9); |
|
214 label.setText(text); |
|
215 gridData = new GridData(SWT.FILL, gridStyle, true, true); |
|
216 gridData.horizontalSpan = gridSpan; |
|
217 label.setLayoutData(gridData); |
|
218 } |
|
219 |
|
220 public void dispose() { |
|
221 if (this.shell != null) { |
|
222 if (!this.shell.isDisposed()) { |
|
223 this.shell.close(); |
|
224 } |
|
225 this.shell.dispose(); |
|
226 } |
|
227 |
|
228 this.shell = null; |
|
229 } |
|
230 |
|
231 private static String showTimeInterval(double startTime, double endTime) { |
|
232 return ProfileVisualiser.TIME_FORMAT.format(startTime) |
|
233 + Messages |
|
234 .getString("GraphicsMemoryStatisticsDialog.interval1") + ProfileVisualiser.TIME_FORMAT.format(endTime) //$NON-NLS-1$ |
|
235 + Messages |
|
236 .getString("GraphicsMemoryStatisticsDialog.interval2") + ProfileVisualiser.TIME_FORMAT.format(endTime - startTime) //$NON-NLS-1$ |
|
237 + Messages |
|
238 .getString("GraphicsMemoryStatisticsDialog.interval3"); //$NON-NLS-1$ |
|
239 } |
|
240 } |