[Hpcviewer-commits] r163 - in trunk/src/edu/rice/cs/hpc: . analysis data/experiment viewer/util

laksono at osp5.lbl.gov laksono at osp5.lbl.gov
Tue Apr 22 07:17:47 PDT 2008


Author: laksono
Date: 2008-04-22 07:17:46 -0700 (Tue, 22 Apr 2008)
New Revision: 163

Added:
   trunk/src/edu/rice/cs/hpc/analysis/ExperimentExt.java
Removed:
   trunk/src/edu/rice/cs/hpc/data/experiment/ICheckProcess.java
   trunk/src/edu/rice/cs/hpc/viewer/util/ShowProgressTask.java
Modified:
   trunk/src/edu/rice/cs/hpc/ApplicationWorkbenchWindowAdvisor.java
   trunk/src/edu/rice/cs/hpc/analysis/ExperimentView.java
   trunk/src/edu/rice/cs/hpc/data/experiment/Experiment.java
   trunk/src/edu/rice/cs/hpc/viewer/util/ExperimentManager.java
Log:
add feature to show a progress bar during loading a database
- the profiling should be replaced by AMD codeslaugth plug-in or others (that has less perturbation)

Modified: trunk/src/edu/rice/cs/hpc/ApplicationWorkbenchWindowAdvisor.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/ApplicationWorkbenchWindowAdvisor.java	2008-04-14 19:00:07 UTC (rev 162)
+++ trunk/src/edu/rice/cs/hpc/ApplicationWorkbenchWindowAdvisor.java	2008-04-22 14:17:46 UTC (rev 163)
@@ -68,8 +68,8 @@
 		// see if the argument provides the database to load
 		if(this.dataEx != null) {
 			// possibly we have express the experiment file in the command line
-			ExperimentView data = new ExperimentView(this.getWindowConfigurer().getWindow().getActivePage());
-		    if(data != null) {
+			ExperimentView expViewer = new ExperimentView(this.getWindowConfigurer().getWindow().getActivePage());
+		    if(expViewer != null) {
 		    	// data looks OK
 		    	String []sArgs = this.dataEx.getArguments();
 		    	String sFilename = null;
@@ -80,7 +80,7 @@
 		    		}
 		    	}
 		    	if(sFilename != null)
-		    		data.loadExperimentAndProcess(sFilename);
+		    		expViewer.loadExperimentAndProcess(sFilename);
 		     }
 		} else {
 			// there is no information about the database

Added: trunk/src/edu/rice/cs/hpc/analysis/ExperimentExt.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/analysis/ExperimentExt.java	                        (rev 0)
+++ trunk/src/edu/rice/cs/hpc/analysis/ExperimentExt.java	2008-04-22 14:17:46 UTC (rev 163)
@@ -0,0 +1,239 @@
+/**
+ * 
+ */
+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());
+          } catch (InterruptedException e) {
+            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-04-14 19:00:07 UTC (rev 162)
+++ trunk/src/edu/rice/cs/hpc/analysis/ExperimentView.java	2008-04-22 14:17:46 UTC (rev 163)
@@ -9,8 +9,6 @@
 import edu.rice.cs.hpc.viewer.resources.*;
 import edu.rice.cs.hpc.data.experiment.scope.RootScope;
 
-import edu.rice.cs.hpc.viewer.util.ShowProgressTask;
-
 /**
  * Class to be used as an interface between the GUI and the data experiment
  * This class should be called from an eclipse view !
@@ -51,12 +49,15 @@
 	 * @param sFilename
 	 */
 	public void loadExperimentAndProcess(String sFilename) {
-		Experiment experiment = this.loadExperiment(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();
 	        this.generateView(experiment);
-	        this.dataExperiment.setExperiment(experiment);
 		}
+		*/
 	}
 	/**
 	 * Load an XML experiment file based on the filename (uncheck for its inexistence)
@@ -66,12 +67,11 @@
 	public Experiment loadExperiment(String sFilename) {
 	       Experiment experiment;
 	       org.eclipse.swt.widgets.Shell objShell = this.objPage.getWorkbenchWindow().getShell();
-	       ShowProgressTask objTask = new ShowProgressTask(this.objPage.getWorkbenchWindow().getShell());
 	       //objTask.run(12, true);
            // open the experiment if possible
       try
            {
-           experiment = new Experiment(new java.io.File(sFilename), objTask);
+           experiment = new Experiment(new java.io.File(sFilename));
            experiment.open();
            
       } catch(java.io.FileNotFoundException fnf)
@@ -114,6 +114,7 @@
 	 * @param experiment Experiment data
 	 */
 	public void generateView(Experiment experiment) {
+        this.dataExperiment.setExperiment(experiment);
 		// optimistic approach: hide all the visible views first
 		this.removeViews();
 		// remove the old-irrelevant editors

Modified: trunk/src/edu/rice/cs/hpc/data/experiment/Experiment.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/data/experiment/Experiment.java	2008-04-14 19:00:07 UTC (rev 162)
+++ trunk/src/edu/rice/cs/hpc/data/experiment/Experiment.java	2008-04-22 14:17:46 UTC (rev 163)
@@ -101,7 +101,7 @@
  *
  ************************************************************************/
 	
-public Experiment(File filename, ICheckProcess objTask)
+public Experiment(File filename)
 // laks: no exception needed
  /* *throws
 	IOException,
@@ -295,7 +295,7 @@
 	this.scopes.addScope(scope);
 }
 
-Scope createCallersView(Scope callingContextViewRootScope)
+protected Scope createCallersView(Scope callingContextViewRootScope)
 {
 	EmptyMetricValuePropagationFilter filter = new EmptyMetricValuePropagationFilter();
 
@@ -310,7 +310,7 @@
 	return callersViewRootScope;
 }
 
-Scope createFlatView(Scope callingContextViewRootScope)
+protected Scope createFlatView(Scope callingContextViewRootScope)
 {
 	MetricValuePropagationFilter fvf = new FlatViewMetricPropagationFilter();
 
@@ -324,7 +324,7 @@
 	return flatViewRootScope;
 }
 
-void normalizeLineScopes(Scope scope, MetricValuePropagationFilter filter)
+protected void normalizeLineScopes(Scope scope, MetricValuePropagationFilter filter)
 {
 	NormalizeLineScopesVisitor nls = new NormalizeLineScopesVisitor(this.getMetricCount(), filter);
 	scope.dfsVisitScopeTree(nls);
@@ -339,13 +339,13 @@
 	System.out.println(rsv.total);
 }
 */
-void addInclusiveMetrics(Scope scope, MetricValuePropagationFilter filter)
+protected void addInclusiveMetrics(Scope scope, MetricValuePropagationFilter filter)
 {
 	InclusiveMetricsScopeVisitor isv = new InclusiveMetricsScopeVisitor(this.getMetricCount(), filter);
 	scope.dfsVisitScopeTree(isv);
 }
 
-void copyMetricsToPartner(Scope scope, MetricType sourceType, MetricValuePropagationFilter filter) {
+protected void copyMetricsToPartner(Scope scope, MetricType sourceType, MetricValuePropagationFilter filter) {
 	for (int i = 0; i< this.getMetricCount(); i++) {
 		Metric metric = this.getMetric(i);
 		if (metric.getMetricType() == sourceType) {
@@ -354,7 +354,7 @@
 	}
 }
 
-void addPercents(Scope scope, RootScope totalScope)
+protected void addPercents(Scope scope, RootScope totalScope)
 {
 	PercentScopeVisitor psv = new PercentScopeVisitor(this.getMetricCount(), totalScope);
 	scope.dfsVisitScopeTree(psv);
@@ -679,7 +679,7 @@
 	           // open the experiment if possible
 	    try
 	           {
-	           experiment = new Experiment(new java.io.File(sFilename), null);
+	           experiment = new Experiment(new java.io.File(sFilename));
 	           // laks: try to debug to verify if apache xml is accessible
 	           System.out.print("DataExperiment: Opening file:"+sFilename);
 	           experiment.open();

Deleted: trunk/src/edu/rice/cs/hpc/data/experiment/ICheckProcess.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/data/experiment/ICheckProcess.java	2008-04-14 19:00:07 UTC (rev 162)
+++ trunk/src/edu/rice/cs/hpc/data/experiment/ICheckProcess.java	2008-04-22 14:17:46 UTC (rev 163)
@@ -1,18 +0,0 @@
-/**
- * 
- */
-package edu.rice.cs.hpc.data.experiment;
-
-/**
- * @author laksono
- *
- */
-public interface ICheckProcess {
-	
-	/**
-	 * The previous process has been done, and ready to go for the
-	 * next task 
-	 * @param str
-	 */
-	public void advance(String str);
-}

Modified: trunk/src/edu/rice/cs/hpc/viewer/util/ExperimentManager.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/viewer/util/ExperimentManager.java	2008-04-14 19:00:07 UTC (rev 162)
+++ trunk/src/edu/rice/cs/hpc/viewer/util/ExperimentManager.java	2008-04-22 14:17:46 UTC (rev 163)
@@ -128,10 +128,10 @@
 	private boolean setExperiment(String sFilename) {
 		IWorkbenchPage objPage= this.window.getActivePage();
 		// read the XML experiment file
-		ExperimentView data = new ExperimentView(objPage);
-	    if(data != null) {
+		ExperimentView expViewer = new ExperimentView(objPage);
+	    if(expViewer != null) {
 	    	// data looks OK
-	    	data.loadExperimentAndProcess(sFilename);
+	    	expViewer.loadExperimentAndProcess(sFilename);
 	     } else
 	    	 return false; //TODO we need to throw an exception instead
 

Deleted: trunk/src/edu/rice/cs/hpc/viewer/util/ShowProgressTask.java
===================================================================
--- trunk/src/edu/rice/cs/hpc/viewer/util/ShowProgressTask.java	2008-04-14 19:00:07 UTC (rev 162)
+++ trunk/src/edu/rice/cs/hpc/viewer/util/ShowProgressTask.java	2008-04-22 14:17:46 UTC (rev 163)
@@ -1,127 +0,0 @@
-package edu.rice.cs.hpc.viewer.util;
-
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.jface.dialogs.*;
-import org.eclipse.swt.widgets.*;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-
-import edu.rice.cs.hpc.data.experiment.ICheckProcess;
-/**
- * This class demonstrates JFace's ProgressMonitorDialog class
- */
-public class ShowProgressTask implements ICheckProcess {
-	
-	private Shell objShell;
-	private TaskOperation objTask;
-	static long lTime;
-
-	/**
-	 * Current task has finished, ready to execute the next task
-	 * @param str name of the new task to execute
-	 */
-	public void advance(String str) {
-		if(this.objTask != null) {
-			this.objTask.advanceTask(str);
-		}
-		long lCurrent = System.currentTimeMillis();
-		long lDuration = lCurrent - lTime;
-		System.out.println("Experiment task: "+ str +" = "+lDuration);
-		lTime = lCurrent;
-	}
-  /**
-   * ShowProgress constructor
-   */
-  public ShowProgressTask(Shell shell) {
-	  this.objShell = shell;
-	  lTime = System.currentTimeMillis();
-  }
-
-  /**
-   * run the progress dialog
-   * @param iTotal
-   * @param indeterminate
-   */
-  public void run(int iTotal, boolean indeterminate) {
-      try {
-    	  this.objTask = new TaskOperation(iTotal); 
-          new ProgressMonitorDialog(objShell).run(true, true, this.objTask);
-        } catch (InvocationTargetException e) {
-          MessageDialog.openError(objShell, "Error", e.getMessage());
-        } catch (InterruptedException e) {
-          MessageDialog.openInformation(objShell, "Cancelled", e.getMessage());
-        }
-  }
-
-  /**
-   * Creates the main window's contents
-   * 
-   * @param parent the main window
-   * @return Control
-   */
-
-  /**
-   * The application entry point
-   * 
-   * @param args the command line arguments
-   */
-  public static void main(String[] args) {
-	  Display display = new Display();
-	  Shell shell = display.getActiveShell();
-	  ShowProgressTask task = new ShowProgressTask(shell);
-	  task.run(10, true);
-  }
-}
-
-
-
-/**
- * This class represents a long running operation
- */
-class TaskOperation implements IRunnableWithProgress {
-  // The total sleep time
-  private int TOTAL_TIME = 100;
-  private int iProgress = 0;
-  // The increment sleep time
-  private int SLEEPTIME = 100;
-  private String sTask;
-  private boolean indeterminate;
-
-  /**
-   * LongRunningOperation constructor
-   * 
-   * @param indeterminate whether the animation is unknown
-   */
-  public TaskOperation(boolean indeterminate) {
-    this.indeterminate = indeterminate;
-  }
-
-  public TaskOperation(int iTotalTime) {
-	    this.TOTAL_TIME = iTotalTime;
-  }
-
-  public void advanceTask(String str) {
-	  this.sTask = str;
-	  this.iProgress++;
-  }
-  /**
-   * Runs the long running operation
-   * 
-   * @param monitor the progress monitor
-   */
-  public void run(IProgressMonitor monitor) throws InvocationTargetException,
-      InterruptedException {
-    monitor.beginTask(this.sTask,
-        indeterminate ? IProgressMonitor.UNKNOWN : TOTAL_TIME);
-    for (; this.iProgress < TOTAL_TIME && !monitor.isCanceled(); ) {
-      Thread.sleep(SLEEPTIME);
-      monitor.worked(1);
-      monitor.subTask(this.sTask);
-    }
-    monitor.done();
-    if (monitor.isCanceled())
-        throw new InterruptedException("The operation was cancelled");
-  }
-}
\ No newline at end of file



More information about the Hpcviewer-commits mailing list