|
1 /* |
|
2 * Copyright (c) 2009 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 package com.nokia.carbide.cpp.pi.power; |
|
19 |
|
20 import java.io.File; |
|
21 |
|
22 import org.eclipse.jface.action.Action; |
|
23 import org.eclipse.jface.action.MenuManager; |
|
24 import org.eclipse.jface.action.Separator; |
|
25 import org.eclipse.jface.resource.ImageDescriptor; |
|
26 import org.eclipse.swt.widgets.Display; |
|
27 import org.eclipse.swt.widgets.Event; |
|
28 import org.osgi.framework.BundleContext; |
|
29 |
|
30 import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository; |
|
31 import com.nokia.carbide.cpp.internal.pi.analyser.ProfileVisualiser; |
|
32 import com.nokia.carbide.cpp.internal.pi.model.GenericTrace; |
|
33 import com.nokia.carbide.cpp.internal.pi.model.ParsedTraceData; |
|
34 import com.nokia.carbide.cpp.internal.pi.plugin.model.AbstractPiPlugin; |
|
35 import com.nokia.carbide.cpp.internal.pi.plugin.model.IClassReplacer; |
|
36 import com.nokia.carbide.cpp.internal.pi.plugin.model.IEventListener; |
|
37 import com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace; |
|
38 import com.nokia.carbide.cpp.internal.pi.plugin.model.IViewMenu; |
|
39 import com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable; |
|
40 import com.nokia.carbide.cpp.internal.pi.power.actions.PowerSettingsDialog; |
|
41 import com.nokia.carbide.cpp.internal.pi.power.actions.PowerStatisticsDialog; |
|
42 import com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph; |
|
43 import com.nokia.carbide.cpp.internal.pi.visual.GraphDrawRequest; |
|
44 import com.nokia.carbide.cpp.internal.pi.visual.PIEvent; |
|
45 import com.nokia.carbide.cpp.pi.editors.PIPageEditor; |
|
46 |
|
47 |
|
48 public class PowerPlugin extends AbstractPiPlugin |
|
49 implements IViewMenu, ITrace, IClassReplacer, IVisualizable, IEventListener |
|
50 { |
|
51 private static final String HELP_CONTEXT_ID = PIPageEditor.PI_ID + ".power"; //$NON-NLS-1$ |
|
52 |
|
53 // There will be three graphs - one each for editor pages 0, 1, 2 |
|
54 // This code may assume that page 0 has the threads graph, 1 the binaries, and 2 the functions |
|
55 private final static int GRAPH_COUNT = 3; |
|
56 |
|
57 // the shared instance |
|
58 private static PowerPlugin plugin; |
|
59 |
|
60 private static void setPlugin(PowerPlugin newPlugin) |
|
61 { |
|
62 plugin = newPlugin; |
|
63 } |
|
64 |
|
65 /** |
|
66 * The constructor. |
|
67 */ |
|
68 public PowerPlugin() { |
|
69 super(); |
|
70 setPlugin(this); |
|
71 } |
|
72 |
|
73 /** |
|
74 * This method is called upon plug-in activation |
|
75 */ |
|
76 public void start(BundleContext context) throws Exception { |
|
77 super.start(context); |
|
78 } |
|
79 |
|
80 /** |
|
81 * This method is called when the plug-in is stopped |
|
82 */ |
|
83 public void stop(BundleContext context) throws Exception { |
|
84 super.stop(context); |
|
85 setPlugin(null); |
|
86 } |
|
87 |
|
88 /** |
|
89 * Returns the shared instance. |
|
90 */ |
|
91 public static PowerPlugin getDefault() { |
|
92 return plugin; |
|
93 } |
|
94 |
|
95 /** |
|
96 * Returns an image descriptor for the image file at the given |
|
97 * plug-in relative path. |
|
98 * |
|
99 * @param path the path |
|
100 * @return the image descriptor |
|
101 */ |
|
102 public static ImageDescriptor getImageDescriptor(String path) { |
|
103 return AbstractPiPlugin.imageDescriptorFromPlugin("com.nokia.carbide.cpp.pi.power", path); //$NON-NLS-1$ |
|
104 } |
|
105 |
|
106 public Class getTraceClass() |
|
107 { |
|
108 return PwrTrace.class; |
|
109 } |
|
110 |
|
111 public Class getReplacedClass(String className) |
|
112 { |
|
113 if ( (className.indexOf("com.nokia.carbide.cpp.pi.power.PwrTrace") != -1) //$NON-NLS-1$ |
|
114 || (className.indexOf("com.nokia.carbide.pi.power.PwrTrace") != -1) //$NON-NLS-1$ |
|
115 || (className.indexOf("fi.vtt.bappea.pwrTracePlugin.PwrTrace") != -1)) //$NON-NLS-1$ |
|
116 { |
|
117 return PwrTrace.class; |
|
118 } |
|
119 else if ( className.indexOf("com.nokia.carbide.cpp.pi.power.PwrSample") != -1 //$NON-NLS-1$ |
|
120 || className.indexOf("com.nokia.carbide.pi.power.PwrSample") != -1 //$NON-NLS-1$ |
|
121 || className.indexOf("fi.vtt.bappea.pwrTracePlugin.PwrSample") != -1) //$NON-NLS-1$ |
|
122 { |
|
123 return PwrSample.class; |
|
124 } |
|
125 else |
|
126 return null; |
|
127 } |
|
128 |
|
129 public void initialiseTrace(GenericTrace trace) |
|
130 { |
|
131 if (!(trace instanceof PwrTrace)) |
|
132 return; |
|
133 |
|
134 PwrTrace pwrTrace = (PwrTrace)trace; |
|
135 |
|
136 pwrTrace.setComplete(); |
|
137 |
|
138 // because of the way these traces used to be created, the sample vector may be much too large |
|
139 pwrTrace.samples.trimToSize(); |
|
140 |
|
141 NpiInstanceRepository.getInstance().activeUidAddTrace("com.nokia.carbide.cpp.pi.power", trace); //$NON-NLS-1$ |
|
142 } |
|
143 |
|
144 public String getTraceName() { |
|
145 return "Power"; //$NON-NLS-1$ |
|
146 } |
|
147 |
|
148 public int getTraceId() { |
|
149 return 11; |
|
150 } |
|
151 |
|
152 public ParsedTraceData parseTraceFile(File file) throws Exception |
|
153 { |
|
154 try |
|
155 { |
|
156 PwrTraceParser pwrParser = new PwrTraceParser(); |
|
157 return pwrParser.parse(file); |
|
158 } catch (Exception e) |
|
159 { |
|
160 e.printStackTrace(); |
|
161 throw e; |
|
162 } |
|
163 } |
|
164 |
|
165 public MenuManager getViewOptionManager() { |
|
166 if (NpiInstanceRepository.getInstance().activeUidGetTrace("com.nokia.carbide.cpp.pi.power") == null) //$NON-NLS-1$ |
|
167 return null; // no trace, so no MenuManager |
|
168 |
|
169 Action action; |
|
170 |
|
171 MenuManager manager = new MenuManager(Messages.getString("PowerPlugin.powerGraph")); //$NON-NLS-1$ |
|
172 |
|
173 action = new Action(Messages.getString("PowerPlugin.powerSettingsAction"), Action.AS_PUSH_BUTTON) { //$NON-NLS-1$ |
|
174 public void run() { |
|
175 new PowerSettingsDialog(Display.getCurrent()); |
|
176 } |
|
177 }; |
|
178 |
|
179 action.setToolTipText(Messages.getString("PowerPlugin.powerSettingsTooltip")); //$NON-NLS-1$ |
|
180 manager.add(action); |
|
181 |
|
182 action = new Action(Messages.getString("PowerPlugin.powerStatsAction"), Action.AS_PUSH_BUTTON) { //$NON-NLS-1$ |
|
183 public void run() { |
|
184 new PowerStatisticsDialog(Display.getCurrent()); |
|
185 } |
|
186 }; |
|
187 |
|
188 action.setToolTipText(Messages.getString("PowerPlugin.PowerStatsTooltip")); //$NON-NLS-1$ |
|
189 manager.add(action); |
|
190 |
|
191 manager.add(new Separator()); |
|
192 |
|
193 Boolean showLine = Boolean.TRUE; // by default, show the interval average power as a line |
|
194 |
|
195 // if there is are values associated with the current Analyser tab, then use them |
|
196 Object obj; |
|
197 // do we show any average line? |
|
198 obj = NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.power.showLine"); //$NON-NLS-1$ |
|
199 if ((obj != null) && (obj instanceof Boolean)) |
|
200 // retrieve the current value |
|
201 showLine = (Boolean)obj; |
|
202 else |
|
203 // set the initial value |
|
204 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.power.showLine", showLine); //$NON-NLS-1$ |
|
205 |
|
206 action = new Action(Messages.getString("PowerPlugin.showIntervalLineAction"), Action.AS_CHECK_BOX) { //$NON-NLS-1$ |
|
207 public void run() { |
|
208 if (this.isChecked()) |
|
209 receiveSelectionEvent("show_average"); //$NON-NLS-1$ |
|
210 else |
|
211 receiveSelectionEvent("hide_average"); //$NON-NLS-1$ |
|
212 } |
|
213 }; |
|
214 |
|
215 action.setChecked(showLine); |
|
216 action.setToolTipText(Messages.getString("PowerPlugin.showIntervalLineTooltip")); //$NON-NLS-1$ |
|
217 manager.add(action); |
|
218 |
|
219 return manager; |
|
220 } |
|
221 |
|
222 public void receiveEvent(String actionString, Event event) |
|
223 { |
|
224 PwrTrace trace = (PwrTrace) NpiInstanceRepository.getInstance().activeUidGetTrace("com.nokia.carbide.cpp.pi.power"); //$NON-NLS-1$ |
|
225 |
|
226 if (trace == null) |
|
227 return; |
|
228 |
|
229 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
230 if ( actionString.equals("show_average") //$NON-NLS-1$ |
|
231 || actionString.equals("hide_average")) //$NON-NLS-1$ |
|
232 { |
|
233 ((PowerTraceGraph)trace.getTraceGraph(PIPageEditor.THREADS_PAGE, uid)).action(actionString); |
|
234 ((PowerTraceGraph)trace.getTraceGraph(PIPageEditor.BINARIES_PAGE, uid)).action(actionString); |
|
235 ((PowerTraceGraph)trace.getTraceGraph(PIPageEditor.FUNCTIONS_PAGE, uid)).action(actionString); |
|
236 } else if (actionString.equals("scroll")) //$NON-NLS-1$ |
|
237 { |
|
238 if ( !(event.data instanceof String) |
|
239 || !((String)event.data).equals("FigureCanvas")) //$NON-NLS-1$ |
|
240 return; |
|
241 |
|
242 PIEvent be = new PIEvent(event, PIEvent.SCROLLED); |
|
243 |
|
244 ((PowerTraceGraph)trace.getTraceGraph(PIPageEditor.THREADS_PAGE, uid)).piEventReceived(be); |
|
245 ((PowerTraceGraph)trace.getTraceGraph(PIPageEditor.BINARIES_PAGE, uid)).piEventReceived(be); |
|
246 ((PowerTraceGraph)trace.getTraceGraph(PIPageEditor.FUNCTIONS_PAGE, uid)).piEventReceived(be); |
|
247 } |
|
248 } |
|
249 |
|
250 public void receiveSelectionEvent(String eventString) |
|
251 { |
|
252 if (eventString == null) |
|
253 return; |
|
254 |
|
255 PwrTrace trace = (PwrTrace) NpiInstanceRepository.getInstance().activeUidGetTrace("com.nokia.carbide.cpp.pi.power"); //$NON-NLS-1$ |
|
256 |
|
257 if (eventString.equals("show_average")) { //$NON-NLS-1$ |
|
258 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.power.showLine", Boolean.TRUE); //$NON-NLS-1$ |
|
259 } else if (eventString.equals("hide_average")){ //$NON-NLS-1$ |
|
260 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.power.showLine", Boolean.FALSE); //$NON-NLS-1$ |
|
261 } else { |
|
262 return; |
|
263 } |
|
264 |
|
265 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
266 trace.getPowerGraph(PIPageEditor.THREADS_PAGE, uid).action(eventString); |
|
267 trace.getPowerGraph(PIPageEditor.BINARIES_PAGE, uid).action(eventString); |
|
268 trace.getPowerGraph(PIPageEditor.FUNCTIONS_PAGE, uid).action(eventString); |
|
269 } |
|
270 |
|
271 public GenericTraceGraph getTraceGraph(int graphIndex) |
|
272 { |
|
273 PwrTrace trace = (PwrTrace) NpiInstanceRepository.getInstance().activeUidGetTrace("com.nokia.carbide.cpp.pi.power"); //$NON-NLS-1$ |
|
274 |
|
275 int uid = NpiInstanceRepository.getInstance().activeUid(); |
|
276 |
|
277 if (trace != null) |
|
278 return trace.getTraceGraph(graphIndex, uid); |
|
279 else |
|
280 return null; |
|
281 } |
|
282 |
|
283 /* |
|
284 public GenericTraceGraph getTraceGraph(int graphIndex, int uid) { |
|
285 PwrTrace trace = (PwrTrace) NpiInstanceRepository.getInstance().activeUidGetTrace("com.nokia.carbide.cpp.pi.power"); //$NON-NLS-1$ |
|
286 |
|
287 if (trace != null) |
|
288 return trace.getTraceGraph(graphIndex, uid); |
|
289 else |
|
290 return null; |
|
291 } |
|
292 */ |
|
293 |
|
294 public Integer getLastSample(int graphIndex) { |
|
295 PwrTrace trace = (PwrTrace) NpiInstanceRepository.getInstance().activeUidGetTrace("com.nokia.carbide.cpp.pi.power"); //$NON-NLS-1$ |
|
296 |
|
297 if (trace != null) |
|
298 return new Integer(trace.getLastSampleNumber()); |
|
299 else |
|
300 return null; |
|
301 } |
|
302 |
|
303 public GraphDrawRequest getDrawRequest(int graphIndex) { |
|
304 return null; |
|
305 } |
|
306 |
|
307 public int getGraphCount() { |
|
308 return GRAPH_COUNT; |
|
309 } |
|
310 |
|
311 public int getPageNumber(int graphIndex) { |
|
312 // Assumes page 0 has the threads graph, 1 has the binaries, and 2 has the functions |
|
313 if (graphIndex == 0) |
|
314 return PIPageEditor.THREADS_PAGE; |
|
315 else if (graphIndex == 1) |
|
316 return PIPageEditor.BINARIES_PAGE; |
|
317 else if (graphIndex == 2) |
|
318 return PIPageEditor.FUNCTIONS_PAGE; |
|
319 |
|
320 return PIPageEditor.NEXT_AVAILABLE_PAGE; |
|
321 } |
|
322 |
|
323 // return whether this plugin's editor pages have been created |
|
324 public boolean arePagesCreated() { |
|
325 return false; |
|
326 } |
|
327 |
|
328 // set whether this plugin's editor pages have been created |
|
329 public void setPagesCreated(boolean pagesCreated) { |
|
330 return; |
|
331 } |
|
332 |
|
333 // number of editor pages to create |
|
334 public int getCreatePageCount() { |
|
335 return 0; |
|
336 } |
|
337 |
|
338 public int getCreatePageIndex(int index) { |
|
339 return 0; |
|
340 } |
|
341 |
|
342 public ProfileVisualiser createPage(int index) { |
|
343 return null; |
|
344 } |
|
345 |
|
346 public void setPageIndex(int index, int pageIndex) { |
|
347 return; |
|
348 } |
|
349 |
|
350 /* (non-Javadoc) |
|
351 * @see com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#getGraphTitle(int) |
|
352 */ |
|
353 public String getGraphTitle(int graphIndex) { |
|
354 return Messages.getString("PowerPlugin.pluginTitle"); //$NON-NLS-1$ |
|
355 } |
|
356 } |