To pinpoint the latency source in an application, you may need to measure not only the entire real-time cycle but also stages within it. You can add measurement library APIs to each of these parts of your code.
The multiple measurements sample (
) illustrates how to instrument code with measurement library APIs. You can copy and modify the source code to instrument your real-time application.
This sample runs a workload consisting of two parts:
One part is the multiplication of two matrices. Matrices in this sample are square, and you can set their size.
The other part calculates the Nth approximation of the number 2 / pi. You can set the parameter N, an increase in N leads to an increase in the accuracy of the approximation.
The sample measures the execution time of each part, as well as the total execution time of both parts combined.
This sample represents an arbitrary computation workload that might be executed as part of a real-time control loop,
such as computation of a robotic arm’s next position. The computation itself and the result are not relevant for this demonstration.
The sample also represents a use case in which an application is instrumented with measurement library APIs and the data generated from the application is intended to be analyzed by a separate profiling application. The sample does not print latency data but the data can be viewed when it is run with the Measurement Analysis Sample
This sample demonstrates the use of the following functions:
- Create ITT domain.
- Create ITT task handle.
__itt_task_begin(domain, __itt_null, __itt_null, measurement)
- Collect the measurement start time based on the CPU’s timestamp counter (TSC).
- Collect the measurement end time based on the TSC and calculate the difference between the start and end times to get the latency measurement.
The sample has the following flow:
The sample starts by defining the ITT domain and the task handle.
When all the required variables are initialized, the sample runs the
function which starts two workloads:
The first workload executes matrices multiplication.
The second workload calculates the Nth approximation of the 2/pi number.
The sample measures the overall latency for both workloads and the latencies for each workload.