我正在考虑编写一个测试工具,用于使 CPU 在 Linux 上以指定级别忙碌,例如 80% 的使用率。我怎样才能做到这一点?这个工具是脚本还是 c++ 程序都没有关系。
问问题
251 次
2 回答
2
您可以使用压力程序。您还可以cpuburn
在 Ubuntu(或 Debian)中使用该套件:
apt-get install cpuburn
于 2013-03-26T08:57:57.497 回答
1
对于独立于平台的解决方案,您可以编译并运行此 C++11 程序的一个或多个实例,并使用针对所需 CPU 使用百分比进行微调的命令行参数。
//
// Application to sleep for nanoseconds specified by command-line argument
//
#include <chrono>
#include <iostream>
#include <limits>
#include <sstream>
#include <thread>
int main(int argc, char* argv[]){
if (argc >= 2) {
std::istringstream iss(argv[1]);
unsigned int interval;
if (iss >> interval)
for(uint64_t i=0; i<std::numeric_limits<uint64_t>::max(); i++)
std::this_thread::sleep_for(std::chrono::nanoseconds(interval));
}
}
于 2013-03-26T09:25:27.650 回答