|
Class Reference
%SYS.PTools.SQLStats
|
|
![]() |
|||
Private Storage |
This class can be used to gather statistical information on SQL queries run on a give Caché system.
You can invoke different levels of the Stats gathering with the following command:
DO $SYSTEM.SQL.SetSQLStats(flag)
Where flag can be:
The Stats gathered are:
It is also possible to invoke Stats gathering for just the current process. That command is:
DO $SYSTEM.SQL.SetSQLStatsJob(flag)
The modules can be nested in one another. The outer module will display inclusive numbers, so the Module MAIN will be the overall results for the full query.
Upon first enabling SQLStats you should Purge Cached Queries in order to force code regeneration. When you stop gathering Stats using the following command:
DO $SYSTEM.SQL.SetSQLStats(0)
You do not need to Purge Cached Queries. The small number of additional lines of code should not affect performance.
All of the data is stored in
A view, %SYS_PTools.SQLStatsView, has been defined to make looking at the data easier.
For Example:
or for a more condensed output:
These classes store data in globals that default to the %SYS NameSpace: ^%SYS.PTools.SQLQueryD, ^%SYS.PTools.SQLQueryC, and ^%SYS.PTools.SQLQueryI. If you are going to run this on a large system for some time you might want to create global mapping to move these globals out of the CACHESYS database into a different one.
Error information is stored in ^%SYS.PTools.SQLQuery("Error",$j)
|
|
Properties | |||
---|---|---|---|
ChildSub | Counter | ExeName | GlobalRefs |
IPAddress | LinesOfCode | MachineName | ModuleCount |
ModuleName | RoutineInfo | RowCount | SQLQueryPointer |
StartTime | TimeToFirstRow | TotalTime | UserName |
|
|
This method is used to export data from the %SYS.PTools.SQLStats class to a comma delimited text file. Caché SQL Manager.
This method will return the SQLStats from the last query called. If makes use of a local variable that gets set when the stats data is saved. This only works if you are running in the same process. From terminal to see the data you can call d %sqlcontext.DumpResults()
This method returns the Stats for a given module of a given SQL statement It is called from the Show Plan code when Stats are to be included
This is the method that stores all of the runtime data in the%SYS_PTools.SQLStats table Caché SQL Manager.
This method is called once from the cursor open code, initializes local variables, and called Start() for the MAIN loop.
This is the header row that will be in the output file. The columns should be comma delimited
This method is called to remove data from the %SYS.PTools.SQLStats table. It does not remove data from%SYS_PTools.SQLQuery , those rows are cleaned up when a query is compiled it takes two parameters: NameSpace - The NameSpace that you want to delete stats from, default is all NameSpaces RoutineName - the name of the Routine that you want to delete Stats for, should be used with NameSpace, default is all routines
This method is called from the cursor close code. It is called once for each query run. It calls the GlobalSave method that adds data to the%SYS_PTools.SQLStats table. Caché SQL Manager.
This method is called every time you enter a module.
This method is called every time you exit a module.
|
SQL Query as view "SQLStatsView":
SELECT S.ID, Q.NameSpace, Q.RoutineName, Q.CursorName, Q.CompileTime,
S.StartTime, S.Counter, S.ModuleName, S.ModuleCount,
S.GlobalRefs, S.LinesOfCode, S.TotalTime, S.TimeToFirstRow, S.RowCount,
S.UserName, S.ExeName, S.MachineName, S.IPAddress, Q.QueryType, Q.QueryText
FROM %SYS_PTools.SQLQuery Q LEFT OUTER JOIN %SYS_PTools.SQLStats S ON Q.ID = S.SQLQueryPointer
This query def joins%SYS_PTools.SQLQuery and %SYS.PTools.SQLStats to make SQL reporting on the data easier. Caché SQL Manager.
|