📄 cpuload.c
字号:
#include <vxworks.h>
#include <limits.h>
#include <stdio.h>
#include <ticklib.h>
#include <tasklib.h>
#define TEST_SCALE 1000
static unsigned long cpuCompareValue;
unsigned long cpuLoadTicks;
static void cpuLoadTask()
{
unsigned long value, count, tickstart, i;
i=0;
while(1) {
// Disable cpu load test
if (cpuCompareValue == 0){
taskDelay(sysClkRateGet());
continue;
}
count = 0;
tickstart = tickGet();
while(cpuLoadTicks > (tickGet() - tickstart)){
count++;
taskDelay(0);
}
count /= TEST_SCALE;
if(cpuCompareValue < 2) value = count;
else
value = ((cpuCompareValue - count) * 100 ) / cpuCompareValue;
if((i++ % 10) == 0)
printf("\nCPU Load: %d ", value);
else
printf("%d ", value);
}
}
//
// Input test cycle value, unit is 0.5s
//
void cpuLoadInit()
{
cpuCompareValue = 0; // Disable Show & no compare value
cpuLoadTicks = sysClkRateGet(); // Default 500ms test period
taskSpawn("cpuLoadTask", 255, VX_FP_TASK, 1000, (FUNCPTR)cpuLoadTask, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
//
// 0/1 dis/enable load value show
// more than 1000, regards it as compare value
//
void cpuLoadSet(int value)
{
cpuCompareValue = value;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -