This class allows manipulation and display of InterSystems IRIS processes running on the system. More...
Public Member Functions | |
def | __init__ (self) |
Number of Lines Executed. More... | |
Static Public Member Functions | |
_.Library.Status | ExamStackByPid (_.Library.String Pid, _.Library.Boolean GetVariables, _.Library.Integer Timeout) |
Retrieve a snapshot of the execution stack and variables for a process in. More... | |
_.Library.List | GetAppFrameInfo (_.Library.Integer pid) |
Return the entire application metadata frame information for the current process. More... | |
_.Library.String | GetCPUTime (_.Library.Integer pid) |
Get CPU time used for current process (without method arguments) More... | |
_.Library.Integer | GetInternalStackLevel (_.Library.Integer stack, newlevels) |
Convert a $STACK value to the corresponding internal stack level that can be used. More... | |
_.Library.Status | GetLoginRoutine (_.Library.String Label, _.Library.String Routine) |
Get routine and label specified in process login. More... | |
_.Library.String | GetOSUsername () |
This method returns the OSUsername of the process as returned by the operating system. More... | |
_.Library.List | GetOpenDevices (_.Library.Integer Pid) |
Get a $LIST of devices that a process has open. More... | |
GetVariableList (_.Library.Integer InternalStack, ListVar) | |
Get a list of all variables defined at the specified internal execution stack level. More... | |
_.Library.Status | KillAllPrivateGlobals () |
Kill all process private globals for the calling process. More... | |
_.Library.String | NextProcess (_.Library.String Pid, _.Library.Integer Flag) |
Returns the next process pid on the system. More... | |
_.Library.ObjectHandle | Open (_.Library.String Id, _.Library.Integer concurrency, _.Library.Status sc) |
Open an instance to a process. More... | |
_.Library.Integer | VariableDataFlags (_.Library.String Variable, _.Library.Integer InternalStack) |
Get the $Data() value of a variable at the specified internal execution stack level. More... | |
_.Library.String | VariableQuery (_.Library.String Variable, _.Library.Integer InternalStack) |
Perform a $Query() operation on a variable reference at the specified internal execution stack level. More... | |
VariableValue (_.Library.String Variable, _.Library.Integer InternalStack) | |
Get the value of a variable at the specified internal execution stack level. More... | |
Public Attributes | |
AppFrameInfo | |
The entire application metadata frame information. More... | |
CPUTime | |
Sum of system and user CPU Time in ms for process (no mailbox message) More... | |
CSPSessionID | |
CSP Session ID of client connected to process. More... | |
CanBeExamined | |
Process can be examined. More... | |
CanBeSuspended | |
Process can be suspended. More... | |
CanBeTerminated | |
Process can be terminated. More... | |
CanReceiveBroadcast | |
Process can receive broadcast. More... | |
ClientExecutableName | |
Executable name of the process on the client. More... | |
ClientIPAddress | |
IP Address of client connected to the process. More... | |
ClientNodeName | |
Node Name of the client connected to the process. More... | |
CommandsExecuted | |
Number of Commands Executed. More... | |
CurrentDevice | |
Current Device ($i). More... | |
CurrentLineAndRoutine | |
Current Line and Routine. More... | |
CurrentSrcLine | |
Current Source Line being executed. More... | |
DataBlockWrites | |
Total number of database blocks queued for writing by this process. More... | |
EscalatedRoles | |
Additional roles granted to the set of login roles. More... | |
GlobalBlocks | |
Number of Database Block Allocations. More... | |
GlobalDiskReads | |
Number of Physical Database Reads. More... | |
GlobalReferences | |
Number of Global References. More... | |
GlobalUpdates | |
Number of Global Updates. More... | |
InTransaction | |
In a transaction. More... | |
IsGhost | |
Is a Ghost process. More... | |
JobNumber | |
Job number in process table. More... | |
JobType | |
Job type. More... | |
JournalEntries | |
Number of Journal Entries. More... | |
LastGlobalReference | |
Last Global Reference. More... | |
LicenseUserId | |
User Id used for license. More... | |
LinesExecuted | |
Location | |
Location. More... | |
LoginRoles | |
Login roles. More... | |
MemoryAllocated | |
Maximum memory able to be used in KB ($ZS). More... | |
MemoryPeak | |
Peak memory allocated in KB. More... | |
MemoryUsed | |
Memory used in KB (Current $s). More... | |
NameSpace | |
Namespace process is executing in. More... | |
OSUserName | |
Operating system username of process. More... | |
OpenDevices | |
List of open devices. More... | |
Pid | |
Process ID. More... | |
PidExternal | |
External Process PID. More... | |
PrincipalDevice | |
Principal Device ($P). More... | |
Priority | |
Priority. More... | |
PrivateGlobalBlockCount | |
Number of private global database blocks. More... | |
PrivateGlobalReferences | |
Number of Process Private Global References. More... | |
PrivateGlobalUpdates | |
Number of Process Private Global Updates. More... | |
Roles | |
$Roles. More... | |
Routine | |
Routine currently executing. More... | |
StartupClientIPAddress | |
Startup IP Address of client. More... | |
StartupClientNodeName | |
Startup Node Name of client. More... | |
State | |
Current state of the process as determined by the processes state bits. More... | |
Switch10 | |
Process Owns switch 10. More... | |
UserInfo | |
User defined information. More... | |
UserName | |
$Username of process. More... | |
Static Public Attributes | |
DOMAIN = None | |
Set this to the correct domain. | |
This class allows manipulation and display of InterSystems IRIS processes running on the system.
An instance of the class can be opened by passing the PID (O/S process id) to the OpenId Method. The PID is in decimal form ($J) for all platforms.
NOTE: Previous versions of this class allowed you to call the OpenId method and pass in either a PID preceded by the letter "P", or a job number preceded by the letter "J". This functionality has been removed from the OpenId() method, and moved to the new Open() method which supports this syntax.
For example, the following open a process with a PID of 2078:
s Process=##CLASS(SYS.ProcessQuery).OpenId("2078")
s Process=##CLASS(SYS.ProcessQuery).Open("P2078")
s Process=##CLASS(SYS.ProcessQuery).Open("2078")
The following will open Job number 23
s Process=##CLASS(SYS.ProcessQuery).Open("J23")
Performance considerations:
When you use OpenId() to examine a process, several mailbox messages will get sent to the process to return ALL of the properties for the object. On systems with lots of processes running, and you are collecting data for a lot of processes, this can cause a lot of overhead. The call to each OpenId() in this case may actually take several seconds to complete. Most of a processes properties can be retrieved without the overhead of a mailbox message. See the description of the individual properties below for which properties require a mailbox message to be sent.
If you want to minimize overhead, you should use an SQL statement to select ONLY the data which you want returned. For example, here is some code which loops through all the processes on the system, and retrieves specific data for each process. Note that the properties which are returned in this example are ones which do not require a mailbox messages to be sent to the process being examined. Note that the syPidtab.inc file needs to be included in your routine in order for the following code to compile cleanly.
#include syPidtab
Set Rset = ##class(ResultSet).New("%SYS.ProcessQuery:ListPids")
d Rset.Execute()
While Rset.Next() {
&sql(SELECT CommandsExecuted,GlobalReferences INTO :CommandsExecuted,:GlobalReferences
FROM SYS.ProcessQuery
WHERE Pid = :Rset.GetData(1))
i SQLCODE'=0 w !,"SQL Error "_SQLCODE continue ; 100 means process does not exist (halted)
w !,Rset.GetData(1)," ",CommandsExecuted," ",GlobalReferences
}
d Rset.Close()
Security considerations:
Any process can open an instance to their own process by passing the value of $J to the OpenId() method:
s Process=##CLASS(SYS.ProcessQuery).OpenId($j)
If you wish to open another process, you must own the Admin_Manage:Use resource, or have read or write access to the CACHESYS database. To minimize overhead in the OpenId() method, having the Admin_Manage:Use privilege is recommended.
This class has an SQL table called SYS.ProcessQuery where you can execute an SQL query to return process data. For example you could execute the following queries:
Select * from SYS.ProcessQuery - Return all information about all processes
Select * from SYS.ProcessQuery where NameSpace = 'User" - Return all information about all processes in the USER namespace.
Note that in order to run this from an unprivileged user, you may need to grant privileges to that user on the table as follows:
GRANT SELECT ON SYS.ProcessQuery TO _PUBLIC<br>
Notes:
Replace _PUBLIC to a specific user or role name if you don't want everyone to have the privilege.
This is per-namespace. This needs to be executed in each namespace the table needs to be queried from.
def __init__ | ( | self | ) |
Number of Lines Executed.
Total number of lines which the process has executed. NOTE: This property is deprecated, line counts are no longer available and this actually returns the CommandsExecuted. It is left here for backwards compatibility, but should no longer be used.
|
static |
Retrieve a snapshot of the execution stack and variables for a process in.
the same format as JOBEXAM.
Parameters:
Pid - Process ID ($J) of the process to examine
GetVariables - Flag specifies variable and/or object info should be returned 0 - do not dump local variable or object info 1 - dump all local variable info 2 - dump all active oref info 3 - dump local variable and object info
Timeout - How long to wait for the process to respond to the request
Return Value:
On success, the method will return an index of the ^mtemp global (greater than zero). If an error occurs a status code is returned.
Note that, like JOBEXAM, the request will time out if the process is not executing commands.
The data in the ^mtemp node can be displayed by calling Show^STACK(index). It is the responsibility of the caller to Kill ^mtemp(index) when finished with the data.
The data is returned in these nodes of the ^mtemp(index) global:
("*STACK") = the number of stack levels
("*STACK",0,"V",SpecialVar) = the values of special variables such as $S and $ZE
("*STACK",level,"L") = the text line for this level, as displayed by STACK or JOBEXAM
("*STACK",level,"S") = the source line for this level, with a tilde inserted in front of the current command
("*STACK",level,"I") = the internal data for this level
If variables are requested:
("*LEVEL",level,variable) = the base level of a 'variable' that is visible at this 'level'
("*NAMES",variable,base,level) - this is the same information as *LEVEL in a different format
("*STACK",base,"V",variable) - top of subtree containing information of 'variable' defined at 'base' level
The function call $$VGetn^STACK(index,l,v) returns information about the value of variable 'v' at stack level 'l'. If the variable is a private local variable then argument 'v' must be string starting with a tilde character, "~", followed by the variable identifier text. The variable 'v' can include a parenthesized list of subscript literals. Note that lookup of a subscripted local variable requires that the examined process and the examining process are using the same local collation. It returns "" if the variable 'v' is undefined at that stack level; otherwise it returns $LISTBUILD(flags,value) where 'value' is the value of the variable and 'flags' is a sequence of flag letters. If flags["O" then the variable contains an oref and 'value' is the oref string representation.
If objects are requested:
("*CLASS",class) = number of active local objects in Class 'class'
("*CLASS",class,oref) = "" is defined if 'oref' value is a local object of class 'class'. The function call $$OGetn^STACK(index,oref,property) returns $LISTBUILD(flags,value) if the object 'oref' has a property name 'property' and it returns "" if either the oref or the property does not exist. If the property is multidimensional then the property name can include a parenthesized list of subscript literals. Note that lookup of a subscripted multidim property requires that the examined process and the examining process are using the same local collation. The 'value' of the returned $LIST is usually the value of the property (see 'flags'.) The 'flags' of the returned $LIST is a sequence of flag letters. An empty flags string means 'value' is an ordinary ObjectScript value. The flag "U" means the property is not defined, which may indicate an internal error. The flag "J" means the object is a DynamicAbstractObject and 'value' contains the oref.FromJSON() JSON string as the result of any attempt to access a property. The flag "O" means 'value' is the string representation of an object reference. The flags "G" or "C" mean the property has a propertyGet method or is Calculated. Evaluating such a property can cause unwanted side effects so the returned 'value' is the internal value of the iproperty name which might be undefined or might not contain useful information.
|
static |
Return the entire application metadata frame information for the current process.
or the specified process. Parameters:
Pid - Pid (decimal) of the process
Return Value:
The application frame information in $LIST form.
|
static |
Get CPU time used for current process (without method arguments)
or CPU time for the process specified by pid (with method arguments)
Parameters:
pid (optional) - JobNumber (integer +$J)
of the IRIS process you want to get information about<br>
Return Value:
Returns two comma-delimited pieces, "system" CPU time and "user" CPU time Time is returned as milliseconds of CPU time.
0,0 is returned if the specified pid does not exist.
|
static |
Convert a $STACK value to the corresponding internal stack level that can be used.
for the VariableList query and Variable methods that have an InternalStack argument.
The default for stack is the current $STACK value.
When there are NEW commands in a level, each NEW command creates a new internal stack level without increasing $STACK. This method returns the highest internal stack level for the given $STACK. If there are other internal levels created by NEW commands within the given $STACK, they are returned in the newlevels argument as a $LIST of values. There may be different variables defined at each of those levels and the same variable may have different values at each level.
|
static |
Get routine and label specified in process login.
Available only for the current process, you can not query another process. If a class method is passed on the command line then 'Label' will be the method name and 'Routine' will be the class name with a trailing '#' to identify it as a class.
|
static |
This method returns the OSUsername of the process as returned by the operating system.
This method differs from the OSUsername property in that it is the actual username assigned to the process by the operating system.
|
static |
Get a $LIST of devices that a process has open.
Parameters:
Pid - Process ID ($J) of the process to examine
Return Value:
On success, the method will return a $LIST of devices that are currently open by the process. The principal device is the first item in the list. The current device has an asterisk appended to the name.
If an error occurs an empty string is returned.
|
static |
Get a list of all variables defined at the specified internal execution stack level.
If no stack level is given, the current stack level is the default.
The list is returned as nodes of the listvar argument.
listvar will be set to the number of sublists.
listvar(1) will be set to the first sublist, listvar(2) to the second, etc.
Each sublist is a $List of variable entries.
Each variable entry is a $ListBuild(name,$Data(name)).
Private variables are identified with a tilde (~) as the first character in the name.
The names are not sorted, except private variables follow the public variables.
The return value of the method is the total number of variables in the sublists.
|
static |
Kill all process private globals for the calling process.
|
static |
Returns the next process pid on the system.
This is like a $order function on processes running on the system, similar to the way $ZJOB works. It differs from $zjob in one respect though. If the pid passed into the function has halted before this call, we will still return the next pid on the system. $zjob would return the first pid on the system in this case. Using $zjob in this way with lots of processes starting and halting could lead to inaccurate results. Flag=1 means pass in and return the internal decimal representation of a VMS pid ($zh(pid))
|
static |
Open an instance to a process.
This method will open an instance to a process by passing either a PID or Job number to the method. A Pid can either be directly passed in or prefaced with a "P". A Job number can be passed in prefaced by a "J".
The following open an instance to a process with a pid = 2078:
s Process=##CLASS(SYS.ProcessQuery).Open("P2078")
s Process=##CLASS(SYS.ProcessQuery).Open("2078")
The following will open Job number 23
s Process=##CLASS(SYS.ProcessQuery).Open("J23")
Parameters:
Id - Pid or Job number to open
Concurrency - Pass -1 or use default
sc (by ref)- Status of the Open
Return values:
On success, the method returns an object handle to the opened process.
On failure, the method returns a null string, and an error in sc.
|
static |
Get the $Data() value of a variable at the specified internal execution stack level.
If no stack level is given, the current stack level is the default.
The variable reference may include subscripts.
To get the value for a private variable, add a tilde in front of the name, as in "~info".
|
static |
Perform a $Query() operation on a variable reference at the specified internal execution stack level.
If no stack level is given, the current stack level is the default.
The variable reference may include subscripts.
To operate on a private variable, add a tilde in front of the name, as in "~info".
|
static |
Get the value of a variable at the specified internal execution stack level.
If no stack level is given, the current stack level is the default.
The variable reference may include subscripts.
To get the value of a private variable, add a tilde in front of the name, as in "~info".
If the variable is undefined an <UNDEFINED> error will be thrown.
AppFrameInfo |
The entire application metadata frame information.
CPUTime |
Sum of system and user CPU Time in ms for process (no mailbox message)
CSPSessionID |
CanBeExamined |
Process can be examined.
Flag checked by JOBEXAM and Management Portal to see if a process can be examined in detail.
CanBeSuspended |
Process can be suspended.
Flag checked by JOBEXAM and Management Portal to see if a process can be suspended.
CanBeTerminated |
Process can be terminated.
Flag checked by JOBEXAM and Management Portal to see if a process can be terminated.
CanReceiveBroadcast |
Process can receive broadcast.
Flag checked by JOBEXAM and Management Portal to see if a process can receive a broadcast. Usually this means they are attached to a terminal.
ClientExecutableName |
Executable name of the process on the client.
The name of the Executable or DLL on the client which initiated the connection. It is passed down to the process as part of the initial connection message. This property may be set by the end-user if they are managing their own connections.
ClientIPAddress |
IP Address of client connected to the process.
IP address of the client which initiated the connection. It is passed down to the process as part of the initial connection message. This property may be set by the end-user if they are managing their own connections.
ClientNodeName |
Node Name of the client connected to the process.
Node name of the client which initiated the connection. It is passed down to the process as part of the initial connection message. This property may be set by the end-user if they are managing their own connections.
CommandsExecuted |
Number of Commands Executed.
Total number of commands which the process has executed.
CurrentDevice |
Current Device ($i).
Current device that the process has open and is USEing via the USE command.
CurrentLineAndRoutine |
Current Line and Routine.
Current line and routine that the process is executing. Returned in +number^routine format.
This property requires a mailbox message to be sent to the process being examined.
CurrentSrcLine |
Current Source Line being executed.
Current line of source code which is being executed by the process. If "", then the source code line is unavailable.
This property requires a mailbox message to be sent to the process being examined. If the routine has been modified compared to the pcode being run then this will point to the current routine source rather than the actual source of the code being executed.
DataBlockWrites |
Total number of database blocks queued for writing by this process.
EscalatedRoles |
Additional roles granted to the set of login roles.
GlobalBlocks |
Number of Database Block Allocations.
Total number of new database blocks the process has allocated. An indication of database growth.
GlobalDiskReads |
Number of Physical Database Reads.
Total number of times the process has fetched data from disk.
GlobalReferences |
Number of Global References.
Total number of global references the process has made.
GlobalUpdates |
Number of Global Updates.
Total number of global updates (sets and kills) the process has made.
InTransaction |
In a transaction.
If 0, the process is not in a transaction.
If >0, the process has executed a tstart command, is in a transaction, and the value is the offset in the journal file where the transaction has started.
IsGhost |
Is a Ghost process.
The process has been killed at the O/S level, and has not yet been cleaned up by the CLNDMN process. Until the process is cleaned, there may be outstanding locks or resources which may be unavailable to other processes.
This property requires a mailbox message to be sent to the process being examined.
JobNumber |
Job number in process table.
Used as an index into the job table. May be passed to the Open() method to open an object instance to that process.
JobType |
Job type.
Number which tells what type of process it is.
See the syPidtab.inc include file for a definition of macros for these fields. Only use the defined macros in syPidtab when referencing these fields. For example:
If Process.JobType=$$$WDTYPE w !,"Process is the write daemon"
JournalEntries |
Number of Journal Entries.
Total number of journaled global updates the process has recorded. An indication of journal file growth.
LastGlobalReference |
Last Global Reference.
Last global reference that the process made.
This property requires a mailbox message to be sent to the process being examined.
LicenseUserId |
User Id used for license.
The User ID which took out the license for the process.
LinesExecuted |
Location |
Location.
If a system process, will be the system processes name.
If a user process, will be the value of $g(^IS(0,Job.CurrentDevice),"")
LoginRoles |
Login roles.
Roles a process has when it initially logs in.
MemoryAllocated |
Maximum memory able to be used in KB ($ZS).
Maximum amount of memory in KB that the process is allowed to use.
This property requires a mailbox message to be sent to the process being examined.
MemoryPeak |
Peak memory allocated in KB.
This property requires a mailbox message to be sent to the process being examined.
MemoryUsed |
Memory used in KB (Current $s).
Current amount of memory the process has used in KB.
This property requires a mailbox message to be sent to the process being examined.
NameSpace |
OSUserName |
Operating system username of process.
Username given to the process by the operating system when the process is created. When displayed, it is truncated to 16 characters. Note that the real O/S username is only returned when connecting to UNIX or VMS systems; For Windows, it will return the O/S username for a console process, but for telnet it will return the $USERNAME of the process. For client connections, it contains the O/S username of the client. This field is truncated at 16 characters.
OpenDevices |
List of open devices.
List of devices which the process has opened. Returned as a comma separated string.
If any device name in the list contained ",", users won't be able to parse the list. Users should use $LFS(OpenDevices,",",2) to convert the comma separated string to a $List() format string in order to get each device in the list.
This property requires a mailbox message to be sent to the process being examined.
Pid |
Process ID.
Process ID ($J) given to the process by the O/S, decimal form on all platforms.
PidExternal |
External Process PID.
Decimal value for Windows, Unix and Mac, hex for VMS.
PrincipalDevice |
Principal Device ($P).
This property requires a mailbox message to be sent to the process being examined.
Priority |
Priority.
Priority of the process at the O/S level.
PrivateGlobalBlockCount |
Number of private global database blocks.
This property contains the # of database blocks currently allocated to store process private globals.
PrivateGlobalReferences |
Number of Process Private Global References.
Total number of private global references the process has made.
PrivateGlobalUpdates |
Number of Process Private Global Updates.
Total number of private global updates (sets and kills) the process has made.
Roles |
$Roles.
Roles a process currently has.
Routine |
Routine currently executing.
Name of the routine which the process is currently executing.
StartupClientIPAddress |
Startup IP Address of client.
IP address of the client as detected on the TCP channel by the server process.
StartupClientNodeName |
Startup Node Name of client.
IP Node name of the client as detected on the TCP channel by the server process.
State |
Current state of the process as determined by the processes state bits.
The following are all the different states a process can be in. The process may also have a number of different flags within these states which are appended to the end of the state name:
LOCK - Executing a Lock command
OPEN - Opening a device
CLOS - Closing a device
USE - Using a device
READ - Read command
WRT - Write command
GET - Executing a $Get on a global
GSET - Setting a global
GKLL - Killing a global
GORD - $Order on a global
GQRY - $Query on a global
GDEF - $Data on a global
ZF - Executing a $ZF command
HANG - Executing a Hang command
JOB - Executing a Job command
EXAM - Executing a variable exam
BRD - Executing a broadcast
SUSP - Process is suspended
INCR - Executing a $Increment
BSET - Global Set $Bit
BGET - Global $Bit
EVT - Waiting on event
SLCT - $System.Socket wait
SEM - $System.Semaphore wait
IPQ - Inter-process queue wait
DEQ - Dequeue wait (currently unusued)
VSET - Global Set vector element
VKLL - Global Kill vector element
RUN - Process is running in none of the aformentioned states
The following flags can be appended to the state:
NL - Net lock waiting
DT - The dead job has open transaction
S - Suspension requested
GW - Global Wait
NR - Net Read
D - Dead
H - Halting
NH - Netharden
N - Remote network
W - Hibernating
Switch10 |
Process Owns switch 10.
This property is set to 1 if the process has set switch 10.
UserInfo |
User defined information.
This is a user-defined property where the process can set any value into it up to 16 bytes long. The data in it is viewable in JOBEXAM. Note that the information can only be set into one's own process, not into another user's process.
UserName |
$Username of process.
$Username of the process as set by the processes authentication method.