How to get the CPU usage of thread

Discussion in 'Mac Programming' started by tonybai, Apr 29, 2010.

  1. tonybai macrumors newbie

    Joined:
    Apr 29, 2010
    #1
    Hi,
    I can got the CPU usage of process by Active Monitor or top or htop. But I don't know how to get the CPU usage of thread.
    Who can help me? Thanks
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    Do you mean in your own threaded application code?
    What programming language are you using? What are you using to create threads?
     
  3. tonybai thread starter macrumors newbie

    Joined:
    Apr 29, 2010
    #3
    I need a tool to get the CPU usage of thread. Forexample, I write an multi-thread program with c++. This process cost 100% CPU, I want to know which thread in this process cost most CPU.
     
  4. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    Shark can do this (set it to "all thread states" mode).
     
  5. tonybai thread starter macrumors newbie

    Joined:
    Apr 29, 2010
    #5
    I have used Shark, it can not do it. It can not show the CPU usage of thread, it just give some statics about function. We can know one function cost many CPU, but if this function was called by many threads, how can I know which thread call this function frequently? I want to know the thread, not the function.
     
  6. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #6
    Have you set names for your threads using pthread_setname_np? If not, they're anonymous and interchangeable.
     
  7. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #7
    If for example Activity Monitor shows "100%" then your application isn't multi-threaded, at least there are no two threads running at the same time.
     

Share This Page