Basics
Profiling is a procedure for analyzing the runtime behavior of a software application. The aim is to identify performance bottlenecks and inefficient code in order to improve the performance of the application.
The TwinCAT 3 PLC Profiler is based on the technology of the TE1010 | TC3 Realtime Monitor and is specially tailored to the requirements of PLC development. Profiling provides answers to questions such as:
- Which POUs consume most of the cycle execution time?
- What is the minimum, maximum and average execution time of a POU?
- What is the execution time in µs and as a percentage in relation to the cycle execution time?
- Which Call Tree has the maximum execution time for a specific POU?
Measuring principle: instrumentation
The “Instrumentation” measurement principle is used for the TwinCAT 3 PLC Profiler. Measurement marks (entry and exit methods) are automatically inserted into the compiled code during compilation. The PLC source code is not changed. The measurement marks record the execution times of individual function blocks and thus enable the precise assignment of runtimes to program elements.
Removing the profiler file from the PLC project removes all instrumentation.
Important terms
Term | Meaning |
|---|---|
Total Time | The elapsed time of an element including the elapsed time of all sub-elements. |
Own Time | The elapsed time of an element excluding the elapsed time of all sub-elements. Indicates how much time is spent in the element itself. |
Task execution time | The total time spent on all program blocks that are called by a task. |
Influence of the measurement marks on the measurement results
The measurement marks that are inserted into the code during instrumentation cause additional runtime overhead. This can influence the measured execution times. Areas of the code with many instrumented elements may appear over-represented in the analysis, as the measurement methods themselves take time.
The profiler offers two correction modes to subtract the runtime component of the measurement marks from the measured values:
- Automatic correction: The Add Measure Method option in the profiler configuration inserts an additional measurement mark that measures the overhead per cycle. With the Automatic Correction Value property, the measured value is automatically subtracted from the results (see Window Properties).
- Default correction: The Default Correction Value property can be used to configure a default correction value in nanoseconds that is used for all cycles.
Variability of the measured values
The measured values may vary between cycles. The reasons for this include dynamic CPU clocking and other system factors. The variability can be reduced by the following measures:
- Use of isolated CPU cores for real-time requirements.
- Disabling power management mechanisms of the processor.
Effects on the system
Consider the following effects on the system when using the profiler:
- Real-time load: Instrumentation increases the execution time of PLC cycles. The Call Tree is measured in each cycle, which increases the real-time load.
- Network utilization: The measured values are transmitted to the development environment via ADS. Network utilization can increase with high information density (many instrumented elements, high cycle frequency).