System Stack Profiling

Overview

Along with real-time task execution profiling, the software enables you to determine how your application uses the processor system stack. Using the profile method, you can initialize and test the size and usage of the stack. This capability helps you optimize both the size of the stack and how your code uses the stack.

To provide stack profiling, profile writes a known pattern to the addresses in the stack. After you run your application for a while, and then stop your application, profile examines the contents of the stack addresses. profile counts each address that no longer contains the known pattern as used. The total number of address that have been used, compared to the total number of addresses you allocated, becomes the stack usage profile. This profile process does not tell you how often any address was changed by your application.

When you use profile to initialize and test the stack operation, the software returns a report that contains information about stack size, usage, addresses, and direction. With this information, you can modify your code to use the stack efficiently. The following program listing shows the stack usage results from running an application on a simulator.

profile(cc,'stack','report')

Maximum stack usage:
 
System Stack: 532/1024 (51.95%) MAUs used.


           name: System Stack
   startAddress: [512    0]
     endAddress: [1535     0]
      stackSize: 1024 MAUs
growthDirection: ascending

The following table describes the entries in the report:

Report EntryUnits Description
System StackMinimum Addressable Unit (MAU)Maximum number of MAUs used and the total MAUs allocated for the stack.
nameString for the stack nameLists the name assigned to the stack.
startAddressDecimal address and pageLists the address of the stack start and the memory page.
endAddressDecimal address and pageLists the address of the end of the stack and the memory page.
stackSizeAddressesReports number of address locations, in MAUs, allocated for the stack.
growthDirectionNot applicableReports whether the stack grows from the lower address to the higher address (ascending) or from higher to lower (descending).

Profiling System Stack Use

To profile the system stack operation, perform these tasks in order:

  1. Load an application.

  2. Set up the stack to enable profiling.

  3. Run your application.

  4. Request the stack profile information.

Follow these steps to profile the stack as your application interacts with it. In this example, cc is an existing adivdsp object.

  1. Load the application to profile.

  2. Use the profile method with the setup input keyword to initialize the stack to a known state.

    profile(cc,'stack','setup')

    With the setup input argument, profile writes a known pattern into the addresses that compose the stack. For all processors, the pattern is A5. As long as your application does not write the same pattern to the system stack, profile can report the stack usage correctly.

  3. Run your application.

  4. Stop your running application. Stack use results gathered from an application that is running may be incorrect.

  5. Use the profile method to capture and view the results of profiling the stack.

    profile(cc,'stack','report')

The following example demonstrates setting up and profiling the stack. The adivdsp object vd must exist in your MATLAB workspace and your application must be loaded on your processor. This example comes from a SHARC ADSP–2136x simulator.

profile(vd,'stack','setup')  % Set up processor stack--write A5 to the stack addresses.
 
Maximum stack usage:
 
System Stack: 0/512 (0%) MAUs used.
 

           name: System Stack
   startAddress: [785920       1]
     endAddress: [786431       1]
      stackSize: 512 MAUs
growthDirection: ascending

 
run(vd)
halt(vd)
profile(vd,'stack','report')
 
Maximum stack usage:
 
System Stack: 91/512 (17.77%) MAUs used.
 

           name: System Stack
   startAddress: [785920       1]
     endAddress: [786431       1]
      stackSize: 512 MAUs
growthDirection: ascending
  


 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS