sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/ui/statistic/StatisticView.java
changeset 1 1050670c6980
child 6 f65f740e69f9
equal deleted inserted replaced
0:5ad7ad99af01 1:1050670c6980
       
     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 StatisticView
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.s60tools.analyzetool.ui.statistic;
       
    19 
       
    20 import java.util.AbstractList;
       
    21 import java.util.ArrayList;
       
    22 import java.util.HashMap;
       
    23 import java.util.Iterator;
       
    24 import java.util.Locale;
       
    25 import java.util.Calendar;
       
    26 
       
    27 import org.eclipse.core.resources.IFile;
       
    28 import org.eclipse.core.resources.IMarker;
       
    29 import org.eclipse.core.resources.IProject;
       
    30 import org.eclipse.core.resources.IResource;
       
    31 import org.eclipse.core.resources.IWorkspaceRoot;
       
    32 import org.eclipse.core.resources.ResourcesPlugin;
       
    33 import org.eclipse.core.runtime.CoreException;
       
    34 import org.eclipse.core.runtime.Path;
       
    35 import org.eclipse.swt.SWT;
       
    36 import org.eclipse.swt.custom.CTabFolder;
       
    37 import org.eclipse.swt.custom.CTabItem;
       
    38 import org.eclipse.swt.custom.SashForm;
       
    39 import org.eclipse.swt.events.MouseEvent;
       
    40 import org.eclipse.swt.events.MouseListener;
       
    41 import org.eclipse.swt.events.SelectionEvent;
       
    42 import org.eclipse.swt.events.SelectionListener;
       
    43 import org.eclipse.swt.layout.GridData;
       
    44 import org.eclipse.swt.widgets.Button;
       
    45 import org.eclipse.swt.widgets.Combo;
       
    46 import org.eclipse.swt.widgets.Label;
       
    47 import org.eclipse.swt.widgets.Table;
       
    48 import org.eclipse.swt.widgets.TableColumn;
       
    49 import org.eclipse.swt.widgets.TableItem;
       
    50 import org.eclipse.ui.IWorkbenchPage;
       
    51 import org.eclipse.ui.PartInitException;
       
    52 import org.eclipse.ui.PlatformUI;
       
    53 import org.eclipse.ui.ide.IDE;
       
    54 
       
    55 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
       
    56 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
       
    57 import com.nokia.cdt.debug.cw.symbian.symbolreader.IFunction;
       
    58 import com.nokia.cdt.debug.cw.symbian.symbolreader.ISourceLocation;
       
    59 import com.nokia.cdt.debug.cw.symbian.symbolreader.ISymbolFile;
       
    60 import com.nokia.s60tools.analyzetool.engine.statistic.AllocCallstack;
       
    61 import com.nokia.s60tools.analyzetool.engine.statistic.AllocInfo;
       
    62 import com.nokia.s60tools.analyzetool.engine.statistic.DllLoad;
       
    63 import com.nokia.s60tools.analyzetool.engine.statistic.ProcessInfo;
       
    64 import com.nokia.s60tools.analyzetool.engine.statistic.SourceFile;
       
    65 import com.nokia.s60tools.analyzetool.engine.statistic.SymReader;
       
    66 import com.nokia.s60tools.analyzetool.global.Util;
       
    67 import com.nokia.s60tools.analyzetool.global.Constants;
       
    68 import com.nokia.s60tools.analyzetool.ui.ResourceVisitor;
       
    69 
       
    70 /**
       
    71  * Creates a statistic view Provides functions to create memory usage statistic
       
    72  * from the AnalyzeTool trace file
       
    73  *
       
    74  * @author kihe
       
    75  *
       
    76  */
       
    77 @SuppressWarnings("restriction")
       
    78 public class StatisticView implements SelectionListener, MouseListener {
       
    79 
       
    80 	/** Tab for the this view */
       
    81 	CTabItem memoryTab;
       
    82 
       
    83 	/** Table for the statistic information */
       
    84 	Table memoryTable;
       
    85 
       
    86 	/** Function column */
       
    87 	TableColumn columnFunction;
       
    88 
       
    89 	/** File column */
       
    90 	TableColumn columnFile;
       
    91 
       
    92 	/** Count column */
       
    93 	TableColumn columnCount;
       
    94 
       
    95 	/** Line column */
       
    96 	TableColumn columnLine;
       
    97 
       
    98 	/** Time column */
       
    99 	TableColumn columnTime;
       
   100 
       
   101 	/** Size column */
       
   102 	TableColumn columnSize;
       
   103 
       
   104 	/** User selected table item */
       
   105 	TableItem selectedItem;
       
   106 
       
   107 	/** Selected run id */
       
   108 	int selectedRun = 0;
       
   109 
       
   110 	/** Combo for run selection */
       
   111 	Combo combo;
       
   112 
       
   113 	/** Active project reference */
       
   114 	IProject currProject;
       
   115 
       
   116 	/** Contains project related results */
       
   117 	HashMap<IProject, AbstractList<ProcessInfo>> projectRelatedRes;
       
   118 
       
   119 	/** Contains only one(selected) project cache */
       
   120 	HashMap<Integer, AbstractList<String[]>> cache;
       
   121 
       
   122 	/** Time cache, this cache is used provide comparison by time */
       
   123 	HashMap<String, Long> timeCache;
       
   124 
       
   125 	/** Contains all created results */
       
   126 	HashMap<IProject, HashMap<Integer, AbstractList<String[]>>> projectCache;
       
   127 
       
   128 	/** Contains build platform and target information. */
       
   129 	Label infoLabel;
       
   130 
       
   131 	/** Default display string when no results are available. */
       
   132 	String noResults = "---";
       
   133 
       
   134 	/** Contains cpp files info. */
       
   135 	private final AbstractList<String> cppFileNames;
       
   136 
       
   137 	/** Symbol reader */
       
   138 	SymReader reader;
       
   139 
       
   140 	boolean errorOccurred = false;
       
   141 
       
   142 	/**
       
   143 	 * Constructor
       
   144 	 */
       
   145 	public StatisticView() {
       
   146 		projectRelatedRes = new HashMap<IProject, AbstractList<ProcessInfo>>();
       
   147 		cache = new HashMap<Integer, AbstractList<String[]>>();
       
   148 		timeCache = new HashMap<String, Long>();
       
   149 		projectCache = new HashMap<IProject, HashMap<Integer, AbstractList<String[]>>>();
       
   150 		cppFileNames = new ArrayList<String>();
       
   151 	}
       
   152 
       
   153 
       
   154 	/**
       
   155 	 * Cleans stored statistic
       
   156 	 * @param project Project reference
       
   157 	 */
       
   158 	public void clean(IProject project) {
       
   159 		memoryTable.clearAll();
       
   160 
       
   161 		combo.removeAll();
       
   162 
       
   163 		if (project == null) {
       
   164 			projectCache.clear();
       
   165 			projectRelatedRes.clear();
       
   166 			cppFileNames.clear();
       
   167 			timeCache.clear();
       
   168 			cache.clear();
       
   169 		} else {
       
   170 			projectRelatedRes.remove(project);
       
   171 			projectCache.remove(project);
       
   172 		}
       
   173 
       
   174 		setDefaultContent();
       
   175 
       
   176 		PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
       
   177 			public void run() {
       
   178 				infoLabel.setText("");
       
   179 			}
       
   180 		});
       
   181 	}
       
   182 
       
   183 	/**
       
   184 	 * Sorts the given statistic and displays it to user
       
   185 	 * @param createAllResults Create all the results, not just one run results
       
   186 	 */
       
   187 	public void compareAndPrint(boolean createAllResults) {
       
   188 		// if current project does not contain statistic => leave
       
   189 		if (!projectRelatedRes.containsKey(currProject)) {
       
   190 			return;
       
   191 		}
       
   192 
       
   193 		// if cache contains statistic for selected run use it
       
   194 		if (cache.containsKey(selectedRun)) {
       
   195 			AbstractList<String[]> items = cache.get(selectedRun);
       
   196 			updateView(items, false);
       
   197 			return;
       
   198 		}
       
   199 
       
   200 		if (reader == null) {
       
   201 			reader = new SymReader(currProject);
       
   202 			reader.loadProjectTargetsInfo();
       
   203 		}
       
   204 
       
   205 		// get project related results
       
   206 		AbstractList<ProcessInfo> processes = projectRelatedRes
       
   207 				.get(currProject);
       
   208 		if (processes.isEmpty()) {
       
   209 			setDefaultContent();
       
   210 			return;
       
   211 		}
       
   212 		// create all the results
       
   213 		else if (createAllResults) {
       
   214 
       
   215 			int runIndex = 0;
       
   216 			Iterator<ProcessInfo> iterProcess = processes.iterator();
       
   217 			while (iterProcess.hasNext()) {
       
   218 				ProcessInfo tempProcess = iterProcess.next();
       
   219 				createResults(tempProcess, runIndex);
       
   220 				runIndex++;
       
   221 			}
       
   222 
       
   223 			// all the runs results are generated => now display the first
       
   224 			// results
       
   225 			// compareAndPrint(false);
       
   226 
       
   227 		}
       
   228 		// create only one(specific) run results
       
   229 		else {
       
   230 			ProcessInfo tempProcessInfo = processes.get(selectedRun);
       
   231 			createResults(tempProcessInfo, selectedRun);
       
   232 		}
       
   233 		if (reader != null) {
       
   234 			reader.dispose();
       
   235 			reader = null;
       
   236 		}
       
   237 
       
   238 	}
       
   239 
       
   240 	/**
       
   241 	 * Find symbol reader api pinpointed class file for project class files.
       
   242 	 *
       
   243 	 * @param fileName
       
   244 	 *            Cpp file name
       
   245 	 * @return Found cpp file location
       
   246 	 */
       
   247 	private String getFileNames(String fileName) {
       
   248 		Iterator<String> iterFiles = cppFileNames.iterator();
       
   249 		int slash = Util.getLastSlashIndex(fileName);
       
   250 		String tempFile = fileName.substring(slash + 1, fileName.length());
       
   251 
       
   252 		String realFileName = fileName;
       
   253 		while (iterFiles.hasNext()) {
       
   254 			String tempFileName = iterFiles.next();
       
   255 			int slashTemp = Util.getLastSlashIndex(tempFileName);
       
   256 			String tempFileWithoutExt = tempFileName.substring(slashTemp + 1,
       
   257 					tempFileName.length());
       
   258 			if (tempFileWithoutExt.equalsIgnoreCase(tempFile)) {
       
   259 				realFileName = tempFileName;
       
   260 				break;
       
   261 			}
       
   262 		}
       
   263 
       
   264 		return realFileName;
       
   265 	}
       
   266 
       
   267 	/**
       
   268 	 * Converts hex time to time value
       
   269 	 *
       
   270 	 * @param timeInHex
       
   271 	 *            Time in hex
       
   272 	 * @return Time
       
   273 	 */
       
   274 	public String converTime(Long timeInHex) {
       
   275 		Calendar cal = Calendar.getInstance();
       
   276 
       
   277 		cal.setTimeInMillis(timeInHex / 1000);
       
   278 
       
   279 		StringBuffer timeStr = new StringBuffer();
       
   280 		String[] monthName = { "Jan", "Feb", "March", "Apr", "May", "June",
       
   281 				"July", "Aug", "Sep", "Oct", "Nov", "Dec" };
       
   282 		char space = ' ';
       
   283 		String[] day = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
       
   284 		timeStr.append(day[cal.get(Calendar.DAY_OF_WEEK) - 1]);
       
   285 		timeStr.append(space);
       
   286 		timeStr.append(monthName[cal.get(Calendar.MONTH)]);
       
   287 		timeStr.append(space);
       
   288 		timeStr.append(cal.get(Calendar.DAY_OF_MONTH));
       
   289 		timeStr.append(space);
       
   290 		timeStr.append(cal.get(Calendar.YEAR));
       
   291 		timeStr.append(space);
       
   292 		timeStr.append(cal.get(Calendar.HOUR_OF_DAY));
       
   293 		timeStr.append(':');
       
   294 		int minute = cal.get(Calendar.MINUTE);
       
   295 		if (minute < 10) {
       
   296 			timeStr.append('0');
       
   297 		}
       
   298 		timeStr.append(minute);
       
   299 		timeStr.append(':');
       
   300 		int second = cal.get(Calendar.SECOND);
       
   301 		if (second < 10) {
       
   302 			timeStr.append('0');
       
   303 		}
       
   304 		timeStr.append(second);
       
   305 		timeStr.append('.');
       
   306 		int millis = cal.get(Calendar.MILLISECOND);
       
   307 		if (millis < 10) {
       
   308 			timeStr.append("00");
       
   309 		} else if (millis < 100) {
       
   310 			timeStr.append('0');
       
   311 		}
       
   312 		timeStr.append(millis);
       
   313 		return timeStr.toString();
       
   314 	}
       
   315 
       
   316 	/**
       
   317 	 * Creates results
       
   318 	 *
       
   319 	 * @param tempProcessInfo
       
   320 	 *           Process info
       
   321 	 * @param runIndex
       
   322 	 *            Selected run index
       
   323 	 */
       
   324 	private void createResults(ProcessInfo tempProcessInfo,
       
   325 			int runIndex) {
       
   326 
       
   327 		//create cache for found source files
       
   328 		HashMap<Long, SourceFile> sourceFileCache = new HashMap<Long, SourceFile>();
       
   329 
       
   330 		//list for found files
       
   331 		AbstractList<SourceFile> files = new ArrayList<SourceFile>();
       
   332 
       
   333 		//get process allocations
       
   334 		AbstractList<AllocInfo> allocs = tempProcessInfo.getAllocs();
       
   335 		Iterator<AllocInfo> iterAllocs = allocs.iterator();
       
   336 
       
   337 		//thru allocations
       
   338 		while (iterAllocs.hasNext()) {
       
   339 
       
   340 			//get one allocation
       
   341 			AllocInfo oneInfo = iterAllocs.next();
       
   342 
       
   343 			//get allocation callstack
       
   344 			AbstractList<AllocCallstack> allocCalls = oneInfo.getCallstack();
       
   345 			Iterator<AllocCallstack> iterAllocCalls = allocCalls.iterator();
       
   346 
       
   347 			//go thru callstack values until find first source file
       
   348 			while (iterAllocCalls.hasNext()) {
       
   349 
       
   350 				if( errorOccurred ) {
       
   351 					return;
       
   352 				}
       
   353 
       
   354 				AllocCallstack oneCallstack = iterAllocCalls.next();
       
   355 
       
   356 				//if callstack item do not contain dll load item => could not be pinpointed
       
   357 				DllLoad tempLoad = oneCallstack.getDllLoad();
       
   358 				if (tempLoad == null) {
       
   359 					continue;
       
   360 				}
       
   361 
       
   362 				//if callstack item memory addreess match to dll load start address => skip these values
       
   363 				if (oneCallstack.getMemoryAddress()== tempLoad.getStartAddress()) {
       
   364 					continue;
       
   365 				}
       
   366 
       
   367 				//find memory address from the cache
       
   368 				if (sourceFileCache
       
   369 						.containsKey(oneCallstack.getMemoryAddress())) {
       
   370 					SourceFile tempFile = sourceFileCache.get(oneCallstack
       
   371 							.getMemoryAddress());
       
   372 					int intValue = oneInfo.getSizeInt();
       
   373 					tempFile.updateSize(intValue);
       
   374 					tempFile.setTime(oneInfo.getTime());
       
   375 					tempFile.updateHowManyTimes();
       
   376 					break;
       
   377 				}
       
   378 
       
   379 				//not found in the cache => try to pinpoint it
       
   380 				SourceFile file = pinpoint(oneCallstack.getMemoryAddress(),
       
   381 						oneCallstack.getDllLoad());
       
   382 
       
   383 				//if source file found
       
   384 				if (file != null) {
       
   385 					//set source file values
       
   386 					int intValue = oneInfo.getSizeInt();
       
   387 					file.updateSize(intValue);
       
   388 					file.setTime(oneInfo.getTime());
       
   389 					files.add(file);
       
   390 
       
   391 					//add found source file to cache
       
   392 					sourceFileCache.put(oneCallstack.getMemoryAddress(), file);
       
   393 					break;
       
   394 				}
       
   395 			}
       
   396 		}
       
   397 
       
   398 		//store found results to cache
       
   399 		storeResults(files, runIndex);
       
   400 
       
   401 		//clear used cache
       
   402 		sourceFileCache.clear();
       
   403 	}
       
   404 
       
   405 	/**
       
   406 	 * Creates statistic view
       
   407 	 *
       
   408 	 * @param parent
       
   409 	 *            View parent
       
   410 	 * @return CTabItem created view
       
   411 	 */
       
   412 	public CTabItem createView(CTabFolder parent) {
       
   413 		// create new sashform for the statistic view
       
   414 		SashForm allFrom = new SashForm(parent, SWT.VERTICAL);
       
   415 
       
   416 		/** new sashform for the run selection */
       
   417 		SashForm infoFrom = new SashForm(allFrom, SWT.HORIZONTAL);
       
   418 
       
   419 		/** new sashform for the memory statistic information */
       
   420 		SashForm memoryFrom = new SashForm(allFrom, SWT.NONE);
       
   421 
       
   422 		// create new tab
       
   423 		memoryTab = new CTabItem(parent, SWT.NONE);
       
   424 		memoryTab.setText(Constants.STATISTICS_TAB_TITLE);
       
   425 
       
   426 		// initialize tab layout
       
   427 		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
       
   428 		gd.grabExcessVerticalSpace = true;
       
   429 		gd.grabExcessHorizontalSpace = true;
       
   430 		gd.horizontalSpan = 1;
       
   431 
       
   432 		/** create new label */
       
   433 		Label label = new Label(infoFrom, SWT.NONE);
       
   434 		label.setText(Constants.STATISTICS_SELECT_RUN);
       
   435 
       
   436 		/** create new choisebox */
       
   437 		combo = new Combo(infoFrom, SWT.DROP_DOWN);
       
   438 		combo.addSelectionListener(this);
       
   439 
       
   440 		/** create empty label to fill non-used space */
       
   441 		infoLabel = new Label(infoFrom, SWT.NONE);
       
   442 		infoLabel.setText("");
       
   443 
       
   444 		/** Set sashform layout */
       
   445 		infoFrom.setWeights(new int[] { 1, 1, 9 });
       
   446 
       
   447 		/** Set sashform layout */
       
   448 		allFrom.setWeights(new int[] { 1, 14 });
       
   449 
       
   450 		// create new table for the tab
       
   451 		memoryTable = new Table(memoryFrom, SWT.VIRTUAL | SWT.FULL_SELECTION
       
   452 				| SWT.BORDER | SWT.V_SCROLL);
       
   453 		memoryTable.setHeaderVisible(true);
       
   454 		memoryTable.setLinesVisible(true);
       
   455 		memoryTable.setItemCount(12);
       
   456 		memoryTab.setControl(allFrom);
       
   457 
       
   458 		columnFile = new TableColumn(memoryTable, SWT.Selection);
       
   459 		columnFile.setText(Constants.STATISTICS_NODE_FILE);
       
   460 		columnFile.setWidth(160);
       
   461 
       
   462 		// create table items
       
   463 		columnFunction = new TableColumn(memoryTable, SWT.Selection);
       
   464 		columnFunction.setText(Constants.STATISTICS_NODE_FUNCTION);
       
   465 		columnFunction.setWidth(120);
       
   466 
       
   467 		columnLine = new TableColumn(memoryTable, SWT.Selection);
       
   468 		columnLine.setText(Constants.STATISTICS_NODE_LINE);
       
   469 		columnLine.setWidth(60);
       
   470 
       
   471 		columnCount = new TableColumn(memoryTable, SWT.Selection);
       
   472 		columnCount.setText(Constants.STATISTICS_NODE_ALLOCS);
       
   473 		columnCount.setWidth(60);
       
   474 		columnCount.addListener(SWT.Selection, new ATComparator(this,
       
   475 				memoryTable, 3, true));
       
   476 
       
   477 		columnTime = new TableColumn(memoryTable, SWT.Selection);
       
   478 		columnTime.setText(Constants.STATISTICS_NODE_TIME);
       
   479 		columnTime.setWidth(60);
       
   480 		columnTime.addListener(SWT.Selection, new ATComparator(this,
       
   481 				memoryTable, 4, false));
       
   482 
       
   483 		columnSize = new TableColumn(memoryTable, SWT.Selection);
       
   484 		columnSize.setText(Constants.STATISTICS_NODE_SIZE);
       
   485 		columnSize.setWidth(60);
       
   486 		columnSize.addListener(SWT.Selection, new ATComparator(this,
       
   487 				memoryTable, 5, true));
       
   488 
       
   489 		memoryTable.addSelectionListener(this);
       
   490 		memoryTable.addMouseListener(this);
       
   491 
       
   492 		memoryTable.pack();
       
   493 		memoryTable.update();
       
   494 		setDefaultContent();
       
   495 		return memoryTab;
       
   496 	}
       
   497 
       
   498 	/**
       
   499 	 * Fit columns size to match column text size.
       
   500 	 */
       
   501 	public void doPack() {
       
   502 		TableColumn[] columns = memoryTable.getColumns();
       
   503 		for (int i = 0; i < columns.length; i++) {
       
   504 			columns[i].pack();
       
   505 		}
       
   506 	}
       
   507 
       
   508 	/**
       
   509 	 * Return time from the time cache
       
   510 	 *
       
   511 	 * @param time
       
   512 	 *            Time
       
   513 	 * @return Time in milliseconds if time found otherwise null
       
   514 	 */
       
   515 	public Long getTimeFromCache(String time) {
       
   516 		// if time is set to cache
       
   517 		if (timeCache.containsKey(time)) {
       
   518 			return timeCache.get(time);
       
   519 		}
       
   520 		return null;
       
   521 	}
       
   522 
       
   523 	/**
       
   524 	 * Handles project changed actions
       
   525 	 *
       
   526 	 * @param projectRef
       
   527 	 *            Project reference
       
   528 	 */
       
   529 	public void handleProjectChange(IProject projectRef) {
       
   530 
       
   531 		//save selected project info
       
   532 		if (projectRef == null) {
       
   533 			return;
       
   534 		} else if (currProject == null) {
       
   535 			currProject = projectRef;
       
   536 		} else if (currProject.equals(projectRef)) {
       
   537 			return;
       
   538 		}
       
   539 
       
   540 		currProject = projectRef;
       
   541 
       
   542 		//update UI items to match selected project results
       
   543 		PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
       
   544 			public void run() {
       
   545 				memoryTable.clearAll();
       
   546 				infoLabel.setText("");
       
   547 				selectedRun = 0;
       
   548 				AbstractList<ProcessInfo> processes = projectRelatedRes
       
   549 						.get(currProject);
       
   550 
       
   551 				if (processes == null || processes.isEmpty()) {
       
   552 					String[] text = new String[1];
       
   553 					text[0] = "Run: 1";
       
   554 					combo.setItems(text);
       
   555 					combo.select(0);
       
   556 				} else {
       
   557 					String[] text = new String[processes.size()];
       
   558 					for (int i = 0; i < processes.size(); i++) {
       
   559 						text[i] = "Run: " + Integer.toString(i + 1);
       
   560 					}
       
   561 					combo.setItems(text);
       
   562 					combo.select(0);
       
   563 				}
       
   564 
       
   565 				updateCache();
       
   566 				compareAndPrint(false);
       
   567 			}
       
   568 		});
       
   569 	}
       
   570 
       
   571 	/**
       
   572 	 * Go thru the project files and stores cpp files.
       
   573 	 *
       
   574 	 * @param resource
       
   575 	 *            One resource file of project
       
   576 	 */
       
   577 	public final void loadFileInfo(IResource resource) {
       
   578 		// get all the cpp file info which are belongs to current project
       
   579 		String cppFileName = Util.getCPPFileNameAndPath(resource);
       
   580 
       
   581 		// if cpp file found, save it
       
   582 		if (cppFileName != null && !cppFileNames.contains(cppFileName)) {
       
   583 			this.cppFileNames.add(cppFileName);
       
   584 		}
       
   585 	}
       
   586 
       
   587 	/**
       
   588 	 * Listen mouse double click actions. Opens selected item in editor
       
   589 	 */
       
   590 	public void mouseDoubleClick(MouseEvent arg0) {
       
   591 		openSourceFile(null);
       
   592 	}
       
   593 
       
   594 	/*
       
   595 	 * (non-Javadoc)
       
   596 	 *
       
   597 	 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
       
   598 	 */
       
   599 	public void mouseDown(MouseEvent arg0) {
       
   600 		//this method is overwrite method of MouseListnener
       
   601 		//and AT do not listens mouse DOWN events
       
   602 	}
       
   603 
       
   604 	/*
       
   605 	 * (non-Javadoc)
       
   606 	 *
       
   607 	 * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
       
   608 	 */
       
   609 	public void mouseUp(MouseEvent arg0) {
       
   610 		//this method is overwrite method of MouseListnener
       
   611 		//and AT do not listens mouse UP events
       
   612 	}
       
   613 
       
   614 	/**
       
   615 	 * Opens current callstack item on default editor and pinpoints memory leak
       
   616 	 * line
       
   617 	 *
       
   618 	 * @param cppFileName
       
   619 	 *            Cpp file name
       
   620 	 * @param lineNumber
       
   621 	 *            Cpp file line number
       
   622 	 */
       
   623 	private void openEditor(String cppFileName, String lineNumber) {
       
   624 
       
   625 		//check that used information is given
       
   626 		//we need to know file name and file line number
       
   627 		//that we could open the right line in editor
       
   628 		if (cppFileName == null || ("").equals(cppFileName)
       
   629 				|| lineNumber == null || ("").equals(lineNumber)) {
       
   630 			return;
       
   631 		}
       
   632 		try {
       
   633 
       
   634 			IFile file = null;
       
   635 			String usedFileName = null;
       
   636 			usedFileName = getFileNames(cppFileName);
       
   637 			if (currProject.isOpen()) {
       
   638 				file = ResourcesPlugin.getWorkspace().getRoot().getFile(
       
   639 						new Path(currProject.getName()
       
   640 								+ usedFileName.toLowerCase(Locale.US)));
       
   641 			}
       
   642 
       
   643 			// if file not found in active project
       
   644 			// go thru all open projects in current workbench
       
   645 			if (file == null || !file.exists()) {
       
   646 				IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace()
       
   647 						.getRoot();
       
   648 				IProject[] projects = myWorkspaceRoot.getProjects();
       
   649 				for (int i = 0; i < projects.length; i++) {
       
   650 					file = ResourcesPlugin.getWorkspace().getRoot().getFile(
       
   651 							new Path(projects[i].getName() + "\\"
       
   652 									+ usedFileName));
       
   653 
       
   654 					// file found => skip the rest of the projects
       
   655 					if (file != null && file.exists()) {
       
   656 						break;
       
   657 					}
       
   658 				}
       
   659 
       
   660 			}
       
   661 
       
   662 			// if file still not found
       
   663 			// display info to user and leave
       
   664 			if (file == null || !file.exists()) {
       
   665 				Util.showMessage(Constants.SOURCE_NOT_FOUND);
       
   666 				return;
       
   667 			}
       
   668 
       
   669 			IWorkbenchPage page = PlatformUI.getWorkbench()
       
   670 					.getActiveWorkbenchWindow().getActivePage();
       
   671 
       
   672 			HashMap<String, Object> map = new HashMap<String, Object>();
       
   673 			map.put(IMarker.LINE_NUMBER, Integer.parseInt(lineNumber));
       
   674 			// map.put(IDE.EDITOR_ID_ATTR,
       
   675 			// "org.eclipse.jdt.ui.ClassFileEditor");
       
   676 			map.put(IDE.EDITOR_ID_ATTR, Constants.SOURCE_FILE_EDITOR_ID);
       
   677 			IMarker marker = file.createMarker(IMarker.TEXT);
       
   678 			marker.setAttributes(map);
       
   679 			IDE.openEditor(page, marker, true);
       
   680 
       
   681 		} catch (PartInitException pie) {
       
   682 			pie.printStackTrace();
       
   683 		} catch (NullPointerException npe) {
       
   684 			npe.printStackTrace();
       
   685 		} catch (CoreException ce) {
       
   686 			ce.printStackTrace();
       
   687 		} catch (Exception e) {
       
   688 			e.printStackTrace();
       
   689 		}
       
   690 	}
       
   691 
       
   692 	/**
       
   693 	 * Opens source file for the selected item
       
   694 	 *
       
   695 	 * @param item
       
   696 	 *            Selected item
       
   697 	 */
       
   698 	private void openSourceFile(TableItem item) {
       
   699 		TableItem usedItem;
       
   700 
       
   701 		if (item == null && selectedItem == null) {
       
   702 			return;
       
   703 		} else if (item == null) {
       
   704 			usedItem = selectedItem;
       
   705 		} else {
       
   706 			usedItem = item;
       
   707 		}
       
   708 
       
   709 		// get source code line
       
   710 		String sourceLine = usedItem.getText(2);
       
   711 
       
   712 		// get source code file name
       
   713 		String sourceFile = usedItem.getText(0);
       
   714 
       
   715 		// open file in editor
       
   716 		openEditor(sourceFile, sourceLine);
       
   717 	}
       
   718 
       
   719 	/**
       
   720 	 * Pinpoints one memory address to source code line.
       
   721 	 *
       
   722 	 * @param memoryAddress
       
   723 	 *            Memory address
       
   724 	 * @param dllLoad
       
   725 	 *           DllLoad item
       
   726 	 * @return SourceFile if found otherwise null
       
   727 	 */
       
   728 	private SourceFile pinpoint(Long memoryAddress, DllLoad dllLoad) {
       
   729 
       
   730 		//if dll load item exists
       
   731 		if (dllLoad != null) {
       
   732 
       
   733 			//get symbol file
       
   734 			ISymbolFile symbolFile = reader.getSymbolFile(dllLoad.getName(),
       
   735 					true);
       
   736 
       
   737 			//if symbol file found => try to pinpoint memory address to source code line
       
   738 			if( symbolFile != null ) {
       
   739 				return pinpointToSrcLine(symbolFile, memoryAddress, dllLoad);
       
   740 			}
       
   741 		}
       
   742 		return null;
       
   743 	}
       
   744 
       
   745 	/**
       
   746 	 * Pinpoints memory address to source code line
       
   747 	 *
       
   748 	 * @param symbolFile
       
   749 	 *            Opened symbol file
       
   750 	 * @param memoryAddress
       
   751 	 *            Used memory address
       
   752 	 * @param dllLoad
       
   753 	 *            DllLoad object where to memory address belongs
       
   754 	 * @return SourceFile
       
   755 	 */
       
   756 	private SourceFile pinpointToSrcLine(ISymbolFile symbolFile,
       
   757 			Long memoryAddress, DllLoad dllLoad) {
       
   758 
       
   759 		ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager()
       
   760 				.getProjectInfo(currProject);
       
   761 		String platform = cpi.getDefaultConfiguration().getPlatformString();
       
   762 
       
   763 		try {
       
   764 			// this is the start address of each symbol file
       
   765 			long defaultLinkAddress = 0;
       
   766 
       
   767 			// if the platform is other than winscw => adjust the memory address
       
   768 			if (!(Constants.BUILD_TARGET_WINSCW).equalsIgnoreCase(platform)) {
       
   769 				defaultLinkAddress = Long.parseLong("8000", 16);
       
   770 			}
       
   771 
       
   772 			// calculate memory address in symbol file
       
   773 			long calculated = (memoryAddress - dllLoad.getStartAddress()) + defaultLinkAddress;
       
   774 
       
   775 			java.math.BigInteger bigAddress = new java.math.BigInteger(Long
       
   776 					.toHexString(calculated), 16);
       
   777 			IFunction func = symbolFile.findFunctionByAddress(bigAddress);
       
   778 			ISourceLocation loc = symbolFile.findSourceLocation(bigAddress);
       
   779 			if (func != null && loc != null) {
       
   780 				if (loc.getSourceFile() == null
       
   781 						|| loc.getSourceFile().equalsIgnoreCase(""))
       
   782 					return null;
       
   783 				if (loc.getLineNumber() == 0)
       
   784 					return null;
       
   785 				if (func.getName() == null
       
   786 						|| func.getName().equalsIgnoreCase(""))
       
   787 					return null;
       
   788 				/*
       
   789 				 * if( onlyForProjectFiles &&
       
   790 				 * !isFilePartOfTheProject(loc.getSourceFile()) ) return null;
       
   791 				 */
       
   792 				SourceFile file = new SourceFile();
       
   793 				file.setFileName(loc.getSourceFile());
       
   794 				file.setLineNumber(loc.getLineNumber());
       
   795 				file.setFunctionName(func.getName());
       
   796 				return file;
       
   797 			}
       
   798 
       
   799 		} catch (java.lang.NumberFormatException nfe) {
       
   800 			errorOccurred = true;
       
   801 			// do nothing by design
       
   802 			nfe.printStackTrace();
       
   803 		} catch (Exception e) {
       
   804 			errorOccurred = true;
       
   805 			// do nothing by design
       
   806 			e.printStackTrace();
       
   807 		}
       
   808 
       
   809 		return null;
       
   810 	}
       
   811 
       
   812 	/**
       
   813 	 * Sets statistic data
       
   814 	 *
       
   815 	 * @param project
       
   816 	 *            Project reference
       
   817 	 * @param processes
       
   818 	 *            Statistic info for the processes
       
   819 	 */
       
   820 	public void setData(IProject project,
       
   821 			final AbstractList<ProcessInfo> processes) {
       
   822 		currProject = project;
       
   823 		cache.clear();
       
   824 
       
   825 		// update ui items
       
   826 		PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
       
   827 			public void run() {
       
   828 				memoryTable.clearAll();
       
   829 				memoryTable.setItemCount(1);
       
   830 				TableItem tableItem = memoryTable.getItem(0);
       
   831 				String[] data = new String[6];
       
   832 				data[0] = Constants.STATISTICS_GENERATING;
       
   833 				data[1] = "";
       
   834 				data[2] = "";
       
   835 				data[3] = "";
       
   836 				data[4] = "";
       
   837 				data[5] = "";
       
   838 				tableItem.setText(data);
       
   839 				doPack();
       
   840 				String[] text = new String[processes.size()];
       
   841 				for (int i = 0; i < processes.size(); i++) {
       
   842 					text[i] = "Run: " + Integer.toString(i + 1);
       
   843 				}
       
   844 				combo.setItems(text);
       
   845 				combo.select(0);
       
   846 				combo.setEnabled(false);
       
   847 				infoLabel.setText("");
       
   848 
       
   849 			}
       
   850 		});
       
   851 		// store data
       
   852 		projectRelatedRes.put(project, new ArrayList<ProcessInfo>(processes));
       
   853 
       
   854 		// create results
       
   855 		compareAndPrint(true);
       
   856 
       
   857 		//update view
       
   858 		updateView(cache.get(selectedRun), true);
       
   859 
       
   860 		//load project cpp files => this helps us to open found source files in editor
       
   861 		ResourceVisitor visitor = new ResourceVisitor(this);
       
   862 		try {
       
   863 			currProject.accept(visitor);
       
   864 		} catch (CoreException ce) {
       
   865 			// DO nothing be design
       
   866 		}
       
   867 	}
       
   868 
       
   869 
       
   870 	@SuppressWarnings("unchecked")
       
   871 	private void storeSortedItems(final int runIndex) {
       
   872 		HashMap<Integer, AbstractList<String[]>> uiItems = new HashMap<Integer, AbstractList<String[]>>();
       
   873 			AbstractList<String[]> strings = new ArrayList<String[]>();
       
   874 			TableItem[] items = memoryTable.getItems();
       
   875 			for(int i=0; i<items.length; i++) {
       
   876 				TableItem oneItem = items[i];
       
   877 				String[] text = new String[6];
       
   878 				for(int j=0; j<6;j++) {
       
   879 					text[j] = oneItem.getText(j);
       
   880 				}
       
   881 				strings.add(text);
       
   882 			}
       
   883 			uiItems.put(runIndex, strings);
       
   884 
       
   885 			cache.put(runIndex, new ArrayList<String[]>(strings));
       
   886 			projectCache.put(currProject,(HashMap<Integer, AbstractList<String[]>>) uiItems.clone());
       
   887 	}
       
   888 
       
   889 
       
   890 	/**
       
   891 	 * Sets default content for the Statistic view.
       
   892 	 */
       
   893 	public void setDefaultContent() {
       
   894 		PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
       
   895 			public void run() {
       
   896 				memoryTable.clearAll();
       
   897 				TableItem oneItem = memoryTable.getItem(0);
       
   898 				String[] data = new String[6];
       
   899 				data[0] = Constants.STATISTICS_NO_STATS;
       
   900 				data[1] = noResults;
       
   901 				data[2] = noResults;
       
   902 				data[3] = noResults;
       
   903 				data[4] = noResults;
       
   904 				data[5] = noResults;
       
   905 				oneItem.setText(data);
       
   906 			}
       
   907 		});
       
   908 	}
       
   909 
       
   910 	/**
       
   911 	 * Stores results to cache
       
   912 	 *
       
   913 	 * @param sortedFiles
       
   914 	 *            Sorted statistic results
       
   915 	 * @param runIndex
       
   916 	 *            Selected run index
       
   917 	 */
       
   918 	@SuppressWarnings("unchecked")
       
   919 	private void storeResults(AbstractList<SourceFile> sortedFiles, int runIndex) {
       
   920 		int founds = 0;
       
   921 		AbstractList<String[]> usedItems = new ArrayList<String[]>();
       
   922 		Iterator<SourceFile> iterSourceFile = sortedFiles.iterator();
       
   923 
       
   924 		//thru sorted source files
       
   925 		//create string table for each found source file because memoryTable use string tables when inserting items
       
   926 		while (iterSourceFile.hasNext()) {
       
   927 			SourceFile tempSrcFile = iterSourceFile.next();
       
   928 			String[] sdata = new String[6];
       
   929 			sdata[0] = tempSrcFile.getFileName();
       
   930 			sdata[1] = tempSrcFile.getFunctionName();
       
   931 			sdata[2] = Integer.toString(tempSrcFile.getLineNumber());
       
   932 			sdata[3] = Integer.toString(tempSrcFile.getHowManyTimes());
       
   933 			String time = converTime(tempSrcFile.getTime());
       
   934 			sdata[4] = time;
       
   935 			sdata[5] = Integer.toString(tempSrcFile.getSize());
       
   936 
       
   937 			//add time to cache
       
   938 			//when sorting UI items with time we using the timeCache
       
   939 			try {
       
   940 				timeCache.put(time, tempSrcFile.getTime());
       
   941 			} catch (java.lang.NumberFormatException nfe) {
       
   942 				// do nothing by design
       
   943 			}
       
   944 
       
   945 			usedItems.add(sdata);
       
   946 			founds++;
       
   947 		}
       
   948 
       
   949 		//if no items => set default content to UI
       
   950 		if (founds == 0) {
       
   951 			String[] data = new String[6];
       
   952 			data[0] = Constants.STATISTICS_NO_STATS;
       
   953 			data[1] = noResults;
       
   954 			data[2] = noResults;
       
   955 			data[3] = noResults;
       
   956 			data[4] = noResults;
       
   957 			data[5] = noResults;
       
   958 			usedItems.add(data);
       
   959 		}
       
   960 
       
   961 		// add pinpointed info to the cache
       
   962 		cache.put(runIndex, usedItems);
       
   963 		projectCache.put(currProject,
       
   964 				(HashMap<Integer, AbstractList<String[]>>) cache.clone());
       
   965 	}
       
   966 
       
   967 	/**
       
   968 	 * Updates cache for match project changes.
       
   969 	 */
       
   970 	@SuppressWarnings("unchecked")
       
   971 	public void updateCache() {
       
   972 
       
   973 		//project cache contains result for selected project
       
   974 		if (projectCache.containsKey(currProject)) {
       
   975 
       
   976 			//clear existing caches
       
   977 			cache.clear();
       
   978 
       
   979 			//update cache
       
   980 			cache = (HashMap<Integer, AbstractList<String[]>>) projectCache
       
   981 					.get(currProject).clone();
       
   982 		}
       
   983 	}
       
   984 
       
   985 	/**
       
   986 	 * Updates build target and platform information.
       
   987 	 */
       
   988 	public void updateTargetInfo() {
       
   989 		if (currProject == null) {
       
   990 			return;
       
   991 		}
       
   992 		ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager()
       
   993 				.getProjectInfo(currProject);
       
   994 		if (cpi != null) {
       
   995 			String platform = cpi.getDefaultConfiguration().getPlatformString();
       
   996 			String buildTarget = cpi.getDefaultConfiguration()
       
   997 					.getTargetString();
       
   998 			infoLabel.setText("Platform: " + platform + "       Build target: "
       
   999 					+ buildTarget);
       
  1000 		}
       
  1001 	}
       
  1002 
       
  1003 	/**
       
  1004 	 * Updates statistic view with entered elements
       
  1005 	 *
       
  1006 	 * @param usedItems
       
  1007 	 *            Elements to UI
       
  1008 	 * @param notify Notify column to sort items
       
  1009 	 */
       
  1010 	public void updateView(final AbstractList<String[]> usedItems, final boolean notify) {
       
  1011 		PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
       
  1012 
       
  1013 			public void run() {
       
  1014 				memoryTable.clearAll();
       
  1015 
       
  1016 				if (usedItems.isEmpty()) {
       
  1017 					memoryTable.setItemCount(1);
       
  1018 					TableItem item = memoryTable.getItem(0);
       
  1019 					String[] data = new String[6];
       
  1020 					data[0] = Constants.STATISTICS_NO_STATS;
       
  1021 					data[1] = noResults;
       
  1022 					data[2] = noResults;
       
  1023 					data[3] = noResults;
       
  1024 					data[4] = noResults;
       
  1025 					data[5] = noResults;
       
  1026 					item.setText(data);
       
  1027 					return;
       
  1028 				}
       
  1029 				memoryTable.setItemCount(usedItems.size());
       
  1030 
       
  1031 				Iterator<String[]> iterItems = usedItems.iterator();
       
  1032 				int counter = 0;
       
  1033 				while (iterItems.hasNext()) {
       
  1034 					String[] text = iterItems.next();
       
  1035 					TableItem item = memoryTable.getItem(counter);
       
  1036 					item.setText(text);
       
  1037 					counter++;
       
  1038 				}
       
  1039 				updateTargetInfo();
       
  1040 				doPack();
       
  1041 				if( notify ) {
       
  1042 					columnCount.notifyListeners(SWT.Selection, null);
       
  1043 					storeSortedItems(selectedRun);
       
  1044 
       
  1045 				}
       
  1046 				combo.setEnabled(true);
       
  1047 			}
       
  1048 		});
       
  1049 
       
  1050 	}
       
  1051 
       
  1052 	/*
       
  1053 	 * (non-Javadoc)
       
  1054 	 *
       
  1055 	 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
       
  1056 	 */
       
  1057 	public void widgetDefaultSelected(SelectionEvent arg0) {
       
  1058 		//this method is overwrite method of SelectionListener
       
  1059 		//and AT do not listens widgetDefaultSelected events
       
  1060 	}
       
  1061 
       
  1062 	/**
       
  1063 	 * Checks which component is used and perform actions
       
  1064 	 *
       
  1065 	 * @param arg0
       
  1066 	 *            Selection event
       
  1067 	 */
       
  1068 	public void widgetSelected(SelectionEvent arg0) {
       
  1069 
       
  1070 		// get selected table item
       
  1071 		if (arg0.item instanceof TableItem) {
       
  1072 			selectedItem = (TableItem) arg0.item;
       
  1073 		} else if (arg0.getSource() instanceof Combo) {
       
  1074 			Combo c = (Combo) arg0.getSource();
       
  1075 			selectedRun = c.getSelectionIndex();
       
  1076 			PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
       
  1077 				public void run() {
       
  1078 					compareAndPrint(false);
       
  1079 				}
       
  1080 			});
       
  1081 		} else if (arg0.getSource() instanceof Button) {
       
  1082 			PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
       
  1083 				public void run() {
       
  1084 					compareAndPrint(false);
       
  1085 				}
       
  1086 			});
       
  1087 		}
       
  1088 	}
       
  1089 }