|
1 /* |
|
2 * Copyright (c) 2008-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 "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: Definitions for the class MainView |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.s60tools.analyzetool.ui; |
|
19 |
|
20 import java.io.FileInputStream; |
|
21 import java.util.AbstractList; |
|
22 import java.util.ArrayList; |
|
23 import java.util.HashMap; |
|
24 import java.util.Hashtable; |
|
25 import java.util.Iterator; |
|
26 import java.util.Locale; |
|
27 |
|
28 import org.eclipse.core.resources.IFile; |
|
29 import org.eclipse.core.resources.IMarker; |
|
30 import org.eclipse.core.resources.IProject; |
|
31 import org.eclipse.core.resources.IResource; |
|
32 import org.eclipse.core.resources.IWorkspaceRoot; |
|
33 import org.eclipse.core.resources.ResourcesPlugin; |
|
34 import org.eclipse.core.runtime.CoreException; |
|
35 import org.eclipse.core.runtime.IAdaptable; |
|
36 import org.eclipse.core.runtime.IProgressMonitor; |
|
37 import org.eclipse.core.runtime.IStatus; |
|
38 import org.eclipse.core.runtime.Path; |
|
39 import org.eclipse.core.runtime.Status; |
|
40 import org.eclipse.core.runtime.jobs.Job; |
|
41 import org.eclipse.jface.action.Action; |
|
42 import org.eclipse.jface.action.IMenuListener; |
|
43 import org.eclipse.jface.action.IMenuManager; |
|
44 import org.eclipse.jface.action.IToolBarManager; |
|
45 import org.eclipse.jface.action.MenuManager; |
|
46 import org.eclipse.jface.action.Separator; |
|
47 import org.eclipse.jface.preference.IPreferenceStore; |
|
48 import org.eclipse.jface.preference.PreferenceDialog; |
|
49 import org.eclipse.jface.viewers.DoubleClickEvent; |
|
50 import org.eclipse.jface.viewers.IDoubleClickListener; |
|
51 import org.eclipse.jface.viewers.ISelection; |
|
52 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
53 import org.eclipse.jface.viewers.IStructuredSelection; |
|
54 import org.eclipse.jface.viewers.ITreeContentProvider; |
|
55 import org.eclipse.jface.viewers.ITreeViewerListener; |
|
56 import org.eclipse.jface.viewers.LabelProvider; |
|
57 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
58 import org.eclipse.jface.viewers.StructuredSelection; |
|
59 import org.eclipse.jface.viewers.TreeExpansionEvent; |
|
60 import org.eclipse.jface.viewers.TreeViewer; |
|
61 import org.eclipse.jface.viewers.Viewer; |
|
62 import org.eclipse.jface.viewers.ViewerSorter; |
|
63 import org.eclipse.swt.SWT; |
|
64 import org.eclipse.swt.custom.CTabFolder; |
|
65 import org.eclipse.swt.custom.CTabItem; |
|
66 import org.eclipse.swt.custom.SashForm; |
|
67 import org.eclipse.swt.dnd.Clipboard; |
|
68 import org.eclipse.swt.dnd.TextTransfer; |
|
69 import org.eclipse.swt.dnd.Transfer; |
|
70 import org.eclipse.swt.events.KeyEvent; |
|
71 import org.eclipse.swt.events.KeyListener; |
|
72 import org.eclipse.swt.graphics.Image; |
|
73 import org.eclipse.swt.layout.GridData; |
|
74 import org.eclipse.swt.widgets.Composite; |
|
75 import org.eclipse.swt.widgets.Label; |
|
76 import org.eclipse.swt.widgets.Menu; |
|
77 import org.eclipse.swt.widgets.Shell; |
|
78 import org.eclipse.ui.IActionBars; |
|
79 import org.eclipse.ui.ISelectionListener; |
|
80 import org.eclipse.ui.ISharedImages; |
|
81 import org.eclipse.ui.IWorkbenchActionConstants; |
|
82 import org.eclipse.ui.IWorkbenchPage; |
|
83 import org.eclipse.ui.IWorkbenchPart; |
|
84 import org.eclipse.ui.PlatformUI; |
|
85 import org.eclipse.ui.dialogs.PreferencesUtil; |
|
86 import org.eclipse.ui.ide.IDE; |
|
87 import org.eclipse.ui.part.ViewPart; |
|
88 |
|
89 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; |
|
90 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration; |
|
91 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo; |
|
92 import com.nokia.s60tools.analyzetool.Activator; |
|
93 import com.nokia.s60tools.analyzetool.AnalyzeToolHelpContextIDs; |
|
94 import com.nokia.s60tools.analyzetool.builder.BuilderUtil; |
|
95 import com.nokia.s60tools.analyzetool.engine.AnalysisItem; |
|
96 import com.nokia.s60tools.analyzetool.engine.AnalyzeFactory; |
|
97 import com.nokia.s60tools.analyzetool.engine.CallstackItem; |
|
98 import com.nokia.s60tools.analyzetool.engine.EpocReader; |
|
99 import com.nokia.s60tools.analyzetool.engine.IMemoryActivityModel; |
|
100 import com.nokia.s60tools.analyzetool.engine.MMPInfo; |
|
101 import com.nokia.s60tools.analyzetool.engine.ParseAnalyzeData; |
|
102 import com.nokia.s60tools.analyzetool.engine.ParseXMLFileSAX; |
|
103 import com.nokia.s60tools.analyzetool.engine.ProjectResults; |
|
104 import com.nokia.s60tools.analyzetool.engine.RunResults; |
|
105 import com.nokia.s60tools.analyzetool.engine.UseAtool; |
|
106 import com.nokia.s60tools.analyzetool.engine.statistic.ProcessInfo; |
|
107 import com.nokia.s60tools.analyzetool.engine.statistic.ReadFile; |
|
108 import com.nokia.s60tools.analyzetool.global.Constants; |
|
109 import com.nokia.s60tools.analyzetool.global.Util; |
|
110 import com.nokia.s60tools.analyzetool.internal.ui.graph.ChartContainer; |
|
111 import com.nokia.s60tools.analyzetool.ui.actions.DropDownMenu; |
|
112 import com.nokia.s60tools.analyzetool.ui.actions.FileActionHistory; |
|
113 import com.nokia.s60tools.analyzetool.ui.statistic.StatisticView; |
|
114 |
|
115 /** |
|
116 * Class to display memory analysis results also provides all the |
|
117 * functionalities what AnalyzeTool has. |
|
118 * |
|
119 * @author kihe |
|
120 * |
|
121 */ |
|
122 public class MainView extends ViewPart implements ISelectionListener, |
|
123 ITreeViewerListener, IActionListener, ISelectionChangedListener, KeyListener { |
|
124 |
|
125 /** |
|
126 * Sorts tree view objects. |
|
127 * |
|
128 * @author kihe |
|
129 */ |
|
130 public static class NameSorter extends ViewerSorter { |
|
131 |
|
132 /** |
|
133 * Compares view items. |
|
134 * |
|
135 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, |
|
136 * java.lang.Object, java.lang.Object) |
|
137 * |
|
138 * @param viewer |
|
139 * Viewer |
|
140 * @param e1 |
|
141 * Object |
|
142 * @param e2 |
|
143 * Object |
|
144 * @return int Always return 0 |
|
145 */ |
|
146 @Override |
|
147 public int compare(final Viewer viewer, final Object e1, final Object e2) { |
|
148 return 0; |
|
149 } |
|
150 } |
|
151 |
|
152 /** |
|
153 * The content provider class is responsible for providing objects to the |
|
154 * view. It can wrap existing objects in adapters or simply return objects |
|
155 * as-is. These objects may be sensitive to the current input of the view, |
|
156 * or ignore it and always show the same content (like Task List, for |
|
157 * example). |
|
158 */ |
|
159 class ViewContentProvider implements ITreeContentProvider { |
|
160 |
|
161 /** |
|
162 * |
|
163 * @see org.eclipse.jface.viewers.IContentProvider#dispose() |
|
164 */ |
|
165 public void dispose() { |
|
166 // MethodDeclaration/Block[count(BlockStatement) = 0 and |
|
167 // @containsComment = 'false'] |
|
168 } |
|
169 |
|
170 /** |
|
171 * |
|
172 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) |
|
173 */ |
|
174 public Object[] getChildren(Object parent) { |
|
175 if (parent instanceof TreeParent) { |
|
176 return ((TreeParent) parent).getChildren(); |
|
177 } |
|
178 return new Object[0]; |
|
179 } |
|
180 |
|
181 /* |
|
182 * (non-Javadoc) |
|
183 * |
|
184 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|
185 */ |
|
186 public Object[] getElements(Object parent) { |
|
187 if (parent.equals(getViewSite())) { |
|
188 if (invisibleRoot == null) { |
|
189 getStartupContent(); |
|
190 } |
|
191 return getChildren(invisibleRoot); |
|
192 } |
|
193 return getChildren(parent); |
|
194 } |
|
195 |
|
196 /* |
|
197 * (non-Javadoc) |
|
198 * |
|
199 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) |
|
200 */ |
|
201 public Object getParent(Object child) { |
|
202 if (child instanceof TreeObject) { |
|
203 return ((TreeObject) child).getParent(); |
|
204 } |
|
205 return null; |
|
206 } |
|
207 |
|
208 /* |
|
209 * (non-Javadoc) |
|
210 * |
|
211 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) |
|
212 */ |
|
213 public boolean hasChildren(Object parent) { |
|
214 if (parent instanceof TreeParent) { |
|
215 return ((TreeParent) parent).hasChildren(); |
|
216 } |
|
217 return false; |
|
218 } |
|
219 |
|
220 /* |
|
221 * (non-Javadoc) |
|
222 * |
|
223 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, |
|
224 * java.lang.Object, java.lang.Object) |
|
225 */ |
|
226 public void inputChanged(Viewer v, Object oldInput, Object newInput) { |
|
227 // MethodDeclaration/Block[count(BlockStatement) = 0 and |
|
228 // @containsComment = 'false'] |
|
229 } |
|
230 |
|
231 } |
|
232 |
|
233 /** |
|
234 * Provides elements of tree view. |
|
235 * |
|
236 * @author kihe |
|
237 * |
|
238 */ |
|
239 public class ViewLabelProvider extends LabelProvider { |
|
240 |
|
241 /** |
|
242 * Used when tree model item is TreeParent. |
|
243 */ |
|
244 private final Image folder; |
|
245 |
|
246 /** |
|
247 * Default element only used to show error situations. |
|
248 */ |
|
249 private final Image element; |
|
250 |
|
251 /** |
|
252 * Used when tree model item is part of the module which is build with |
|
253 * AnalyzeTool. |
|
254 */ |
|
255 private final Image build; |
|
256 |
|
257 /** |
|
258 * Used when tree model item is part of the project but not build with |
|
259 * with AnalyzeTool. |
|
260 */ |
|
261 private final Image notBuild; |
|
262 |
|
263 /** |
|
264 * Used when tree model item is outside of the project modules. |
|
265 */ |
|
266 public Image outside; |
|
267 |
|
268 /** |
|
269 * Constructor. Created all the images which is used in the AnalyzeTool |
|
270 * tree model. |
|
271 */ |
|
272 public ViewLabelProvider() { |
|
273 // create images |
|
274 folder = PlatformUI.getWorkbench().getSharedImages().getImage( |
|
275 ISharedImages.IMG_OBJ_FOLDER); |
|
276 element = PlatformUI.getWorkbench().getSharedImages().getImage( |
|
277 ISharedImages.IMG_OBJ_ELEMENT); |
|
278 build = Activator.getImageDescriptor(Constants.ICON_BUILD) |
|
279 .createImage(); |
|
280 notBuild = Activator.getImageDescriptor(Constants.ICON_NOT_BUILD) |
|
281 .createImage(); |
|
282 outside = Activator.getImageDescriptor(Constants.ICON_OUTSIDE) |
|
283 .createImage(); |
|
284 } |
|
285 |
|
286 /** |
|
287 * Gets current tree object image. |
|
288 * |
|
289 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) |
|
290 * |
|
291 * @param obj |
|
292 * Current tree model item |
|
293 * @return Corresponding image of tree view object |
|
294 */ |
|
295 @Override |
|
296 public Image getImage(final Object obj) { |
|
297 |
|
298 // if object is TreeParent return "folder" icon |
|
299 if (obj instanceof TreeParent) { |
|
300 return folder; |
|
301 } |
|
302 |
|
303 // if object is TreeObject, need to change icon to match object |
|
304 // state |
|
305 else if (obj instanceof TreeObject) { |
|
306 // get TreeObject |
|
307 TreeObject tempObject = (TreeObject) obj; |
|
308 |
|
309 // change object icon if module belongs to selected project |
|
310 if (tempObject.isBelongs()) { |
|
311 // if module is built with AnalyzeTool |
|
312 if (tempObject.isBuild()) { |
|
313 return build; |
|
314 } |
|
315 // module not build with AnalyzeTool |
|
316 return notBuild; |
|
317 } |
|
318 // module not belong to selected project |
|
319 return outside; |
|
320 } |
|
321 |
|
322 return element; |
|
323 } |
|
324 |
|
325 /** |
|
326 * Gets current tree view object name. |
|
327 * |
|
328 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) |
|
329 * |
|
330 * @return Current tree view object name |
|
331 */ |
|
332 @Override |
|
333 public final String getText(final Object obj) { |
|
334 return obj.toString(); |
|
335 } |
|
336 } |
|
337 |
|
338 /** Is trace actions enabled. */ |
|
339 public static boolean enableTrace; |
|
340 |
|
341 /** Title of the AnalyzeTool view */ |
|
342 private String viewTitle = Constants.ANALYZE_TOOL_TITLE; |
|
343 |
|
344 /** Line feed character. */ |
|
345 private static String lineFeed = "\n"; |
|
346 |
|
347 /** Contains information of test runs. */ |
|
348 public TreeViewer runView; |
|
349 |
|
350 /** Contains one memory leak call stack addresses. */ |
|
351 private TreeViewer callstackView; |
|
352 |
|
353 /** Tree parent object which not shown to user. */ |
|
354 private TreeParent invisibleRoot; |
|
355 |
|
356 /** Double click action. */ |
|
357 private Action doubleClickAction; |
|
358 /** Click action. */ |
|
359 private Action clickAction; |
|
360 /** Change detail level action. */ |
|
361 public Action changeDetails; |
|
362 /** Select S60 log file action. */ |
|
363 private Action s60LogTargetAction; |
|
364 /** Select Tracing utility connection action. */ |
|
365 private Action externalLogTargetAction; |
|
366 /** Select fast data gathering mode */ |
|
367 private Action externalFastLogTargetAction; |
|
368 /** Select Ask always action. */ |
|
369 private Action askLogTargetAction; |
|
370 /** Save report file action. */ |
|
371 private Action saveReportAction; |
|
372 /** Save test run action. */ |
|
373 private Action saveDataFileAction; |
|
374 /** AnalyzeTool results action. */ |
|
375 private Action analyzeResults; |
|
376 /** Activate AnalyzeTool build action. */ |
|
377 public Action buildWithAtool; |
|
378 /** Clean AnalyzeTool changes action. */ |
|
379 private Action cleanAtoolChanges; |
|
380 /** Start/Stop trace action. */ |
|
381 public Action traceAction; |
|
382 /** Start subtest action. */ |
|
383 private Action startSubtest; |
|
384 /** Stop subtest action. */ |
|
385 private Action stopSubtest; |
|
386 /**Refresh(re-creates) project results*/ |
|
387 private Action refreshResults; |
|
388 /**Copies selected memory leak item info to the clipboard.*/ |
|
389 private Action copyAction; |
|
390 /** Action to open AnalyzeTool preference page.*/ |
|
391 private Action openPrefs; |
|
392 /** |
|
393 * Clears selected project results without removing temporary files |
|
394 */ |
|
395 private Action clearProjectResults; |
|
396 |
|
397 /** Selected project reference. */ |
|
398 public IProject project; |
|
399 |
|
400 /** Previously select project reference. */ |
|
401 public IProject lastProjectRef; |
|
402 |
|
403 /** Project reference for active trace. */ |
|
404 private IProject traceStartedProjectRef; |
|
405 |
|
406 /** Contains detailed information of selected run or memory leak. */ |
|
407 public Label informationLabel; |
|
408 |
|
409 /** Memory analysis parser. */ |
|
410 public ParseAnalyzeData parser; |
|
411 |
|
412 /** Used data file. */ |
|
413 public String usedDataFileName = null; |
|
414 |
|
415 /** Is trace active. */ |
|
416 private boolean traceActive = false; |
|
417 |
|
418 /** Last active memory leak tree item. */ |
|
419 private TreeObject activeTreeItem; |
|
420 |
|
421 /** Contains workbench (all project) related cpp file info. */ |
|
422 private final AbstractList<String> cppFileNames; |
|
423 |
|
424 /** Contains started subtest information. */ |
|
425 private final AbstractList<ActiveSubtests> startedSubtest; |
|
426 |
|
427 /** Contains project related module results. */ |
|
428 private final ProjectResults projectResults; |
|
429 |
|
430 /** Job for analyzing data files. */ |
|
431 private Job analyzeJob; |
|
432 |
|
433 /** Last selected tree item. */ |
|
434 private Object lastSelectedObject; |
|
435 |
|
436 /** Contains information of which files is opened. */ |
|
437 public FileActionHistory fileOpenHistory; |
|
438 |
|
439 /** File open drop down menu. */ |
|
440 private DropDownMenu fileOpenMenu; |
|
441 |
|
442 /** Log target action drop down menu. */ |
|
443 private DropDownMenu logTargetMenu; |
|
444 |
|
445 /** Save file drop down menu. */ |
|
446 private DropDownMenu saveFileMenu; |
|
447 |
|
448 /** Tab item for the "Top allocation locations" tab */ |
|
449 CTabItem memoryTab; |
|
450 |
|
451 /** Tab item for the memory results tab*/ |
|
452 CTabItem mainTab; |
|
453 |
|
454 /** StatisticView reference */ |
|
455 StatisticView statisticView; |
|
456 |
|
457 /** Contains project related modules */ |
|
458 private final Hashtable<IProject, AbstractList<MMPInfo>> projectModules; |
|
459 |
|
460 /**Reads epocwind.out file*/ |
|
461 EpocReader listeningJob; |
|
462 |
|
463 /** The chart view composite */ |
|
464 protected ChartContainer chart; |
|
465 |
|
466 |
|
467 /** |
|
468 * The constructor. |
|
469 */ |
|
470 public MainView() { |
|
471 parser = new ParseAnalyzeData(true, false); |
|
472 cppFileNames = new ArrayList<String>(); |
|
473 startedSubtest = new ArrayList<ActiveSubtests>(); |
|
474 projectResults = new ProjectResults(); |
|
475 fileOpenHistory = new FileActionHistory(Constants.HISTORY_LEVEL); |
|
476 projectModules = new Hashtable<IProject, AbstractList<MMPInfo>>(); |
|
477 } |
|
478 |
|
479 /** |
|
480 * Activates AnalyzeTool custom build if it is not activated. |
|
481 */ |
|
482 public final void activateAnalysisBuild() { |
|
483 // check project validity |
|
484 if (checkProjectValidity()) { |
|
485 // add AnalyzeTool custom builder natures to project build nature |
|
486 BuilderUtil bUtil = new BuilderUtil(); |
|
487 if (bUtil.isNatureEnabled(project)) { |
|
488 bUtil.disableNatures(project); |
|
489 } else { |
|
490 bUtil.enableNatures(project); |
|
491 } |
|
492 |
|
493 } |
|
494 |
|
495 // update build state |
|
496 updateBuildState(project); |
|
497 |
|
498 } |
|
499 |
|
500 /* |
|
501 * (non-Javadoc) |
|
502 * |
|
503 * @see com.nokia.s60tools.analyzetool.ui.IActionListener#allModulesBuilt() |
|
504 */ |
|
505 public final void buildStateChanged(final IProject projRef) { |
|
506 |
|
507 //check validity |
|
508 if(!project.equals(projRef) || projectResults == null) { |
|
509 return; |
|
510 } |
|
511 |
|
512 |
|
513 final String datafile = projectResults.getDataFileName(projRef); |
|
514 |
|
515 // if trace is captured or data file is opened |
|
516 if (datafile != null && runView != null) { |
|
517 |
|
518 // need to check is data file available in the disk |
|
519 FileInputStream fis = null; |
|
520 try { |
|
521 |
|
522 // get existing file stream |
|
523 fis = new FileInputStream(datafile); |
|
524 |
|
525 // if file is empty => do nothing |
|
526 if (fis.available() == 0) { |
|
527 return; |
|
528 } |
|
529 } catch (java.io.FileNotFoundException fnfe) { |
|
530 fnfe.printStackTrace(); |
|
531 return; |
|
532 } catch (java.io.IOException ioe) { |
|
533 ioe.printStackTrace(); |
|
534 return; |
|
535 } finally { // finally close input stream |
|
536 try { |
|
537 if (fis != null) { |
|
538 fis.close(); |
|
539 fis = null; |
|
540 } |
|
541 } catch (java.io.IOException ioe) { |
|
542 ioe.printStackTrace(); |
|
543 } |
|
544 } |
|
545 |
|
546 |
|
547 //data file is available |
|
548 int dataFileType = UseAtool.checkFileType(datafile); |
|
549 |
|
550 if( dataFileType == Constants.DATAFILE_INVALID || dataFileType == Constants.DATAFILE_XML || dataFileType == Constants.DATAFILE_EMPTY ) { |
|
551 return; |
|
552 } |
|
553 boolean reGenerate = Util.openConfirmationDialog(Constants.BUILD_STATE_CHANGED); |
|
554 |
|
555 if( reGenerate ) { |
|
556 // sync with UI thread |
|
557 runView.getControl().getDisplay().asyncExec(new Runnable() { |
|
558 public void run() { |
|
559 analyzeDataFile(Constants.ANALYZE_USE_DATA_FILE, datafile, |
|
560 false); |
|
561 } |
|
562 }); |
|
563 } |
|
564 |
|
565 } |
|
566 } |
|
567 |
|
568 |
|
569 /** |
|
570 * Opens file dialog and analyzing data file for given location. |
|
571 * |
|
572 * @param type |
|
573 * Type to define is data file asked from the user or using the |
|
574 * give data file |
|
575 * @param existingDataFile |
|
576 * Data file path |
|
577 * @param showErrorInfo |
|
578 * Flag to determinate that displaying error info or not |
|
579 */ |
|
580 public final void analyzeDataFile(final int type, |
|
581 final String existingDataFile, final boolean showErrorInfo) { |
|
582 |
|
583 // is project selected |
|
584 if (!checkProjectValidity()) { |
|
585 return; |
|
586 } |
|
587 |
|
588 // user selected file |
|
589 final String selectedFile; |
|
590 |
|
591 // ask for user data file |
|
592 if (type == Constants.ANALYZE_ASK_FOR_USER) { |
|
593 selectedFile = Util.openFileDialog(getSite().getShell(), |
|
594 Constants.DIALOG_SELECT_DATA_FILE, project.getLocation() |
|
595 .toOSString()); |
|
596 } else if (existingDataFile == null) { |
|
597 selectedFile = parser.getDataFileName(); |
|
598 } else { |
|
599 selectedFile = existingDataFile; |
|
600 } |
|
601 |
|
602 // if user select some file |
|
603 if (selectedFile != null) { |
|
604 |
|
605 // clear previous data |
|
606 projectResults.clearProjectData(project); |
|
607 activeTreeItem = null; |
|
608 clearCallstackViewContent(); |
|
609 updateInformationLabel(""); |
|
610 runView.setInput(getStartupContent()); |
|
611 changeViewTitle(viewTitle); |
|
612 |
|
613 AbstractList<MMPInfo> modules = Util.loadProjectTargetsInfo(project); |
|
614 projectModules.put(project, modules); |
|
615 |
|
616 boolean xmlFile = Util.isFileXML(selectedFile); |
|
617 // if file is xml file |
|
618 // no need to analyze data file |
|
619 // => just create results from xml file |
|
620 if (xmlFile) { |
|
621 Job analyzingXMLJob = new Job(Constants.ANALYZE_TOOL_TITLE) { |
|
622 @Override |
|
623 protected IStatus run(IProgressMonitor monitor) { |
|
624 |
|
625 // update progress monitor state |
|
626 monitor.beginTask(Constants.PROGRESSDIALOG_TITLE, |
|
627 IProgressMonitor.UNKNOWN); |
|
628 // Parse the data file |
|
629 ParseXMLFileSAX dataFileParser = new ParseXMLFileSAX(project, selectedFile, projectResults); |
|
630 boolean ret = dataFileParser.parse(); |
|
631 |
|
632 // set used datafile name |
|
633 usedDataFileName = selectedFile; |
|
634 |
|
635 fileOpenHistory.setFileName(selectedFile); |
|
636 |
|
637 // if parsing success |
|
638 // display memory leak results |
|
639 if (ret) { |
|
640 // update project results |
|
641 projectResults.setProjectModules(project, projectModules.get(project), dataFileParser.getModules()); |
|
642 } else { |
|
643 fileOpenHistory.removeFileName(selectedFile); |
|
644 if (showErrorInfo) { |
|
645 showErrorMessage(Constants.INFO_FILE_INVALID); |
|
646 } |
|
647 } |
|
648 updateChangeDetailState(project); |
|
649 refreshView(); |
|
650 dataFileParser = null; |
|
651 return new Status(IStatus.OK, |
|
652 Constants.ANALYZE_CONSOLE_ID, IStatus.OK, |
|
653 Constants.PROGRESSDIALOG_ANALYZE_COMPLETE, null); |
|
654 } |
|
655 }; |
|
656 analyzingXMLJob.setUser(true); |
|
657 analyzingXMLJob.schedule(); |
|
658 |
|
659 } else { |
|
660 try{ |
|
661 analyzeWithAtool(project, selectedFile, showErrorInfo); |
|
662 } |
|
663 catch( Exception e ) { |
|
664 analyzeJob = null; |
|
665 } |
|
666 } |
|
667 } |
|
668 } |
|
669 |
|
670 /** |
|
671 * Analyzing memory analysis results using atool.exe. |
|
672 * |
|
673 * @param projectRef |
|
674 * Project reference |
|
675 * @param usedFile |
|
676 * Data file which contains memory analyze data |
|
677 * @param showErrorInfo |
|
678 * Flag to determinate that displaying error info or not |
|
679 */ |
|
680 public final void analyzeWithAtool(final IProject projectRef, |
|
681 final String usedFile, final boolean showErrorInfo) { |
|
682 // check that no existing job running |
|
683 if (analyzeJob == null |
|
684 || analyzeJob.getResult().getCode() == IStatus.CANCEL |
|
685 || analyzeJob.getResult().getCode() == IStatus.ERROR) { |
|
686 analyzeJob = new Job(Constants.ANALYZE_TOOL_TITLE) { |
|
687 @Override |
|
688 protected IStatus run(IProgressMonitor monitor) { |
|
689 // inform progressdialog that task execution starts |
|
690 // this make progressdialog visible on the UI |
|
691 monitor.beginTask(Constants.PROGRESSDIALOG_ATOOL, |
|
692 IProgressMonitor.UNKNOWN); |
|
693 |
|
694 fileOpenHistory.setFileName(usedFile); |
|
695 // add2UserActionHistory( "File opened: " + usedFile ); |
|
696 |
|
697 // set used datafile name |
|
698 usedDataFileName = usedFile; |
|
699 |
|
700 // create atool object and execute atool |
|
701 UseAtool atool = new UseAtool(); |
|
702 |
|
703 // create xml file |
|
704 Constants.COMMAND_LINE_ERROR_CODE errorCode = atool.createXMLFileToCarbide( |
|
705 monitor, projectRef, usedFile, "-a"); |
|
706 String xmlFileLocation = null; |
|
707 xmlFileLocation = atool.getDataFileName(); |
|
708 |
|
709 // if some error occurs display it to user. |
|
710 if( errorCode != Constants.COMMAND_LINE_ERROR_CODE.OK ) { |
|
711 fileOpenHistory.removeFileName(usedFile); |
|
712 Util.displayCommandLineError(errorCode); |
|
713 } |
|
714 // if XML file generation failed => info to the user |
|
715 else if (xmlFileLocation == null) { |
|
716 fileOpenHistory.removeFileName(usedFile); |
|
717 if (showErrorInfo) { |
|
718 showErrorMessage(Constants.INFO_FILE_INVALID); |
|
719 } |
|
720 } else { |
|
721 // Parse the xml file |
|
722 ParseXMLFileSAX dataFileParser = new ParseXMLFileSAX(project, |
|
723 xmlFileLocation, projectResults); |
|
724 boolean error = dataFileParser.parse(); |
|
725 if (showErrorInfo && !error) { |
|
726 fileOpenHistory.removeFileName(usedFile); |
|
727 showErrorMessage(Constants.INFO_FILE_INVALID); |
|
728 } |
|
729 |
|
730 projectResults.setProjectModules(project, projectModules.get(project), dataFileParser.getModules()); |
|
731 projectResults.setDataFileName(projectRef, usedDataFileName); |
|
732 // update display |
|
733 refreshView(); |
|
734 } |
|
735 |
|
736 updateChangeDetailState(projectRef); |
|
737 |
|
738 // //this only generates statistics and this feature is currently disabled |
|
739 // if( !monitor.isCanceled() ) { |
|
740 // |
|
741 // IPreferenceStore store = Activator.getPreferences(); |
|
742 // boolean generateStatistic = store.getBoolean(Constants.CREATE_STATISTIC); |
|
743 // //used file data file create statistic also |
|
744 // if( generateStatistic && UseAtool.checkFileType(usedFile) == Constants.DATAFILE_TRACE ) |
|
745 // { |
|
746 // monitor.setTaskName(Constants.STATISTICS_GENERATING_PROG_TITLE); |
|
747 // |
|
748 // ReadFile fileReader = new ReadFile(); |
|
749 // boolean error = fileReader.readFile(usedFile); |
|
750 // if( error && statisticView != null) { |
|
751 // AbstractList<ProcessInfo> processes = fileReader.getStatistic(); |
|
752 // statisticView.setData( project, processes); |
|
753 // fileReader.finish(); |
|
754 // } |
|
755 // |
|
756 // } |
|
757 // } |
|
758 if (!monitor.isCanceled()) { |
|
759 |
|
760 monitor.setTaskName(Constants.GRAPH_GENERATING_PROG_TITLE); |
|
761 try { |
|
762 ReadFile fileReader = new ReadFile(); |
|
763 boolean success = fileReader.readFile(usedFile); |
|
764 if (success) { |
|
765 if (chart != null){ |
|
766 resetGraphView(); |
|
767 } |
|
768 AbstractList<ProcessInfo> processes = fileReader.getStatistic(); |
|
769 IMemoryActivityModel model = new AnalyzeFactory().createModel(processes.size() == 0); |
|
770 chart.setInput(project, model); |
|
771 model.addProcesses(processes); |
|
772 fileReader.finish(); |
|
773 } |
|
774 }catch( OutOfMemoryError oome ) { |
|
775 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "Can not allocate enough memory for the memory usage graph model."); |
|
776 analyzeJob = null; |
|
777 }catch (Exception e ) { |
|
778 Activator.getDefault().log(IStatus.ERROR, "Error while generating graph model", e); |
|
779 analyzeJob = null; |
|
780 } |
|
781 } |
|
782 analyzeJob = null; |
|
783 return new Status(IStatus.OK, Constants.ANALYZE_CONSOLE_ID, |
|
784 IStatus.OK, |
|
785 Constants.PROGRESSDIALOG_ANALYZE_COMPLETE, null); |
|
786 } |
|
787 }; |
|
788 |
|
789 analyzeJob.setUser(true); |
|
790 analyzeJob.setPriority(Job.LONG); |
|
791 analyzeJob.schedule(); |
|
792 |
|
793 } else { // if existing job is running display info to user |
|
794 showMessage(Constants.INFO_ALLREADY_RUNNING); |
|
795 } |
|
796 } |
|
797 |
|
798 |
|
799 /** |
|
800 * Change report detail level. |
|
801 */ |
|
802 public final void changeDetailLevel() { |
|
803 |
|
804 // sync with UI thread |
|
805 PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { |
|
806 public void run() { |
|
807 // get preference store |
|
808 IPreferenceStore store = Activator.getPreferences(); |
|
809 |
|
810 // get active report level |
|
811 String reportLevel = store.getString(Constants.REPORT_LEVEL); |
|
812 |
|
813 boolean updateMemLeakAlso = false; |
|
814 |
|
815 // set new report level |
|
816 if (Constants.REPORT_EVERY.equals(reportLevel)) { |
|
817 store.setValue(Constants.REPORT_LEVEL, |
|
818 Constants.REPORT_KNOWN); |
|
819 updateMemLeakAlso = true; |
|
820 } else if (Constants.REPORT_KNOWN.equals(reportLevel)) { |
|
821 store.setValue(Constants.REPORT_LEVEL, |
|
822 Constants.REPORT_TOPMOST); |
|
823 } else if (Constants.REPORT_TOPMOST.equals(reportLevel)) { |
|
824 store.setValue(Constants.REPORT_LEVEL, |
|
825 Constants.REPORT_EVERY); |
|
826 updateMemLeakAlso = true; |
|
827 } |
|
828 |
|
829 if (updateMemLeakAlso && runView != null) { |
|
830 activeTreeItem = null; |
|
831 |
|
832 // set view content |
|
833 runView.setInput(getResults(false)); |
|
834 |
|
835 // refresh view |
|
836 runView.refresh(); |
|
837 |
|
838 // if last selected item not found current item list |
|
839 if (activeTreeItem == null) { |
|
840 runView.setAutoExpandLevel(2); |
|
841 } else { |
|
842 // set selection to correct item |
|
843 runView.setSelection(new StructuredSelection( |
|
844 activeTreeItem), true); |
|
845 } |
|
846 |
|
847 } |
|
848 |
|
849 if (callstackView != null) { |
|
850 // update view callstack view content |
|
851 callstackView.setInput(getCallStack(activeTreeItem)); |
|
852 |
|
853 // expand all the trees on call stack view |
|
854 callstackView.expandAll(); |
|
855 |
|
856 } |
|
857 |
|
858 // change tooltip |
|
859 changeReportActionTooltip(); |
|
860 |
|
861 } |
|
862 }); |
|
863 |
|
864 } |
|
865 |
|
866 /** |
|
867 * Change logging mode. |
|
868 * |
|
869 * @param loggingMode |
|
870 * Used logging mode |
|
871 */ |
|
872 public final void changeLogTarget(final String loggingMode) { |
|
873 |
|
874 if (logTargetMenu == null) { |
|
875 return; |
|
876 } |
|
877 |
|
878 // get preference store |
|
879 IPreferenceStore store = Activator.getPreferences(); |
|
880 String usedLoggingMode = ""; |
|
881 |
|
882 // if no loggingmode given get it from the AnalyzeTool preferences |
|
883 if (loggingMode == null) { |
|
884 usedLoggingMode = store.getString(Constants.LOGGING_MODE); |
|
885 } |
|
886 // logging mode is given => so start to use it |
|
887 else { |
|
888 store.setValue(Constants.LOGGING_MODE, loggingMode); |
|
889 usedLoggingMode = loggingMode; |
|
890 } |
|
891 |
|
892 // current logging mode is external change it to external |
|
893 if (Constants.LOGGING_EXT.equals(usedLoggingMode)) { |
|
894 logTargetMenu.setImageDescriptor(Activator |
|
895 .getImageDescriptor(Constants.BUTTON_COMPUTER)); |
|
896 logTargetMenu |
|
897 .setToolTipText(Constants.ACTION_CHANGE_LOGGING_MODE_TOOLTIP_EXT); |
|
898 if (loggingMode == null){ |
|
899 externalLogTargetAction.setChecked(true); |
|
900 s60LogTargetAction.setChecked(false); |
|
901 externalFastLogTargetAction.setChecked(false); |
|
902 askLogTargetAction.setChecked(false); |
|
903 } |
|
904 } |
|
905 // current logging mode is s60 change it to s60 |
|
906 else if (Constants.LOGGING_S60.equals(usedLoggingMode)) { |
|
907 |
|
908 logTargetMenu.setImageDescriptor(Activator |
|
909 .getImageDescriptor(Constants.BUTTON_CELLURAR)); |
|
910 logTargetMenu |
|
911 .setToolTipText(Constants.ACTION_CHANGE_LOGGING_MODE_TOOLTIP_S60); |
|
912 if (loggingMode == null){ |
|
913 externalLogTargetAction.setChecked(false); |
|
914 s60LogTargetAction.setChecked(true); |
|
915 externalFastLogTargetAction.setChecked(false); |
|
916 askLogTargetAction.setChecked(false); |
|
917 } |
|
918 } |
|
919 |
|
920 else if( Constants.LOGGING_EXT_FAST.equals(usedLoggingMode)) { |
|
921 logTargetMenu.setImageDescriptor(Activator |
|
922 .getImageDescriptor(Constants.BUTTON_COMPUTER_FAST)); |
|
923 logTargetMenu.setToolTipText(Constants.ACTION_CHANGE_LOGGING_MODE_TOOLTIP_FAST); |
|
924 if( loggingMode == null) { |
|
925 externalLogTargetAction.setChecked(false); |
|
926 s60LogTargetAction.setChecked(false); |
|
927 externalFastLogTargetAction.setChecked(true); |
|
928 askLogTargetAction.setChecked(false); |
|
929 } |
|
930 } |
|
931 // current logging mode is "ask_always" |
|
932 else { |
|
933 logTargetMenu.setImageDescriptor(Activator |
|
934 .getImageDescriptor(Constants.BUTTON_ASK)); |
|
935 logTargetMenu |
|
936 .setToolTipText(Constants.ACTION_CHANGE_LOGGING_MODE_TOOLTIP_ASK); |
|
937 if (loggingMode == null){ |
|
938 externalLogTargetAction.setChecked(false); |
|
939 s60LogTargetAction.setChecked(false); |
|
940 externalFastLogTargetAction.setChecked(false); |
|
941 askLogTargetAction.setChecked(true); |
|
942 } |
|
943 } |
|
944 |
|
945 // if the fast data gathering mode is enabled by the preference page => enable also toolbar option |
|
946 // else disable fast data gathering mode |
|
947 externalFastLogTargetAction.setEnabled(store.getBoolean(Constants.LOGGING_FAST_ENABLED)); |
|
948 } |
|
949 |
|
950 /** |
|
951 * Changes "Change report detail level" action tooltip. |
|
952 */ |
|
953 public final void changeReportActionTooltip() { |
|
954 if (changeDetails == null) { |
|
955 return; |
|
956 } |
|
957 |
|
958 // get preference store |
|
959 IPreferenceStore store = Activator.getPreferences(); |
|
960 |
|
961 // get active report level |
|
962 String reportLevel = store.getString(Constants.REPORT_LEVEL); |
|
963 |
|
964 // set new report level |
|
965 if (Constants.REPORT_EVERY.equals(reportLevel)) { |
|
966 changeDetails.setImageDescriptor(Activator |
|
967 .getImageDescriptor(Constants.BUTTON_DETAILS_ALL)); |
|
968 changeDetails |
|
969 .setToolTipText(Constants.ACTION_CHANGE_REPORT_LEVEL_ALL); |
|
970 } else if (Constants.REPORT_KNOWN.equals(reportLevel)) { |
|
971 changeDetails.setImageDescriptor(Activator |
|
972 .getImageDescriptor(Constants.BUTTON_DETAILS_KNOWN)); |
|
973 changeDetails |
|
974 .setToolTipText(Constants.ACTION_CHANGE_REPORT_LEVEL_KNOWN); |
|
975 } else if (Constants.REPORT_TOPMOST.equals(reportLevel)) { |
|
976 changeDetails.setImageDescriptor(Activator |
|
977 .getImageDescriptor(Constants.BUTTON_DETAILS_TOPMOST)); |
|
978 changeDetails |
|
979 .setToolTipText(Constants.ACTION_CHANGE_REPORT_LEVEL_TOPMOST); |
|
980 } |
|
981 |
|
982 } |
|
983 |
|
984 /** |
|
985 * Change view title. |
|
986 * |
|
987 * @param newTitle |
|
988 * New title text |
|
989 */ |
|
990 private void changeViewTitle(final String newTitle) { |
|
991 |
|
992 // if newTitle contains text |
|
993 if (newTitle != null) { |
|
994 super.setContentDescription(newTitle); |
|
995 } |
|
996 } |
|
997 |
|
998 /** |
|
999 * Check project validity that is project is selected. |
|
1000 * |
|
1001 * @return True if project is open and accessible otherwise False |
|
1002 */ |
|
1003 public final boolean checkProjectValidity() { |
|
1004 // project is not selected show info to user |
|
1005 if (project == null || !project.isOpen()) { |
|
1006 Util.showMessage(Constants.NO_PROJ_SELECT); |
|
1007 return false; |
|
1008 } |
|
1009 return true; |
|
1010 } |
|
1011 |
|
1012 /** |
|
1013 * Cleans atool.exe made changes. |
|
1014 */ |
|
1015 public final void clean() { |
|
1016 if (!checkProjectValidity()) { |
|
1017 return; |
|
1018 } |
|
1019 |
|
1020 // check is atool.exe available |
|
1021 if (!Util.isAtoolAvailable()) { |
|
1022 showErrorMessage(Constants.INFO_ATOOL_NOT_AVAILABLE); |
|
1023 return; |
|
1024 } |
|
1025 |
|
1026 // ask for user |
|
1027 boolean ret = Util.openConfirmationDialog(Constants.CONFIRM_DELETE_ALL); |
|
1028 |
|
1029 // if user confirms |
|
1030 if (ret) { |
|
1031 // clear AnalyzeTool made changes |
|
1032 Util util = new Util(); |
|
1033 util.clearAtoolChanges(project); |
|
1034 |
|
1035 cleanAnalyzeData(null); |
|
1036 updateChangeDetailState(project); |
|
1037 } |
|
1038 |
|
1039 if( statisticView != null ) { |
|
1040 statisticView.clean(null); |
|
1041 } |
|
1042 |
|
1043 if (chart != null){ |
|
1044 resetGraphView(); |
|
1045 } |
|
1046 |
|
1047 } |
|
1048 |
|
1049 /** |
|
1050 * Cleans all the saved data. |
|
1051 */ |
|
1052 private void cleanAnalyzeData(final IProject projectRef) { |
|
1053 // clean all data if project not specified |
|
1054 if (projectRef == null) { |
|
1055 // clean all the project related info and data |
|
1056 projectResults.clear(); |
|
1057 projectModules.clear(); |
|
1058 } |
|
1059 else { |
|
1060 // clear only one project results |
|
1061 if (projectResults.contains(projectRef)) { |
|
1062 projectResults.clearProjectData(projectRef); |
|
1063 } |
|
1064 |
|
1065 if( projectModules.contains(projectRef)) { |
|
1066 projectModules.remove(projectRef); |
|
1067 } |
|
1068 } |
|
1069 |
|
1070 |
|
1071 |
|
1072 cppFileNames.clear(); |
|
1073 |
|
1074 // update variables |
|
1075 activeTreeItem = null; |
|
1076 usedDataFileName = ""; |
|
1077 |
|
1078 |
|
1079 // set default view contents |
|
1080 if (runView != null) { |
|
1081 runView.getControl().getDisplay().syncExec(new Runnable() { |
|
1082 public void run() { |
|
1083 runView.setInput(getStartupContent()); |
|
1084 if (informationLabel != null) { |
|
1085 updateInformationLabel(""); |
|
1086 } |
|
1087 |
|
1088 changeViewTitle(viewTitle); |
|
1089 if( statisticView != null ) { |
|
1090 statisticView.clean(projectRef); |
|
1091 } |
|
1092 } |
|
1093 }); |
|
1094 } |
|
1095 |
|
1096 clearCallstackViewContent(); |
|
1097 if( clearProjectResults != null && clearProjectResults != null ) { |
|
1098 clearProjectResults.setEnabled(false); |
|
1099 }else if( clearProjectResults != null ) { |
|
1100 updateChangeDetailState(projectRef); |
|
1101 } |
|
1102 |
|
1103 } |
|
1104 |
|
1105 /** |
|
1106 * Clears callstack view contents. |
|
1107 */ |
|
1108 private void clearCallstackViewContent() { |
|
1109 if (runView == null) { |
|
1110 return; |
|
1111 } |
|
1112 |
|
1113 // if view exists |
|
1114 runView.getControl().getDisplay().syncExec(new Runnable() { |
|
1115 public void run() { |
|
1116 |
|
1117 if (callstackView != null) { |
|
1118 callstackView.setInput(null); |
|
1119 } |
|
1120 } |
|
1121 }); |
|
1122 |
|
1123 } |
|
1124 |
|
1125 /** |
|
1126 * Contributes action bar. |
|
1127 */ |
|
1128 private void contributeToActionBars() { |
|
1129 if (getViewSite() == null) { |
|
1130 return; |
|
1131 } |
|
1132 IActionBars bars = getViewSite().getActionBars(); |
|
1133 fillLocalPullDown(bars.getMenuManager()); |
|
1134 fillLocalToolBar(bars.getToolBarManager()); |
|
1135 } |
|
1136 |
|
1137 |
|
1138 /** |
|
1139 * This is a callback that will allow us |
|
1140 * to create the viewer and initialize it. |
|
1141 */ |
|
1142 @Override |
|
1143 public void createPartControl( Composite parent ){ |
|
1144 |
|
1145 //create new Tab |
|
1146 CTabFolder mainFolder = new CTabFolder( parent, SWT.TOP ); |
|
1147 |
|
1148 //create main view and add it tab |
|
1149 createMainView( mainFolder ); |
|
1150 |
|
1151 //create new statistic view |
|
1152 //createMemoryView( mainFolder ); |
|
1153 //create graph |
|
1154 createGraphView(mainFolder); |
|
1155 |
|
1156 //set initial selection |
|
1157 mainFolder.setSelection( mainTab ); |
|
1158 } |
|
1159 |
|
1160 /** |
|
1161 * Creates graph view and add it to graph tab |
|
1162 * @param parent CTabFolder parent of the view |
|
1163 */ |
|
1164 private void createGraphView(CTabFolder mainFolder) { |
|
1165 final CTabItem chartTabItem = new CTabItem(mainFolder, SWT.NONE); |
|
1166 chartTabItem.setText("Graph"); |
|
1167 chartTabItem.setToolTipText("AnalyzeTool graph per process"); |
|
1168 |
|
1169 chart = new ChartContainer(mainFolder, SWT.NONE); |
|
1170 chartTabItem.setControl(chart); |
|
1171 IMemoryActivityModel model = AnalyzeFactory.getEmptyModel(); |
|
1172 chart.setInput(project, model); |
|
1173 model.addProcesses(model.getProcesses());//charts should get notified via listeners on the model |
|
1174 } |
|
1175 |
|
1176 /** |
|
1177 * Clears the graph by setting an empty model and causing paint events |
|
1178 */ |
|
1179 private void resetGraphView(){ |
|
1180 if (chart != null){ |
|
1181 chart.setInput(project, AnalyzeFactory.getEmptyModel()); |
|
1182 //chart.update(); |
|
1183 } |
|
1184 } |
|
1185 |
|
1186 /** |
|
1187 * Creates new statistic view and add it to memory tab |
|
1188 * @param parent Statistic view parent( CTabFolder ) |
|
1189 */ |
|
1190 public void createMemoryView( CTabFolder parent ) |
|
1191 { |
|
1192 statisticView = new StatisticView(); |
|
1193 memoryTab = statisticView.createView( parent ); |
|
1194 } |
|
1195 |
|
1196 /** |
|
1197 * Creates memory results view |
|
1198 * @param parent View parent ( CTabFolder ) |
|
1199 */ |
|
1200 public void createMainView(CTabFolder parent) { |
|
1201 |
|
1202 // Create SashForm this form includes all the current view components |
|
1203 SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL); |
|
1204 |
|
1205 mainTab = new CTabItem( parent, SWT.NONE ); |
|
1206 mainTab.setControl( sashForm ); |
|
1207 mainTab.setText(Constants.MAIN_TAB_TITLE); |
|
1208 |
|
1209 // create new treeviewer to shown memory analysis runs and leaks |
|
1210 runView = new TreeViewer(sashForm, SWT.VIRTUAL); |
|
1211 |
|
1212 // create SashForm to display call stack addresses and more detailed |
|
1213 // information |
|
1214 // of selected run or leak |
|
1215 SashForm callstackForm = new SashForm(sashForm, SWT.VERTICAL); |
|
1216 |
|
1217 // set content and label providers |
|
1218 runView.setContentProvider(new ViewContentProvider()); |
|
1219 runView.setLabelProvider(new ViewLabelProvider()); |
|
1220 // runView.addFilter( new ATFilter() ); |
|
1221 // get init content |
|
1222 runView.setInput(getStartupContent()); |
|
1223 |
|
1224 // add listener to provide selection change events |
|
1225 runView.addTreeListener(this); |
|
1226 |
|
1227 runView.setAutoExpandLevel(2); |
|
1228 |
|
1229 // create new information label |
|
1230 // this label contains more detailed information of selected item |
|
1231 informationLabel = new Label(callstackForm, SWT.BORDER | SWT.CENTER); |
|
1232 |
|
1233 // create grid data => this provides layout changes |
|
1234 GridData data = new GridData(); |
|
1235 |
|
1236 // add grid data to label, this enables label ui modifications e.g. line |
|
1237 // feed |
|
1238 informationLabel.setLayoutData(data); |
|
1239 |
|
1240 // set init text |
|
1241 informationLabel.setText(Constants.INFO_NO_DATA); |
|
1242 |
|
1243 // create new call stack view |
|
1244 // this components contains information of one memory leak call stack |
|
1245 // addresses |
|
1246 callstackView = new TreeViewer(callstackForm, SWT.MULTI | SWT.H_SCROLL |
|
1247 | SWT.V_SCROLL); |
|
1248 |
|
1249 // modify UI components layouts |
|
1250 // reserve more space for left side of UI |
|
1251 sashForm.setWeights(new int[] { 5, 3 }); |
|
1252 callstackForm.setWeights(new int[] { 2, 8 }); |
|
1253 |
|
1254 // add content and label providers |
|
1255 callstackView.setContentProvider(new ViewContentProvider()); |
|
1256 callstackView.setLabelProvider(new ViewLabelProvider()); |
|
1257 |
|
1258 // make actions and construct click listeners |
|
1259 makeActions(); |
|
1260 hookContextMenu(); |
|
1261 hookDoubleClickAction(); |
|
1262 hookClicks(); |
|
1263 contributeToActionBars(); |
|
1264 |
|
1265 // set view title |
|
1266 viewTitle = String.format(Constants.ANALYZE_TOOL_TITLE_WITH_VERSION, Util.getAToolFeatureVersionNumber()); |
|
1267 this.setContentDescription(viewTitle); |
|
1268 |
|
1269 // add selection listener |
|
1270 if (getSite() != null) { |
|
1271 getSite().getPage().addSelectionListener(this); |
|
1272 runView.getControl().addKeyListener(this); |
|
1273 } |
|
1274 |
|
1275 // set actionlistener |
|
1276 Activator.setActionListener(this); |
|
1277 |
|
1278 // set help shortcuts |
|
1279 PlatformUI.getWorkbench().getHelpSystem().setHelp( |
|
1280 callstackView.getControl(), |
|
1281 AnalyzeToolHelpContextIDs.ANALYZE_MAIN); |
|
1282 PlatformUI.getWorkbench().getHelpSystem().setHelp(runView.getControl(), |
|
1283 AnalyzeToolHelpContextIDs.ANALYZE_MAIN); |
|
1284 |
|
1285 ResourcesPlugin.getWorkspace().addResourceChangeListener(new ATResourceListener()); |
|
1286 |
|
1287 //get used command line engine version |
|
1288 String version = Util.getAtoolVersionNumber(Util.getAtoolInstallFolder()); |
|
1289 |
|
1290 //compare current version to min version |
|
1291 int comp = Util.compareVersionNumber(Constants.CS_SUPPORT_MIN_VERSION, version); |
|
1292 |
|
1293 IPreferenceStore store = Activator.getPreferences(); |
|
1294 //if current version is same or higher than required version => set flag to true |
|
1295 if( comp == Constants.VERSION_NUMBERS_EQUALS || comp == Constants.VERSION_NUMBERS_SECOND ) { |
|
1296 store.setValue(Constants.LOGGING_FAST_ENABLED, true); |
|
1297 } |
|
1298 else { |
|
1299 store.setValue(Constants.LOGGING_FAST_ENABLED, false); |
|
1300 } |
|
1301 |
|
1302 // get default value for logging mode |
|
1303 preferenceChanged(); |
|
1304 } |
|
1305 |
|
1306 /** |
|
1307 * When AnalyzeTool view is activated and Tracing utility plug-in is not |
|
1308 * available disable AnalyzeTool trace actions. |
|
1309 * |
|
1310 * @see com.nokia.s60tools.analyzetool.ui.IActionListener#disableTraceActions(boolean) |
|
1311 * |
|
1312 * @param disable |
|
1313 * Boolean state of trace action |
|
1314 */ |
|
1315 public void disableTraceActions(final boolean disable) { |
|
1316 |
|
1317 if (traceAction != null && disable) { |
|
1318 // enable trace action |
|
1319 traceAction.setToolTipText(Constants.ACTION_START_TRACE); |
|
1320 traceAction.setEnabled(disable); |
|
1321 } else if (traceAction != null && !disable) { |
|
1322 // disable trace action |
|
1323 traceAction.setToolTipText(Constants.TRACE_NOT_FOUND); |
|
1324 traceAction.setEnabled(disable); |
|
1325 } |
|
1326 |
|
1327 traceActive = false; |
|
1328 } |
|
1329 |
|
1330 /** |
|
1331 * Fills context menu. |
|
1332 * |
|
1333 * @param manager |
|
1334 * Menu manager |
|
1335 */ |
|
1336 private void fillContextMenu(IMenuManager manager) { |
|
1337 |
|
1338 manager.add(buildWithAtool); |
|
1339 manager.add(new Separator()); |
|
1340 manager.add(traceAction); |
|
1341 manager.add(startSubtest); |
|
1342 manager.add(stopSubtest); |
|
1343 manager.add(new Separator()); |
|
1344 manager.add(changeDetails); |
|
1345 manager.add(refreshResults); |
|
1346 manager.add(clearProjectResults); |
|
1347 manager.add(new Separator()); |
|
1348 manager.add(cleanAtoolChanges); |
|
1349 manager.add(copyAction); |
|
1350 // Other plug-ins can contribute there actions here |
|
1351 manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
1352 } |
|
1353 |
|
1354 /** |
|
1355 * Fills local pull down menu. |
|
1356 * |
|
1357 * @param manager |
|
1358 * Menu manager |
|
1359 */ |
|
1360 private void fillLocalPullDown(IMenuManager manager) { |
|
1361 manager.add(buildWithAtool); |
|
1362 manager.add(new Separator()); |
|
1363 manager.add(traceAction); |
|
1364 manager.add(startSubtest); |
|
1365 manager.add(stopSubtest); |
|
1366 manager.add(new Separator()); |
|
1367 manager.add(changeDetails); |
|
1368 manager.add(refreshResults); |
|
1369 manager.add(new Separator()); |
|
1370 manager.add(cleanAtoolChanges); |
|
1371 manager.add(new Separator()); |
|
1372 manager.add(openPrefs); |
|
1373 } |
|
1374 |
|
1375 /** |
|
1376 * Fills local toolbar. |
|
1377 * |
|
1378 * @param manager |
|
1379 * Menu manager |
|
1380 */ |
|
1381 private void fillLocalToolBar(IToolBarManager manager) { |
|
1382 |
|
1383 logTargetMenu = new DropDownMenu(Constants.ACTION_SAVE, this, false, |
|
1384 false); |
|
1385 makeLogTargetActions(); |
|
1386 logTargetMenu.addAction(s60LogTargetAction); |
|
1387 logTargetMenu.addAction(externalLogTargetAction); |
|
1388 logTargetMenu.addAction(externalFastLogTargetAction); |
|
1389 logTargetMenu.addAction(askLogTargetAction); |
|
1390 manager.add(logTargetMenu); |
|
1391 |
|
1392 manager.add(buildWithAtool); |
|
1393 manager.add(new Separator()); |
|
1394 manager.add(traceAction); |
|
1395 manager.add(startSubtest); |
|
1396 manager.add(stopSubtest); |
|
1397 manager.add(new Separator()); |
|
1398 manager.add(changeDetails); |
|
1399 manager.add(new Separator()); |
|
1400 fileOpenMenu = new DropDownMenu(Constants.ACTION_OPEN, this, false, |
|
1401 true); |
|
1402 makeFileOpenActions(); |
|
1403 manager.add(fileOpenMenu); |
|
1404 |
|
1405 // get drop down menu for save action |
|
1406 saveFileMenu = new DropDownMenu(Constants.ACTION_SAVE, this, true, |
|
1407 false); |
|
1408 saveFileMenu.setImageDescriptor(Activator |
|
1409 .getImageDescriptor(Constants.BUTTON_SAVE)); |
|
1410 |
|
1411 saveFileMenu.addAction(saveReportAction); |
|
1412 saveFileMenu.addAction(saveDataFileAction); |
|
1413 manager.add(saveFileMenu); |
|
1414 manager.add(new Separator()); |
|
1415 manager.add(cleanAtoolChanges); |
|
1416 manager.add(new Separator()); |
|
1417 manager.add(openPrefs); |
|
1418 } |
|
1419 |
|
1420 /** |
|
1421 * Gets call stack information of current leak. |
|
1422 * |
|
1423 * @param treeObject |
|
1424 * Tree object |
|
1425 * @return Object |
|
1426 */ |
|
1427 Object getCallStack(final TreeObject treeObject) { |
|
1428 IPreferenceStore store = Activator.getPreferences(); |
|
1429 // if project is not selected or treeobject is not created |
|
1430 // => leave |
|
1431 if (project == null || treeObject == null) { |
|
1432 return null; |
|
1433 } |
|
1434 |
|
1435 // set active tree item |
|
1436 activeTreeItem = treeObject; |
|
1437 |
|
1438 AnalysisItem item = null; |
|
1439 if (treeObject.isSubTest()) { |
|
1440 item = projectResults.getSubtestItem(project, |
|
1441 treeObject.getRunID(), treeObject.getMemLeakID(), |
|
1442 treeObject.getSubtestID()); |
|
1443 } |
|
1444 // get AnalysisItem |
|
1445 else { |
|
1446 item = projectResults.getSpecific(project, treeObject.getRunID(), |
|
1447 treeObject.getMemLeakID()); |
|
1448 } |
|
1449 |
|
1450 if (item == null) { |
|
1451 return null; |
|
1452 } |
|
1453 |
|
1454 if (store == null) { |
|
1455 return null; |
|
1456 } |
|
1457 AbstractList<MMPInfo> modules = projectModules.get(project); |
|
1458 TreeHelper helper = new TreeHelper(null, store); |
|
1459 |
|
1460 TreeParent parent = helper.getCallstack(item, modules); |
|
1461 |
|
1462 return parent; |
|
1463 } |
|
1464 |
|
1465 |
|
1466 /** |
|
1467 * Gets callstack item name. |
|
1468 * |
|
1469 * @param callstackItem |
|
1470 * One callstack item |
|
1471 * @return Callstack name if found otherwise null |
|
1472 */ |
|
1473 public final String getCallstackItemName(final CallstackItem callstackItem) { |
|
1474 // if call stack item not set => return |
|
1475 if (callstackItem == null) { |
|
1476 return null; |
|
1477 } |
|
1478 |
|
1479 String cppFileName = ""; |
|
1480 String fileName = callstackItem.getFileName().toLowerCase(Locale.US); |
|
1481 |
|
1482 if (fileName.indexOf(".cpp") == -1) { |
|
1483 return null; |
|
1484 } |
|
1485 |
|
1486 // check that project contains cpp file which is parsed from call stack |
|
1487 // list |
|
1488 Iterator<String> iterCppFiles = cppFileNames.iterator(); |
|
1489 while( iterCppFiles.hasNext() ) { |
|
1490 String cppFileLocation = iterCppFiles.next(); |
|
1491 |
|
1492 //parse file name from the source path |
|
1493 int slash = Util.getLastSlashIndex(cppFileLocation); |
|
1494 if( slash != -1 ) { |
|
1495 String cppFile = cppFileLocation.substring(slash+1, cppFileLocation.length()); |
|
1496 if( cppFile.equalsIgnoreCase(fileName)) { |
|
1497 cppFileName = cppFileLocation; |
|
1498 break; |
|
1499 } |
|
1500 } |
|
1501 } |
|
1502 return cppFileName; |
|
1503 } |
|
1504 |
|
1505 /** |
|
1506 * Gets file info for current project. |
|
1507 * |
|
1508 * @param projectRef |
|
1509 * Project reference |
|
1510 */ |
|
1511 private void getFileInfos(final IProject projectRef) { |
|
1512 ResourceVisitor visitor = new ResourceVisitor(this); |
|
1513 |
|
1514 // go thru all open projects |
|
1515 // this enables to display one memory address corresponding source code |
|
1516 // line |
|
1517 // for outside of active project |
|
1518 try { |
|
1519 if (projectRef == null) { |
|
1520 IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace() |
|
1521 .getRoot(); |
|
1522 IProject[] projects = myWorkspaceRoot.getProjects(); |
|
1523 for (int i = 0; i < projects.length; i++) { |
|
1524 IProject tempProject = projects[i]; |
|
1525 if (tempProject.isOpen()) { |
|
1526 tempProject.accept(visitor); |
|
1527 } |
|
1528 } |
|
1529 |
|
1530 } else { // project is selected |
|
1531 // if project is open => accept resource visitor |
|
1532 if (projectRef.isOpen()) { |
|
1533 projectRef.accept(visitor); |
|
1534 } |
|
1535 } |
|
1536 } catch (CoreException e) { |
|
1537 e.printStackTrace(); |
|
1538 |
|
1539 } |
|
1540 } |
|
1541 |
|
1542 /** |
|
1543 * Gets project results. |
|
1544 * |
|
1545 * @param projectRef |
|
1546 * Project reference |
|
1547 */ |
|
1548 public void getProjectResults(final IProject projectRef) { |
|
1549 // if project reference is null => leave |
|
1550 if (projectRef == null) { |
|
1551 return; |
|
1552 } |
|
1553 // if project is selected and it is open |
|
1554 else if (projectRef.isOpen()) { |
|
1555 // if this is the first time to get project results |
|
1556 if (lastProjectRef == null) { |
|
1557 lastProjectRef = projectRef; |
|
1558 updateBuildState(lastProjectRef); |
|
1559 updateChangeDetailState(lastProjectRef); |
|
1560 } |
|
1561 // project selection changed |
|
1562 // need to get selected project results and mmp file info |
|
1563 else if (!lastProjectRef.equals(projectRef)) { |
|
1564 activeTreeItem = null; |
|
1565 lastProjectRef = projectRef; |
|
1566 |
|
1567 runView.setInput(getResults(false)); |
|
1568 callstackView.setInput(getCallStack(null)); |
|
1569 |
|
1570 updateInformationLabel(""); |
|
1571 updateBuildState(lastProjectRef); |
|
1572 updateChangeDetailState(lastProjectRef); |
|
1573 } |
|
1574 } |
|
1575 |
|
1576 //update clear project results action state |
|
1577 if( projectResults.contains(projectRef) ) { |
|
1578 clearProjectResults.setEnabled(true); |
|
1579 } |
|
1580 else { |
|
1581 clearProjectResults.setEnabled(false); |
|
1582 } |
|
1583 } |
|
1584 |
|
1585 /** |
|
1586 * Gets memory leak analysis results. |
|
1587 * |
|
1588 * @param showErrorInfo |
|
1589 * Display error info or not |
|
1590 * @return Object memory leak analysis results |
|
1591 */ |
|
1592 private Object getResults(final boolean showErrorInfo) { |
|
1593 |
|
1594 try { |
|
1595 // create new tree paretn |
|
1596 TreeParent testRuns = new TreeParent(Constants.TEST_RUNS_TREE_TITLE); |
|
1597 invisibleRoot = null; |
|
1598 invisibleRoot = new TreeParent(Constants.TREE_TITLE); |
|
1599 invisibleRoot.addChild(testRuns); |
|
1600 |
|
1601 // if current project does not contain results => just update |
|
1602 // default view values |
|
1603 if (!projectResults.contains(project)) { |
|
1604 changeViewTitle(viewTitle); |
|
1605 updateInformationLabel(Constants.INFO_NO_DATA); |
|
1606 return getStartupContent(); |
|
1607 } |
|
1608 |
|
1609 if( !projectModules.containsKey(project) ) |
|
1610 { |
|
1611 AbstractList<MMPInfo> modules = Util.loadProjectTargetsInfo(project); |
|
1612 projectModules.put(project, modules); |
|
1613 } |
|
1614 |
|
1615 // get run results |
|
1616 AbstractList<RunResults> runs = projectResults.getResults(project); |
|
1617 AbstractList<MMPInfo> modules = projectModules.get(project); |
|
1618 |
|
1619 // if no results available => show default view content |
|
1620 if (runs == null || runs.isEmpty()) { |
|
1621 changeViewTitle(viewTitle); |
|
1622 updateInformationLabel(Constants.INFO_NO_DATA); |
|
1623 |
|
1624 // because no results created => delete project empty results |
|
1625 projectResults.clearProjectData(project); |
|
1626 |
|
1627 fileOpenHistory.removeFileName(projectResults |
|
1628 .getDataFileName(project)); |
|
1629 |
|
1630 // display info to user |
|
1631 if (showErrorInfo) { |
|
1632 showErrorMessage(Constants.INFO_FILE_INVALID); |
|
1633 } |
|
1634 |
|
1635 return getStartupContent(); |
|
1636 } |
|
1637 |
|
1638 IPreferenceStore store = Activator.getPreferences(); |
|
1639 |
|
1640 // create TreeHelper object |
|
1641 // TreeHelper class creates tree model to this view. |
|
1642 TreeHelper helper = new TreeHelper(lastSelectedObject, |
|
1643 store); |
|
1644 |
|
1645 // clear active item |
|
1646 activeTreeItem = null; |
|
1647 |
|
1648 // update used data file name |
|
1649 usedDataFileName = projectResults.getDataFileName(project); |
|
1650 |
|
1651 // change view title |
|
1652 changeViewTitle(viewTitle |
|
1653 + " results from file: " + usedDataFileName); |
|
1654 |
|
1655 // thru runs |
|
1656 Iterator<RunResults> runIterator = runs.iterator(); |
|
1657 while (runIterator.hasNext()) { |
|
1658 // get one run info |
|
1659 RunResults oneRunResults = runIterator.next(); |
|
1660 |
|
1661 // creates one run information at the time |
|
1662 TreeParent oneRunTree = helper.createRunResults(oneRunResults, modules); |
|
1663 |
|
1664 // get active item |
|
1665 // active must ask from the TreeHelper class |
|
1666 // because it can be filtered out when creating new tree model |
|
1667 activeTreeItem = helper.getActiveItem(); |
|
1668 testRuns.addChild(oneRunTree); |
|
1669 |
|
1670 } |
|
1671 |
|
1672 } catch (java.lang.NullPointerException npe) { |
|
1673 npe.printStackTrace(); |
|
1674 return null; |
|
1675 } |
|
1676 |
|
1677 // expand to runs level |
|
1678 runView.setAutoExpandLevel(2); |
|
1679 |
|
1680 return invisibleRoot; |
|
1681 } |
|
1682 |
|
1683 /** |
|
1684 * Sets startup contents for view. |
|
1685 * |
|
1686 * @return Object which can be displayd |
|
1687 */ |
|
1688 public TreeParent getStartupContent() { |
|
1689 // create default treeviewer content |
|
1690 invisibleRoot = new TreeParent(Constants.ANALYZE_TOOL_TITLE); |
|
1691 TreeParent child = new TreeParent(Constants.INFO_NO_DATA_FILE_AVAILABLE); |
|
1692 invisibleRoot.addChild(child); |
|
1693 |
|
1694 return invisibleRoot; |
|
1695 } |
|
1696 |
|
1697 /** |
|
1698 * Adds selection changed listener to view. |
|
1699 */ |
|
1700 private void hookClicks() { |
|
1701 runView.addSelectionChangedListener(this); |
|
1702 } |
|
1703 |
|
1704 /** |
|
1705 * Hooks context menu. |
|
1706 */ |
|
1707 private void hookContextMenu() { |
|
1708 MenuManager menuMgr = new MenuManager("#PopupMenu"); |
|
1709 menuMgr.setRemoveAllWhenShown(true); |
|
1710 menuMgr.addMenuListener(new IMenuListener() { |
|
1711 @SuppressWarnings("synthetic-access") |
|
1712 public void menuAboutToShow(IMenuManager manager) { |
|
1713 MainView.this.fillContextMenu(manager); |
|
1714 } |
|
1715 }); |
|
1716 Menu menu = menuMgr.createContextMenu(runView.getControl()); |
|
1717 runView.getControl().setMenu(menu); |
|
1718 if (getSite() != null) { |
|
1719 getSite().registerContextMenu(menuMgr, runView); |
|
1720 } |
|
1721 |
|
1722 } |
|
1723 |
|
1724 /** |
|
1725 * Hook double click actions. |
|
1726 */ |
|
1727 private void hookDoubleClickAction() { |
|
1728 callstackView.addDoubleClickListener(new IDoubleClickListener() { |
|
1729 public void doubleClick(DoubleClickEvent event) { |
|
1730 |
|
1731 doubleClickAction.run(); |
|
1732 } |
|
1733 }); |
|
1734 } |
|
1735 |
|
1736 /** |
|
1737 * Check that if subtest by given name allready exists. |
|
1738 * |
|
1739 * @param subTestName |
|
1740 * Subtest name |
|
1741 * @param target |
|
1742 * Testing target |
|
1743 * @return True if allready exists otherwise False |
|
1744 */ |
|
1745 public final boolean isSubtestExists(final String subTestName, |
|
1746 final String target) { |
|
1747 Iterator<ActiveSubtests> subTestIter = startedSubtest.iterator(); |
|
1748 while (subTestIter.hasNext()) { |
|
1749 ActiveSubtests oneSubtest = subTestIter.next(); |
|
1750 if (oneSubtest.getName().equals(subTestName) |
|
1751 && oneSubtest.getTargetName().equals(target)) { |
|
1752 return true; |
|
1753 } |
|
1754 |
|
1755 } |
|
1756 return false; |
|
1757 } |
|
1758 |
|
1759 |
|
1760 |
|
1761 /** |
|
1762 * Go thru the project files and stores mmp files. |
|
1763 * |
|
1764 * @param resource |
|
1765 * One resource file of project |
|
1766 */ |
|
1767 public final void loadFileInfo(IResource resource) { |
|
1768 // get all the cpp file info which are imported to workspace |
|
1769 // this enable pinpointing the code line for outside active project cpp |
|
1770 // file than |
|
1771 // the memory analysis is made |
|
1772 // get cpp file info |
|
1773 String cppFileName = Util.getCPPFileNameAndPath(resource); |
|
1774 |
|
1775 // if cpp file found, save it |
|
1776 if (cppFileName != null && !cppFileNames.contains(cppFileName)) { |
|
1777 this.cppFileNames.add(cppFileName); |
|
1778 } |
|
1779 } |
|
1780 |
|
1781 /** |
|
1782 * Construct all the actions. |
|
1783 */ |
|
1784 private void makeActions() { |
|
1785 |
|
1786 // listens click actions |
|
1787 clickAction = new Action() { |
|
1788 @Override |
|
1789 public void run() { |
|
1790 // get selection |
|
1791 ISelection selection = runView.getSelection(); |
|
1792 |
|
1793 // get selection object |
|
1794 Object obj = ((IStructuredSelection) selection) |
|
1795 .getFirstElement(); |
|
1796 |
|
1797 // if object exists |
|
1798 if (obj == null) { |
|
1799 copyAction.setEnabled(false); |
|
1800 return; |
|
1801 } |
|
1802 |
|
1803 // get call stack addresses to view |
|
1804 if (obj instanceof TreeObject) { |
|
1805 lastSelectedObject = obj; |
|
1806 |
|
1807 //get callstack items |
|
1808 Object resultObject = getCallStack((TreeObject) obj); |
|
1809 |
|
1810 // if results not found |
|
1811 if( resultObject == null ) { |
|
1812 copyAction.setEnabled(false); |
|
1813 } |
|
1814 else { |
|
1815 callstackView.setInput(resultObject); |
|
1816 copyAction.setEnabled(true); |
|
1817 } |
|
1818 |
|
1819 } |
|
1820 |
|
1821 // expand all the trees on call stack view |
|
1822 callstackView.expandAll(); |
|
1823 |
|
1824 setTextToInformationLabel(); |
|
1825 } |
|
1826 }; |
|
1827 |
|
1828 // listens double click actions |
|
1829 doubleClickAction = new Action() { |
|
1830 @Override |
|
1831 public void run() { |
|
1832 // get selection |
|
1833 ISelection selection = callstackView.getSelection(); |
|
1834 Object obj = ((IStructuredSelection) selection) |
|
1835 .getFirstElement(); |
|
1836 |
|
1837 // open file in editor |
|
1838 if (obj instanceof TreeObject) { |
|
1839 openEditor((TreeObject) obj); |
|
1840 } |
|
1841 } |
|
1842 }; |
|
1843 |
|
1844 // data capture |
|
1845 traceAction = new Action() { |
|
1846 @Override |
|
1847 public void run() { |
|
1848 |
|
1849 // if trace is active => stop the trace |
|
1850 if (traceActive) { |
|
1851 stop(true); |
|
1852 } |
|
1853 // if trace is not active => start the trace |
|
1854 else { |
|
1855 start(); |
|
1856 } |
|
1857 } |
|
1858 }; |
|
1859 traceAction.setText(Constants.ACTION_START_TRACE); |
|
1860 traceAction.setToolTipText(Constants.ACTION_START_TRACE); |
|
1861 traceAction.setImageDescriptor(Activator |
|
1862 .getImageDescriptor((Constants.BUTTON_RUN))); |
|
1863 |
|
1864 // if trace actions are disabled |
|
1865 if (!enableTrace) { |
|
1866 traceAction.setEnabled(false); |
|
1867 traceAction.setToolTipText(Constants.TRACE_NOT_FOUND); |
|
1868 } |
|
1869 |
|
1870 // build with atool |
|
1871 buildWithAtool = new Action() { |
|
1872 @Override |
|
1873 public void run() { |
|
1874 activateAnalysisBuild(); |
|
1875 } |
|
1876 }; |
|
1877 buildWithAtool.setText(Constants.ACTION_AT_BUILD_ACTIVE); |
|
1878 buildWithAtool.setToolTipText(Constants.ACTION_AT_BUILD_ACTIVE); |
|
1879 buildWithAtool.setImageDescriptor(Activator |
|
1880 .getImageDescriptor(Constants.BUTTON_BUILD)); |
|
1881 |
|
1882 // clean atool changes |
|
1883 cleanAtoolChanges = new Action() { |
|
1884 @Override |
|
1885 public void run() { |
|
1886 clean(); |
|
1887 } |
|
1888 }; |
|
1889 cleanAtoolChanges.setText(Constants.ACTION_CLEAR_CHANGES); |
|
1890 cleanAtoolChanges |
|
1891 .setToolTipText(Constants.ACTION_CLEAR_CHANGES_TOOLTIP); |
|
1892 cleanAtoolChanges.setImageDescriptor(Activator |
|
1893 .getImageDescriptor(Constants.BUTTON_CLEAN)); |
|
1894 |
|
1895 // change detail level |
|
1896 changeDetails = new Action() { |
|
1897 @Override |
|
1898 public void run() { |
|
1899 changeDetailLevel(); |
|
1900 } |
|
1901 }; |
|
1902 changeDetails.setText(Constants.ACTION_CHANGE_REPORT_LEVEL); |
|
1903 |
|
1904 // save report( xml ) file |
|
1905 saveReportAction = new Action() { |
|
1906 @Override |
|
1907 public void run() { |
|
1908 saveReportFile(Constants.SAVE_REPORT_FILE_XML); |
|
1909 } |
|
1910 }; |
|
1911 saveReportAction.setText(Constants.ACTION_SAVE_REPORT); |
|
1912 saveReportAction.setToolTipText(Constants.ACTION_SAVE_REPORT); |
|
1913 |
|
1914 // save data file |
|
1915 saveDataFileAction = new Action() { |
|
1916 @Override |
|
1917 public void run() { |
|
1918 saveReportFile(Constants.SAVE_REPORT_FILE_DATA); |
|
1919 |
|
1920 } |
|
1921 }; |
|
1922 saveDataFileAction.setText(Constants.ACTION_SAVE_DATA); |
|
1923 saveDataFileAction.setToolTipText(Constants.ACTION_SAVE_DATA); |
|
1924 |
|
1925 // start subtest |
|
1926 startSubtest = new Action() { |
|
1927 @Override |
|
1928 public void run() { |
|
1929 startSubTest(); |
|
1930 } |
|
1931 }; |
|
1932 startSubtest.setText(Constants.ACTION_START_SUBTEST); |
|
1933 startSubtest.setToolTipText(Constants.ACTION_START_SUBTEST); |
|
1934 startSubtest.setImageDescriptor(Activator |
|
1935 .getImageDescriptor(Constants.BUTTON_START_SUBTEST)); |
|
1936 |
|
1937 // stop subtest |
|
1938 stopSubtest = new Action() { |
|
1939 @Override |
|
1940 public void run() { |
|
1941 stopSubTest(); |
|
1942 } |
|
1943 }; |
|
1944 stopSubtest.setText(Constants.ACTION_STOP_SUBTEST); |
|
1945 stopSubtest.setToolTipText(Constants.ACTION_STOP_SUBTEST); |
|
1946 stopSubtest.setImageDescriptor(Activator |
|
1947 .getImageDescriptor(Constants.BUTTON_STOP_SUBTEST)); |
|
1948 stopSubtest.setDescription(Constants.ACTION_STOP_SUBTEST); |
|
1949 |
|
1950 // set start and stop subtest not visible at the beginning |
|
1951 startSubtest.setEnabled(false); |
|
1952 stopSubtest.setEnabled(false); |
|
1953 |
|
1954 analyzeResults = new Action() { |
|
1955 @Override |
|
1956 public void run() { |
|
1957 analyzeDataFile(Constants.ANALYZE_ASK_FOR_USER, null, true); |
|
1958 } |
|
1959 }; |
|
1960 |
|
1961 analyzeResults.setText(Constants.ACTION_OPEN); |
|
1962 analyzeResults.setToolTipText(Constants.ACTION_OPEN); |
|
1963 analyzeResults.setImageDescriptor(Activator |
|
1964 .getImageDescriptor(Constants.BUTTON_OPEN)); |
|
1965 |
|
1966 clearProjectResults = new Action() { |
|
1967 @Override |
|
1968 public void run() { |
|
1969 cleanAnalyzeData(project); |
|
1970 if(statisticView != null ) { |
|
1971 statisticView.clean(project); |
|
1972 } |
|
1973 updateChangeDetailState(project); |
|
1974 } |
|
1975 }; |
|
1976 clearProjectResults.setText(Constants.ACTION_CLEAR_RESULTS); |
|
1977 clearProjectResults.setToolTipText(Constants.ACTION_CLEAR_RESULTS); |
|
1978 |
|
1979 refreshResults = new Action() { |
|
1980 @Override |
|
1981 public void run() { |
|
1982 if( project != null && project.isOpen() && projectResults != null ) { |
|
1983 String dataFile = projectResults.getDataFileName(project); |
|
1984 if( dataFile != null || !("").equals(dataFile) ) { |
|
1985 analyzeDataFile(Constants.ANALYZE_USE_DATA_FILE, dataFile, true); |
|
1986 } |
|
1987 else { |
|
1988 //some internal error occurred => disable this action |
|
1989 refreshResults.setEnabled(false); |
|
1990 } |
|
1991 |
|
1992 } |
|
1993 } |
|
1994 }; |
|
1995 refreshResults.setText(Constants.ACTION_RE_ANALYZE); |
|
1996 refreshResults.setToolTipText(Constants.ACTION_RE_ANALYZE_TOOLTIP); |
|
1997 refreshResults.setEnabled(false); |
|
1998 |
|
1999 //copy active item contents to clipboard |
|
2000 copyAction = new Action(){ |
|
2001 @Override |
|
2002 public void run() { |
|
2003 //copy active item contents to clipboard |
|
2004 |
|
2005 //Create new clipboard object |
|
2006 Clipboard cp = new Clipboard(runView.getControl().getDisplay()); |
|
2007 |
|
2008 //Create new TextTransfer object |
|
2009 //TextTransfer converts plain text represented as a java String to a platform specific representation of the data and vice versa |
|
2010 TextTransfer tt = TextTransfer.getInstance(); |
|
2011 |
|
2012 //new StringBuffer which contains the copied text |
|
2013 StringBuffer sb = new StringBuffer(64); |
|
2014 |
|
2015 // chech that project contains results |
|
2016 if( projectResults == null || !projectResults.contains(project) || activeTreeItem == null ) { |
|
2017 return; |
|
2018 } |
|
2019 //get active item info (also callstack info) |
|
2020 AnalysisItem item = null; |
|
2021 |
|
2022 // if selected item is subtest |
|
2023 if( activeTreeItem.isSubTest() ) { |
|
2024 item = projectResults.getSubtestItem(project, |
|
2025 activeTreeItem.getRunID(), activeTreeItem.getMemLeakID(), |
|
2026 activeTreeItem.getSubtestID()); |
|
2027 } |
|
2028 else { |
|
2029 item = projectResults.getSpecific(project, activeTreeItem.getRunID(), activeTreeItem.getMemLeakID()); |
|
2030 } |
|
2031 |
|
2032 // check that item found |
|
2033 if( item == null ) { |
|
2034 return; |
|
2035 } |
|
2036 |
|
2037 sb.append(activeTreeItem.getName()); |
|
2038 String separator = System.getProperty ( "line.separator" ); |
|
2039 sb.append(separator); |
|
2040 char space = ' '; |
|
2041 AbstractList<CallstackItem> callstackItems = item.getCallstackItems(); |
|
2042 Iterator<CallstackItem> iterCallstack = callstackItems.iterator(); |
|
2043 while( iterCallstack.hasNext() ) { |
|
2044 CallstackItem oneItem = iterCallstack.next(); |
|
2045 sb.append(" "); |
|
2046 sb.append(oneItem.getMemoryAddress()); |
|
2047 sb.append(space); |
|
2048 sb.append(oneItem.getModuleName()); |
|
2049 sb.append(space); |
|
2050 sb.append(oneItem.getFunctionName()); |
|
2051 sb.append(space); |
|
2052 sb.append(oneItem.getFileName()); |
|
2053 sb.append(space); |
|
2054 int lineNbr = oneItem.getLeakLineNumber(); |
|
2055 if( lineNbr > 0 ) { |
|
2056 sb.append(lineNbr); |
|
2057 } |
|
2058 sb.append(separator); |
|
2059 } |
|
2060 |
|
2061 //info is ready => now copy info to clipboard |
|
2062 cp.setContents(new Object[] { sb.toString() }, |
|
2063 new Transfer[] { tt }); |
|
2064 } |
|
2065 }; |
|
2066 copyAction.setText(Constants.ACTION_COPY); |
|
2067 copyAction.setEnabled(false); |
|
2068 |
|
2069 // open preferences action |
|
2070 openPrefs = new Action() { |
|
2071 @Override |
|
2072 public void run() { |
|
2073 PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
|
2074 Constants.ANALYZE_TOOL_PREFS_ID, null, null); |
|
2075 |
|
2076 if( dialog != null ) { |
|
2077 dialog.open(); |
|
2078 } |
|
2079 } |
|
2080 }; |
|
2081 openPrefs.setText(Constants.ACTION_OPEN_PREFS); |
|
2082 openPrefs.setToolTipText(Constants.ACTION_OPEN_PREFS_TOOLTIP); |
|
2083 openPrefs.setImageDescriptor(Activator.getImageDescriptor(Constants.BUTTON_OPEN_PREFS)); |
|
2084 |
|
2085 changeReportActionTooltip(); |
|
2086 updateChangeDetailState(project); |
|
2087 updateBuildState(project); |
|
2088 } |
|
2089 |
|
2090 /** |
|
2091 * Creates file open actions. |
|
2092 */ |
|
2093 private void makeFileOpenActions() { |
|
2094 fileOpenMenu.setText(Constants.ACTION_OPEN); |
|
2095 fileOpenMenu.setToolTipText(Constants.ACTION_OPEN); |
|
2096 fileOpenMenu.setImageDescriptor(Activator |
|
2097 .getImageDescriptor(Constants.BUTTON_OPEN)); |
|
2098 } |
|
2099 |
|
2100 /** |
|
2101 * Creates file open actions. |
|
2102 */ |
|
2103 private void makeLogTargetActions() { |
|
2104 |
|
2105 s60LogTargetAction = new Action(Constants.LOGGING_S60, Action.AS_RADIO_BUTTON) { |
|
2106 @Override |
|
2107 public void run() { |
|
2108 changeLogTarget(Constants.LOGGING_S60); |
|
2109 } |
|
2110 }; |
|
2111 s60LogTargetAction.setText(Constants.PREFS_S60); |
|
2112 s60LogTargetAction |
|
2113 .setToolTipText(Constants.ACTION_CHANGE_LOGGING_MODE_TOOLTIP_S60); |
|
2114 s60LogTargetAction.setImageDescriptor(Activator |
|
2115 .getImageDescriptor(Constants.BUTTON_CELLURAR)); |
|
2116 |
|
2117 externalLogTargetAction = new Action(Constants.LOGGING_EXT, Action.AS_RADIO_BUTTON) { |
|
2118 @Override |
|
2119 public void run() { |
|
2120 changeLogTarget(Constants.LOGGING_EXT); |
|
2121 } |
|
2122 }; |
|
2123 externalLogTargetAction.setText(Constants.PREFS_EXT); |
|
2124 externalLogTargetAction |
|
2125 .setToolTipText(Constants.ACTION_CHANGE_LOGGING_MODE_TOOLTIP_EXT); |
|
2126 externalLogTargetAction.setImageDescriptor(Activator |
|
2127 .getImageDescriptor(Constants.BUTTON_COMPUTER)); |
|
2128 |
|
2129 externalFastLogTargetAction = new Action(Constants.LOGGING_EXT_FAST, Action.AS_RADIO_BUTTON) { |
|
2130 @Override |
|
2131 public void run() { |
|
2132 changeLogTarget(Constants.LOGGING_EXT_FAST); |
|
2133 } |
|
2134 }; |
|
2135 externalFastLogTargetAction.setText(Constants.PREFS_EXT_FAST); |
|
2136 externalFastLogTargetAction.setToolTipText(Constants.PREFS_EXT_FAST_TOOLTIP); |
|
2137 externalFastLogTargetAction.setImageDescriptor(Activator |
|
2138 .getImageDescriptor(Constants.BUTTON_COMPUTER_FAST)); |
|
2139 |
|
2140 askLogTargetAction = new Action(Constants.LOGGING_ASK_ALLWAYS, Action.AS_RADIO_BUTTON) { |
|
2141 @Override |
|
2142 public void run() { |
|
2143 changeLogTarget(Constants.LOGGING_ASK_ALLWAYS); |
|
2144 } |
|
2145 }; |
|
2146 |
|
2147 |
|
2148 askLogTargetAction.setText(Constants.PREFS_ASK_ALWAYS); |
|
2149 askLogTargetAction |
|
2150 .setToolTipText(Constants.ACTION_CHANGE_LOGGING_MODE_TOOLTIP_ASK); |
|
2151 askLogTargetAction.setImageDescriptor(Activator |
|
2152 .getImageDescriptor(Constants.BUTTON_ASK)); |
|
2153 |
|
2154 } |
|
2155 |
|
2156 /** |
|
2157 * Opens current callstack item on default editor and pinpoints memory leak. |
|
2158 * line |
|
2159 * |
|
2160 * @param treeObject |
|
2161 * Tree object |
|
2162 */ |
|
2163 public final void openEditor(final TreeObject treeObject) { |
|
2164 // get file info for all projects |
|
2165 getFileInfos(project); |
|
2166 |
|
2167 try { |
|
2168 |
|
2169 // if no project selected |
|
2170 if (project == null || !project.isOpen()) { |
|
2171 Util.showMessage(Constants.NO_PROJ_SELECT); |
|
2172 return; |
|
2173 } |
|
2174 |
|
2175 // get selected call stack item |
|
2176 CallstackItem callstackItem = treeObject.getCallstackItem(); |
|
2177 if (callstackItem == null) { |
|
2178 return; |
|
2179 } |
|
2180 |
|
2181 String cppFileName = getCallstackItemName(callstackItem); |
|
2182 |
|
2183 if (cppFileName == null || ("").equals(cppFileName)) { |
|
2184 cppFileName = callstackItem.getFileName(); |
|
2185 } |
|
2186 |
|
2187 // if leak number is invalid => leave |
|
2188 if (callstackItem.getLeakLineNumber() < 1) { |
|
2189 return; |
|
2190 } |
|
2191 |
|
2192 String line = Integer.toString(callstackItem.getLeakLineNumber()); |
|
2193 |
|
2194 IFile file = null; |
|
2195 if (project.isOpen()) { |
|
2196 file = ResourcesPlugin.getWorkspace().getRoot().getFile( |
|
2197 new Path(project.getName() + "\\" + cppFileName)); |
|
2198 } |
|
2199 |
|
2200 // if file not found in active project |
|
2201 // go thru all open projects in current workbench |
|
2202 if (file == null || !file.exists()) { |
|
2203 IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace() |
|
2204 .getRoot(); |
|
2205 IProject[] projects = myWorkspaceRoot.getProjects(); |
|
2206 for (int i = 0; i < projects.length; i++) { |
|
2207 file = ResourcesPlugin.getWorkspace().getRoot() |
|
2208 .getFile( |
|
2209 new Path(projects[i].getName() + "\\" |
|
2210 + cppFileName)); |
|
2211 |
|
2212 // file found => skip the rest of the projects |
|
2213 if (file != null && file.exists()) { |
|
2214 break; |
|
2215 } |
|
2216 } |
|
2217 |
|
2218 } |
|
2219 |
|
2220 // if file still not found |
|
2221 // display info to user and leave |
|
2222 if (file == null || !file.exists()) { |
|
2223 Util.showMessage(Constants.SOURCE_NOT_FOUND); |
|
2224 return; |
|
2225 } |
|
2226 |
|
2227 IWorkbenchPage page = PlatformUI.getWorkbench() |
|
2228 .getActiveWorkbenchWindow().getActivePage(); |
|
2229 |
|
2230 HashMap<String, Object> map = new HashMap<String, Object>(); |
|
2231 map.put(IMarker.LINE_NUMBER, Integer.parseInt(line)); |
|
2232 map.put(IDE.EDITOR_ID_ATTR, Constants.SOURCE_FILE_EDITOR_ID); |
|
2233 IMarker marker = file.createMarker(IMarker.TEXT); |
|
2234 marker.setAttributes(map); |
|
2235 IDE.openEditor(page, marker); |
|
2236 |
|
2237 } catch (NullPointerException npe) { |
|
2238 npe.printStackTrace(); |
|
2239 } catch (CoreException ce) { |
|
2240 ce.printStackTrace(); |
|
2241 } catch (Exception e) { |
|
2242 e.printStackTrace(); |
|
2243 } |
|
2244 } |
|
2245 |
|
2246 /** |
|
2247 * Updates log target action and report action tooltips. |
|
2248 * |
|
2249 * @see com.nokia.s60tools.analyzetool.ui.IActionListener#preferenceChanged() |
|
2250 */ |
|
2251 public void preferenceChanged() { |
|
2252 // get active logging mode |
|
2253 changeLogTarget(null); |
|
2254 |
|
2255 changeReportActionTooltip(); |
|
2256 } |
|
2257 |
|
2258 /** |
|
2259 * Refresh AnalyzeTool view. |
|
2260 */ |
|
2261 public final void refreshView() { |
|
2262 // update display content |
|
2263 runView.getControl().getDisplay().syncExec(new Runnable() { |
|
2264 public void run() { |
|
2265 |
|
2266 updateInformationLabel(""); |
|
2267 |
|
2268 // refresh view |
|
2269 runView.setInput(getResults(false)); |
|
2270 |
|
2271 // refresh callstack view |
|
2272 getCallStack(activeTreeItem); |
|
2273 if( project != null && project.isOpen() && projectResults.contains(project)) { |
|
2274 clearProjectResults.setEnabled(true); |
|
2275 } |
|
2276 else { |
|
2277 clearProjectResults.setEnabled(false); |
|
2278 } |
|
2279 updateChangeDetailState(project); |
|
2280 |
|
2281 } |
|
2282 }); |
|
2283 } |
|
2284 |
|
2285 /** |
|
2286 * Runs user selected AnalyzeTool action. |
|
2287 * |
|
2288 * @see com.nokia.s60tools.analyzetool.ui.IActionListener#runAction(IProject, com.nokia.s60tools.analyzetool.global.Constants.ACTIONS) |
|
2289 * |
|
2290 * @param projectRef |
|
2291 * Project reference |
|
2292 * |
|
2293 * @param action |
|
2294 * Which action to execute |
|
2295 */ |
|
2296 public void runAction(IProject projectRef, Constants.ACTIONS action) { |
|
2297 project = projectRef; |
|
2298 |
|
2299 switch (action) { |
|
2300 case RUN_VIEW_MEM_LEAKS: |
|
2301 analyzeResults.run(); |
|
2302 break; |
|
2303 |
|
2304 case RUN_BUILD: |
|
2305 buildWithAtool.run(); |
|
2306 break; |
|
2307 |
|
2308 case RUN_CLEAN: |
|
2309 cleanAtoolChanges.run(); |
|
2310 break; |
|
2311 |
|
2312 default: // by design default statement is empty |
|
2313 break; |
|
2314 } |
|
2315 } |
|
2316 |
|
2317 /** |
|
2318 * Saves existing report or data file asks user where to save. |
|
2319 * |
|
2320 * @param type |
|
2321 * Which kind of type the file is. Possible types xml or data |
|
2322 * file |
|
2323 * |
|
2324 * @return True if saving successfully otherwise false |
|
2325 */ |
|
2326 public final boolean saveReportFile(final int type) { |
|
2327 // copy success? |
|
2328 boolean success = false; |
|
2329 |
|
2330 // check if project is selected |
|
2331 if (project == null) { |
|
2332 showMessage(Constants.NO_PROJ_SELECT); |
|
2333 return success; |
|
2334 } |
|
2335 |
|
2336 // folder location |
|
2337 String folder = null; |
|
2338 |
|
2339 // file path and name to use |
|
2340 String usedFile = null; |
|
2341 |
|
2342 // save xml file |
|
2343 if (type == Constants.SAVE_REPORT_FILE_XML) { |
|
2344 String targetPath = Util.getBldInfFolder(project, true) |
|
2345 + Constants.FILENAME_CARBIDE; |
|
2346 java.io.File file = new java.io.File(targetPath); |
|
2347 if (file.exists()) { |
|
2348 String[] names = new String[2]; |
|
2349 names[0] = "*.xml"; |
|
2350 names[1] = "*.*"; |
|
2351 |
|
2352 Shell shell = null; |
|
2353 |
|
2354 // get shell from teh active view |
|
2355 if (runView != null) { |
|
2356 shell = runView.getControl().getShell(); |
|
2357 } |
|
2358 |
|
2359 // if for some reason shell is null => leave |
|
2360 if (shell == null) { |
|
2361 return success; |
|
2362 } |
|
2363 |
|
2364 // ask user where to save xml report file |
|
2365 folder = Util.fileSaveDialog(Constants.DIALOG_SAVE_REPORT, |
|
2366 names, shell); |
|
2367 usedFile = targetPath; |
|
2368 } else { |
|
2369 Util.showMessage(Constants.INFO_NO_RESULTS_FILE); |
|
2370 return success; |
|
2371 } |
|
2372 |
|
2373 } |
|
2374 // save data file |
|
2375 else { |
|
2376 String dataFile = Util.isDataFileAvailable(project); |
|
2377 // check is there data file which can be used |
|
2378 if ((dataFile == null || dataFile.equals("")) |
|
2379 && (usedDataFileName == null || usedDataFileName.equals(""))) { |
|
2380 Util.showMessage(Constants.INFO_NO_DATA_FILE); |
|
2381 return success; |
|
2382 } |
|
2383 // if no existing data file opened |
|
2384 else if (usedDataFileName == null || usedDataFileName.equals("")) { |
|
2385 usedFile = dataFile; |
|
2386 |
|
2387 } |
|
2388 // user is already opened data file => save it |
|
2389 else { |
|
2390 usedFile = usedDataFileName; |
|
2391 } |
|
2392 |
|
2393 String[] names = new String[2]; |
|
2394 names[0] = "*.dat"; |
|
2395 names[1] = "*.*"; |
|
2396 |
|
2397 Shell shell = null; |
|
2398 |
|
2399 // get shell from teh active view |
|
2400 if (runView != null) { |
|
2401 shell = runView.getControl().getShell(); |
|
2402 } |
|
2403 |
|
2404 // if for some reason shell is null => leave |
|
2405 if (shell == null) { |
|
2406 return success; |
|
2407 } |
|
2408 |
|
2409 // ask user where to save xml report file |
|
2410 folder = Util.fileSaveDialog(Constants.DIALOG_SAVE_TRACE, names, |
|
2411 shell); |
|
2412 } |
|
2413 |
|
2414 // no folder selected |
|
2415 // user press "cancel" button; |
|
2416 if (folder == null) { |
|
2417 return success; |
|
2418 } |
|
2419 |
|
2420 // copy file to folder |
|
2421 success = Util.copyFileToFolder(usedFile, folder); |
|
2422 |
|
2423 // report to user |
|
2424 if (success) { |
|
2425 Util.showMessage(Constants.INFO_SAVE_SUCCESS + folder); |
|
2426 } else { |
|
2427 Util.showMessage(Constants.MAIN_CAN_NOT_COPY + usedFile); |
|
2428 } |
|
2429 return success; |
|
2430 } |
|
2431 |
|
2432 /** |
|
2433 * Notifies this action delegate that the selection in the workbench has |
|
2434 * changed. |
|
2435 * |
|
2436 * @param part |
|
2437 * Workbench part |
|
2438 * |
|
2439 * @param selection |
|
2440 * User selection |
|
2441 */ |
|
2442 @SuppressWarnings("restriction") |
|
2443 public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
|
2444 // project reference |
|
2445 IProject selectedProject = null; |
|
2446 |
|
2447 // check where the selection comes |
|
2448 // supported views: CommonNavigator and SymbianProjectNavigator |
|
2449 if (!(part instanceof org.eclipse.ui.navigator.CommonNavigator) ) { |
|
2450 return; |
|
2451 } |
|
2452 |
|
2453 // get selection |
|
2454 IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
|
2455 |
|
2456 // get first element of selection |
|
2457 Object element = structuredSelection.getFirstElement(); |
|
2458 |
|
2459 // check selection |
|
2460 if (element instanceof IAdaptable) { |
|
2461 IAdaptable adaptable = (IAdaptable) element; |
|
2462 |
|
2463 IResource resource = null; |
|
2464 if (adaptable instanceof IResource) { |
|
2465 resource = (IResource) adaptable; |
|
2466 } else if (adaptable instanceof org.eclipse.cdt.internal.ui.cview.IncludeRefContainer) { |
|
2467 selectedProject = ((org.eclipse.cdt.internal.ui.cview.IncludeRefContainer) adaptable) |
|
2468 .getCProject().getProject(); |
|
2469 } else if (adaptable instanceof org.eclipse.cdt.core.model.ICProject) { |
|
2470 selectedProject = ((org.eclipse.cdt.core.model.ICProject) adaptable) |
|
2471 .getProject(); |
|
2472 } else { |
|
2473 resource = (IResource) adaptable |
|
2474 .getAdapter(IResource.class); |
|
2475 } |
|
2476 |
|
2477 // resource found => get resource project |
|
2478 if (resource != null) { |
|
2479 selectedProject = resource.getProject(); |
|
2480 } |
|
2481 |
|
2482 } |
|
2483 // first item is null => update build state |
|
2484 else if (element == null) { |
|
2485 updateBuildState(null); |
|
2486 } |
|
2487 |
|
2488 // if project found and it is open => get project results |
|
2489 if (selectedProject != null && selectedProject.isOpen()) { |
|
2490 project = selectedProject; |
|
2491 getProjectResults(selectedProject); |
|
2492 updateBuildState(project); |
|
2493 if( statisticView != null ) { |
|
2494 statisticView.handleProjectChange(project); |
|
2495 } |
|
2496 } |
|
2497 } |
|
2498 |
|
2499 |
|
2500 /** |
|
2501 * Executes clicAction when user selects item in the AnalyzeTool view. |
|
2502 * |
|
2503 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) |
|
2504 * |
|
2505 * @param event |
|
2506 * Selection changed event |
|
2507 */ |
|
2508 public void selectionChanged(SelectionChangedEvent event) { |
|
2509 clickAction.run(); |
|
2510 } |
|
2511 |
|
2512 /** |
|
2513 * Passing the focus request to the viewer's control. |
|
2514 */ |
|
2515 @Override |
|
2516 public void setFocus() { |
|
2517 runView.getControl().setFocus(); |
|
2518 |
|
2519 } |
|
2520 |
|
2521 /** |
|
2522 * Sets text to information label. |
|
2523 */ |
|
2524 public final void setTextToInformationLabel() { |
|
2525 if (activeTreeItem == null) { |
|
2526 return; |
|
2527 } |
|
2528 |
|
2529 // run information |
|
2530 RunResults oneRunResults = projectResults.getRun(project, |
|
2531 activeTreeItem.getRunID()); |
|
2532 |
|
2533 // no results found => update label |
|
2534 if (oneRunResults == null) { |
|
2535 updateInformationLabel(""); |
|
2536 } else { |
|
2537 StringBuffer buffer = new StringBuffer(32); |
|
2538 buffer.append("Run: "); |
|
2539 buffer.append(oneRunResults.getItemID()); |
|
2540 |
|
2541 buffer.append(" Memory leaks: "); |
|
2542 buffer.append(oneRunResults.getAnalysisItems().size()); |
|
2543 buffer.append(" Handle leaks: "); |
|
2544 buffer.append(oneRunResults.getHandleLeaks().size()); |
|
2545 if (("").equals(oneRunResults.getEndTime())) { |
|
2546 buffer.append("\nStart time: " + oneRunResults.getStartTime() |
|
2547 + " \nEnd time: FAILED"); |
|
2548 } else { |
|
2549 buffer.append("\nStart time: " + oneRunResults.getStartTime() |
|
2550 + " \nEnd time: " + oneRunResults.getEndTime()); |
|
2551 } |
|
2552 |
|
2553 updateInformationLabel(buffer.toString()); |
|
2554 |
|
2555 } |
|
2556 |
|
2557 } |
|
2558 |
|
2559 /** |
|
2560 * Shows error message. |
|
2561 * |
|
2562 * @param message |
|
2563 * Error message to show |
|
2564 */ |
|
2565 public final void showErrorMessage(final String message) { |
|
2566 runView.getControl().getDisplay().syncExec(new Runnable() { |
|
2567 public void run() { |
|
2568 Util.showErrorMessage(message); |
|
2569 } |
|
2570 }); |
|
2571 } |
|
2572 |
|
2573 /** |
|
2574 * Shows message. |
|
2575 * |
|
2576 * @param message |
|
2577 * Message to show |
|
2578 */ |
|
2579 public final void showMessage(final String message) { |
|
2580 runView.getControl().getDisplay().syncExec(new Runnable() { |
|
2581 public void run() { |
|
2582 Util.showMessage(message); |
|
2583 } |
|
2584 }); |
|
2585 } |
|
2586 |
|
2587 /** |
|
2588 * Starts traceviewer connection. |
|
2589 */ |
|
2590 private void start() { |
|
2591 // check is project selected and open |
|
2592 if (!checkProjectValidity()) { |
|
2593 return; |
|
2594 } |
|
2595 |
|
2596 // get project file infos |
|
2597 getFileInfos(project); |
|
2598 |
|
2599 String dataFile = Util.isDataFileAvailable(project); |
|
2600 // if data file already exists, ask for overwrite |
|
2601 if (dataFile != null && !dataFile.equalsIgnoreCase("")) { |
|
2602 int saveDataFiles = Util |
|
2603 .openConfirmationDialogWithCancel(Constants.CONFIRM_OVERWRITE_FILE); |
|
2604 if (saveDataFiles == Constants.SAVE_DATA_FILE) { |
|
2605 if (!saveReportFile(Constants.SAVE_REPORT_FILE_DATA)) { |
|
2606 return; |
|
2607 } |
|
2608 } else if (saveDataFiles == Constants.SAVE_DATA_FILE_CANCEL) { |
|
2609 // user press "Cancel" so return and do nothing |
|
2610 return; |
|
2611 } |
|
2612 |
|
2613 // delete existing data file |
|
2614 Util.deleteDataFile(project); |
|
2615 } |
|
2616 |
|
2617 ICarbideProjectInfo info = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project); |
|
2618 ICarbideBuildConfiguration config = info.getDefaultConfiguration(); |
|
2619 |
|
2620 //start listening emulator output |
|
2621 if( config.getPlatformString().equals(Constants.BUILD_TARGET_WINSCW) ) { |
|
2622 |
|
2623 listeningJob = new EpocReader(project, this); |
|
2624 listeningJob.start(); |
|
2625 |
|
2626 traceStarted(); |
|
2627 |
|
2628 return; |
|
2629 } |
|
2630 |
|
2631 // else start trace capturing using Tracing utility connection |
|
2632 |
|
2633 // main view class instance |
|
2634 // this instance if passed to the TraceWrapper class |
|
2635 final MainView selfInstance = this; |
|
2636 Job activateTrace = new Job(Constants.STARTING_TRACE) { |
|
2637 @Override |
|
2638 protected IStatus run(IProgressMonitor monitor) { |
|
2639 try { |
|
2640 |
|
2641 // update progress monitor state |
|
2642 monitor.beginTask(Constants.STARTING_TRACE, |
|
2643 IProgressMonitor.UNKNOWN); |
|
2644 |
|
2645 // load TraceWrapper class |
|
2646 Class<?> buildManagerClass = Class |
|
2647 .forName("com.nokia.s60tools.analyzetool.trace.TraceWrapper"); |
|
2648 |
|
2649 // get TraceWrapper class available methods |
|
2650 java.lang.reflect.Method[] methods = buildManagerClass |
|
2651 .getMethods(); |
|
2652 |
|
2653 // thru methods |
|
2654 for (int i = 0; i < methods.length; i++) { |
|
2655 // get one method |
|
2656 java.lang.reflect.Method oneMethod = methods[i]; |
|
2657 |
|
2658 // if method name is "connect" |
|
2659 if (oneMethod.getName().equalsIgnoreCase("connect")) { |
|
2660 |
|
2661 // parameters for the connect method |
|
2662 Object[] objs = new Object[1]; |
|
2663 objs[0] = selfInstance; |
|
2664 |
|
2665 // call connect method |
|
2666 String returnValue = (String) oneMethod.invoke( |
|
2667 buildManagerClass.newInstance(), objs); |
|
2668 |
|
2669 // if there was no errors while connection |
|
2670 if (("").equals(returnValue)) { |
|
2671 |
|
2672 // invoke parser to open needed streams |
|
2673 parser.openStreams(Util.getBldInfFolder( |
|
2674 project, true)); |
|
2675 |
|
2676 traceStarted(); |
|
2677 } else { |
|
2678 traceAction |
|
2679 .setImageDescriptor(Activator |
|
2680 .getImageDescriptor((Constants.BUTTON_RUN))); |
|
2681 traceActive = false; |
|
2682 |
|
2683 showErrorMessage(returnValue); |
|
2684 } |
|
2685 } |
|
2686 } |
|
2687 } catch (ClassNotFoundException cnfe) { |
|
2688 cnfe.printStackTrace(); |
|
2689 |
|
2690 } catch (SecurityException se) { |
|
2691 se.printStackTrace(); |
|
2692 |
|
2693 } catch (IllegalAccessException iae) { |
|
2694 iae.printStackTrace(); |
|
2695 |
|
2696 } catch (IllegalArgumentException iare) { |
|
2697 iare.printStackTrace(); |
|
2698 |
|
2699 } catch (java.lang.reflect.InvocationTargetException ite) { |
|
2700 ite.printStackTrace(); |
|
2701 |
|
2702 } catch (InstantiationException iv) { |
|
2703 iv.printStackTrace(); |
|
2704 } |
|
2705 |
|
2706 return new Status(IStatus.OK, Constants.ANALYZE_CONSOLE_ID, |
|
2707 IStatus.OK, "Trace started", null); |
|
2708 } |
|
2709 }; |
|
2710 activateTrace.setUser(true); |
|
2711 activateTrace.schedule(); |
|
2712 |
|
2713 } |
|
2714 |
|
2715 /** |
|
2716 * Starts subtests. |
|
2717 */ |
|
2718 public final void startSubTest() { |
|
2719 // get started processes |
|
2720 Hashtable<String, Integer> startedPros = null; |
|
2721 |
|
2722 // if parser exists => means that the tracing is started and processes |
|
2723 // info is available |
|
2724 if (parser != null) { |
|
2725 startedPros = parser.getStartedProcesses(); |
|
2726 } |
|
2727 |
|
2728 // no processes = >show info and leave |
|
2729 if (startedPros == null || startedPros.isEmpty()) { |
|
2730 Util.showMessage(Constants.SUBTEST_NO_PROCESSES); |
|
2731 return; |
|
2732 } |
|
2733 |
|
2734 // get started target info |
|
2735 AbstractList<String> targets = new ArrayList<String>(); |
|
2736 for (java.util.Enumeration<String> e = startedPros.keys(); e |
|
2737 .hasMoreElements();) { |
|
2738 String processName = e.nextElement(); |
|
2739 targets.add(processName); |
|
2740 } |
|
2741 |
|
2742 // used target |
|
2743 String target = null; |
|
2744 |
|
2745 // processes found, print info to user |
|
2746 if (targets.size() == 1) { |
|
2747 target = targets.get(0); |
|
2748 } else { |
|
2749 target = Util.openSelectionDialog(Constants.SUBTEST_SELECT_TARGET, |
|
2750 Constants.SUBTEST_RUNNING_PROCESSES_INFO, targets); |
|
2751 |
|
2752 } |
|
2753 if (target == null || ("").equals(target) ) { |
|
2754 return; |
|
2755 } |
|
2756 |
|
2757 // ask for subtest name |
|
2758 CustomInputDialog dialog = new CustomInputDialog( |
|
2759 Constants.ANALYZE_TOOL_TITLE, Constants.SUBTEST_INPUT_NAME, ""); |
|
2760 dialog.open(); |
|
2761 String subTestName = dialog.getUserInput(); |
|
2762 |
|
2763 if (subTestName == null || subTestName.length() == 0) { |
|
2764 return; |
|
2765 } |
|
2766 |
|
2767 // get process id for selected target |
|
2768 int processID = startedPros.get(target); |
|
2769 |
|
2770 // if subtest allready exists |
|
2771 if (isSubtestExists(subTestName, target)) { |
|
2772 Util.showMessage(Constants.SUBTEST_ALLREADY_RUNNING); |
|
2773 return; |
|
2774 } |
|
2775 |
|
2776 // create new subtes object and add it to AbstractList |
|
2777 ActiveSubtests subtes = new ActiveSubtests(subTestName, target, |
|
2778 processID); |
|
2779 startedSubtest.add(subtes); |
|
2780 |
|
2781 // start subtest |
|
2782 parser.parse(Constants.PREFIX + " " + processID + " TEST_START 0000 " |
|
2783 + subTestName); |
|
2784 updateSubtestInfoText(Constants.SUBTEST_STARTED + target |
|
2785 + Constants.ENRULE + subTestName); |
|
2786 |
|
2787 stopSubtest.setEnabled(true); |
|
2788 } |
|
2789 |
|
2790 /** |
|
2791 * Stop external message tracing. |
|
2792 */ |
|
2793 public final void stop(boolean analyze) { |
|
2794 |
|
2795 ICarbideProjectInfo info = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project); |
|
2796 ICarbideBuildConfiguration config = info.getDefaultConfiguration(); |
|
2797 if( config.getPlatformString().equalsIgnoreCase(Constants.BUILD_TARGET_WINSCW) ) { |
|
2798 listeningJob.stop(); |
|
2799 traceStopped(analyze); |
|
2800 return; |
|
2801 } |
|
2802 |
|
2803 //else stop Tracing utility connection |
|
2804 try { |
|
2805 Class<?> buildManagerClass = Class |
|
2806 .forName("com.nokia.s60tools.analyzetool.trace.TraceWrapper"); |
|
2807 |
|
2808 java.lang.reflect.Method[] methods = buildManagerClass.getMethods(); |
|
2809 for (int i = 0; i < methods.length; i++) { |
|
2810 java.lang.reflect.Method oneMethod = methods[i]; |
|
2811 if (oneMethod.getName().equalsIgnoreCase("disconnect")) { |
|
2812 |
|
2813 Object[] objs = new Object[1]; |
|
2814 objs[0] = this; |
|
2815 String returnValue = (String) oneMethod.invoke( |
|
2816 buildManagerClass.newInstance(), new Object[] {}); |
|
2817 if (("").equals(returnValue)) { |
|
2818 traceStopped(analyze); |
|
2819 } else { |
|
2820 showErrorMessage("Error while disconnecting Tracing utility"); |
|
2821 traceAction.setImageDescriptor(Activator |
|
2822 .getImageDescriptor((Constants.BUTTON_STOP))); |
|
2823 traceActive = true; |
|
2824 } |
|
2825 } |
|
2826 } |
|
2827 } catch (ClassNotFoundException cnfe) { |
|
2828 cnfe.printStackTrace(); |
|
2829 |
|
2830 } catch (SecurityException se) { |
|
2831 se.printStackTrace(); |
|
2832 |
|
2833 } catch (IllegalAccessException iae) { |
|
2834 iae.printStackTrace(); |
|
2835 |
|
2836 } catch (IllegalArgumentException iare) { |
|
2837 iare.printStackTrace(); |
|
2838 |
|
2839 } catch (java.lang.reflect.InvocationTargetException ite) { |
|
2840 ite.printStackTrace(); |
|
2841 |
|
2842 } catch (InstantiationException iv) { |
|
2843 iv.printStackTrace(); |
|
2844 } |
|
2845 |
|
2846 } |
|
2847 |
|
2848 /** |
|
2849 * Updates button states and creates results for project. |
|
2850 */ |
|
2851 private void traceStopped(boolean analyze) { |
|
2852 // update icon and information text |
|
2853 traceAction.setImageDescriptor(Activator |
|
2854 .getImageDescriptor((Constants.BUTTON_RUN))); |
|
2855 traceAction.setText(Constants.ACTION_START_TRACE); |
|
2856 traceAction |
|
2857 .setToolTipText(Constants.ACTION_START_TRACE); |
|
2858 traceActive = false; |
|
2859 |
|
2860 // close any active subtests |
|
2861 if (!startedSubtest.isEmpty()) { |
|
2862 for (int j = 0; j < startedSubtest.size(); j++) { |
|
2863 ActiveSubtests oneSubtest = startedSubtest |
|
2864 .get(j); |
|
2865 parser.parse(Constants.PREFIX + " " |
|
2866 + oneSubtest.getProcessID() |
|
2867 + " TEST_END" + " 0000 " |
|
2868 + oneSubtest.getName()); |
|
2869 } |
|
2870 startedSubtest.clear(); |
|
2871 } |
|
2872 |
|
2873 // tell parser to finish => write data to file |
|
2874 parser.finish(); |
|
2875 |
|
2876 // inform user |
|
2877 updateLabel(Constants.INFO_TRACE_STOP); |
|
2878 |
|
2879 // set start and stop trace not visible |
|
2880 startSubtest.setEnabled(false); |
|
2881 stopSubtest.setEnabled(false); |
|
2882 fileOpenMenu.setEnabled(true); |
|
2883 saveFileMenu.setEnabled(true); |
|
2884 cleanAtoolChanges.setEnabled(true); |
|
2885 |
|
2886 project = traceStartedProjectRef; |
|
2887 |
|
2888 // parse and analyze saved data file |
|
2889 if( analyze ) { |
|
2890 analyzeDataFile(Constants.ANALYZE_USE_DATA_FILE, null, |
|
2891 true); |
|
2892 } |
|
2893 } |
|
2894 |
|
2895 /** |
|
2896 * Stop one subtest If there multiple subtest running ask for user to which |
|
2897 * one to stop. |
|
2898 */ |
|
2899 public final void stopSubTest() { |
|
2900 // no processes show info |
|
2901 if (startedSubtest.isEmpty()) { |
|
2902 Util.showMessage(Constants.SUBTEST_NO_SUBTESTS); |
|
2903 } else { |
|
2904 // only one subtest no need to ask for users |
|
2905 if (startedSubtest.size() == 1) { |
|
2906 ActiveSubtests oneSubtest = startedSubtest.get(0); |
|
2907 parser.parse(Constants.PREFIX + " " + oneSubtest.getProcessID() |
|
2908 + " TEST_END" + " 0000 " + oneSubtest.getName()); |
|
2909 updateSubtestInfoText(Constants.SUBTEST_ENDED |
|
2910 + oneSubtest.getTargetName() + Constants.ENRULE |
|
2911 + oneSubtest.getName()); |
|
2912 startedSubtest.remove(0); |
|
2913 stopSubtest.setEnabled(false); |
|
2914 } else { // multiple subtest found ask for the user which to stop |
|
2915 // multiple subtest found ask for user which to be ended |
|
2916 AbstractList<String> tmpSubtest = new ArrayList<String>(); |
|
2917 |
|
2918 // get list of active subtests |
|
2919 for (int i = 0; i < startedSubtest.size(); i++) { |
|
2920 ActiveSubtests oneSubtest = startedSubtest.get(i); |
|
2921 String tmpStr = oneSubtest.getTargetName() |
|
2922 + Constants.ENRULE + oneSubtest.getName(); |
|
2923 tmpSubtest.add(tmpStr); |
|
2924 } |
|
2925 |
|
2926 String selection = Util.openSelectionDialog( |
|
2927 Constants.SUBTEST_SELECT_SUBTEST_TO_STOP, null, |
|
2928 tmpSubtest); |
|
2929 // thru active subtests |
|
2930 for (int k = 0; k < startedSubtest.size(); k++) { |
|
2931 // get one subtest |
|
2932 ActiveSubtests oneSubtest = startedSubtest.get(k); |
|
2933 |
|
2934 // split user selected subtest information to get subtest |
|
2935 // name |
|
2936 String[] splittedText = selection.split(" "); |
|
2937 |
|
2938 // if user selected subtest name and current subtest equals |
|
2939 if (splittedText[2].equals(oneSubtest.getName())) { |
|
2940 // write subtest end tag to data file |
|
2941 parser.parse(Constants.PREFIX + " " |
|
2942 + oneSubtest.getProcessID() + " TEST_END" |
|
2943 + " 0000 " + oneSubtest.getName()); |
|
2944 updateSubtestInfoText(Constants.SUBTEST_ENDED |
|
2945 + oneSubtest.getTargetName() + Constants.ENRULE |
|
2946 + oneSubtest.getName()); |
|
2947 // remove current subtest from active subtest |
|
2948 // AbstractList |
|
2949 startedSubtest.remove(k); |
|
2950 break; |
|
2951 } |
|
2952 } |
|
2953 |
|
2954 if (startedSubtest.isEmpty()) { |
|
2955 stopSubtest.setEnabled(false); |
|
2956 } |
|
2957 } |
|
2958 } |
|
2959 } |
|
2960 |
|
2961 /** |
|
2962 * When AnalyzeTool view tree model is collapsed. |
|
2963 * |
|
2964 * @see org.eclipse.jface.viewers.ITreeViewerListener#treeCollapsed(org.eclipse.jface.viewers.TreeExpansionEvent) |
|
2965 * |
|
2966 * @param event |
|
2967 * Tree expansion event |
|
2968 */ |
|
2969 public void treeCollapsed(TreeExpansionEvent event) { |
|
2970 // MethodDeclaration/Block[count(BlockStatement) = 0 and |
|
2971 // @containsComment = 'false'] |
|
2972 } |
|
2973 |
|
2974 /** |
|
2975 * When AnalyzeTool view tree model is expanded. |
|
2976 * |
|
2977 * @see org.eclipse.jface.viewers.ITreeViewerListener#treeExpanded(org.eclipse.jface.viewers.TreeExpansionEvent) |
|
2978 * |
|
2979 * @param event |
|
2980 * Tree expansion event |
|
2981 */ |
|
2982 public void treeExpanded(TreeExpansionEvent event) { |
|
2983 // MethodDeclaration/Block[count(BlockStatement) = 0 and |
|
2984 // @containsComment = 'false'] |
|
2985 } |
|
2986 |
|
2987 /** |
|
2988 * Updates allocation count in the information label. |
|
2989 * |
|
2990 * The information layout is hard to modify so we need to manage information |
|
2991 * label text |
|
2992 */ |
|
2993 public final void updateAllocNumber() { |
|
2994 |
|
2995 runView.getControl().getDisplay().syncExec(new Runnable() { |
|
2996 public void run() { |
|
2997 |
|
2998 // if lable is created |
|
2999 if (informationLabel != null) { |
|
3000 // get existing label text |
|
3001 String tmpText = informationLabel.getText(); |
|
3002 |
|
3003 // split existing text |
|
3004 String[] strArray = tmpText.split(lineFeed); |
|
3005 |
|
3006 // if text contains more than 3 lines |
|
3007 if (strArray.length >= 2) { |
|
3008 // create new buffer |
|
3009 StringBuffer tmpBuffer = new StringBuffer( |
|
3010 strArray.length); |
|
3011 |
|
3012 // set memory allocation size |
|
3013 strArray[1] = Constants.INFO_ALLOCATED_MEM |
|
3014 + parser.getAllocationsSize(); |
|
3015 |
|
3016 // get updated text to buffer |
|
3017 for (int i = 0; i < strArray.length; i++) { |
|
3018 tmpBuffer.append(strArray[i]); |
|
3019 tmpBuffer.append(lineFeed); |
|
3020 } |
|
3021 |
|
3022 // set new text to information label |
|
3023 informationLabel.setText(tmpBuffer.toString()); |
|
3024 } else { |
|
3025 informationLabel.setText(tmpText + lineFeed |
|
3026 + Constants.INFO_ALLOCATED_MEM |
|
3027 + parser.getAllocationsSize()); |
|
3028 } |
|
3029 |
|
3030 } |
|
3031 |
|
3032 } |
|
3033 }); |
|
3034 |
|
3035 } |
|
3036 |
|
3037 /** |
|
3038 * Update build action icon and tooltip text. |
|
3039 * |
|
3040 * @param projectRef |
|
3041 * Project reference |
|
3042 */ |
|
3043 public final void updateBuildState(final IProject projectRef) { |
|
3044 if (buildWithAtool == null) { |
|
3045 return; |
|
3046 } |
|
3047 |
|
3048 BuilderUtil util = new BuilderUtil(); |
|
3049 |
|
3050 // if project is not selected |
|
3051 if (projectRef == null) { |
|
3052 buildWithAtool.setText(Constants.ACTION_AT_BUILD_DEACTIVE); |
|
3053 buildWithAtool.setToolTipText(Constants.ACTION_AT_BUILD_DEACTIVE); |
|
3054 buildWithAtool.setChecked(false); |
|
3055 } |
|
3056 // if AnalyzeTool build is enabled |
|
3057 else if (util.isNatureEnabled(projectRef)) { |
|
3058 buildWithAtool.setText(Constants.ACTION_AT_BUILD_ACTIVE); |
|
3059 buildWithAtool.setToolTipText(Constants.ACTION_AT_BUILD_ACTIVE); |
|
3060 buildWithAtool.setChecked(true); |
|
3061 } else { |
|
3062 buildWithAtool.setText(Constants.ACTION_AT_BUILD_DEACTIVE); |
|
3063 buildWithAtool.setToolTipText(Constants.ACTION_AT_BUILD_DEACTIVE); |
|
3064 buildWithAtool.setChecked(false); |
|
3065 } |
|
3066 |
|
3067 } |
|
3068 |
|
3069 /** |
|
3070 * Indicates the target (emulator/device) by inspecting the given projects build configuration. |
|
3071 * @param selectedProject the currently active project |
|
3072 * @return "emulator" if the build configuration is WINSCW, "device" otherwise |
|
3073 */ |
|
3074 private static String getTraceTarget(final IProject selectedProject) { |
|
3075 String target = ""; |
|
3076 if (selectedProject != null && selectedProject.isOpen()) { |
|
3077 ICarbideProjectInfo info = CarbideBuilderPlugin.getBuildManager().getProjectInfo(selectedProject); |
|
3078 if (info != null) { |
|
3079 ICarbideBuildConfiguration config = info.getDefaultConfiguration(); |
|
3080 target = config.getPlatformString().equals( |
|
3081 Constants.BUILD_TARGET_WINSCW) ? Constants.INFO_TRACE_FROM_EMULATOR : Constants.INFO_TRACE_FROM_DEVICE; |
|
3082 } |
|
3083 } |
|
3084 return target; |
|
3085 } |
|
3086 |
|
3087 /** |
|
3088 * Update change detail action state. |
|
3089 * |
|
3090 * @param projectRef |
|
3091 * Current project |
|
3092 */ |
|
3093 public final void updateChangeDetailState(final IProject projectRef) { |
|
3094 if (changeDetails == null) { |
|
3095 return; |
|
3096 } |
|
3097 |
|
3098 if (projectRef == null) { |
|
3099 changeDetails.setEnabled(false); |
|
3100 refreshResults.setEnabled(false); |
|
3101 return; |
|
3102 } else if (projectResults.contains(projectRef)) { |
|
3103 changeDetails.setEnabled(true); |
|
3104 } else { |
|
3105 changeDetails.setEnabled(false); |
|
3106 } |
|
3107 |
|
3108 String dataFile = projectResults.getDataFileName(projectRef); |
|
3109 if( dataFile != null ) { |
|
3110 int fileType = UseAtool.checkFileType(dataFile); |
|
3111 if( fileType == Constants.DATAFILE_TRACE || fileType == Constants.DATAFILE_LOG ) { |
|
3112 refreshResults.setEnabled(true); |
|
3113 } |
|
3114 else { |
|
3115 refreshResults.setEnabled(false); |
|
3116 } |
|
3117 } |
|
3118 else { |
|
3119 refreshResults.setEnabled(false); |
|
3120 } |
|
3121 } |
|
3122 |
|
3123 /** |
|
3124 * Sets information to the information label. |
|
3125 * |
|
3126 * @param infoText |
|
3127 * Info text |
|
3128 */ |
|
3129 private void updateInformationLabel(final String infoText) { |
|
3130 // trace is active => do not update information label |
|
3131 if (traceActive) { |
|
3132 return; |
|
3133 } |
|
3134 |
|
3135 // sync with the UI thread |
|
3136 runView.getControl().getDisplay().syncExec(new Runnable() { |
|
3137 public void run() { |
|
3138 // if informationlabel exists set text |
|
3139 if (informationLabel != null) { |
|
3140 informationLabel.setText(infoText); |
|
3141 } |
|
3142 } |
|
3143 }); |
|
3144 } |
|
3145 |
|
3146 /** |
|
3147 * Updates label by given string. |
|
3148 * |
|
3149 * @param line |
|
3150 * String to display |
|
3151 */ |
|
3152 public final void updateLabel(final String line) { |
|
3153 |
|
3154 final String oneLine = line; |
|
3155 |
|
3156 runView.getControl().getDisplay().syncExec(new Runnable() { |
|
3157 public void run() { |
|
3158 // if informationlabel exists set text |
|
3159 if (informationLabel != null) { |
|
3160 informationLabel.setText(oneLine); |
|
3161 } |
|
3162 |
|
3163 } |
|
3164 }); |
|
3165 |
|
3166 } |
|
3167 |
|
3168 /** |
|
3169 * Updates Subtest info to the information label. |
|
3170 * |
|
3171 * The information layout is hard to modify so we need to manage information |
|
3172 * label text |
|
3173 * |
|
3174 * @param text |
|
3175 * New label text |
|
3176 */ |
|
3177 private void updateSubtestInfoText(final String text) { |
|
3178 final String newText = text; |
|
3179 |
|
3180 runView.getControl().getDisplay().syncExec(new Runnable() { |
|
3181 public void run() { |
|
3182 |
|
3183 // if label exists |
|
3184 if (informationLabel != null) { |
|
3185 // get existing label text |
|
3186 String origText = informationLabel.getText(); |
|
3187 |
|
3188 // split existing text |
|
3189 String[] strArray = origText.split(lineFeed); |
|
3190 |
|
3191 // create new buffer |
|
3192 StringBuffer tmpBuffer = new StringBuffer(strArray.length); |
|
3193 if (strArray.length >= 3) { |
|
3194 // update text |
|
3195 strArray[2] = newText; |
|
3196 |
|
3197 // get updated text to buffer |
|
3198 for (int i = 0; i < strArray.length; i++) { |
|
3199 tmpBuffer.append(strArray[i]); |
|
3200 tmpBuffer.append(lineFeed); |
|
3201 } |
|
3202 // set new text to information label |
|
3203 informationLabel.setText(tmpBuffer.toString()); |
|
3204 } else { |
|
3205 informationLabel.setText(origText + newText); |
|
3206 } |
|
3207 |
|
3208 } |
|
3209 |
|
3210 } |
|
3211 }); |
|
3212 } |
|
3213 |
|
3214 /** |
|
3215 * Updates button states, clears existing project data and updating view. |
|
3216 */ |
|
3217 private void traceStarted() { |
|
3218 // clear view contents |
|
3219 cleanAnalyzeData(project); |
|
3220 clearCallstackViewContent(); |
|
3221 traceStartedProjectRef = project; |
|
3222 |
|
3223 // change icon and information text |
|
3224 traceAction |
|
3225 .setImageDescriptor(Activator |
|
3226 .getImageDescriptor((Constants.BUTTON_STOP))); |
|
3227 traceAction |
|
3228 .setText(Constants.ACTION_STOP_TRACE); |
|
3229 traceAction |
|
3230 .setToolTipText(Constants.ACTION_STOP_TRACE); |
|
3231 traceActive = true; |
|
3232 |
|
3233 String fromTarget = getTraceTarget(traceStartedProjectRef); |
|
3234 updateLabel(fromTarget.length()==0 ? Constants.INFO_TRACE_START : String.format(Constants.INFO_TRACE_FROM_TARGET_START, fromTarget)); |
|
3235 // add2UserActionHistory( "Trace started for |
|
3236 // project: " |
|
3237 // +project.getName() +" at "+ Util.getTime() ); |
|
3238 |
|
3239 // set start and stop subtest visible |
|
3240 startSubtest.setEnabled(true); |
|
3241 stopSubtest.setEnabled(false); |
|
3242 fileOpenMenu.setEnabled(false); |
|
3243 saveFileMenu.setEnabled(false); |
|
3244 cleanAtoolChanges.setEnabled(false); |
|
3245 |
|
3246 updateAllocNumber(); |
|
3247 } |
|
3248 |
|
3249 /** |
|
3250 * Overrided method to capture keyevents. |
|
3251 * |
|
3252 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent) |
|
3253 */ |
|
3254 public void keyPressed(KeyEvent e) { |
|
3255 |
|
3256 // C key address(hex) |
|
3257 final int CTRL_C = 0x3; |
|
3258 |
|
3259 // key event character |
|
3260 int charValue = e.character; |
|
3261 |
|
3262 // c key pressed |
|
3263 boolean cPressed = (charValue == CTRL_C); // This should be enough |
|
3264 |
|
3265 // ctrl key pressed |
|
3266 boolean ctrlPressed = (e.stateMask & SWT.CTRL) != 0; |
|
3267 |
|
3268 //if ctrl and c key pressed => run copy action |
|
3269 if(ctrlPressed & cPressed){ |
|
3270 // Triggering copy action |
|
3271 copyAction.run(); |
|
3272 } |
|
3273 |
|
3274 } |
|
3275 |
|
3276 /** |
|
3277 * (non-Javadoc) |
|
3278 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent) |
|
3279 */ |
|
3280 public void keyReleased(KeyEvent e) { |
|
3281 // This method is overrided |
|
3282 } |
|
3283 } |