测量 CPU/memory 消费
Measure CPU/memory consumption
我用它来测量 C++ 中的执行时间:
struct timeval t1, t2;
gettimeofday(&t1, NULL);
gettimeofday(&t2, NULL);
int milliSeconds = (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec)/1000;
但我还想测量 cpu / 内存消耗。我该怎么做?
要计算已用 CPU 的百分比,您可以使用 Alexsis Wilke advice for using getrusage()
并除以您在问题中计算的总运行时间。
这将为您提供单个 CPU 的已用 CPU 的平均百分比。如果你使用的处理器很多,也可以除以处理器的个数。
我用它来测量 C++ 中的执行时间:
struct timeval t1, t2;
gettimeofday(&t1, NULL);
gettimeofday(&t2, NULL);
int milliSeconds = (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec)/1000;
但我还想测量 cpu / 内存消耗。我该怎么做?
要计算已用 CPU 的百分比,您可以使用 Alexsis Wilke advice for using getrusage()
并除以您在问题中计算的总运行时间。
这将为您提供单个 CPU 的已用 CPU 的平均百分比。如果你使用的处理器很多,也可以除以处理器的个数。