harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shi Jun Zhang <chancedr...@gmail.com>
Subject [classlib]Internal diagnostic information for native code
Date Tue, 03 Aug 2010 07:59:46 GMT
Hi all,

I wrote some native trace code for internal diagnoses in
instrument/luni/nio/prefs modules. The trace format is very similar to the
one we used in jpda module.

In each native source file need to use the trace, first include "log.h",
then insert trace statement in any method. The trace statement is like this:

TRACE(LOG_LEVEL_MIN, (LOG_ENTER_FL, "method_name(%p, %p, %p)", arg1, arg2,

This statement will output the string of method name with its arguments to
standard output or file or anywhere can be redirected to. In this statement,
there is 4 parts.

The first part is "TRACE". This is a macro when macro NDEBUG is defined, the
TRACE line will be replaced with empty line and if NDEBUG is not defined,
the TRACE line will be replaced with real trace statement.

The second part is "LOG_LEVEL_MIN". There are 3 levels currently,
LOG_LEVEL_MAX, LOG_LEVEL_MED, LOG_LEVEL_MIN. Once a custom level is set when
initializing the log manager, output will only contain the level equal or
less than custom level. The default level is min.

The third part is "LOG_ENTER_FL". This macro will expand to "\"Enter\",
__FILE__, __LINE__", which means the log type is entering a method. __FILE__
and __LINE__ will be replaced with file name and line number by C compiler.
Currently there are 4 kinds, LOG_ENTER_FL means entering a method,
LOG_EXIT_FL means exit a method, LOG_ERROR_FL means error/exception occurs
and LOG_DATA_FL means logging some variable values. More kinds can be added.

The last part is "method_name(%p, %p, %p)", arg1, arg2, arg3. The string
with the arguments will be formatted and output.

To turn on the trace function, building native code without defining NDEBUG
and starting jvm with argument -DtraceLevel=min -DtraceFile=filePath.

There are lots of things can be improved. Any comments are welcomed.

Shi Jun Zhang

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message