Perl language logging and runtime information
This example uses the following file name: LogRunAE.pm
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.
package LogRunAe;
use strict;
use autodie;
use nzae::Ae;
our @ISA = qw(nzae::Ae);
my $ae = LogRunAe->new();
$ae->run();
sub _run()
{
my $self = shift;
while ($self->getNext())
{
next;
}
$self->output("Dataslice ID: ".$self->getDatasliceId());
$self->output("Hardware ID: ".$self->getHardwareId());
$self->output("Number of Data Slices: ".$self->getNumberOfDataSlices());
$self->output("Number of Spus: ".$self->getNumberOfSpus());
$self->output("Suggested Memory Limit: ".$self->getSuggestedMemoryLimit());
$self->output("Transaction ID: ".$self->getTransactionId());
my $userquery = $self->isAUserQuery()? "false" : "true";
$self->output("Is A User Query: ".$userquery);
my $loggingenabled = $self->isLoggingEnabled()? "true":"false";
$self->output("Is Logging Enabled: ".$loggingenabled);
my $runningonspu = $self->isRunningOnSpu()? "true" : "false";
$self->output("Is Running on a spu: ".$runningonspu);
my $runninginpostgres = $self->isRunningInPostgres()? "true" : "false";
$self->output("Is Running in Postgres: ".$runninginpostgres);
my $runningindbos = $self->isRunningInDbos()? "true" : "false";
$self->output("Is Running in DBOS: ".$runningindbos);
my $uda = $self->isUda()? "true" : "false";
$self->output("Is a UDA: ".$uda);
my $udf = $self->isUdf()? "true" : "false";
$self->output("Is a UDF: ".$udf);
my $udtf = $self->isUdtf()? "true" : "false";
$self->output("Is a UDTF: ".$udtf);
$self->log("Here is some logging text!", $self->getLogLevelDebug());
$self->log("Here is some more logging text!", $self->getLogLevelDebug());
}
1;
Deployment
Deploy the script:
$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language perl --version 3 \
--template deploy LogRunAe.pm
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 perl --version 3 \
--template udtf --exe LogRunAe.pm --sig "log_run(int4)" \
--return "table(text varchar(1000))" --level 4 --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 on the system database:
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: 304796
Is A User Query: false
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 whether 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