changeset 19699:ef30b2318658

Truffle/Instrumentation: the Visualizer for language-specific values now has a "trim" option to limit result size.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Thu, 05 Mar 2015 16:58:12 -0800
parents 32b4b06b6fac
children d57ca11a6883
files graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Visualizer.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLDefaultVisualizer.java
diffstat 3 files changed, 34 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Visualizer.java	Wed Mar 04 16:38:36 2015 -0800
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Visualizer.java	Thu Mar 05 16:58:12 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -60,9 +60,12 @@
     String displayCallTargetName(CallTarget callTarget);
 
     /**
-     * Converts a value in the guest language to a display string.
+     * Converts a value in the guest language to a display string. If
+     *
+     * @param trim if {@code > 0}, them limit size of String to either the value of trim or the
+     *            number of characters in the first line, whichever is lower.
      */
-    String displayValue(ExecutionContext context, Object value);
+    String displayValue(ExecutionContext context, Object value, int trim);
 
     /**
      * Converts a slot identifier in the guest language to a display string.
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java	Wed Mar 04 16:38:36 2015 -0800
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java	Thu Mar 05 16:58:12 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -70,12 +70,34 @@
         return callTarget.toString();
     }
 
-    public String displayValue(ExecutionContext context, Object value) {
-        return value.toString();
+    public String displayValue(ExecutionContext context, Object value, int trim) {
+        return trim(value.toString(), trim);
     }
 
     public String displayIdentifier(FrameSlot slot) {
         return slot.getIdentifier().toString();
     }
 
+    /**
+     * Trims text if {@code trim > 0} to the shorter of {@code trim} or the length of the first line
+     * of test. Identity if {@code trim <= 0}.
+     */
+    protected String trim(String text, int trim) {
+        if (trim == 0) {
+            return text;
+        }
+        final String[] lines = text.split("\n");
+        String result = lines[0];
+        if (lines.length == 1) {
+            if (result.length() <= trim) {
+                return result;
+            }
+            if (trim <= 3) {
+                return result.substring(0, Math.min(result.length() - 1, trim - 1));
+            } else {
+                return result.substring(0, trim - 4) + "...";
+            }
+        }
+        return (result.length() < trim - 3 ? result : result.substring(0, trim - 4)) + "...";
+    }
 }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLDefaultVisualizer.java	Wed Mar 04 16:38:36 2015 -0800
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLDefaultVisualizer.java	Thu Mar 05 16:58:12 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -73,11 +73,11 @@
     }
 
     @Override
-    public String displayValue(ExecutionContext context, Object value) {
+    public String displayValue(ExecutionContext context, Object value, int trim) {
         if (value == SLNull.SINGLETON) {
             return "null";
         }
-        return value.toString();
+        return trim(value.toString(), trim);
     }
 
     @Override