scale.common
Class Debug

java.lang.Object
  extended by scale.common.Debug

public class Debug
extends java.lang.Object

A class for aiding in debuging.

$Id: Debug.java,v 1.37 2007-01-04 16:58:27 burrill Exp $

Copyright 2006 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

Use Debug.trace(...) to decide if debug trace information should be printed. The standard way of using this class is to:

  1. Put
     public static boolean classTrace = false;
     
    in the class that you wish to be able to trace.
  2. Put
     private boolean trace;
     
    in the class as well.
  3. Add the statement
       trace = Debug.trace("routine name", classTrace, level);
     
    to the class constructor where the level is some intger. Or,
      this.trace = classTrace || Debug.debug(level);
     
    for classes that operate over more than one routine at a time,
  4. Use constructs such as
      if (trace)
        System.out.println(...);
     
    to generate the trace information.

Use Debug.debug(level) to decide if extra validity tests should be performed or to print more detailed warnings, etc.

The debug level is meant for displaying general debugging information. A debug level of 1 causes validity checking at various places of the compiler. A level of 2 causes the output of general information. A level of 3 causes the output of some large tables.


Field Summary
static int FULL
          Debug level FULL.
static int MEDIUM
          Debug level between MINIMUM and FULL.
static int MINIMUM
          Debug level minimum.
static int OFF
          Debug level off.
 
Method Summary
static boolean debug(int level)
          Return true if the debug level is greater than or equal to the given level.
static java.lang.String formatInt(long value, int size)
          Return the string representation of a long integer value.
static int getDebugLevel()
          Return the debug level value.
static java.lang.String getReportName()
          Get the report name.
static boolean printMessage(java.lang.String msg)
          Print out the specified message.
static boolean printMessage(java.lang.String msg, java.lang.Object o)
          Print out the specified message followed by the object.
static boolean printMessage(java.lang.String msg, java.lang.Object o, int indent)
          Print out the specified message followed by the object.
static boolean printStackTrace()
          Print out a stack trace.
static boolean printStackTrace(java.lang.Throwable ex)
          Print out the specified stack trace.
static void setDebugLevel(int level)
          Set the debug level.
static void setReportName(java.lang.String name)
          Set the report name.
static boolean trace(java.lang.String name, boolean flag, int level)
          Return true if the report name is the same as the specified name and the flag argument is true, or the debug level is greater than or equal to the given level.
static long trackMemory()
          Return the amount of memory used in bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OFF

public static final int OFF
Debug level off.

See Also:
Constant Field Values

MINIMUM

public static final int MINIMUM
Debug level minimum.

See Also:
Constant Field Values

MEDIUM

public static final int MEDIUM
Debug level between MINIMUM and FULL.

See Also:
Constant Field Values

FULL

public static final int FULL
Debug level FULL.

See Also:
Constant Field Values
Method Detail

setDebugLevel

public static void setDebugLevel(int level)
Set the debug level. The debug level control the amount of debug level that is printed.

Parameters:
level - a positive integer control the debug level

setReportName

public static void setReportName(java.lang.String name)
Set the report name.

Parameters:
name - is the name to be traced

getReportName

public static java.lang.String getReportName()
Get the report name.


getDebugLevel

public static int getDebugLevel()
Return the debug level value.


debug

public static final boolean debug(int level)
Return true if the debug level is greater than or equal to the given level.

Parameters:
level - the debug level
Returns:
true if at level level or greater

trace

public static final boolean trace(java.lang.String name,
                                  boolean flag,
                                  int level)
Return true if

Parameters:
name - is name to be traced
flag - is the (class) trace flag
level - is the debug level
Returns:
true if tracing should be done

printStackTrace

public static boolean printStackTrace()
Print out a stack trace. This method is designed so that it can be used with the assert Java statement.

Returns:
true

printStackTrace

public static boolean printStackTrace(java.lang.Throwable ex)
Print out the specified stack trace. This method is designed so that it can be used with the assert Java statement.

Parameters:
ex - is the exception to be displayed
Returns:
true

printMessage

public static boolean printMessage(java.lang.String msg)
Print out the specified message. This method is designed so that it can be used with the assert Java statement.

Parameters:
msg - is the message
Returns:
true

printMessage

public static boolean printMessage(java.lang.String msg,
                                   java.lang.Object o)
Print out the specified message followed by the object. If the object is null only the message is printed. This method is designed so that it can be used with the assert Java statement.

Parameters:
msg - is the message
o - is the object
Returns:
true

printMessage

public static boolean printMessage(java.lang.String msg,
                                   java.lang.Object o,
                                   int indent)
Print out the specified message followed by the object. If the object is null only the message is printed. This method is designed so that it can be used with the assert Java statement.

Parameters:
msg - is the message
o - is the object
indent - specifies the number of spaces to output before the message
Returns:
true

trackMemory

public static long trackMemory()
Return the amount of memory used in bytes. This memory includes the class representations. This method depends on the garbage collection algorithm. Not all un-referenced objects are guarantteed to be collected when the memory stats are obtained.


formatInt

public static java.lang.String formatInt(long value,
                                         int size)
Return the string representation of a long integer value. The length of the string will be exactly size characters, pre-appended with blanks as necessary. If the value cannot be represented in the space provided, a string of asterisks is returned instead.

Parameters:
value - is the value
size - is the number of characters required.