在上一节中,讲了通过 PerformanceCounter 进行CPU的占用率控制。
上一节连接:
http://blog.youkuaiyun.com/weixingstudio/article/details/6867473
本届中主要介绍如何实现控制CPU占用率曲线为一个正弦曲线。
在一段时间内,通过控制CPU繁忙时间调整CPU的占用率显示。
代码:
// cpu_4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdlib.h"
#include "stdio.h"
#include "iostream"
#include "math.h"
#include "windows.h"
using namespace std;
const int SAMPLING_COUNT=200;
const double PI=3.1415926;
const int TOTAL_AMPLITUDE=250;
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"test the cpu"<<endl;
DWORD cpuRate[SAMPLING_COUNT];
int amplitude=TOTAL_AMPLITUDE/2;
double radian=0.0;
double radianIncrement=2.0/(double)SAMPLING_COUNT;
for(int i