Fortran language logging and runtime information
This example uses the following file name: logrun.f
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.
program logRunUdtf
call nzaeRun()
stop
end
subroutine nzaeHandleRequest(handle)
character(100) infoString
integer infoInt, isSpu, isUdf, isUda, isUdtf
double precision infoDouble
infoString = "init"
infoDouble = -1
infoInt = -1
isSpu = -1
isUda = -1
isUdf = -1
isUdtf = -1
c IGNORE ALL INPUT.
10 call nzaeGetNext(handle, hasNext)
if (hasNext .eq. 1) then
goto 10
endif
c OUTPUT WHERE WE ARE RUNNING.
call nzaeSetOutputString(handle, 0, "Host or Spu?")
call nzaeIsRunningOnSpu(handle, isSpu)
if (isSpu .eq. 1) then
call nzaeSetOutputString(handle, 1, "host")
else
call nzaeSetOutputString(handle, 1, "spu")
endif
call nzaeSetOutputNull(handle, 2)
call nzaeSetOutputNull(handle, 3)
call nzaeOutputResult(handle)
c OUTPUT SUGGESTED MEMORY LIMIT.
call nzaeGetSuggestedMemoryLimit(handle, infoDouble)
call nzaeSetOutputString(handle, 0, "Memory Limit")
call nzaeSetOutputNull(handle, 1)
call nzaeSetOutputDouble(handle, 2, infoDouble)
call nzaeSetOutputNull(handle, 3)
call nzaeOutputResult(handle)
c OUTPUT IS-USER-QUERY.
call nzaeIsUserQuery(handle, infoInt)
call nzaeSetOutputString(handle, 0, "User Query?")
if (infoInt .eq. 1) then
call nzaeSetOutputString(handle, 1, "Yes")
else
call nzaeSetOutputString(handle, 1, "No")
endif
call nzaeSetOutputNull(handle, 2)
call nzaeSetOutputNull(handle, 3)
call nzaeOutputResult(handle)
c OUTPUT ADAPTER TYPE.
call nzaeIsUdf(handle, isUdf)
call nzaeIsUda(handle, isUda)
call nzaeIsUdtf(handle, isUdtf)
call nzaeSetOutputString(handle, 0, "Adapter Type")
if (isUdf .eq. 1) then
call nzaeSetOutputString(handle, 1, "udf")
endif
if (isUda .eq. 1) then
call nzaeSetOutputString(handle, 1, "uda")
endif
if (isUdtf .eq. 1) then
call nzaeSetOutputString(handle, 1, "udtf")
endif
call nzaeSetOutputNull(handle, 2)
call nzaeSetOutputNull(handle, 3)
call nzaeOutputResult(handle)
c OUTPUT DATA SLICE ID.
call nzaeGetDataSliceId(handle, infoInt)
call nzaeSetOutputString(handle, 0, "Dataslice ID")
call nzaeSetOutputNull(handle, 1)
call nzaeSetOutputNull(handle, 2)
call nzaeSetOutputInt32(handle, 3, infoInt)
call nzaeOutputResult(handle)
c OUTPUT TRANSACTION ID.
call nzaeGetTransactionId(handle, infoString)
call nzaeSetOutputString(handle, 0, "Transaction ID")
call nzaeSetOutputString(handle, 1, infoString)
call nzaeSetOutputNull(handle, 2)
call nzaeSetOutputNull(handle, 3)
c OUTPUT HARDWARE ID.
call nzaeGetHardwareId(handle, infoString)
call nzaeSetOutputString(handle, 0, "Hardware ID")
call nzaeSetOutputString(handle, 1, infoString)
call nzaeSetOutputNull(handle, 2)
call nzaeSetOutputNull(handle, 3)
call nzaeOutputResult(handle)
c OUTPUT NUMBER OF DATASLICES.
call nzaeGetNumberOfDataslices(handle, infoInt)
call nzaeSetOutputString(handle, 0, "Number of Dataslices")
call nzaeSetOutputNull(handle, 1)
call nzaeSetOutputNull(handle, 2)
call nzaeSetOutputInt32(handle, 3, infoInt)
call nzaeOutputResult(handle)
c OUTPUT NUMBER OF SPUS.
call nzaeGetNumberOfSpus(handle, infoInt)
call nzaeSetOutputString(handle, 0, "Number of Spus")
call nzaeSetOutputNull(handle, 1)
call nzaeSetOutputNull(handle, 2)
call nzaeSetOutputInt32(handle, 3, infoInt)
call nzaeOutputResult(handle)
c DO SOME LOGGING.
call nzaeLog(handle, "Here is some logging text!")
call nzaeLog(handle, "Here is some more logging text!")
return
end
Compilation
Use the standard compile:
$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language fortran --version 3 \
--template compile logrun.f
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 fortran --version 3 \
--template udtf --exe logrun --sig "log_run(int4)" \
--return "table(name varchar(100), val_str varchar(100), \
val_double double, val_int int4)" --mem 100k --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(log_run(1));
NAME | VAL_STR | VAL_DOUBLE | VAL_INT
----------------------+---------+------------+---------
Host OR Spu? | spu | |
Memory LIMIT | | 102400 |
User Query? | Yes | |
Adapter Type | udtf | |
Dataslice ID | | | 0
Hardware ID | 0 | |
Number of Dataslices | | | 4
Number of Spus | | | 1
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!