|
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.call; |
|
19 |
|
20 import java.io.File; |
|
21 import java.util.ArrayList; |
|
22 |
|
23 import org.eclipse.jface.resource.ImageDescriptor; |
|
24 import org.eclipse.swt.SWT; |
|
25 import org.eclipse.swt.widgets.Composite; |
|
26 import org.eclipse.swt.widgets.Event; |
|
27 import org.eclipse.ui.PlatformUI; |
|
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.interfaces.IToolBarActionListener; |
|
33 import com.nokia.carbide.cpp.internal.pi.model.GenericTrace; |
|
34 import com.nokia.carbide.cpp.internal.pi.model.ParsedTraceData; |
|
35 import com.nokia.carbide.cpp.internal.pi.plugin.model.AbstractPiPlugin; |
|
36 import com.nokia.carbide.cpp.internal.pi.plugin.model.IClassReplacer; |
|
37 import com.nokia.carbide.cpp.internal.pi.plugin.model.IEventListener; |
|
38 import com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace; |
|
39 import com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable; |
|
40 import com.nokia.carbide.cpp.internal.pi.test.AnalysisInfoHandler; |
|
41 import com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph; |
|
42 import com.nokia.carbide.cpp.internal.pi.visual.GraphDrawRequest; |
|
43 import com.nokia.carbide.cpp.pi.call.GfcFunctionItem.GfcFunctionItemData; |
|
44 import com.nokia.carbide.cpp.pi.editors.PIPageEditor; |
|
45 import com.nokia.carbide.cpp.pi.util.GeneralMessages; |
|
46 |
|
47 |
|
48 /** |
|
49 * The main plugin class to be used in the desktop. |
|
50 */ |
|
51 public class CallPlugin extends AbstractPiPlugin |
|
52 implements ITrace, IClassReplacer, IVisualizable, IEventListener, IToolBarActionListener |
|
53 { |
|
54 private static final String HELP_CONTEXT_ID = PIPageEditor.PI_ID + ".call"; //$NON-NLS-1$ |
|
55 |
|
56 // the shared instance |
|
57 private static CallPlugin plugin; |
|
58 |
|
59 // page index assigned to the page displaying call info |
|
60 private int pageIndex = PIPageEditor.NEXT_AVAILABLE_PAGE; |
|
61 |
|
62 // call trace |
|
63 private GfcTrace trace; |
|
64 |
|
65 // call page |
|
66 private ProfileVisualiser profileVisualiser; |
|
67 |
|
68 // call table handler |
|
69 private CallVisualiser callVisualiser; |
|
70 |
|
71 private static void setPlugin(CallPlugin newPlugin) |
|
72 { |
|
73 plugin = newPlugin; |
|
74 } |
|
75 |
|
76 /** |
|
77 * The constructor. |
|
78 */ |
|
79 public CallPlugin() { |
|
80 super(); |
|
81 setPlugin(this); |
|
82 } |
|
83 |
|
84 public Class getTraceClass() |
|
85 { |
|
86 return GfcTrace.class; |
|
87 } |
|
88 |
|
89 public Class getReplacedClass(String className) |
|
90 { |
|
91 if ( className.indexOf("com.nokia.carbide.cpp.pi.call.GfcTrace") != -1 //$NON-NLS-1$ |
|
92 || className.indexOf("com.nokia.carbide.pi.call.GfcTrace") != -1 //$NON-NLS-1$ |
|
93 || className.indexOf("fi.vtt.bappea.model.GfcTrace") != -1 //$NON-NLS-1$ |
|
94 || className.indexOf("fi.vtt.bappea.gfcTracePlugin.GfcTrace") != -1) //$NON-NLS-1$ |
|
95 { |
|
96 return GfcTrace.class; |
|
97 } |
|
98 else if ( className.indexOf("com.nokia.carbide.cpp.pi.call.GfcSample") != -1 //$NON-NLS-1$ |
|
99 || className.indexOf("com.nokia.carbide.pi.call.GfcSample") != -1 //$NON-NLS-1$ |
|
100 || className.indexOf("fi.vtt.bappea.model.GfcSample") != -1 //$NON-NLS-1$ |
|
101 || className.indexOf("fi.vtt.bappea.gfcTracePlugin.GfcSample") != -1) //$NON-NLS-1$ |
|
102 { |
|
103 return GfcSample.class; |
|
104 } |
|
105 else if ( className.indexOf("com.nokia.carbide.cpp.pi.call.GfcFunctionItem$GfcFunctionItemData") != -1 //$NON-NLS-1$ |
|
106 || className.indexOf("com.nokia.carbide.pi.call.GfcFunctionItem$GfcFunctionItemData") != -1 //$NON-NLS-1$ |
|
107 || className.indexOf("fi.vtt.bappea.gfcTracePlugin.GfcFunctionItem$GfcFunctionItemData") != -1) //$NON-NLS-1$ |
|
108 { |
|
109 return GfcFunctionItemData.class; |
|
110 } |
|
111 else if ( className.indexOf("com.nokia.carbide.cpp.pi.call.GfcFunctionItem") != -1 //$NON-NLS-1$ |
|
112 || className.indexOf("com.nokia.carbide.pi.call.GfcFunctionItem") != -1 //$NON-NLS-1$ |
|
113 || className.indexOf("fi.vtt.bappea.analyser.GfcFunctionItem") != -1 //$NON-NLS-1$ |
|
114 || className.indexOf("fi.vtt.bappea.gfcTracePlugin.GfcFunctionItem") != -1) //$NON-NLS-1$ |
|
115 { |
|
116 return GfcFunctionItem.class; |
|
117 } |
|
118 else |
|
119 { |
|
120 return null; |
|
121 } |
|
122 } |
|
123 |
|
124 public void initialiseTrace(GenericTrace trace) |
|
125 { |
|
126 if (!(trace instanceof GfcTrace)) |
|
127 return; |
|
128 |
|
129 this.trace = (GfcTrace) trace; |
|
130 |
|
131 this.trace.samples.trimToSize(); |
|
132 this.trace.getCompleteGfcTrace().trimToSize(); |
|
133 |
|
134 NpiInstanceRepository.getInstance().activeUidAddTrace("com.nokia.carbide.cpp.pi.call", trace); //$NON-NLS-1$ |
|
135 |
|
136 /* |
|
137 * Check if the trace is complete (first sample is at time 1, |
|
138 * sample N is at time N) |
|
139 */ |
|
140 this.trace.setComplete(); |
|
141 |
|
142 ArrayList<CallVisualiser> callVisualiserList = new ArrayList<CallVisualiser>(); |
|
143 |
|
144 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.call.CallPlugin.callVisualiserList", callVisualiserList); //$NON-NLS-1$ |
|
145 |
|
146 ArrayList<ProfileVisualiser> profileVisualiserList = new ArrayList<ProfileVisualiser>(); |
|
147 NpiInstanceRepository.getInstance().activeUidSetPersistState("com.nokia.carbide.cpp.pi.call.CallPlugin.profileVisualiserList", profileVisualiserList); //$NON-NLS-1$ |
|
148 |
|
149 } |
|
150 |
|
151 public String getTraceName() { |
|
152 return "Function Call"; //$NON-NLS-1$ |
|
153 } |
|
154 |
|
155 public int getTraceId() { |
|
156 return 2; |
|
157 } |
|
158 |
|
159 public ParsedTraceData parseTraceFile(File file /*, ProgressBar progressBar*/) throws Exception |
|
160 { |
|
161 GfcTraceParser gfcParser; |
|
162 gfcParser = new GfcTraceParser(); |
|
163 |
|
164 return gfcParser.parse(file); |
|
165 } |
|
166 |
|
167 /** |
|
168 * This method is called upon plug-in activation |
|
169 */ |
|
170 public void start(BundleContext context) throws Exception { |
|
171 super.start(context); |
|
172 } |
|
173 |
|
174 /** |
|
175 * This method is called when the plug-in is stopped |
|
176 */ |
|
177 public void stop(BundleContext context) throws Exception { |
|
178 super.stop(context); |
|
179 setPlugin(null); |
|
180 } |
|
181 |
|
182 /** |
|
183 * Returns the shared instance. |
|
184 */ |
|
185 public static CallPlugin getDefault() { |
|
186 return plugin; |
|
187 } |
|
188 |
|
189 /** |
|
190 * Returns an image descriptor for the image file at the given |
|
191 * plug-in relative path. |
|
192 * |
|
193 * @param path the path |
|
194 * @return the image descriptor |
|
195 */ |
|
196 public static ImageDescriptor getImageDescriptor(String path) { |
|
197 return AbstractPiPlugin.imageDescriptorFromPlugin("com.nokia.carbide.cpp.pi.call", path); //$NON-NLS-1$ |
|
198 } |
|
199 |
|
200 boolean pagesCreated = false; |
|
201 |
|
202 // return whether this plugin's editor pages have been created |
|
203 public boolean arePagesCreated() { |
|
204 return this.pagesCreated; |
|
205 } |
|
206 |
|
207 // set whether this plugin's editor pages have been created |
|
208 public void setPagesCreated(boolean pagesCreated) { |
|
209 this.pagesCreated = pagesCreated; |
|
210 } |
|
211 |
|
212 // number of editor pages to create |
|
213 public int getCreatePageCount() { |
|
214 return 1; |
|
215 } |
|
216 |
|
217 // editor page index for each created editor page |
|
218 public int getCreatePageIndex(int index) { |
|
219 return PIPageEditor.NEXT_AVAILABLE_PAGE; |
|
220 } |
|
221 |
|
222 // page index actually assigned to a created page |
|
223 public void setPageIndex(int index, int pageIndex) { |
|
224 if (index == 0) |
|
225 this.pageIndex = pageIndex; |
|
226 } |
|
227 |
|
228 // create the page(s) |
|
229 public ProfileVisualiser createPage(int index) { |
|
230 Composite parent = NpiInstanceRepository.getInstance().activeUidGetParentComposite(); |
|
231 if (parent == null) { |
|
232 // no parent composite is only for temp instance used by non-GUI importer |
|
233 GeneralMessages.showErrorMessage(Messages.getString("CallPlugin.0")); //$NON-NLS-1$ |
|
234 return null; |
|
235 } |
|
236 |
|
237 // there is one page, with no graph |
|
238 this.profileVisualiser = new ProfileVisualiser(ProfileVisualiser.TOP_ONLY, parent, |
|
239 Messages.getString("CallPlugin.functionCalls")); //$NON-NLS-1$ |
|
240 AnalysisInfoHandler infoHandler = NpiInstanceRepository.getInstance().activeUidGetAnalysisInfoHandler(); |
|
241 this.profileVisualiser.getParserRepository().setPIAnalysisInfoHandler(infoHandler); |
|
242 |
|
243 PlatformUI.getWorkbench().getHelpSystem().setHelp(profileVisualiser.getContentPane(), |
|
244 HELP_CONTEXT_ID + ".functionCallsPageContext"); //$NON-NLS-1$ |
|
245 |
|
246 PIPageEditor pageEditor = PIPageEditor.currentPageEditor(); |
|
247 |
|
248 this.callVisualiser = new CallVisualiser(pageEditor, pageIndex, profileVisualiser.getTopComposite().getSashForm(), this.trace); |
|
249 |
|
250 this.profileVisualiser.getTitle().setText(Messages.getString("CallPlugin.functionCallAnalysis")); //$NON-NLS-1$ |
|
251 this.profileVisualiser.getTitle().setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); |
|
252 this.profileVisualiser.getTitle().setFont(PIPageEditor.helvetica_12); |
|
253 |
|
254 this.profileVisualiser.getTitle2().setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); |
|
255 |
|
256 this.profileVisualiser.getTimeString().setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); |
|
257 this.profileVisualiser.getTimeString().setFont(PIPageEditor.helvetica_10); |
|
258 |
|
259 Object objCallList = NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.call.CallPlugin.callVisualiserList"); //$NON-NLS-1$ |
|
260 ArrayList<CallVisualiser> callVisualiserList = (ArrayList<CallVisualiser>) objCallList; |
|
261 |
|
262 Object objProfileList = NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.call.CallPlugin.profileVisualiserList"); //$NON-NLS-1$ |
|
263 ArrayList<ProfileVisualiser> profileVisualiserList = (ArrayList<ProfileVisualiser>) objProfileList; |
|
264 |
|
265 if (callVisualiserList != null) |
|
266 callVisualiserList.add(this.callVisualiser); |
|
267 |
|
268 if (profileVisualiserList != null) |
|
269 profileVisualiserList.add(this.profileVisualiser); |
|
270 |
|
271 return this.profileVisualiser; |
|
272 } |
|
273 |
|
274 // number of graphs supplied by this plugin |
|
275 public int getGraphCount() { |
|
276 return 0; |
|
277 } |
|
278 |
|
279 // page number of each graph supplied by this plugin |
|
280 public int getPageNumber(int graphIndex) { |
|
281 Object objCallList = NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.call.CallPlugin.callVisualiserList"); //$NON-NLS-1$ |
|
282 ArrayList<CallVisualiser> callVisualiserList = (ArrayList<CallVisualiser>) objCallList; |
|
283 |
|
284 if (callVisualiserList == null) |
|
285 return this.pageIndex; |
|
286 |
|
287 for (int i = 0; i < callVisualiserList.size(); i++) { |
|
288 if (callVisualiserList.get(i).getPageEditor() == PIPageEditor.currentPageEditor()) |
|
289 return callVisualiserList.get(i).getPageIndex(); |
|
290 } |
|
291 |
|
292 return this.pageIndex; |
|
293 } |
|
294 |
|
295 public GenericTraceGraph getTraceGraph(int graphIndex) { |
|
296 return null; |
|
297 } |
|
298 |
|
299 public Integer getLastSample(int graphIndex) { |
|
300 return null; |
|
301 } |
|
302 |
|
303 public GraphDrawRequest getDrawRequest(int graphIndex) { |
|
304 return null; |
|
305 } |
|
306 |
|
307 public void receiveEvent(String action, Event event) { |
|
308 Object objCallList = NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.call.CallPlugin.callVisualiserList"); //$NON-NLS-1$ |
|
309 ArrayList<CallVisualiser> callVisualiserList = (ArrayList<CallVisualiser>) objCallList; |
|
310 |
|
311 if (callVisualiserList == null) |
|
312 return; |
|
313 |
|
314 Object objProfileList = NpiInstanceRepository.getInstance().activeUidGetPersistState("com.nokia.carbide.cpp.pi.call.CallPlugin.profileVisualiserList"); //$NON-NLS-1$ |
|
315 ArrayList<ProfileVisualiser> profileVisualiserList = (ArrayList<ProfileVisualiser>) objProfileList; |
|
316 |
|
317 if (profileVisualiserList == null) |
|
318 return; |
|
319 |
|
320 if (action.equals("changeSelection")) { //$NON-NLS-1$ |
|
321 // find the right callVisualiser and ProfileVisualiser |
|
322 for (int i = 0; i < callVisualiserList.size(); i++) { |
|
323 if (callVisualiserList.get(i).getPageEditor() == PIPageEditor.currentPageEditor()) { |
|
324 callVisualiserList.get(i).setStartAndEnd(event.start, event.end); |
|
325 double startTime = PIPageEditor.currentPageEditor().getStartTime(); |
|
326 double endTime = PIPageEditor.currentPageEditor().getEndTime(); |
|
327 profileVisualiserList.get(i).getTimeString().setText(ProfileVisualiser.getTimeInterval(startTime, endTime)); |
|
328 } |
|
329 } |
|
330 } |
|
331 } |
|
332 |
|
333 /* (non-Javadoc) |
|
334 * @see com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable#getGraphTitle(int) |
|
335 */ |
|
336 public String getGraphTitle(int graphIndex) { |
|
337 return null; |
|
338 } |
|
339 |
|
340 public void setActions(boolean entering, int pageIndex) { |
|
341 if (pageIndex != this.pageIndex) |
|
342 return; |
|
343 |
|
344 if (entering) { |
|
345 PIPageEditor.getZoomInAction().setEnabled(false); |
|
346 PIPageEditor.getZoomOutAction().setEnabled(false); |
|
347 PIPageEditor.getZoomToSelectionAction().setEnabled(false); |
|
348 PIPageEditor.getZoomToTraceAction().setEnabled(false); |
|
349 } else { |
|
350 PIPageEditor.getZoomInAction().setEnabled(true); |
|
351 PIPageEditor.getZoomOutAction().setEnabled(true); |
|
352 PIPageEditor.getZoomToSelectionAction().setEnabled(true); |
|
353 PIPageEditor.getZoomToTraceAction().setEnabled(true); |
|
354 } |
|
355 } |
|
356 } |