[Hpcviewer-commits] r176 - in trunk/src/edu/rice/cs/hpc: analysis viewer/actions viewer/scope viewer/util

laksono at osp5.lbl.gov laksono at osp5.lbl.gov
Mon May 12 13:35:44 PDT 2008


Author: laksono
Date: 2008-05-12 13:35:43 -0700 (Mon, 12 May 2008)
New Revision: 176

Removed:
   trunk/src/edu/rice/cs/hpc/analysis/ExperimentExt.java
Modified:
   trunk/src/edu/rice/cs/hpc/analysis/ExperimentView.java
   trunk/src/edu/rice/cs/hpc/viewer/actions/DisplayExperiment.java
   trunk/src/edu/rice/cs/hpc/viewer/scope/ScopeView.java
   trunk/src/edu/rice/cs/hpc/viewer/scope/ScopeViewActions.java
   trunk/src/edu/rice/cs/hpc/viewer/util/EditorManager.java
Log:
Fix bug on showing error message on the "message toolbar" by using additional thread to display the message and GUI-thread to restore the toolbar state.
TODO: for unknown reason, the "open processing" has blocked the GUI thread. We need to handle this in the future.

Removing ExperimentExt since we want to avoid using ProgressMonitor which can only be used once and it has to be reserved in memory. This may give impact to more memory consumption (perhaps).

Deleted: trunk/src/edu/rice/cs/hpc/analysis/ExperimentExt.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/analysis/ExperimentExt.java	2008-05-09 17:48:03 UTC (rev 175)
+++ trunk/src/edu/rice/cs/hpc/analysis/ExperimentExt.java	2008-05-12 20:35:43 UTC (rev 176)
@@ -1,241 +0,0 @@
-/**
- * 
- */
-package edu.rice.cs.hpc.analysis;
-
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-
-import edu.rice.cs.hpc.data.experiment.Experiment;
-import edu.rice.cs.hpc.data.experiment.InvalExperimentException;
-import edu.rice.cs.hpc.data.experiment.metric.MetricType;
-import edu.rice.cs.hpc.data.experiment.scope.RootScope;
-import edu.rice.cs.hpc.data.experiment.scope.RootScopeType;
-import edu.rice.cs.hpc.data.experiment.scope.Scope;
-import edu.rice.cs.hpc.data.experiment.scope.filters.EmptyMetricValuePropagationFilter;
-import edu.rice.cs.hpc.data.experiment.scope.filters.ExclusiveOnlyMetricPropagationFilter;
-import edu.rice.cs.hpc.data.experiment.scope.filters.FlatViewInclMetricPropagationFilter;
-import edu.rice.cs.hpc.data.experiment.scope.filters.InclusiveOnlyMetricPropagationFilter;
-
-/**
- * Class to manage, open and post-processing long and big experiment file.
- * User needs to call the method  openAndprocessExperiment to process the database
- * @author laksono
- *
- */
-public class ExperimentExt {
-
-	protected Shell shell;
-	protected ExperimentProcessing expProc;
-	
-	/**
-	 * Constructor of the class. 
-	 * @param objShell shell window
-	 * @param expView experiment-viewer interface to generate scope view
-	 * @param exp the copy-constructor for experiemnt
-	 */
-	public ExperimentExt(Shell objShell, ExperimentView expView, Experiment exp) {
-		this.shell = objShell;
-		this.expProc = new ExperimentProcessing(objShell, expView, exp);
-	}
-
-	/**
-	 * constructor with the file
-	 * @param objShell shell window
-	 * @param expView the viewer interface
-	 * @param filename the name of the database file
-	 */
-	public ExperimentExt(Shell objShell, ExperimentView expView, File filename) {
-		this.shell = objShell;
-		this.expProc = new ExperimentProcessing(objShell, expView, filename);
-	}
-	
-	/**
-	 * Open and processing the experiment database. This method will show a monitor dialog
-	 * to show the progress.
-	 */
-	public void openAndprocessExperiment() {
-		ProgressMonitorDialog monitorDlg = new ProgressMonitorDialog(shell); 
-        try {
-            monitorDlg.run(true, true, this.expProc);
-          } catch (InvocationTargetException e) {
-            //MessageDialog.openError(shell, "Error", e.getMessage());
-        	  System.err.println("Progress-monitor:"+e.getCause());
-          } catch (InterruptedException e) {
-        	  System.err.println("Progress-monitor: canceled");
-            //MessageDialog.openInformation(shell, "Cancelled", e.getMessage());
-          }
-
-	}
-}
-
-/**
- * This class represents a long running opening, parsing and postprocessing
- * experiment file.
- *  For some database, it takes really long time, others don't
- */
-class ExperimentProcessing extends Experiment implements IRunnableWithProgress {
-  // The total sleep time
-  private static final int TOTAL_TIME = 8;
-  private Shell shell;
-  private ExperimentView expViewer;
-  /**
-   * Experiment with long running processing feature
-   * 
-   * @param objShell
-   * @param indeterminate whether the animation is unknown
-   */
-  public ExperimentProcessing(Shell objShell, ExperimentView expView, Experiment exp) {
-	  super(exp);
-	  this.shell = objShell;
-	  this.expViewer = expView;
-  }
-
-  /**
-   * 
-   * @param objShell
-   * @param filename
-   */
-  public ExperimentProcessing(Shell objShell, ExperimentView expView, File filename) {
-	  super(filename);
-	  this.shell =objShell;
-	  this.expViewer = expView;
-  }
-  /**
-   * Runs the long running operation: parsing, opening and post-processing (if necessary)
-   * 
-   * @param monitor the progress monitor
-   */
-  public void run(IProgressMonitor monitor) throws InvocationTargetException,
-      InterruptedException {
-	  boolean bSuccessful = false;
-	  
-	  // ---- begin long operation
-	  monitor.beginTask("Processing experiment database", TOTAL_TIME);
-	  if (this.parse()) {
-	      monitor.worked(1);
-	      monitor.subTask("Post-processing the database");
-	      bSuccessful = this.postprocess(monitor);
-	  }
-      monitor.done();
-      
-      // ----- end long operation
-      if (monitor.isCanceled())
-        throw new InterruptedException("Experiment database processing has been canceled.");
-      else if(bSuccessful) {
-    	  this.expViewer.generateView(this);
-      }
-  }
-  
-  /**
-   * Parsing the XML file
-   * @return true if everything is OK, false otherwise
-   */
-  public boolean parse() {
-	  String sFilename = this.fileExperiment.getName();
-	  boolean bSuccess = false;
-	  try {
-		  this.experimentFile.parse(this);
-		  bSuccess = true;
-      } catch(java.io.FileNotFoundException fnf)
-      {
-           System.err.println("File not found:" + fnf.getMessage());
-           MessageDialog.openError(this.shell, "Error:File not found", "Cannot find the file "+sFilename);
-      }
-      catch(java.io.IOException io)
-      {
-           System.err.println("IO error:" +  io.getMessage());
-           MessageDialog.openError(this.shell, "Error: Unable to read", "Cannot read the file "+sFilename);
-      }
-      catch(InvalExperimentException ex)
-      {
-           String where = ""+ ex.getLineNumber();
-           System.err.println("$" +  where);
-           MessageDialog.openError(this.shell, "Incorrect Experiment File", "File "+this.experimentFile + 
-        		   " has incorrect tag at line:"+ex.getLineNumber());
-      } 
-      catch(NullPointerException npe)
-      {
-           System.err.println("$" + npe.getMessage() + sFilename);
-           MessageDialog.openError(this.shell, "File is invalid", "File has null pointer:"+sFilename + ":"+npe.getMessage());
-      }
-      return bSuccess;
-  }
-  
-  /**
-   * Long post-processing
-   * @param monitor
-   * @return
-   */
-  public boolean postprocess(IProgressMonitor monitor) {
-		if (this.rootScope.getSubscopeCount() <= 0) return false;
-		// Get first scope subtree: CCT or Flat
-		Scope firstSubTree = this.rootScope.getSubscope(0);
-		if (!(firstSubTree instanceof RootScope)) return false;
-		RootScopeType firstRootType = ((RootScope)firstSubTree).getType();
-		
-		if (firstRootType.equals(RootScopeType.CallTree)) {
-			// accumulate, create views, percents, etc
-			Scope callingContextViewRootScope = firstSubTree;
-
-			// laks: prepare metrics
-			monitor.setTaskName("Metric preparation .... ");
-			EmptyMetricValuePropagationFilter emptyFilter = new EmptyMetricValuePropagationFilter();
-			InclusiveOnlyMetricPropagationFilter rootInclProp = new InclusiveOnlyMetricPropagationFilter(this.getMetrics());
-			if(monitor.isCanceled()) return false;
-			else  monitor.worked(1);
-
-			// Laks: normalize the line scope
-			monitor.setTaskName("Calling context: Normalize line scope .... ");
-			normalizeLineScopes(callingContextViewRootScope, emptyFilter); // normalize all
-			if(monitor.isCanceled()) return false;
-			else  monitor.worked(1);
-
-			// DFS computation for inclusive metrics
-			monitor.setTaskName("Calling context: Computing inclusive metrics .... ");
-			addInclusiveMetrics(callingContextViewRootScope, rootInclProp);
-			addInclusiveMetrics(callingContextViewRootScope, 
-			  new ExclusiveOnlyMetricPropagationFilter(this.getMetrics()));
-
-			copyMetricsToPartner(callingContextViewRootScope, MetricType.INCLUSIVE, emptyFilter);
-			if(monitor.isCanceled()) return false;
-			else  monitor.worked(1);
-
-
-			// Callers View
-			monitor.setTaskName("Caller view: creation .... ");
-			Scope callersViewRootScope = createCallersView(callingContextViewRootScope);
-			copyMetricsToPartner(callersViewRootScope, MetricType.EXCLUSIVE, emptyFilter);
-			if(monitor.isCanceled()) return false;
-			else  monitor.worked(1);
-
-			// Flat View
-			monitor.setTaskName("Flat view: creation .... ");
-			Scope flatViewRootScope = createFlatView(callingContextViewRootScope);
-			addInclusiveMetrics(flatViewRootScope, new FlatViewInclMetricPropagationFilter(this.getMetrics()));
-			flatViewRootScope.accumulateMetrics(callingContextViewRootScope, rootInclProp, this.getMetricCount());
-			if(monitor.isCanceled()) return false;
-			else  monitor.worked(1);
-
-			monitor.setTaskName("Computing percentage .... ");
-			addPercents(callingContextViewRootScope, (RootScope) callingContextViewRootScope);
-			addPercents(callersViewRootScope, (RootScope) callingContextViewRootScope);
-			addPercents(flatViewRootScope, (RootScope) callingContextViewRootScope);
-			if(monitor.isCanceled()) return false;
-			else  monitor.worked(1);
-
-		} else if (firstRootType.equals(RootScopeType.Flat)) {
-			addPercents(firstSubTree, (RootScope) firstSubTree);
-		} else {
-			// ignore; do no postprocessing
-		}
-		 return true;
-	}
-}
\ No newline at end of file

Modified: trunk/src/edu/rice/cs/hpc/analysis/ExperimentView.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/analysis/ExperimentView.java	2008-05-09 17:48:03 UTC (rev 175)
+++ trunk/src/edu/rice/cs/hpc/analysis/ExperimentView.java	2008-05-12 20:35:43 UTC (rev 176)
@@ -61,20 +61,21 @@
 		}
 	}
 	
+	/**
+	 * Asynchronously showing a processing message in the message bar and opening a database 
+	 * @param sFilename: the name of XML database file
+	 */
 	public void asyncLoadExperimentAndProcess(String sFilename) {
 		ThrLoadProcessingThread thr = new ThrLoadProcessingThread(sFilename);
 		thr.start();
 		loadExperimentAndProcess(sFilename);
 	}
+	
 	/**
 	 * A wrapper of loadExperiment() by adding some processing and generate the views
 	 * @param sFilename
 	 */
 	public void loadExperimentAndProcess(String sFilename) {
-		/*ExperimentExt exp = new ExperimentExt(this.objPage.getWorkbenchWindow().getShell(),
-				this, new java.io.File(sFilename));
-		exp.openAndprocessExperiment();
-		*/
 		Experiment experiment = this.loadExperiment(sFilename);
 		if(experiment != null) {
 	        experiment.postprocess();

Modified: trunk/src/edu/rice/cs/hpc/viewer/actions/DisplayExperiment.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/viewer/actions/DisplayExperiment.java	2008-05-09 17:48:03 UTC (rev 175)
+++ trunk/src/edu/rice/cs/hpc/viewer/actions/DisplayExperiment.java	2008-05-12 20:35:43 UTC (rev 176)
@@ -1,9 +1,13 @@
 package edu.rice.cs.hpc.viewer.actions;
 
+import java.io.FileNotFoundException;
+
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.jface.dialogs.MessageDialog;
 
 import edu.rice.cs.hpc.viewer.util.EditorManager;
 import edu.rice.cs.hpc.viewer.resources.ExperimentData;
@@ -30,9 +34,15 @@
 		ExperimentData expData = ExperimentData.getInstance();
 		if(expData.getExperiment() != null) {
 			EditorManager editor = new EditorManager(this.windowCurrent);
-			editor.openFileEditor(expData.getFilename());
+			try {
+				editor.openFileEditor(expData.getFilename());
+			} catch (FileNotFoundException e) {
+				MessageDialog.openError(this.windowCurrent.getShell(), 
+						"Error: File not found", 
+						e.getMessage());
+			}
 		} else {
-			org.eclipse.jface.dialogs.MessageDialog.openError(this.windowCurrent.getShell(), 
+			MessageDialog.openError(this.windowCurrent.getShell(), 
 					"Error: Need to open an experiment database", 
 					"In order to display the XML file of the experiment, you need to load first the experiment database !");
 		}

Modified: trunk/src/edu/rice/cs/hpc/viewer/scope/ScopeView.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/viewer/scope/ScopeView.java	2008-05-09 17:48:03 UTC (rev 175)
+++ trunk/src/edu/rice/cs/hpc/viewer/scope/ScopeView.java	2008-05-12 20:35:43 UTC (rev 176)
@@ -1,9 +1,11 @@
 package edu.rice.cs.hpc.viewer.scope;
 
+import java.io.FileNotFoundException;
+
 // User interface
 import org.eclipse.ui.part.ViewPart;
 import org.eclipse.ui.IWorkbenchActionConstants;
-
+import org.eclipse.ui.PartInitException;
 // SWT
 import org.eclipse.swt.*;
 import org.eclipse.swt.layout.GridData;
@@ -51,7 +53,11 @@
     	if(editorSourceCode == null) {
     		this.editorSourceCode = new EditorManager(this.getSite());
     	}
-    	this.editorSourceCode.displayFileEditor(node);
+    	try {
+    		this.editorSourceCode.displayFileEditor(node);
+    	} catch (FileNotFoundException e) {
+    		this.objViewActions.showErrorMessage(e.getMessage());
+    	}
     }
 
     //======================================================

Modified: trunk/src/edu/rice/cs/hpc/viewer/scope/ScopeViewActions.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/viewer/scope/ScopeViewActions.java	2008-05-09 17:48:03 UTC (rev 175)
+++ trunk/src/edu/rice/cs/hpc/viewer/scope/ScopeViewActions.java	2008-05-12 20:35:43 UTC (rev 176)
@@ -181,9 +181,21 @@
 	//====================================================================================
 	// ----------------------------- ACTIONS ---------------------------------------------
 	//====================================================================================
+	
 	public void showProcessingMessage() {
-		this.objActionsGUI.showWarningMessagge("... Processing .... Please wait ...");
+		this.objSite.getShell().getDisplay().asyncExec(new Runnable(){
+			public void run() {
+				objActionsGUI.showWarningMessagge("... Processing .... Please wait ...");
+			}
+		});
 	}
+	
+	/**
+	 * Class to restoring the background of the message bar by waiting for 5 seconds
+	 * TODO: we need to parameterize the timing for the wait
+	 * @author la5
+	 *
+	 */
 	class RestoreMessageThread extends Thread {	
 		RestoreMessageThread() {
 			super();
@@ -194,19 +206,39 @@
              } catch(InterruptedException e) {
             	 e.printStackTrace();
              }
-        	 restoreProcessingMessage();
+             // need to run from UI-thread for restoring the background
+             // without UI-thread we will get SWTException !!
+             objSite.getShell().getDisplay().asyncExec( new Runnable() {
+            	 public void run() {
+                	 objActionsGUI.restoreMessage();
+            	 }
+             });
          }
      }
 	
+	/**
+	 * Show an error message on the message bar (closed to the toolbar) and
+	 * wait for 5 seconds before removing the message
+	 * @param strMsg
+	 */
 	public void showErrorMessage(String strMsg) {
 		this.objActionsGUI.showErrorMessage(strMsg);
 		// remove the msg in 5 secs
 		RestoreMessageThread thrRestoreMessage = new RestoreMessageThread();
 		thrRestoreMessage.start();
+
 	}
 	
+	/**
+	 * asynchronously removing the message on the message bar and restoring the
+	 * background color
+	 */
 	public void restoreProcessingMessage() {
-		this.objActionsGUI.restoreMessage();
+		this.objSite.getShell().getDisplay().asyncExec(new Runnable(){
+			public void run() {
+				objActionsGUI.restoreMessage();
+			}
+		});
 	}
 	/**
 	 * show the hot path below the selected node in the tree

Modified: trunk/src/edu/rice/cs/hpc/viewer/util/EditorManager.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/viewer/util/EditorManager.java	2008-05-09 17:48:03 UTC (rev 175)
+++ trunk/src/edu/rice/cs/hpc/viewer/util/EditorManager.java	2008-05-12 20:35:43 UTC (rev 176)
@@ -1,6 +1,7 @@
 package edu.rice.cs.hpc.viewer.util;
 
 import java.util.ArrayList;
+import java.io.FileNotFoundException;
 
 import org.eclipse.core.filesystem.IFileStore;
 import org.eclipse.core.resources.IFile;
@@ -63,7 +64,9 @@
 	 * Open and Display editor
 	 * @param node
 	 */
-	public void displayFileEditor(Scope.Node node) {
+	public void displayFileEditor(Scope.Node node) 
+	throws FileNotFoundException
+	{
 		// get the complete file name
 		if(Utilities.isFileReadable(node.getScope())) {
 			String sLongName;
@@ -81,14 +84,18 @@
 	 * The filename should be a complete absolute path to the local file
 	 * @param sFilename
 	 */
-	public void openFileEditor(String sFilename) {
+	public void openFileEditor(String sFilename) 
+	throws FileNotFoundException
+	{
 		java.io.File objInfo = new java.io.File(sFilename);
 		if(objInfo.exists())
 			this.openFileEditor(sFilename, objInfo.getName(), 1);
 		else
+			throw new FileNotFoundException("File not found: "+sFilename);
+			/*
 			org.eclipse.jface.dialogs.MessageDialog.openError(this.windowCurrent.getShell(), 
 					"Error Opening File",
-					"File:" +sFilename + "("+objInfo.getName()+") does not exist");
+					"File:" +sFilename + "("+objInfo.getName()+") does not exist");*/
 	}
 	
 	/**
@@ -97,7 +104,9 @@
 	 * 			this project should be cleaned in the future !
 	 * @param sFilename the complete path of the file to display in IDE
 	 */
-	private void openFileEditor(String sLongFilename, String sFilename, int iLineNumber) {
+	private void openFileEditor(String sLongFilename, String sFilename, int iLineNumber)
+		throws FileNotFoundException
+	{
 		// get the complete path of the file
 		org.eclipse.core.filesystem.IFileStore objFile = 
 			org.eclipse.core.filesystem.EFS.getLocalFileSystem().getStore(new 
@@ -108,8 +117,7 @@
 			//objFile=objFile.getChild(objFile.fetchInfo().getName());
 			objFile=objFile.getChild(sFilename);
 	    	if(!objFile.fetchInfo().exists()) {
-	    		System.err.println(sFilename+": File not found.");
-	    		 return; // do we need this ?
+	    		throw new FileNotFoundException(sFilename+": File not found.");
 	    	}
 	    	try {
 	    		IEditorPart objEditor = openEditorOnFileStore(wbPage, objFile); 
@@ -117,7 +125,7 @@
 	    	} catch (PartInitException e) {
 	    		System.err.println("Error opening the file !");
 	    		System.err.println(e.getMessage());
-	     }
+	    	}
 		}
 	}
 



More information about the Hpcviewer-commits mailing list