我有一个使用动态链接库library.so
的示例应用程序。我使用top命令测量示例应用程序的CPU使用率。但它显示了每秒示例应用程序和library.so
的CPU使用率。但我只想查看library.so
的CPU使用率。有没有办法做到这一点?我听说它可以用htop实现,但不知道如何实现。我使用了树视图,但它显示了几个进程作为示例应用程序进程。我不知道哪一个是library.so
。我使用的是centos 5.11。内核版本3.2.63-1.el5.elrepo。
发布于 2014-10-23 23:00:19
鉴于该库被认为是程序的一部分,一种方法是在您的代码中实现度量。以下最小示例是在仅运行假设库中的一个函数的C++11上实现的:
#include <chrono>
#include <iostream>
#include <hypothetical>
int main() {
using namespace std::chrono;
system_clock systemClock;
system_clock::time_point startingTime{systemClock.now()};
hypothetical::function();
system_clock::duration libraryTime{systemClock.now() - startingTime};
std::cout << "Hypothetical library took " << duration_cast<seconds>(libraryTime).count() << " seconds to run.\n";
return 0;
}
您需要将其扩展到程序从库中调用的所有函数。
https://stackoverflow.com/questions/26520675
复制相似问题