R language logging and runtime information

This example explores logging functionality that might not be commonly be used.

Code

Logging can help you trace the execution of an AE. The AE must be registered with a log mask, and logging must be enabled through nzudxdbg. Runtime information provides statistics about the NPS system including the number of data slices, S-Blades, and locus of execution.

Enter the following code in the /tmp/logrun.R file.

nz.fun <- function(){
    getNext()
    logMessage(NZ.DEBUG, "before getRuntime()")
    r <- getRuntime()
    apply(cbind(names(r),as.character(r)), 1, function(X){
        setOutput(0, X[1])
        setOutput(1, X[2])
        outputResult()
    })
    logMessage(NZ.DEBUG, "after getRuntime()")
}

Compilation

Compile the code:

/nz/export/ae/utilities/bin/compile_ae --language r --template compile \
     --version 3 --db dev --user nz /tmp/logrun.R

Registration

Register the example using the --mem and --mask options. The --mask option enables logging for DEBUG and the --mem option sets the memory runtime information.

/nz/export/ae/utilities/bin/register_ae --language r --version 3 \
     --template udtf --exe logrun.R --sig "logrun(VARARGS)" \
     --return "TABLE(name VARCHAR(1000), value VARCHAR(1000))" \
     --db dev --user nz --level 4 --mask DEBUG

Running

Before running, enable logging by running nzudxdbg:

>nzudxdbg
Processing 1 spus
.
done
Processing host
done

Run the query in nzsql:

SELECT * FROM TABLE WITH FINAL(logrun());
          NAME          | VALUE
------------------------+-------
 data.slice.id          | 0
 transaction.id         | 21814
 hardware.id            | 0
 number.data.slices     | 4
 number.spus            | 1
 suggested.memory.limit | 0
 locus                  | 1
 adapter.type           | 1
 user.query             | 1
 session.id             | 16231
(10 rows)

The NPS system logging appears in the window where the NPS system was started:

04-06-11 09:48:54 (dbos.14577) [d,udx ] before getRuntime()
04-06-11 09:48:54 (dbos.14577) [d,udx ] after getRuntime()