Steady State Memory Analysis

From OC Systems Wiki!
Revision as of 03:16, 10 May 2017 by Swn (talk | contribs) (Memstat)
Jump to: navigation, search

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 RuntimeStartTime configuration option;
  • 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 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.

RuntimeStartTime

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

RuntimeStartTime 60

would turn tracking on after one minute.

Note: this is different from the StartTime and StopTime configuration options, which control what data is analyzed at format-time to produce reports.

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, or 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:

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

Note, this example assumes you include:

TrackingEnabledInitially FALSE 

in your memstat configuration file.


Apdemand 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.