Repository: systemml
Updated Branches:
  refs/heads/master 1d83cedb7 -> ac0416883


[MINOR] Print statistics to stderr if an error has occured

Closes #631


Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/ac041688
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/ac041688
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/ac041688

Branch: refs/heads/master
Commit: ac04168836cc68f9af940c08baccab575c7e2cb3
Parents: 1d83ced
Author: Nakul Jindal <naku...@gmail.com>
Authored: Fri Aug 25 17:08:44 2017 -0700
Committer: Nakul Jindal <naku...@gmail.com>
Committed: Fri Aug 25 17:08:44 2017 -0700

----------------------------------------------------------------------
 .../apache/sysml/api/ScriptExecutorUtils.java   | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/ac041688/src/main/java/org/apache/sysml/api/ScriptExecutorUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/ScriptExecutorUtils.java 
b/src/main/java/org/apache/sysml/api/ScriptExecutorUtils.java
index 5f9c0a2..09897a5 100644
--- a/src/main/java/org/apache/sysml/api/ScriptExecutorUtils.java
+++ b/src/main/java/org/apache/sysml/api/ScriptExecutorUtils.java
@@ -80,6 +80,8 @@ public class ScriptExecutorUtils {
                DMLScript.FINEGRAINED_STATISTICS = 
dmlconf.getBooleanValue(DMLConfig.EXTRA_FINEGRAINED_STATS);
                DMLScript.STATISTICS_MAX_WRAP_LEN = 
dmlconf.getIntValue(DMLConfig.STATS_MAX_WRAP_LEN);
 
+               boolean exceptionThrown = false;
+
                Statistics.startRunTimer();
                try {
                        // run execute (w/ exception handling to ensure proper 
shutdown)
@@ -93,6 +95,9 @@ public class ScriptExecutorUtils {
                                ec.setGPUContexts(gCtxs);
                        }
                        rtprog.execute(ec);
+               } catch (Throwable e) {
+                       exceptionThrown = true;
+                       throw e;
                } finally { // ensure cleanup/shutdown
                        if (DMLScript.USE_ACCELERATOR && 
!ec.getGPUContexts().isEmpty()) {
                                ec.getGPUContexts().forEach(gCtx -> 
gCtx.clearTemporaryMemory());
@@ -104,10 +109,17 @@ public class ScriptExecutorUtils {
                        // display statistics (incl caching stats if enabled)
                        Statistics.stopRunTimer();
 
-                       if(statisticsMaxHeavyHitters > 0)
-                               
System.out.println(Statistics.display(statisticsMaxHeavyHitters));
-                       else
-                               System.out.println(Statistics.display());
+                       if (!exceptionThrown) {
+                               if (statisticsMaxHeavyHitters > 0)
+                                       
System.out.println(Statistics.display(statisticsMaxHeavyHitters));
+                               else
+                                       
System.out.println(Statistics.display());
+                       } else {
+                               if (statisticsMaxHeavyHitters > 0)
+                                       
System.err.println(Statistics.display(statisticsMaxHeavyHitters));
+                               else
+                                       
System.err.println(Statistics.display());
+                       }
                }
        }
 

Reply via email to