How to profile my C++ application on linux

前端 未结 9 1507
北海茫月
北海茫月 2021-01-04 04:27

I would like to profile my c++ application on linux. I would like to find out how much time my application spent on CPU processing vs time spent on block by IO/being idle.

9条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 05:06

    See this post.

    And this post.

    Basically, between the time the program starts and when it finishes, it has a call stack. During I/O, the stack terminates in a system call. During computation, it terminates in a typical instruction.

    Either way, if you can sample the stack at random wall-clock times, you can see exactly why it's spending that time.

    The only remaining point is - thousands of samples might give a sense of confidence, but they won't tell you much more than 10 or 20 samples will.

提交回复
热议问题