Python language logging and runtime information

This example uses the following file name: logrun.py

Code

The code in this example explores functionality that may not be commonly used. Logging can be used to help trace the execution of an AE. To be of use, the AE must be registered with a log mask and logging must be enabled via nzudxdbg. To receive system logging messages in the window where the NPS system was started, you need to start NPS with the '-i' option (for example, 'nzstart -i'). This causes the NPS processes to remain attached to the terminal. Runtime information provides statistics about the NPS system, including the number of dataslices, the number of SPUs, and locus of execution.

import nzae
class LogRunAe(nzae.Ae):
    def _run(self):
        for row in self:
            pass
        self.output("Dataslice ID: " + repr(self.getDatasliceId()))
        self.output("Hardware ID: " + repr(self.getHardwareId()))
        self.output("Number of Data Slices: " +
repr(self.getNumberOfDataSlices()))
        self.output("Number of Spus: " + repr(self.getNumberOfSpus()))
        self.output("Suggested Memory Limit: " +
repr(self.getSuggestedMemoryLimit()))
        self.output("Transaction ID: " + repr(self.getTransactionId()))
        self.output("Is A User Query: " + repr(self.isAUserQuery()))
        self.output("Is Logging Enabled: " + repr(self.isLoggingEnabled()))
        self.output("Is Running on a spu: " + repr(self.isRunningOnSpu()))
        self.output("Is Running in Postgres: " +
repr(self.isRunningInPostgres()))
        self.output("Is Running in DBOS: " + repr(self.isRunningInDbos()))
        self.output("Is a UDA: " + repr(self.isUda()))
        self.output("Is a UDF: " + repr(self.isUdf()))
        self.output("Is a UDTF: " + repr(self.isUdtf()))

        self.log("Here is some logging text!", self.LOG_LEVEL__DEBUG)
        self.log("Here is some more logging text!", self.LOG_LEVEL__DEBUG)

LogRunAe.run()

Deployment

Deploy the script:

$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language python64 \
     --template deploy ./logrun.py --version 3 

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_DIR/ae/utilities/bin/register_ae --language python64 --version 3 \
     --template udtf --exe logrun.py --sig "log_run(int4)" \
     --return "table(text varchar(1000))" --mask debug --mem 100k

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(log_run(1));
             TEXT
-------------------------------
 Dataslice ID:           0
 Hardware ID:            0
 Number of DATA Slices:  4
 Number of Spus:         1
 Suggested Memory LIMIT: 102400
 Transaction ID:         8520
 IS A User Query:        True
 IS Logging Enabled:     True
 IS Running ON a spu:    False
 IS Running IN Postgres: False
 IS Running IN DBOS:     True
 IS a UDA:               False
 IS a UDF:               False
 IS a UDTF:              True
(14 rows)

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

05-05-10 14:33:18 (dbos.18728) [d,udx ] Here is some logging text!
05-05-10 14:33:18 (dbos.18728) [d,udx ] Here is some more logging text