Skip to content

Instantly share code, notes, and snippets.

@nikvoronin
Last active January 3, 2021 21:50
Show Gist options
  • Save nikvoronin/c95e6e98fa14cbd9e1700a68ee5e762a to your computer and use it in GitHub Desktop.
Save nikvoronin/c95e6e98fa14cbd9e1700a68ee5e762a to your computer and use it in GitHub Desktop.
PROGRAM MAIN
VAR
PAYLOAD: UINT := 100;
usage, usageMax: UDINT;
latencyMax, latencyAct: UDINT;
cycleExecTime, cycleTimeSti, cycleExecSti: REAL;
cycleLoad, cycleLoadUser: REAL;
TcSysLatency: TC_SysLatency;
TcCpuUsage: TC_CpuUsage;
CpuCounter: GETCPUCOUNTER;
i: UDINT;
a: LREAL := 3.1415926;
b: LREAL := 2.7182818;
cpustart: UDINT;
Timer: TON := (PT := T#10s);
sti: SYSTEMTASKINFOTYPE;
END_VAR
cycleExecTime := (CpuCounter.cpuCntLoDW - cpustart) / 10000.0;
cycleLoad := sti.lastExecTime / (sti.cycleTime / 100.0);
cycleLoadUser := (CpuCounter.cpuCntLoDW - cpustart) / (sti.cycleTime / 100.0);
CpuCounter();
cpustart := CpuCounter.cpuCntLoDW;
sti := SystemTaskInfoArr[1];
cycleExecSti := sti.lastExecTime / 10000.0;
cycleTimeSti := sti.cycleTime / 10000.0;
TcCpuUsage(START:= TRUE);
TcSysLatency(START:= TRUE);
IF NOT TcSysLatency.BUSY THEN
TcSysLatency(START:= FALSE);
latencyMax := TcSysLatency.MAXIMUM;
latencyAct := TcSysLatency.ACTUAL;
END_IF
Timer(IN := NOT Timer.Q);
IF Timer.Q THEN
usageMax := 0;
END_IF
IF NOT TcCpuUsage.BUSY THEN
TcCpuUsage(START:= FALSE);
usage := TcCpuUsage.USAGE;
usageMax := MAX(usageMax, usage);
END_IF
FOR i := 0 TO PAYLOAD DO
a := a / b;
a := a * b;
END_FOR
CpuCounter();
END_PROGRAM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment