You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.




org.mozilla.util
Class Debug

java.lang.Object
  |
  +--org.mozilla.util.Debug

public class Debug
extends java.lang.Object

Debug Vendor of debug "filter" strings set & queried by clients. This allows conditional code to only be executed if a certain filter is set.
Example of use from JAG days:
JDApplication allows the setting of filters from the commandline at app startup time, and Log supports printing debug messages only when a specific filter string has been set.

Alternatively, users can use the System Properties table to define filter strings at runtime:

java -DDebug.filters=String ...

where String is comma (,) separated list of constants WITH NO WHITESPACE. ie "AXISPANEL_PAINT,BODYPANEL_PAINT".

All filters are case-sensitive. This class also provides various timing routines.


Field Summary
static java.lang.String ALL_FILTER_STRING
           
static java.lang.String HELP_FILTER_STRING
           
static java.lang.String PROGRESS_FILTER_STRING
           
static java.lang.String TIMING_FILTER_STRING
           
 
Constructor Summary
Debug()
           
 
Method Summary
static void addFilter(java.lang.String aFilter)
          Sets a debug filter, for future consumption by this class, as well as other utility classes, like Log, etc.
static boolean containsFilter(java.lang.String aFilter)
          Returns true if any of the following conditions are true: 1.
static boolean containsFilter(java.lang.String aFilter, java.lang.String allFiltersgMatchThisString)
          Funnel-point method, which takes a filter and an "allFiltersgMatchThisString" string.
static boolean containsFilterWithPrefix(java.lang.String aFilterPrefix)
          Look for any "filter" with the specified prefix.
static void elapsedTime(java.lang.String logMessage)
          Identical to the "elapsedTime(String logMessage, String aFilter)" method, except it will only show the message if the filter "TIMING" exists in Debug's filter list.
static void elapsedTime(java.lang.String logMessage, java.lang.String aFilter)
          This method does absolutely nothing unless: 1.
static long elapsedTimeSinceElapsedTime()
          Returns the elapsed time since this class was initialized.
static long elapsedTimeSinceInitialization()
          Returns the elapsed time since this class was initialized.
static long elapsedTimeSinceStartTime()
          Returns the elapsed time since the preceeding startTiming() call, This method does not check debug filters...
static java.lang.String getHashCode(java.lang.Object anObject)
          Returns a String containing the hexadecimal hashCode of the passed in object, of the form: "0x0000"
static java.lang.String getNameAndHashCode(java.lang.Object anObject)
          Returns a String containing the class name and hexadecimal hashCode of the passed in object, of the form: "fully.qualified.ClassName[0x0000]"
static void printTime(java.lang.String msg, java.lang.String aFilter)
          Print time since start of app, and time since the last time this method was called.
static void removeAllFilters()
          Removes all filters from the list of filters.
static void removeFilter(java.lang.String aFilter)
          Removes the specified filter from the list of filters.
static void startTiming()
          Starts a timer which can be stopped using one of the "stopTiming()" methods.
static void startTiming(java.lang.String logMessage)
          Identical to the "startTiming(String logMessage, String aFilter)" method, except it will only show the message if the filter "TIMING" exists in Debug's filter list.
static void startTiming(java.lang.String logMessage, java.lang.String aFilter)
          This method does absolutely nothing unless: 1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HELP_FILTER_STRING

public static final java.lang.String HELP_FILTER_STRING

ALL_FILTER_STRING

public static final java.lang.String ALL_FILTER_STRING

TIMING_FILTER_STRING

public static final java.lang.String TIMING_FILTER_STRING

PROGRESS_FILTER_STRING

public static final java.lang.String PROGRESS_FILTER_STRING
Constructor Detail

Debug

public Debug()
Method Detail

addFilter

public static void addFilter(java.lang.String aFilter)
Sets a debug filter, for future consumption by this class, as well as other utility classes, like Log, etc. Virtually all "filters" are simply developer-meaningful strings which will be tested within developer code, to conditionally execute code. There are some predefined filters, which this class actually does something with (besides simply handing it back when asked for). The predefined filters are: HELP ALL TIMING If the "HELP" filter is found, this class will print a message displaying the predefined filters and what they do. If the "ALL" filter is found, this class will return "true" when queried for the existence of any filter, effectively turning on all debugging tests. This is useful for both quick and easy tests, as well as to find forgotten debug filters (see Log class for more info on this). If the "TIMING" filter is specified, then the time routines will always print their info, regardless of what filter string is passed to them. This is useful for turning on all timing tests.

removeFilter

public static void removeFilter(java.lang.String aFilter)
Removes the specified filter from the list of filters.

removeAllFilters

public static void removeAllFilters()
Removes all filters from the list of filters.

containsFilterWithPrefix

public static boolean containsFilterWithPrefix(java.lang.String aFilterPrefix)
Look for any "filter" with the specified prefix. "ALL" is not considered to be a match. This method works in (normally) O-n time (if no match).

containsFilter

public static boolean containsFilter(java.lang.String aFilter,
                                     java.lang.String allFiltersgMatchThisString)
Funnel-point method, which takes a filter and an "allFiltersgMatchThisString" string. See the javadoc for "containsFilter(String aFilter)" for the rest of what this method does. This method works in (normally) O-1 time. NOTE: The "allFiltersgMatchThisString" parameter can be used to conditionally execute code while preventing the "ALL" filter from having any effect. So, the conditional code should use the test "if (Debug.containsFilter("SomeFilter", ""))" to see if a filter has been set, and not get a false positive from the "ALL" filter.

containsFilter

public static boolean containsFilter(java.lang.String aFilter)
Returns true if any of the following conditions are true: 1. The specified filter is contained in the current filter set. 2. The "ALL" filter is set (this is true even if the passed-in filter is "null"). 3. The passed-in filter is ""... as that filter is considered to always be a match, regardless of the current filter set. 4. The passed in filter is "null" and the "ALL" filter is currently set. Otherwise returns false. NOTE: This method, and all filtering of this class is case-sensitive.

startTiming

public static void startTiming()
Starts a timer which can be stopped using one of the "stopTiming()" methods. This method does not check debug filters... it always does what it's told. Calling this method resets the elapsed time ("lap time").

startTiming

public static void startTiming(java.lang.String logMessage)
Identical to the "startTiming(String logMessage, String aFilter)" method, except it will only show the message if the filter "TIMING" exists in Debug's filter list.

startTiming

public static void startTiming(java.lang.String logMessage,
                               java.lang.String aFilter)
This method does absolutely nothing unless: 1. The specified filter is contained in the current filter set. 2. The "TIMING" filter is set (this is true even if the passed-in filter is "null"). 3. The passed-in filter is ""... as that filter is considered to always be a match, and so will cause this method to always work, regardless of the current filter set. NOTE: The "ALL" filter has no effect on timing methods. Otherwise, starts a timer which can be stopped using one of the "stopTiming()" methods and prints out a logMessage indicating that timing has begun. This method may be called with a "null" logMessage. A logMessage is sometimes unneccesary since the matched filter string is printed with the output anyway, and that is frequently enough information. Calling this method resets the elapsed time ("lap time").

elapsedTimeSinceInitialization

public static long elapsedTimeSinceInitialization()
Returns the elapsed time since this class was initialized. This method does not check debug filters... it always does what it's told. Calling this method resets the elapsed time ("lap time"). This method may be called repeatedly to get "lap" times.

elapsedTimeSinceStartTime

public static long elapsedTimeSinceStartTime()
Returns the elapsed time since the preceeding startTiming() call, This method does not check debug filters... it always does what it's told. Calling this method resets the elapsed time ("lap time"). This method may be called repeatedly to get "lap" times.

elapsedTimeSinceElapsedTime

public static long elapsedTimeSinceElapsedTime()
Returns the elapsed time since this class was initialized. This method does not check debug filters... it always does what it's told. Calling this method resets the elapsed time ("lap time"). This method may be called repeatedly to get "lap" times.

elapsedTime

public static void elapsedTime(java.lang.String logMessage)
Identical to the "elapsedTime(String logMessage, String aFilter)" method, except it will only show the message if the filter "TIMING" exists in Debug's filter list.

elapsedTime

public static void elapsedTime(java.lang.String logMessage,
                               java.lang.String aFilter)
This method does absolutely nothing unless: 1. The specified filter is contained in the current filter set. 2. The "TIMING" filter is set (this is true even if the passed-in filter is "null"). 3. The passed-in filter is ""... as that filter is considered to always be a match, and so will cause this method to always work, regardless of the current filter set. NOTE: The "ALL" filter has no effect on timing methods. Otherwise, prints the following information: 1. The elapsed time since initialization of this class. 2. The elapsed time since the preceeding startTiming() call. 3. The "lap" time, since the last time "elapsedTime()" was called. 4. A client-supplied message. When a filter matches, this method invokes the following methods: elapsedTime() elapsedTimeSinceInitialization() elapsedTimeSinceElapsedTime() When a filter matches, calling this method resets the elapsed time ("lap time"). This method may be called with a "null" logMessage. A logMessage is sometimes unneccesary since the matched filter string is printed with the output anyway, and that is frequently enough information. This method may be called repeatedly to get "lap" times.

printTime

public static void printTime(java.lang.String msg,
                             java.lang.String aFilter)
Print time since start of app, and time since the last time this method was called. Call this with a msg you want printed, and a filter. Then run with -jsdebug filter and all these timing msgs will come out.

getHashCode

public static java.lang.String getHashCode(java.lang.Object anObject)
Returns a String containing the hexadecimal hashCode of the passed in object, of the form: "0x0000"

getNameAndHashCode

public static java.lang.String getNameAndHashCode(java.lang.Object anObject)
Returns a String containing the class name and hexadecimal hashCode of the passed in object, of the form: "fully.qualified.ClassName[0x0000]"