harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Regis <xu.re...@gmail.com>
Subject Re: [classlib]Internal diagnostic information for native code
Date Wed, 04 Aug 2010 02:06:16 GMT
On 2010-08-03 15:59, Shi Jun Zhang wrote:
> 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,
> arg3));
>
> 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.
>

Sometimes I have to add "printf" to debug native code of classlib, it's very 
nice to have trace like jpda module. Would you like to raise a JIRA and attach 
your patch on it? It's easier to understand how it works with code.

-- 
Best Regards,
Regis.

Mime
View raw message