uint16 FlowPoolFilter(uint32 *Pool,uint16 Data,uint8 *PoolIndex,uint8 PoolSize)
{
(*Pool)+=Data;
if((*PoolIndex)< PoolSize )(*PoolIndex)++;
else (*Pool)-=((*Pool)/(*PoolIndex));
return (*Pool)/(*PoolIndex);
}
Eg: 獲取TOS CPU的使用率
void Tos_ComputeCPURate()
{
static uint8 Count,i;
static uint32 Pool;
static uint8 Use;
if(_Tos_TaskTotal-1!=Tos_TaskCurrent)Use++;
Count++;
if(Count>100){Count=0;Tos_CPUInfor.Userate_CPU=FlowPoolFilter(&Pool,Use,&i,100);Use=0;}
}
|