Measure CPU usage per second of a dynamically linked library

I have an example application that uses a dynamically linked library.so library. I measured CPU usage by an example application using the top command. But this shows the processor usage of both the library.so application and library.so per second. But I want to see CPU usage only library.so . Is there any way to do this? I heard that it is available using htop, but could not figure out how to do this. I used a tree view, but it shows several processes as an example of an application process. I could not figure out which one is library.so . I am using centos 5.11. Kernel version 3.2.63-1.el5.elrepo.

0
source share
1 answer

Given that the library is considered part of your program, one way would be to implement a dimension in your code. The following minimal example is implemented in C ++ 11, performing only one function from a hypothetical library:

 #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; } 

You will need to extend this to all the functions that your program calls from your library.

0
source

Source: https://habr.com/ru/post/977171/


All Articles