This is the mail archive of the kawa@sourceware.cygnus.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Even better (was: Re: tracing cosmetics)


This time I spent a little bit more energy and I tried to reorganize
this part.

I changed the following:

  - Added two static flags to control the output of thread name and
    time stamp.  While not beautiful to see I think it's the best
    layout to further process the output and get more elaborated
    reports.  For instance: extract just one thread output, profiling,
    etc.

  - Made pubblic the indentationStep.

  - Added the static print method which enable Scheme code to output
    additional informations obeying the indentation.

What do you think about it?


--- TracedProcedure.java.save	Mon Oct 11 12:16:24 1999
+++ TracedProcedure.java	Thu Oct 14 15:30:08 1999
@@ -12,7 +12,9 @@
 
   static Binding indentation
   = Binding.make(gnu.math.IntNum.zero(), "indentation");
-  static int indentationStep = 2;
+  public static int indentationStep = 2;
+  public static boolean withTimeStamp = false;
+  public static boolean withThreadName = false;
 
   public TracedProcedure (Procedure proc, boolean enable)
   {
@@ -44,54 +46,73 @@
       out.print(' ');
   }
 
+  public static void print (String line)
+    {
+      printTrace(((IntNum) indentation.getValue()).intValue(), line);
+    }
+
+  static synchronized void printTrace (int indentation, String line)
+    {
+      PrintWriter out = OutPort.errDefault();
+      if (withThreadName)
+	out.print(Thread.currentThread().getName() + ": ");
+      if (withTimeStamp)
+	out.print((new java.util.Date()).getTime() + ": ");
+      indent(indentation, out);
+      out.println(line);
+    }
+
+  static void entering (String name, Object[] args, int indentation)
+    {
+      String line = "call to " + name + " (";
+      int len = args.length;
+      for (int i = 0;  i < len;  i++)
+	line += (i > 0 ? " " : "") + args[i].toString();
+      printTrace(indentation, line + ")");
+    }
+
+  static void exiting (String name, Object result, int indentation)
+    {
+      printTrace(indentation, "return from " + name + " => " + result);
+    }
+
+  static void throwing (String name, Object result, int indentation)
+    {
+      printTrace(indentation, name + " throws exception " + result);
+    }
+
   public Object applyN(Object[] args)
   {
     if (enabled)
       {
-	 int curIndent = ((IntNum) indentation.getValue()).intValue();
-	PrintWriter out = OutPort.errDefault();
+	int curIndent = ((IntNum) indentation.getValue()).intValue();
 	String name = getName();
 	if (name == null)
 	  name = "??";
 
-	 // Print the call arguments (indented).
-	 indent(curIndent, out);
-	out.print("call to ");
-	out.print(name);
-	int len = args.length;
-	out.print(" (");
-	for (int i = 0;  i < len;  i++)
+	entering(name, args, curIndent);
+	// Now do the actual call, but with the indentation incremented.
+	gnu.mapping.Future context = gnu.mapping.Future.getContext();
+	FluidBinding oldBindings = context.fluidBindings;
+	IntNum newIndentation = IntNum.make(curIndent + indentationStep);
+	FluidBinding newBindings
+	  = new FluidBinding(oldBindings, newIndentation, indentation);
+	Object result = null;
+	try
 	  {
-	    if (i > 0)
-	      out.print(' ');
-	    put(args[i], out);
+	    context.setFluids(newBindings);
+	    result = proc.applyN(args);
 	  }
-	out.println(")");
-
-	 // Now do the actual call, but with the indentation incremented.
-	 gnu.mapping.Future context = gnu.mapping.Future.getContext();
-	 FluidBinding oldBindings = context.fluidBindings;
-	 IntNum newIndentation = IntNum.make(curIndent+indentationStep);
-	 FluidBinding newBindings
-	   = new FluidBinding(oldBindings, newIndentation, indentation);
-	Object result;
-	 try
-	   {
-	     context.setFluids(newBindings);
-	     result = proc.applyN(args);
-	   }
-	 finally
-	   {
-	     context.resetFluids(oldBindings);
-	   }
-
-	 // Print the result (indented).
-	 indent(curIndent, out);
-	out.print("return from ");
-	out.print(name);
-	out.print(" => ");
-	put(result, out);
-	out.println();
+	catch (RuntimeException e)
+	  {
+	    throwing(name, e, curIndent);
+	    throw e;
+	  }
+	finally
+	  {
+	    context.resetFluids(oldBindings);
+	  }
+	exiting(name, result, curIndent);
 	return result;
       }
     return proc.applyN(args);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]