Skip to main content

Profiling by Code Instrumentation

Important

The implicitly added IEC code for a Profiler measurement method, as well as the breakpoints for POUs in the watch list, result in a change and slows down the evaluated program.

When a profiling or code coverage measurement is active, an online is generally not possible. Moreover, some online features are not available, such as "flow control" and "breakpoints". There are no restrictions for the watch list in this respect.

Enabling or disabling a Profiler measurement method, or changing any settings in the Profiler editor each requires a download. Then an online change is no longer possible. There are no restrictions for the watch list in this respect.

Tip

The recording and processing of the measured values takes place on the controller and therefore can also be performed without connecting the development system to the controller (in contrast to the other measuring methods).

With this profiling method, CODESYS Profiler inserts additional code into the entry and exit of each function in the program. The runtimes of a entire task cycle are measured and stored.

The method is useful for detecting individual outliers in the task runtimes. To do this, select the Record max cycle recording mode.

When the entire project is instrumented, this can have a considerable impact on task runtimes and memory consumption. Therefore, select only a part of the application POUs for instrumentation whenever possible. One recommended approach is to first select only those POUs that are called directly by the task. Determine the "hot spots" of the runtime for these POUs and then based on these select the called POUs for measurement.

Important

  • POUs which are not selected for measurement are not shown on the measurement list, the call tree, or the backtrace tabs. Therefore, it is possible that a call tree "POU1 -> POU3" is displayed, although there is no direct call of POU3 by POU1. This is because there are POU calls which are not selected for measurement between POU1 and POU3.

  • The "own time" output in the measurement for a POU can also contain times of called POUs which are not selected for measurement.

Profiling activation and execution by means of instrumentation

Requirement:

  • A CODESYS project application with multiple POUs is open in offline mode.

  • A task is defined to control POU calls.

  • The application is the active application and can be compiled without errors.

  • A connection to the standard controller is configured in the communication settings, and the controller is running.

  1. To activate and deactivate profiling programmatically, you define a Boolean variable in the application. (This is optional for the example described here. Activation can also be performed by a menu command.)

  2. Click Add Object to add a Profiler object below the application in the device tree.

  3. Double-click the object.

    The object editor opens. The _prf_icon_settings.png Settings tab is in focus.

  4. Set the Method to Instrumentation. Select the Task with the POU calls that you want to perform time measurements on.

  5. Under Recording, select the task for controlling the POUs to be instrumented.

    For Condition, click the _cds_icon_three_dots.png button and select the Boolean variable from your application that you want to use to switch the value recording on and off. Note: Using this kind of variable is optional. If you leave the field blank, then every cycle is recorded.

  6. Under Instrumentation parameters, set the Recording mode to Record next cycle. Leave the required Buffer size (the maximum number of POU calls that are recorded per task cycle) as the default 10000.

    Under Snapshot appearance, select the Time format for displaying the recording.

  7. In POU selection, select the POUs that should be instrumented. Note that you could also select "Instrument whole application", which would include all POUs of the project as well as the POUs of the integrated libraries.

  8. Click Online → Login to download the application to the controller.

    The display _prf_img_status.png is shown in the status bar of CODESYS.

  9. Click Online → Start to start the application.

    The project runs and you see the current variables values in the usual monitoring view.

  10. If you have configured a Boolean variable as a condition to start profiling, then now set this variable to TRUE.

    Background information about recording: Because you selected the Record next cycle option in this example, only the first cycle is recorded when the application is started and the profiling. No additional cycle is recorded. An additional measurement is performed only when a recording is uploaded from the controller. This uploading is done either by opening the Online tab for the first time or by clicking the Refresh snapshot button. For information about the alternative Record max cycle option, see the reference part of the help: 'Settings' Tab.

    Now look at the sampling results. Open the editor of the Profiler object and its Online tab.

    The _prf_icon_online.png Online tab provides four subtabs which can be selected from the menu on the left side. In addition, you see an area with buttons and settings for the profiling that is currently running. For more information, see: 'Online' Tab

Procedure. Detailed information about a POU call in the Properties dialog
  1. On the Online tab, click the Call Tree category.

    You see the hierarchy of all calls that have originated from the task specified in the Settings dialog.

  2. Select one of the calls and click Properties in the context menu.

    The Properties dialog for the called POU opens with detailed information, such as Own time and Standard deviation.