thiagoralves / OpenPLC_v3

OpenPLC Runtime version 3
1.02k stars 421 forks source link

webserver/core/main.cpp: Get REAL-TIME time values #201

Closed ngu-niny closed 1 year ago

ngu-niny commented 1 year ago

Add code to get the real time cycle time and latency, the maximum/minimum/average values would be printed out in the logs as a summary at the end of the OpenPLC running. The following diagram describes the logic.

"|": Beginning of execution of the PLC code "s": Start of execution of PLC code "e": End of execution of PLC code

Therefore, the time interval between two "|" symbols is usually 20ms by default(defined in OpenPLC Editor program), while "timeof(e) - timeof(s)" represents the cycle time and "timeof(s) - timeof(|)" represents the latency after sleep.

|_se__|s_e__|s_e__|_____|

Also a new function RecordCycletimeLatency() was added which uses special_function[4] and special_function[5] to store the cycle time and latency in the running OpenPLC cycle, so in the webpage they can be displayed if necessary.

Thanks my colleagues Alexander Lougovski, Marcelo Tosatti and Wenkang Ji a lot for the initiating, ideas and help.

ngu-niny commented 1 year ago

The statistics for about 12 minutes in the OpenPLC runtime log is as follows:

Summary: The maximum/minimum/average cycle time in microsecond is 149/14/18

Summary: The maximum/minimum/average latency in microsecond is 26/5/7

The webpage display effect of cyclic time and latency is as follows: OpenPLC_LatencyCycleTime 2023-03-21 17-13-12