Main Content

Analyze Code Execution Data

After a SIL or PIL simulation, you can analyze execution-time data using methods from the coder.profile.ExecutionTime and coder.profile.ExecutionTimeSection classes.

  1. Open rtwdemo_sil_topmodel.

  2. On the Configuration Parameters > Code Generation > Verification pane, specify profiling options:

    • Select the Measure task execution time check box.

    • Specify a Workspace variable, for example, myExecutionProfile.

    • From the Save options drop-down list, select All data.

  3. Run a SIL simulation.

The software generates the workspace variable myExecutionProfile, an coder.profile.ExecutionTime object.

To get the total number of code sections that have profiling data, use the Sections method.

>> no_of_Sections = myExecutionProfile.Sections

no_of_Sections = 

  1×2 ExecutionTimeTaskSection array with properties:

    Name
    Number
    ExecutionTimeInTicks
    SelfTimeInTicks
    TurnaroundTimeInTicks
    TotalExecutionTimeInTicks
    TotalSelfTimeInTicks
    TotalTurnaroundTimeInTicks
    MaximumExecutionTimeInTicks
    MaximumExecutionTimeCallNum
    MaximumSelfTimeInTicks
    MaximumSelfTimeCallNum
    MaximumTurnaroundTimeInTicks
    MaximumTurnaroundTimeCallNum
    NumCalls
    ExecutionTimeInSeconds
    Time
To get the coder.profile.ExecutionTimeSection object for a profiled code section, use the method Sections.
>> FirstSectionProfile = myExecutionProfile.Sections(1)
SecondSectionProfile = myExecutionProfile.Sections(2)

FirstSectionProfile = 

  ExecutionTimeTaskSection with properties:

                            Name: 'rtwdemo_sil_topmodel_initialize'
                          Number: 1
            ExecutionTimeInTicks: 1188
                 SelfTimeInTicks: 1188
           TurnaroundTimeInTicks: 1188
       TotalExecutionTimeInTicks: 1188
            TotalSelfTimeInTicks: 1188
      TotalTurnaroundTimeInTicks: 1188
     MaximumExecutionTimeInTicks: 1188
     MaximumExecutionTimeCallNum: 1
          MaximumSelfTimeInTicks: 1188
          MaximumSelfTimeCallNum: 1
    MaximumTurnaroundTimeInTicks: 1188
    MaximumTurnaroundTimeCallNum: 1
                        NumCalls: 1
          ExecutionTimeInSeconds: 5.4000e-07
                            Time: 0


SecondSectionProfile = 

  ExecutionTimeTaskSection with properties:

                            Name: 'rtwdemo_sil_topmodel_step [0.1 0]'
                          Number: 2
            ExecutionTimeInTicks: [1×101 uint64]
                 SelfTimeInTicks: [1×101 uint64]
           TurnaroundTimeInTicks: [1×101 uint64]
       TotalExecutionTimeInTicks: 70316
            TotalSelfTimeInTicks: 70316
      TotalTurnaroundTimeInTicks: 70316
     MaximumExecutionTimeInTicks: 2448
     MaximumExecutionTimeCallNum: 2
          MaximumSelfTimeInTicks: 2448
          MaximumSelfTimeCallNum: 2
    MaximumTurnaroundTimeInTicks: 2448
    MaximumTurnaroundTimeCallNum: 2
                        NumCalls: 101
          ExecutionTimeInSeconds: [1×101 double]
                            Time: [101×1 double]

Use coder.profile.ExecutionTimeSection methods to extract profiling information for a particular code section. For example, use Name to obtain the name of a profiled task.

>> name_of_section = SecondSectionProfile.Name

name_of_section =

rtwdemo_sil_topmodel_step [0.1 0]

If the timer is uncalibrated and you know the timer rate, for example 2.2 GHz, you can use the coder.profile.ExecutionTime method TimerTicksPerSecond to calibrate the timer:

>> myExecutionProfile.TimerTicksPerSecond = 2.2e9;
>> SecondSectionProfile = myExecutionProfile.Sections(2);

Related Topics