Difference between revisions of "Steady State Memory Analysis"

From OC Systems Wiki!
Jump to: navigation, search
(This entry describes how to do steady-state memory analysis on long-running applications.)
 
Line 1: Line 1:
This entry describes how to do steady-state memory analysis on long-running applications.
+
This entry describes how to do steady-state memory analysis on long-running applications.  Typically, you don't want to track memory used during initialization, and possibly shutdown, so you want to turn on tracking once your application reaches steady-state, and possibly turn it off when leaving steady state.
  
 
Aprobe provides a number of memory/heap analysis predefined probes.  The most recent additions are '''memstat.ual''' and '''memwatch.ual'''.
 
Aprobe provides a number of memory/heap analysis predefined probes.  The most recent additions are '''memstat.ual''' and '''memwatch.ual'''.
  
 +
== Memstat ==
  
TBD
+
There are three mechanisms which can be used to control allocation tracking in memstat:
 +
 
 +
* the StartTime and StopTime configuration options;
 +
* use a custom probe to call the ap_Memstat_Enable and ap_Memstat_Disable entry points; and
 +
* the apdemand enable and disable commands.
 +
 
 +
Note that memstat needs several of minutes of tracking to be able to do leak analysis, so be sure to allow enough time between enabling and disabling tracking.  Alternately, you can lower the sampling ratio to track more allocations in a shorter period of time, but that may increase the overhead of the memstat probe.
 +
 
 +
=== StartTime/StopTime ===
 +
 
 +
By default, memstat tracking is on from program start.  You can specify that tracking be delayed from program start using the '''StartTime''' configuration option to specify the time in seconds from program start to enable tracking.
 +
Similarly, you can use the '''StopTime''' configuration option to specify the time in seconds from program start to disable tracking.  For example:
 +
 
 +
StartTime 60
 +
StopTime 300
 +
 
 +
would turn tracking on after one minute and off after 5 minutes.
 +
 
 +
=== ap_Memstat_Enable/ap_Memstat_Disable ===
 +
 
 +
[Available in ap.4.4.7]
 +
 
 +
You can write a custom probe to call the memstat entry points to enable and disable tracking.  In this case you will probably want to use the '''TrackingEnabledInitially''' configuration option to disable tracking at program start-up so you can enable it later.  Your custom probe would target an application subprogram which is called once steady-state is reached, and from that probe you would call '''ap_Memstat_Enable()''' to turn on tracking.  Similarly, you would have your custom probe target another subprogram where shutdown begins so you can call '''ap_Memstat_Disable()''' to turn tracking off again.  Of course, any combination of enable/disable and '''TrckingEnabledInitially'' can be used to control tracking.
 +
 
 +
For example, this probe targets a fictitious subprogram "Process" which is presumed to be called when steady-state processing beings, and exits when shutdown begins.
 +
 
 +
probe thread
 +
{
 +
  probe "Process"
 +
  {
 +
    // Turn tracking on when we reach steady-state
 +
      on_entry
 +
      {
 +
        ap_Memstat_Enable();
 +
      }
 +
   
 +
      // Turn tracking off when we leave steady-state
 +
      on_exit
 +
      {
 +
        ap_Memstat_Disable();
 +
      }
 +
}
 +
 
 +
Of course, you may need to use two different probe targets to accomplish this, amor you may just terminate your application and not bother with disabling at the end.
 +
 
 +
You will need to compile your custom probes by referencing memstat.ual to resolve the entry points like this:
 +
 
 +
app -x my app.exe my probe.apc memstat.ual
 +
 
 +
Note, this example assumes you include
 +
 
 +
TrackingEnabledInitially FALSE
 +
 
 +
in you memstat configuration file.
 +
 
 +
 
 +
=== Apdeamnd commands ===
 +
 
 +
[Available in ap.4.4.7]
 +
 
 +
The '''apdemand''' interface allows you to issue command from the command line to control apdemand-enabled probes.  Memstat supports two apdemand commands:
 +
 
 +
enable; and
 +
disable.
 +
 
 +
To issue an apdemand command you invoke the tool "$APROBE/bin/apdemand" with the command following the tool name. 
 +
 
 +
For example, the following commands enable then disable memstat during a run:
 +
 
 +
apdemand enable
 +
apdemand disable
 +
 
 +
Note, this example assumes you include
 +
 
 +
TrackingEnabledInitially FALSE
 +
 
 +
in you memstat configuration file.

Revision as of 01:30, 4 May 2017

This entry describes how to do steady-state memory analysis on long-running applications. Typically, you don't want to track memory used during initialization, and possibly shutdown, so you want to turn on tracking once your application reaches steady-state, and possibly turn it off when leaving steady state.

Aprobe provides a number of memory/heap analysis predefined probes. The most recent additions are memstat.ual and memwatch.ual.

Memstat

There are three mechanisms which can be used to control allocation tracking in memstat:

  • the StartTime and StopTime configuration options;
  • use a custom probe to call the ap_Memstat_Enable and ap_Memstat_Disable entry points; and
  • the apdemand enable and disable commands.

Note that memstat needs several of minutes of tracking to be able to do leak analysis, so be sure to allow enough time between enabling and disabling tracking. Alternately, you can lower the sampling ratio to track more allocations in a shorter period of time, but that may increase the overhead of the memstat probe.

StartTime/StopTime

By default, memstat tracking is on from program start. You can specify that tracking be delayed from program start using the StartTime configuration option to specify the time in seconds from program start to enable tracking. Similarly, you can use the StopTime configuration option to specify the time in seconds from program start to disable tracking. For example:

StartTime 60 StopTime 300

would turn tracking on after one minute and off after 5 minutes.

ap_Memstat_Enable/ap_Memstat_Disable

[Available in ap.4.4.7]

You can write a custom probe to call the memstat entry points to enable and disable tracking. In this case you will probably want to use the TrackingEnabledInitially' configuration option to disable tracking at program start-up so you can enable it later. Your custom probe would target an application subprogram which is called once steady-state is reached, and from that probe you would call ap_Memstat_Enable() to turn on tracking. Similarly, you would have your custom probe target another subprogram where shutdown begins so you can call ap_Memstat_Disable() to turn tracking off again. Of course, any combination of enable/disable and TrckingEnabledInitially can be used to control tracking.

For example, this probe targets a fictitious subprogram "Process" which is presumed to be called when steady-state processing beings, and exits when shutdown begins.

probe thread {

  probe "Process"
  {
    // Turn tracking on when we reach steady-state
     on_entry
     {
        ap_Memstat_Enable();
     }
    
     // Turn tracking off when we leave steady-state
     on_exit
     {
        ap_Memstat_Disable();
     }

}

Of course, you may need to use two different probe targets to accomplish this, amor you may just terminate your application and not bother with disabling at the end.

You will need to compile your custom probes by referencing memstat.ual to resolve the entry points like this:

app -x my app.exe my probe.apc memstat.ual

Note, this example assumes you include

TrackingEnabledInitially FALSE

in you memstat configuration file.


Apdeamnd commands

[Available in ap.4.4.7]

The apdemand interface allows you to issue command from the command line to control apdemand-enabled probes. Memstat supports two apdemand commands:

enable; and disable.

To issue an apdemand command you invoke the tool "$APROBE/bin/apdemand" with the command following the tool name.

For example, the following commands enable then disable memstat during a run:

apdemand enable apdemand disable

Note, this example assumes you include

TrackingEnabledInitially FALSE

in you memstat configuration file.