BBj Function Debugging

Description

BBj 15.0 and higher includes low-level function debugging tools that can be enabled in the Enterprise Manager (BBj 23.01 and higher) or with a BBj.properties setting. This feature imposes a very small, but non-zero cost; it should only be enabled for limited periods to gather information about function usage.

In BBj 23.01 and higher, BBjServices will log the following warning on startup if this feature is enabled: "Function Debugging is enabled. This is not recommended for extended use in production environments."

Usage

To enable this feature in BBj 23.01 and higher, enable it in the Enterprise Manager in the "BBj Function Debugging" section of BBjServices > Settings.

To enable this feature in earlier versions of BBj, add the following setting to BBj.properties, then restart BBjServices:

com.basis.bbj.funcs.debug=true

API

When this feature is enabled, all function usage (counts and timings, measured in nanoseconds) are tracked system-wide (globally for BBjServices).  Values can be accessed with the following static variable and methods, all in com.basis.bbj.funcs.FunctionMgr:

Returns Static variable or method Returns
boolean FunctionMgr.DEBUG A boolean value indicating whether function usage is currently being tracked.
HashMap<String,Long>

BBj 21.02+:

bbjapi().getFunctionDebugCounts()

Obsolete:

FunctionMgr.getDebugCounts()

A map keyed by function name, containing all functions used during this BBjServices run (or since resetFunctionDebug() was called). This returns a count of the number of times each function was called.
HashMap<String,Long>

BBj 21.02+:

bbjapi().getFunctionDebugNanoTimes()

Obsolete:

FunctionMgr.getDebugNanoTimes()

A map keyed by function name, containing all functions used during this BBjServices run (or since resetFunctionDebug() was called). This returns total execution time for each function, measured in nanoseconds.
void

BBj 21.02+:

bbjapi().resetFunctionDebug()

Obsolete:

FunctionMgr.resetDebug()

This method clears all logged function information from the maps described above.

Example

rem ' BBj Function Debugging

rem ' Enable by adding this setting to BBj.properties:
rem ' com.basis.bbj.funcs.debug=true
use com.basis.bbj.funcs.FunctionMgr
precision 9
print "com.basis.bbj.funcs.debug=",
print FunctionMgr.DEBUG
print "resetFunctionDebug()"
bbjapi().resetFunctionDebug()
print "Use some BBj functions...."
print cvs(sys,3)," ",rev
print date(0:"%hz:%mz:%sz %p")
a = sqr(2)
b = sqr(100)
c = len("The quick brown fox jumps over the lazy dog.")
d = len("")
print "Report function timing statistics...."
counts! = bbjapi().getFunctionDebugCounts()
times! = bbjapi().getFunctionDebugNanoTimes()
print counts!
print times!
iter! = counts!.entrySet().iterator()
while iter!.hasNext()
    entry! = iter!.next()
    func$ = entry!.getKey()
    count = entry!.getValue()
    nano = times!.get(func$)
    print func$," was used",count," time(s) for a total of",
    print nano/1000000," ms (average",nano/count/1000000," ms)"
wend
end

Sample Run

com.basis.bbj.funcs.debug=true

resetFunctionDebug()

Use some BBj functions....

LEVEL 6 REV 21.02

01:36:34 pm

Report function timing statistics....

{BBJAPI=1, CVS=1, DATE=1, LEN=2, REV=1, SQR=2, SYS=1}

{BBJAPI=4821, CVS=18971, DATE=204105, LEN=2742, REV=19530, SQR=89605, SYS=2259}

BBJAPI was used 1 time(s) for a total of .004821 ms (average .004821 ms)

CVS was used 1 time(s) for a total of .018971 ms (average .018971 ms)

DATE was used 1 time(s) for a total of .204105 ms (average .204105 ms)

LEN was used 2 time(s) for a total of .002742 ms (average .001371 ms)

REV was used 1 time(s) for a total of .01953 ms (average .01953 ms)

SQR was used 2 time(s) for a total of .089605 ms (average .0448025 ms)

SYS was used 1 time(s) for a total of .002259 ms (average .002259 ms)

 

READY

>