sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi/src/com/nokia/carbide/cpp/internal/pi/analyser/AnalyserDataProcessor.java
changeset 5 844b047e260d
parent 2 b9ab3b238396
child 12 ae255c9aa552
equal deleted inserted replaced
4:615035072f7e 5:844b047e260d
    26 import java.net.URI;
    26 import java.net.URI;
    27 import java.util.ArrayList;
    27 import java.util.ArrayList;
    28 import java.util.Enumeration;
    28 import java.util.Enumeration;
    29 import java.util.Hashtable;
    29 import java.util.Hashtable;
    30 import java.util.Iterator;
    30 import java.util.Iterator;
       
    31 import java.util.List;
    31 
    32 
    32 import org.eclipse.core.resources.IFile;
    33 import org.eclipse.core.resources.IFile;
    33 import org.eclipse.core.resources.WorkspaceJob;
    34 import org.eclipse.core.resources.WorkspaceJob;
    34 import org.eclipse.core.runtime.CoreException;
    35 import org.eclipse.core.runtime.CoreException;
    35 import org.eclipse.core.runtime.IProgressMonitor;
    36 import org.eclipse.core.runtime.IProgressMonitor;
    36 import org.eclipse.core.runtime.IStatus;
    37 import org.eclipse.core.runtime.IStatus;
       
    38 import org.eclipse.core.runtime.NullProgressMonitor;
    37 import org.eclipse.core.runtime.Status;
    39 import org.eclipse.core.runtime.Status;
    38 import org.eclipse.core.runtime.jobs.IJobChangeEvent;
    40 import org.eclipse.core.runtime.jobs.IJobChangeEvent;
    39 import org.eclipse.core.runtime.jobs.IJobChangeListener;
    41 import org.eclipse.core.runtime.jobs.IJobChangeListener;
    40 import org.eclipse.core.runtime.jobs.Job;
    42 import org.eclipse.core.runtime.jobs.Job;
    41 import org.eclipse.jface.operation.IRunnableWithProgress;
    43 import org.eclipse.jface.operation.IRunnableWithProgress;
    57 import com.nokia.carbide.cpp.internal.pi.plugin.model.AbstractPiPlugin;
    59 import com.nokia.carbide.cpp.internal.pi.plugin.model.AbstractPiPlugin;
    58 import com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace;
    60 import com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace;
    59 import com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable;
    61 import com.nokia.carbide.cpp.internal.pi.plugin.model.IVisualizable;
    60 import com.nokia.carbide.cpp.internal.pi.test.AnalysisInfoHandler;
    62 import com.nokia.carbide.cpp.internal.pi.test.AnalysisInfoHandler;
    61 import com.nokia.carbide.cpp.internal.pi.test.IProvideTraceAdditionalInfo;
    63 import com.nokia.carbide.cpp.internal.pi.test.IProvideTraceAdditionalInfo;
    62 import com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph;
       
    63 import com.nokia.carbide.cpp.internal.pi.visual.GraphDrawRequest;
    64 import com.nokia.carbide.cpp.internal.pi.visual.GraphDrawRequest;
    64 import com.nokia.carbide.cpp.internal.pi.visual.PICompositePanel;
    65 import com.nokia.carbide.cpp.internal.pi.visual.PICompositePanel;
       
    66 import com.nokia.carbide.cpp.pi.PiPlugin;
    65 import com.nokia.carbide.cpp.pi.editors.PIPageEditor;
    67 import com.nokia.carbide.cpp.pi.editors.PIPageEditor;
    66 import com.nokia.carbide.cpp.pi.importer.SampleImporter;
    68 import com.nokia.carbide.cpp.pi.importer.SampleImporter;
    67 import com.nokia.carbide.cpp.pi.util.GeneralMessages;
    69 import com.nokia.carbide.cpp.pi.util.GeneralMessages;
    68 import com.nokia.carbide.cpp.pi.util.PIExceptionRuntime;
    70 import com.nokia.carbide.cpp.pi.util.PIExceptionRuntime;
       
    71 import com.nokia.carbide.cpp.pi.visual.IGenericTraceGraph;
    69 
    72 
    70 
    73 
    71 /*
    74 /*
    72  * Class for abstracting data processing core routine for open and import
    75  * Class for abstracting data processing core routine for open and import
    73  */
    76  */
    74 
    77 
    75 public class AnalyserDataProcessor {
    78 public class AnalyserDataProcessor {
       
    79 	protected static final int MAX_CPU = 4;
    76 	// whether the profile file was read correctly
    80 	// whether the profile file was read correctly
    77 	public static int STATE_OK				= 0;
    81 	public static int STATE_OK				= 0;
    78 	public static int STATE_IMPORTING		= 1;
    82 	public static int STATE_IMPORTING		= 1;
    79 	public static int STATE_OPENING			= 2;
    83 	public static int STATE_OPENING			= 2;
    80 	public static int STATE_TIMESTAMP		= 3;
    84 	public static int STATE_TIMESTAMP		= 3;
   124 		
   128 		
   125 	public Exception getLastException() {
   129 	public Exception getLastException() {
   126 		return lastException;
   130 		return lastException;
   127 	}
   131 	}
   128 	
   132 	
   129 	private void importNewAnalysis(Hashtable<Integer,String> traceFileNames, int uid) throws InterruptedException, InvocationTargetException {
   133 	private void importNewAnalysis(Hashtable<Integer,String> traceFileNames, int uid, List<ITrace> pluginsToUse) throws InterruptedException, InvocationTargetException {
   130 		analyserDataProcessorState = STATE_IMPORTING;
   134 		analyserDataProcessorState = STATE_IMPORTING;
   131 		final int workUnitsForImport = TOTAL_PROGRESS_COUNT * 60 / 100;
   135 		final int workUnitsForImport = TOTAL_PROGRESS_COUNT * 60 / 100;
   132 		int workUnitsLeft = workUnitsForImport * 99 / 100;
   136 		int workUnitsLeft = workUnitsForImport * 99 / 100;
   133 		
   137 		
   134 		checkCancelledThrowIE();
   138 		checkCancelledThrowIE();
   135 			
   139 			
   136 		// loop through all the plugins associated with traces
   140 		// loop through all the plugins associated with traces
   137 		Enumeration<AbstractPiPlugin> enumer = PluginInitialiser.getPluginInstances(uid, "com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace"); //$NON-NLS-1$
   141 		int numberOfPlugins = pluginsToUse.size();
   138 		Enumeration<AbstractPiPlugin> tmpEnum = PluginInitialiser.getPluginInstances(uid, "com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace"); //$NON-NLS-1$
   142 		for (ITrace plugin : pluginsToUse) {
   139 		int numberOfPlugins = 0;
       
   140 		while (tmpEnum.hasMoreElements()) {
       
   141 			numberOfPlugins++;
       
   142 			tmpEnum.nextElement();
       
   143 		}
       
   144 		while (enumer.hasMoreElements())
       
   145     	{
       
   146     		ITrace plugin = (ITrace)enumer.nextElement();
       
   147     		int traceId = plugin.getTraceId();
   143     		int traceId = plugin.getTraceId();
   148     		AbstractPiPlugin p = (AbstractPiPlugin)plugin;
   144     		AbstractPiPlugin p = (AbstractPiPlugin)plugin;
   149     		
   145     		
   150     		// map trace plugins to this analysis data
   146     		// map trace plugins to this analysis data
   151     		NpiInstanceRepository.getInstance().addPlugin(uid, p);
   147     		NpiInstanceRepository.getInstance().addPlugin(uid, p);
   152     		if (traceId != -1)
   148     		if (traceId != -1)
   153     		{
   149     		{
   154     			String fileName = traceFileNames.get(traceId);
   150     			if (traceId == 1){ //support SMP by expecting one file per CPU
   155     			if (fileName != null)
   151 					List<File> files = new ArrayList<File>();
   156     			{
   152     				for (int i = 0; i < MAX_CPU; i++) {
   157     				File traceFile = new File(fileName);
   153     					int smpTraceId = traceId + i * 20;
   158     				if (traceFile.exists()) 
   154     					{
   159 						if (traceFile.getName().endsWith(".dat"))  //$NON-NLS-1$
   155     	        			String fileName = traceFileNames.get(smpTraceId);
   160 							ProfileReader.getInstance().readTraceFile(plugin, traceFile, this,uid);
   156     	        			if (fileName != null && fileName.endsWith(".dat")) //$NON-NLS-1$
       
   157     	        			{
       
   158     	        				File traceFile = new File(fileName);
       
   159     	        				if (traceFile.exists()){
       
   160     	        					files.add(traceFile);
       
   161     	        				}
       
   162     	        			}    						
       
   163     					}
       
   164     				}
       
   165 					ProfileReader.getInstance().readTraceFile(plugin, files.toArray(new File[files.size()]), this,uid);
       
   166     				 
       
   167     			} else {
       
   168         			String fileName = traceFileNames.get(traceId);
       
   169         			if (fileName != null)
       
   170         			{
       
   171         				File traceFile = new File(fileName);
       
   172         				if (traceFile.exists()) 
       
   173     						if (traceFile.getName().endsWith(".dat"))  //$NON-NLS-1$
       
   174     							ProfileReader.getInstance().readTraceFile(plugin, traceFile, this,uid);
       
   175         			}    				
   161     			}
   176     			}
   162     		}
   177     		}
   163             // assume this load takes 39%
   178             // assume this load takes 39%
   164     		getProgressMonitor().worked((workUnitsForImport * 39 / 100) / numberOfPlugins);
   179     		getProgressMonitor().worked((workUnitsForImport * 39 / 100) / numberOfPlugins);
   165     		checkCancelledThrowIE();
   180     		checkCancelledThrowIE();
   342 		loadExistingAnalysis(parent, filePath, displayName, uid);
   357 		loadExistingAnalysis(parent, filePath, displayName, uid);
   343 		analyserDataProcessorState = STATE_OK;
   358 		analyserDataProcessorState = STATE_OK;
   344 
   359 
   345 	}
   360 	}
   346 		
   361 		
   347 	public void importSaveAndOpen(final IFile analysisFile, boolean pollTillNpiSaved) {
   362 	public void importSaveAndOpen(final IFile analysisFile, boolean pollTillNpiSaved, final List<ITrace> pluginsToUse) {
   348 		analyserDataProcessorState = STATE_IMPORTING;
   363 		analyserDataProcessorState = STATE_IMPORTING;
   349 		setProgressMonitor(null);
   364 		setProgressMonitor(null);
   350 		
   365 		
   351 		final int uid = NpiInstanceRepository.getInstance().register(null);
   366 		final int uid = NpiInstanceRepository.getInstance().register(null);
   352 
   367 
   354 		IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
   369 		IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
   355 		IRunnableWithProgress runnableImportAndSave = new IRunnableWithProgress() {
   370 		IRunnableWithProgress runnableImportAndSave = new IRunnableWithProgress() {
   356 
   371 
   357 			public void run(IProgressMonitor progressMonitor)
   372 			public void run(IProgressMonitor progressMonitor)
   358 					throws InvocationTargetException, InterruptedException {
   373 					throws InvocationTargetException, InterruptedException {
   359 				setProgressMonitor(progressMonitor);
   374 				importAndSave(analysisFile, uid, pluginsToUse, null,progressMonitor);
   360 				progressMonitor.beginTask(Messages.getString("AnalyserDataProcessor.17") + analysisFile.getName(), TOTAL_PROGRESS_COUNT);   //$NON-NLS-1$
   375 			}
   361 				// open a profile data file that should contain at least thread/address information
   376 		};
   362 
       
   363 				// import new .dat
       
   364 				assertThrowITE(SampleImporter.getInstance().validate(), Messages.getString("AnalyserDataProcessor.18"));	  //$NON-NLS-1$
       
   365 				
   377 				
   366 				// invoke analysis-specific plugin instances
       
   367 				PluginInitialiser.invokePluginInstances(uid, "com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace"); //$NON-NLS-1$
       
   368 
       
   369 				StreamFileParser stp;
       
   370 				try {
       
   371 					stp = new StreamFileParser(new File(SampleImporter.getInstance().getDatFileName()));
       
   372 					Hashtable<Integer,String> traceFileNames = new Hashtable<Integer,String>();
       
   373 					ArrayList<File> tracesForCleanUp = new ArrayList<File>();
       
   374 
       
   375 					// loop through all the plugins associated with traces and note their trace IDs names
       
   376 					Enumeration<AbstractPiPlugin> enumer = PluginInitialiser.getPluginInstances(uid, "com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace"); //$NON-NLS-1$
       
   377 					while (enumer.hasMoreElements())
       
   378 					{
       
   379 						File tempFile;
       
   380 						ITrace plugin = (ITrace)enumer.nextElement();
       
   381 						int traceId = plugin.getTraceId();
       
   382 						if (traceId != -1)
       
   383 						{
       
   384 							try {
       
   385 								tempFile = stp.getTempFileForTraceType(traceId);
       
   386 								if (tempFile != null)
       
   387 								{
       
   388 									tempFile.deleteOnExit();
       
   389 									traceFileNames.put(traceId, tempFile.getAbsolutePath());
       
   390 									tracesForCleanUp.add(tempFile);
       
   391 								}
       
   392 
       
   393 							} catch (IOException e) {
       
   394 								throw new InvocationTargetException(e, Messages.getString("AnalyserDataProcessor.25")); //$NON-NLS-1$
       
   395 							}
       
   396 						}
       
   397 					}
       
   398 					
       
   399 					// import a new analysis
       
   400 					importNewAnalysis(traceFileNames, uid);
       
   401 
       
   402 					// clean up temp file for each trace
       
   403 					for (File traceFile : tracesForCleanUp) {
       
   404 						traceFile.delete();
       
   405 					}
       
   406 				} catch (IOException e) {
       
   407 					throw new InvocationTargetException(e, Messages.getString("AnalyserDataProcessor.26") + SampleImporter.getInstance().getDatFileName()); //$NON-NLS-1$
       
   408 				}
       
   409 
       
   410 				if (progressMonitor.isCanceled()) {
       
   411 					throw new InterruptedException(Messages.getString("AnalyserDataProcessor.19"));   //$NON-NLS-1$
       
   412 				}
       
   413 
       
   414 				// give the .NPI file null contents
       
   415 				byte[] b = new byte[0];
       
   416 				try {
       
   417 					analysisFile.create(new ByteArrayInputStream(b), true, null);
       
   418 					// make sure we can open an input stream to the trace file
       
   419 					analysisFile.getContents();
       
   420 				} catch (CoreException e) {
       
   421 					throw new InvocationTargetException(e, Messages.getString("AnalyserDataProcessor.14") + analysisFile.getName()); //$NON-NLS-1$
       
   422 				}
       
   423 				
       
   424 				// extract additional info from importer
       
   425 				int numberOfTraces = 0;
       
   426 				Iterator<ParsedTraceData> enuTraces = TraceDataRepository.getInstance().getTraceCollectionIter(uid);
       
   427 				AnalysisInfoHandler handler = NpiInstanceRepository.getInstance().activeUidGetAnalysisInfoHandler();
       
   428 
       
   429 				// for all traces exist in .dat set up their additional info
       
   430 			    while (enuTraces.hasNext()) {
       
   431 			    	Object object = enuTraces.next();
       
   432 
       
   433 			    	numberOfTraces++;
       
   434 			    	
       
   435 			    	if (object instanceof ParsedTraceData) {
       
   436 			    		ParsedTraceData parsedTraceData = (ParsedTraceData) object;
       
   437 			    		if (parsedTraceData.traceData != null) {
       
   438 				    		Class traceClass = parsedTraceData.traceData.getClass();
       
   439 
       
   440 							// this code is clumsy because the plugin, not the trace, has the trace ID info
       
   441 				    		Enumeration<AbstractPiPlugin> enuPlugins = PluginInitialiser.getPluginInstances(uid, "com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace"); //$NON-NLS-1$
       
   442 							while (enuPlugins.hasMoreElements())
       
   443 							{
       
   444 								ITrace plugin = (ITrace)enuPlugins.nextElement();
       
   445 								// only do when trace exist in .data
       
   446 								if (traceClass == plugin.getTraceClass()) {
       
   447 							    	if (plugin instanceof IProvideTraceAdditionalInfo) {
       
   448 										((IProvideTraceAdditionalInfo)plugin).setupInfoHandler(handler);						    		
       
   449 							    	}
       
   450 								}
       
   451 							}			
       
   452 			    		}
       
   453 			    	}
       
   454 			    }
       
   455 				
       
   456 				// refresh so project know the update done by Java(non-Eclipse API)
       
   457 				try {
       
   458 					analysisFile.refreshLocal(0, null);
       
   459 				} catch (CoreException e) {
       
   460 					throw new InvocationTargetException(e, Messages.getString("AnalyserDataProcessor.15") + analysisFile.getName()); //$NON-NLS-1$
       
   461 				}		
       
   462 			}
       
   463 		};
       
   464 		
       
   465 		IRunnableWithProgress runnableOpen = new IRunnableWithProgress() {
   378 		IRunnableWithProgress runnableOpen = new IRunnableWithProgress() {
   466 
   379 
   467 			public void run(IProgressMonitor arg0)
   380 			public void run(IProgressMonitor arg0)
   468 					throws InvocationTargetException, InterruptedException {
   381 					throws InvocationTargetException, InterruptedException {
   469 				// open the saved file
   382 				// open the saved file
   470 				if (analysisFile.exists() && AnalyserDataProcessor.getInstance().getState() == STATE_IMPORTING ) {
   383 				openFile(analysisFile);
   471 						// open the file itself
       
   472 					
       
   473 					// need to open in UI context
       
   474 					Display.getDefault().syncExec(new Runnable() {
       
   475 
       
   476 						public void run() {
       
   477 							IEditorPart editor = null;
       
   478 							try {
       
   479 								editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() , analysisFile, true);
       
   480 							} catch (PartInitException e) {
       
   481 								try {
       
   482 									assertThrowITE(e, analysisFile.getName() + Messages.getString("AnalyserDataProcessor.24")); //$NON-NLS-1$
       
   483 								} catch (InvocationTargetException e1) {
       
   484 									//already set data structure proper, do nothing
       
   485 								}
       
   486 							}
       
   487 							if (AnalyserDataProcessor.getInstance().getState() == STATE_CANCELED) {
       
   488 								// close the editor file view
       
   489 								editor.getSite().getPage().closeEditor(editor, false);
       
   490 							} else if (AnalyserDataProcessor.getInstance().getState() != STATE_OK ) {
       
   491 								// close the editor file view
       
   492 								editor.getSite().getPage().closeEditor(editor, false);
       
   493 							}							
       
   494 						}
       
   495 					});
       
   496 				}
       
   497 			}
   384 			}
   498 			
   385 			
   499 		};
   386 		};
       
   387 		
       
   388 		
   500 		
   389 		
   501 		try {
   390 		try {
   502 			progressService.busyCursorWhile(runnableImportAndSave);
   391 			progressService.busyCursorWhile(runnableImportAndSave);
   503 		
   392 		
   504 			final WorkspaceJob saveNpi = new WorkspaceJob (Messages.getString("AnalyserDataProcessor.savingImportedFile")) { //$NON-NLS-1$
   393 			final WorkspaceJob saveNpi = new WorkspaceJob (Messages.getString("AnalyserDataProcessor.savingImportedFile")) { //$NON-NLS-1$
   505 
   394 
   506 				public IStatus runInWorkspace(IProgressMonitor monitor)
   395 				public IStatus runInWorkspace(IProgressMonitor monitor)
   507 						throws CoreException {
   396 						throws CoreException {
   508 					try {
   397 					try {
   509 						ProfileReader.getInstance().writeAnalysisFile(analysisFile.getLocation().toString(), monitor, uid);
   398 						ProfileReader.getInstance().writeAnalysisFile(analysisFile.getLocation().toString(), monitor, null, uid);
   510 					} catch (InvocationTargetException e) {
   399 					} catch (InvocationTargetException e) {
   511 						return new Status(IStatus.ERROR, "com.nokia.carbide.cpp.pi", Messages.getString("AnalyserDataProcessor.invocationTargetException"), e); //$NON-NLS-1$ //$NON-NLS-2$
   400 						return new Status(IStatus.ERROR, PiPlugin.PLUGIN_ID, Messages.getString("AnalyserDataProcessor.invocationTargetException"), e); //$NON-NLS-1$ //$NON-NLS-2$
   512 					} catch (InterruptedException e) {
   401 					} catch (InterruptedException e) {
   513 						return new Status(IStatus.CANCEL, "com.nokia.carbide.cpp.pi", Messages.getString("AnalyserDataProcessor.interruptedException"), e); //$NON-NLS-1$ //$NON-NLS-2$
   402 						return new Status(IStatus.CANCEL, PiPlugin.PLUGIN_ID, Messages.getString("AnalyserDataProcessor.interruptedException"), e); //$NON-NLS-1$ //$NON-NLS-2$
   514 					}
   403 					}
   515 					return new Status(IStatus.OK, "com.nokia.carbide.cpp.pi", Messages.getString("AnalyserDataProcessor.ok"), null); //$NON-NLS-1$ //$NON-NLS-2$
   404 					return new Status(IStatus.OK, PiPlugin.PLUGIN_ID, Messages.getString("AnalyserDataProcessor.ok"), null); //$NON-NLS-1$ //$NON-NLS-2$
   516 				}
   405 				}
   517 				
   406 				
   518 			};
   407 			};
   519 		
   408 		
   520 			progressService.busyCursorWhile(runnableOpen);
   409 			progressService.busyCursorWhile(runnableOpen);
   528 				public void awake(IJobChangeEvent event) {
   417 				public void awake(IJobChangeEvent event) {
   529 				}
   418 				}
   530 
   419 
   531 				public void done(IJobChangeEvent event) {
   420 				public void done(IJobChangeEvent event) {
   532 					if (saveNpi.getResult().getSeverity()  != IStatus.OK) {
   421 					if (saveNpi.getResult().getSeverity()  != IStatus.OK) {
   533 						HandleRunnableException (saveNpi.getResult().getException(), uid, analysisFile);
   422 						handleRunnableException (saveNpi.getResult().getException(), uid, analysisFile);
   534 					}
   423 					}
   535 				}
   424 				}
   536 
   425 
   537 				public void running(IJobChangeEvent event) {
   426 				public void running(IJobChangeEvent event) {
   538 				}
   427 				}
   552 					// until it's done
   441 					// until it's done
   553 				}
   442 				}
   554 			}
   443 			}
   555 			
   444 			
   556 		} catch (InvocationTargetException e) {
   445 		} catch (InvocationTargetException e) {
   557 			HandleRunnableException(e, uid, analysisFile);
   446 			handleRunnableException(e, uid, analysisFile);
   558 		} catch (InterruptedException e) {
   447 		} catch (InterruptedException e) {
   559 			HandleRunnableException(e, uid, analysisFile);
   448 			handleRunnableException(e, uid, analysisFile);
   560 		}							
   449 		}							
   561 	}
   450 	}
   562 	
   451 	
   563 	private void HandleRunnableException(Throwable throwable, final int uid, IFile analysisFile) {
   452 	public void importSave(final IFile analysisFile, final List<ITrace> pluginsToUse, String suffixTaskName, IProgressMonitor monitor) {
       
   453 		analyserDataProcessorState = STATE_IMPORTING;
       
   454 		setUp();
       
   455 		setProgressMonitor(monitor);		
       
   456 		final int uid = NpiInstanceRepository.getInstance().register(null);	
       
   457 		try{
       
   458 			importAndSave(analysisFile, uid, pluginsToUse, suffixTaskName, monitor);	
       
   459 			ProfileReader.getInstance().writeAnalysisFile(analysisFile.getLocation().toString(), monitor, suffixTaskName, uid);				
       
   460 			analyserDataProcessorState = STATE_OK;
       
   461 		}catch (Exception e) {
       
   462 			handleRunnableException(e, uid, analysisFile);
       
   463 			monitor.setCanceled(true);
       
   464 		}
       
   465 		
       
   466 	}
       
   467 	
       
   468 	private void importAndSave(final IFile analysisFile, final int uid, List<ITrace> pluginsToUse, String suffixTaskName,IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException{
       
   469 		if(progressMonitor == null){
       
   470 			progressMonitor = new NullProgressMonitor();
       
   471 		}
       
   472 		setProgressMonitor(progressMonitor);
       
   473 		String taskName = Messages.getString("AnalyserDataProcessor.17") + analysisFile.getName();; //$NON-NLS-1$
       
   474 		if(suffixTaskName != null){
       
   475 			taskName += " "+suffixTaskName; //$NON-NLS-1$
       
   476 		}
       
   477 
       
   478 	    progressMonitor.beginTask(taskName, TOTAL_PROGRESS_COUNT);   //$NON-NLS-1$
       
   479 		progressMonitor.setTaskName(taskName);
       
   480 		// open a profile data file that should contain at least thread/address information
       
   481 
       
   482 		// import new .dat
       
   483 		assertThrowITE(SampleImporter.getInstance().validate(), Messages.getString("AnalyserDataProcessor.18"));	  //$NON-NLS-1$
       
   484 		
       
   485 		// invoke analysis-specific plugin instances
       
   486 		PluginInitialiser.invokePluginInstances(uid, "com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace"); //$NON-NLS-1$
       
   487 
       
   488 		StreamFileParser stp;
       
   489 		try {
       
   490 			stp = new StreamFileParser(new File(SampleImporter.getInstance().getDatFileName()));
       
   491 			Hashtable<Integer,String> traceFileNames = new Hashtable<Integer,String>();
       
   492 			ArrayList<File> tracesForCleanUp = new ArrayList<File>();
       
   493 
       
   494 			// loop through all the plugins associated with traces and note their trace IDs names
       
   495 			
       
   496 				
       
   497 			for (ITrace plugin : pluginsToUse) {
       
   498 				File tempFile;
       
   499 				int traceId = plugin.getTraceId();
       
   500 				if (traceId != -1)
       
   501 				{
       
   502 					try {
       
   503 						
       
   504 						if (traceId == 1) {// the SMP change; separate temp data files for each CPU
       
   505 							for (int i = 0; i < MAX_CPU; i++) {
       
   506 								int smpTraceId = traceId + i * 20;
       
   507 								tempFile = stp.getTempFileForTraceType(smpTraceId);
       
   508 								if (tempFile != null) {
       
   509 									tempFile.deleteOnExit();
       
   510 									traceFileNames.put(smpTraceId, tempFile.getAbsolutePath());
       
   511 									tracesForCleanUp.add(tempFile);
       
   512 								}
       
   513 							}
       
   514 						} else {
       
   515 							tempFile = stp.getTempFileForTraceType(traceId);
       
   516 							if (tempFile != null)
       
   517 							{
       
   518 								tempFile.deleteOnExit();
       
   519 								traceFileNames.put(traceId, tempFile.getAbsolutePath());
       
   520 								tracesForCleanUp.add(tempFile);
       
   521 							}									
       
   522 						}
       
   523 
       
   524 					} catch (IOException e) {
       
   525 						throw new InvocationTargetException(e, Messages.getString("AnalyserDataProcessor.25")); //$NON-NLS-1$
       
   526 					}
       
   527 				}
       
   528 			}
       
   529 			
       
   530 			// import a new analysis
       
   531 			importNewAnalysis(traceFileNames, uid, pluginsToUse);
       
   532 
       
   533 			// clean up temp file for each trace
       
   534 			for (File traceFile : tracesForCleanUp) {
       
   535 				traceFile.delete();
       
   536 			}
       
   537 		} catch (IOException e) {
       
   538 			throw new InvocationTargetException(e, Messages.getString("AnalyserDataProcessor.26") + SampleImporter.getInstance().getDatFileName()); //$NON-NLS-1$
       
   539 		}
       
   540 
       
   541 		if (progressMonitor.isCanceled()) {
       
   542 			throw new InterruptedException(Messages.getString("AnalyserDataProcessor.19"));   //$NON-NLS-1$
       
   543 		}
       
   544 
       
   545 		// give the .NPI file null contents
       
   546 		byte[] b = new byte[0];
       
   547 		try {
       
   548 			analysisFile.create(new ByteArrayInputStream(b), true, null);
       
   549 			// make sure we can open an input stream to the trace file
       
   550 			analysisFile.getContents();
       
   551 		} catch (CoreException e) {
       
   552 			throw new InvocationTargetException(e, Messages.getString("AnalyserDataProcessor.14") + analysisFile.getName()); //$NON-NLS-1$
       
   553 		}
       
   554 		
       
   555 		// extract additional info from importer
       
   556 		int numberOfTraces = 0;
       
   557 		Iterator<ParsedTraceData> enuTraces = TraceDataRepository.getInstance().getTraceCollectionIter(uid);
       
   558 		AnalysisInfoHandler handler = NpiInstanceRepository.getInstance().activeUidGetAnalysisInfoHandler();
       
   559 
       
   560 		// for all traces exist in .dat set up their additional info
       
   561 	    while (enuTraces.hasNext()) {
       
   562 	    	Object object = enuTraces.next();
       
   563 
       
   564 	    	numberOfTraces++;
       
   565 	    	
       
   566 	    	if (object instanceof ParsedTraceData) {
       
   567 	    		ParsedTraceData parsedTraceData = (ParsedTraceData) object;
       
   568 	    		if (parsedTraceData.traceData != null) {
       
   569 		    		Class traceClass = parsedTraceData.traceData.getClass();
       
   570 
       
   571 					// this code is clumsy because the plugin, not the trace, has the trace ID info
       
   572 		    		Enumeration<AbstractPiPlugin> enuPlugins = PluginInitialiser.getPluginInstances(uid, "com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace"); //$NON-NLS-1$
       
   573 					while (enuPlugins.hasMoreElements())
       
   574 					{
       
   575 						ITrace plugin = (ITrace)enuPlugins.nextElement();
       
   576 						// only do when trace exist in .data
       
   577 						if (traceClass == plugin.getTraceClass()) {
       
   578 					    	if (plugin instanceof IProvideTraceAdditionalInfo) {
       
   579 								((IProvideTraceAdditionalInfo)plugin).setupInfoHandler(handler);						    		
       
   580 					    	}
       
   581 						}
       
   582 					}			
       
   583 	    		}
       
   584 	    	}
       
   585 	    }
       
   586 		
       
   587 		// refresh so project know the update done by Java(non-Eclipse API)
       
   588 		try {
       
   589 			analysisFile.refreshLocal(0, null);
       
   590 		} catch (CoreException e) {
       
   591 			throw new InvocationTargetException(e, Messages.getString("AnalyserDataProcessor.15") + analysisFile.getName()); //$NON-NLS-1$
       
   592 		}		
       
   593 	}	
       
   594 	
       
   595 	private void openFile(final IFile analysisFile) {
       
   596 		// open the saved file
       
   597 		if (analysisFile.exists() && AnalyserDataProcessor.getInstance().getState() == STATE_IMPORTING ) {
       
   598 				// open the file itself
       
   599 			
       
   600 			// need to open in UI context
       
   601 			Display.getDefault().syncExec(new Runnable() {
       
   602 
       
   603 				public void run() {
       
   604 					IEditorPart editor = null;
       
   605 					try {
       
   606 						editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() , analysisFile, true);
       
   607 					} catch (PartInitException e) {
       
   608 						try {
       
   609 							assertThrowITE(e, analysisFile.getName() + Messages.getString("AnalyserDataProcessor.24")); //$NON-NLS-1$
       
   610 						} catch (InvocationTargetException e1) {
       
   611 							//already set data structure proper, do nothing
       
   612 						}
       
   613 					}
       
   614 					if (AnalyserDataProcessor.getInstance().getState() == STATE_CANCELED) {
       
   615 						// close the editor file view
       
   616 						editor.getSite().getPage().closeEditor(editor, false);
       
   617 					} else if (AnalyserDataProcessor.getInstance().getState() != STATE_OK ) {
       
   618 						// close the editor file view
       
   619 						editor.getSite().getPage().closeEditor(editor, false);
       
   620 					}							
       
   621 				}
       
   622 			});
       
   623 		}
       
   624 	}
       
   625 	
       
   626 	private void handleRunnableException(Throwable throwable, final int uid, IFile analysisFile) {
   564 		NpiInstanceRepository.getInstance().unregister(uid);
   627 		NpiInstanceRepository.getInstance().unregister(uid);
   565 		if (throwable instanceof InvocationTargetException) {
   628 		if (throwable instanceof InvocationTargetException) {
   566 			String error = Messages.getString("AnalyserDataProcessor.20"); //$NON-NLS-1$
   629 			String error = Messages.getString("AnalyserDataProcessor.20"); //$NON-NLS-1$
   567 			if (throwable.getMessage() != null) {
   630 			if (throwable.getMessage() != null) {
   568 				error += throwable.getMessage() + "\n"; //$NON-NLS-1$
   631 				error += throwable.getMessage() + "\n"; //$NON-NLS-1$
   632 		}
   695 		}
   633 	}
   696 	}
   634 
   697 
   635 	// save profiling data to NPI file
   698 	// save profiling data to NPI file
   636 	private void saveAnalysisInternal(final String filename, final int uid) throws InvocationTargetException, InterruptedException {
   699 	private void saveAnalysisInternal(final String filename, final int uid) throws InvocationTargetException, InterruptedException {
   637 		ProfileReader.getInstance().writeAnalysisFile(filename, getProgressMonitor(), uid);
   700 		ProfileReader.getInstance().writeAnalysisFile(filename, getProgressMonitor(), null,uid);
   638 	}
   701 	}
   639 	
   702 	
   640 	private void processVisualizableItem(ITrace plugin)
   703 	private void processVisualizableItem(ITrace plugin)
   641 	{
   704 	{
   642 		IVisualizable visualizable = (IVisualizable)plugin;
   705 		IVisualizable visualizable = (IVisualizable)plugin;
   670 		
   733 		
   671 		// determine how many graphs to draw (several may get added to the same page)
   734 		// determine how many graphs to draw (several may get added to the same page)
   672 		for (int i = 0; i < visualizable.getGraphCount(); i++)
   735 		for (int i = 0; i < visualizable.getGraphCount(); i++)
   673 		{
   736 		{
   674 			GraphDrawRequest gdr   = visualizable.getDrawRequest(i);
   737 			GraphDrawRequest gdr   = visualizable.getDrawRequest(i);
   675 			GenericTraceGraph gtg  = visualizable.getTraceGraph(i);
   738 			IGenericTraceGraph gtg  = visualizable.getTraceGraph(i);
   676 			String title           = visualizable.getGraphTitle(i);
       
   677 			int	pageNumber         = visualizable.getPageNumber(i);
   739 			int	pageNumber         = visualizable.getPageNumber(i);
   678 			
   740 			
   679 			ProfileVisualiser page = NpiInstanceRepository.getInstance().getProfilePage(uid, pageNumber);
   741 			ProfileVisualiser page = NpiInstanceRepository.getInstance().getProfilePage(uid, pageNumber);
   680 
   742 
   681 			if (gtg != null)
   743 			if (gtg != null)
   682 			{
   744 			{
   683 				page.getTopComposite().addGraphComponent(gtg, title, visualizable.getClass(), gdr);
   745 				page.getTopComposite().addGraphComponent(gtg, visualizable.getClass(), gdr);
   684 			}
   746 			}
   685 
   747 
   686 			Integer lastSample = visualizable.getLastSample(i);
   748 			Integer lastSample = visualizable.getLastSample(i);
   687 			if (lastSample != null)
   749 			if (lastSample != null)
   688 			{
   750 			{
   740 								for (final ProfileVisualiser page : pages) {
   802 								for (final ProfileVisualiser page : pages) {
   741 									// NOTE: This assumes that the first profile page has a graph
   803 									// NOTE: This assumes that the first profile page has a graph
   742 						        	final PICompositePanel visibleComposite = page.getTopComposite();
   804 						        	final PICompositePanel visibleComposite = page.getTopComposite();
   743 						        	visibleComposite.performZoomToGraph(visibleComposite, parent.getBounds().width);
   805 						        	visibleComposite.performZoomToGraph(visibleComposite, parent.getBounds().width);
   744 						        	
   806 						        	
   745 						        	//TODO uncomment when performance issues relating to gfc are solved
   807 						        	//TODO uncomment when performance issues relating to fcc are solved
   746 						        	//Select whole graph
   808 						        	//Select whole graph
   747 						        	//visibleComposite.selectWholeGraph();
   809 						        	//visibleComposite.selectWholeGraph();
   748 								}
   810 								}
   749 			
   811 			
   750 								// scale to whole trace only once
   812 								// scale to whole trace only once