メインコンテンツ

polyspace.test.ExecutionProfilingResults Class

Namespace: polyspace.test

(Python) Review execution profiling results

Since R2024b

Description

This Python® class contains execution profiling results obtained from executing C/C++ tests.

Creation

Description

executionResults = profilingResults.Execution loads coverage results:

Properties

expand all

Function execution time metrics, stored as a polyspace.test.ExecutionProfilingDetail object. Each object stores the execution time metrics for one function. Polyspace® Test™ calculates these execution time metrics:

MetricDescription
FileFull path of file that contains the function.
FunctionName of function whose execution time Polyspace Test calculates.
TotalTimeTime measured from the function entry point to when the function returns.
SelfTime

Time measured from the function entry point to when the function returns, but without considering the execution time of callee functions. This value is reported only if you obtain execution profiling results using the polyspace-code-profiler command with the option -exec-metric-level set to standard or detailed.

For example, if a function has an execution time T_func and calls two functions with execution times T_callee1 andT_callee2:

SelfTime =  T_func - (T_callee1 + T_callee2)

CountNumber of times the function executes. This value is reported only if you obtain execution profiling results using the polyspace-code-profiler command with the option -exec-metric-level set to standard or detailed.
SaturatedThis boolean metric is set to false unless the TotalTime overflows a 32-bit counter. When Saturated is set to true, MaxTime is set to the saturated total time value, and TotalTime and SelfTime are set to the last known unsaturated value.
MaxTimeThe maximum calculated SelfTime for a function. This value is reported only if you obtain execution profiling results using the polyspace-code-profiler command with the option -exec-metric-level set to detailed.

See also Execution Time.

Example: print(profRes.Execution.Details[1])

File path and function name for the function whose execution time Polyspace Test calculates. The file path and function name are stored in a list of polyspace.test.ProfilingFunction objects, where each object stores the information for one function.

Examples

collapse all

This example shows how to print the list of tested C/C++ functions sorted by their execution times.

In general, you generate and manage execution profiling results by using classes from the polyspace.project and polyspace.test modules. Before starting, make sure you can import these modules on a Python shell or in a Python script without errors. For more information, see Set Up Python API for Polyspace.

  1. Import the required modules:

    import polyspace.project
    import polyspace.test
    import os

  2. Add source files and xUnit test files to a project. This example uses some example source and test files available with a Polyspace Test installation. Instead, you can use your own sources and tests.

    examples_path = os.path.join(polyspace.__install_path__, "polyspace", 
                                "examples", "pstest", "Getting_Started_Example")
    polyspaceProject = polyspace.project.Project("newProject")
    polyspaceProject.Code.Files.add(os.path.join(examples_path, "sources", "utils.c"))
    polyspaceProject.IncludePaths.add(os.path.join(examples_path, "includes"))
    polyspaceProject.Tests.Files.add(os.path.join(examples_path, "tests", "test.c"))

  3. Run the tests added to the project with execution profiling enabled.

    res = polyspace.test.run(
       polyspaceProject,
       ProfilingSelection=polyspace.test.ProfilingSelection.EXECUTION
    )

  4. Read the execution profiling results from the test results.

    profilingResults = res.Profiling
    execProfilingResults = profilingResults.Execution
  5. Sort the execution profiling result details by the SelfTime property and print the function names along with their self execution times.

    executionResultDetails = execProfilingResults.Details
    sortedDetails = sorted(executionResultDetails, 
           key=lambda detail: -detail.SelfTime)
    for detail in sortedDetails:
        print(detail.Function + ": " + str(detail.SelfTime) + "ms")
    If you use the example source and test files, you should see an output such as the following:
    initOrReset: 5354ms
    addLatestReading: 3620ms
    checkLastSpeeds: 2286ms
    checkAgainstSpeedLimit: 2192ms
    update: 2122ms
    updateAcceleration: 2074ms
    checkAccelerations: 1784ms
    isGreaterThanSpeedLimit: 98ms

Version History

Introduced in R2024b