G2 collects profile data about these executable items:
The G2 software includes two KBs that supply higher-level profiling capabilities:
profile.kb in the G2 samples directory.
profiler.kb in the G2 utils directory.
Both the
profile.kb sample and the profiler.kb utility are self-documenting. To use either of them, merge it into the KB that you want to profile, then follow the directions in the KB to start and stop collecting profile data, and display reports of the KB's activity.In most cases, the
profiler.kb utility provides all the profiling capabilities that are needed. However, even if you do not intend to create your own profiler or extend one that is provided with G2, you should skim this chapter to gain a general understanding what a profiler does, and how and why it does it.
You can direct G2 to start collecting profile data, to stop collecting data, and to start and stop again as many times as necessary. G2 always adds new profile data to any profile data already collected. By starting and stopping profiling more than once as your KB runs, you can measure different parts of the KB at various times without losing data.
You direct G2 to create a
SYSTEM-PROFILE-INFORMATION item that contains a copy of the profile data collected so far.
sys-mod.kb into your KB before you attempt to collect profile data. The KB defines these system procedures for profiling:
Add actions or statements in your KB's items so that they call the procedures in a manner that supports your profiling strategy. Identifying Your Profiling Strategy offers basic recommendations.
Note: Profiling does not track activities performed by the same item from which profiling is enabled.
Collecting Profile Data
G2 starts collecting profile data when your KB invokes the g2-enable-profiling system procedure. G2 stops collecting profile data when your KB invokes the g2-disable-profiling system procedure. g2-enable-profiling, G2 collects a new set of profile data. If your KB calls g2-disable-profiling to stop collecting profile data, and, later in the KB's processing, calls g2-enable-profiling again, G2 adds the newest profile data to the data already collected.
Note: G2's profile data exists only as long as the G2 process itself exists. When you exit or close a G2 process, G2 discards any profile data already collected.
Changing the run-state of the current KB does not affect whether profiling is enabled. If profiling is enabled when the current KB is reset or paused, profiling remains enabled, but G2 collects no additional profiling data until the KB starts again. When the KB resumes, G2 adds any new profile data to the existing profile data. g2-enable-profiling and g2-disable-profiling system procedures. Creating a Copy of G2's Collected Profile Data
While G2 is collecting profile data, or after G2 has stopped collecting profile data, you can direct G2 to create an item that contains a copy of the profile data collected so far. The g2-get-profiled-information system procedure creates a transient system-profile-information. You can optionally transfer this system-profile-information to the workspace of your choice.
Note: You cannot add data to, or remove data from, a system-profile-information item.
See the G2 System Procedures Reference Manual for a complete description of the g2-get-profiled-information system procedure. Identifying the Contents of a System-Profile-Information
Each call to the g2-get-profile-information system procedure creates a new system-profile-information. The definition for the SYSTEM-PROFILE-INFORMATION class is stored in sys-mod.kb.
ITEM-PROFILE-INFORMATION class
A system-profile-information's data does not show the sum of the CPU timeslices within which your G2 process executed during the profiling period. Therefore, you cannot use the data from a system-profile-information to evaluate how efficiently G2 uses your computer's resources in relation to the computer's other activities. Such an analysis requires platform-specific techniques to monitor operating-system processes.
The following table summarizes the attributes specific to the
SYSTEM-PROFILE-INFORMATION class.
Understanding Relationships Among System-Profile-Information Attributes
As you attempt to make your KB perform more efficiently, you should observe the ratio of its Processing-time to its Total-profiled-time and the ratio of its Idle-time to its Total-profiled-time. profile-data indicate that, during this particular profiling period, G2 spent more of its time waiting for user-defined processing to execute than performing that processing.
![]() |
The ratio of
Processing-time to Total-profiled-time ( 0.257 / 5.982 = 0.04, or 4%) is much smaller than the ratio of Idle-time to Total-profiled-time ( 5.528 / 5.982 = 0.92, or 92%). Representing Empty Profile Data
If your KB has not called g2-enable-profiling since your G2 process started, or since your KB most recently called g2-clear-profile, and your KB calls g2-get-profiled-information, G2 creates a system-profile-information whose timing attributes are values of zero and whose Profiled-items item-list contains zero elements. Understanding the Processing-Time Attribute
G2 derives system-profile-information's Processing-time value from the Total-profiled-time minus the sum of the time spent performing schedulable tasks, which consists of the values in the Idle-time, Icp-time, Workstation-time, Display-time, Scheduling-time, Data-service-time, Kb-io-time, and Overhead-time attributes.
Note: G2 calculates the value of the Processing-time attribute from a real time measure, not from G2's CPU timeslice measure. Therefore, to allow g2-get-profiled-information to return a Processing-time measure that most accurately reflects your KB's actual performance within G2, you should profile your KB when G2 is the only process running, or one of very few processes running, on your computer.
Note: If you are profiling a G2 process whose process window (or connected Telewindows) displays under the control of an X Windows server process, the actual time spent during scheduled screen-drawing cannot be included in the Processing-time attribute's value.
Understanding the Profiled-Items Attribute
The Profiled-items attribute of a system-profile-information is an item-list. If G2 has collected profile data before g2-get-profiled-information was most recently called, then G2 inserts ITEM-PROFILE-INFORMATION items into this item-list. Each item-profile-information contains profile data about each executable item that was invoked during profiling. ITEM-PROFILE-INFORMATION class is stored in sys-mod.kb. The following table summarizes the attributes specific to the ITEM-PROFILE-INFORMATION class.
For each item-profile-information inserted in the
Profiled-items attribute's item-list, G2 automatically concludes an instance of a profiled-by relation between the item-profile-information and the item it references. Find the profiled-by relation definition in the Profiling Procedures workspace in the sys-mod.kb file.
Tip: Use the profiled-by relations in conjunction with the g2-name-for-item system procedure to assign G2-generated names to unnamed items that were invoked during profiling.
Understanding the Profiled-Activities Attribute
The Profiled-activities attribute of an item-profile-information is an item-list. For each action or statement that G2 performed within an invoked item during profiling, G2 creates an ACTIVITY-PROFILE-INFORMATION item and inserts it into this item-list. ACTIVITY-PROFILE-INFORMATION class is stored in the Profiling Procedures workspace in sys-mod.kb. The following table summarizes the attributes specific to the ACTIVITY-PROFILE-INFORMATION class.
The following table lists the activities in an invocable item for which G2 collects profile data. Each activity represents either an action or a statement.
Profiling Executable Items and Activities
G2 profiles executable items starting with the first operation executed in the item and ending with the first operation executed in the next executable item that the KB's processing invokes, or ending with the first operation in the next distinct G2 task that is invoked. Resetting G2's Profile Data
In some situations, you might prefer to clear G2's existing profile data before collecting more profile data. To clear all profile data from G2, invoke the g2-clear-profile system procedure. g2-enable-profiling once, G2 retains a set of profile data in memory until g2-clear-profile is invoked. g2-clear-profile system procedure. Identifying Your Profiling Strategy
Typically, you collect profile data for some length of time that is significant for testing purposes. You can begin by collecting profile data for all executable items in your KB. For example, to do so, you could include an initially rule in your KB that invokes g2-enable-profiling.
g2-enable-profiling in the item that represents the start of the portion of KB processing that you want to profile.
g2-disable-profiling in the item that represents the end of the portion of KB processing that you want to profile.
g2-get-profiled-information; you might prefer to transfer the new system-profile-information to a particular workspace.
g2-clear-profile in an item that is invoked when you wish to collect an entirely new set of profile data.
g2-enable-profiling to begin collecting profile data.
g2-disable-profiling to stop collecting profile data.
g2-get-profiled-information.
g2-clear-profile or not, repeat Steps 1 through 3 to capture and report on your KB's processing again under different circumstances.
Hint: Some items that are profiled might not have a name. As shown in the sample procedure that follows, you can use the g2-name-for-item system procedure to assign a generated name to any unnamed profiled item. See the G2 System Procedures Reference Manual for a full description of g2-name-for-item.
![]() |
![]() |
Analyzing Profiling Data
Collecting and analyzing profile data are the first steps in evaluating your KB's performance. With this information, you can use several techniques to improve your KB's efficiency of execution: