locked
How to get processor usage for the thread? RRS feed

  • Question

  • Can somebody explain me how to get processor usage for some thread (not process). MSDN describe process very brief ((( 

    It seems to me that it can be done using performance counter, but I can't find what parameters must be... I.e. it's possible to use (PdhAddCounter(m_hQuery, CounterName,... for that purpose, but what is syntax of CounterName in case of threads? Something like "\\Thread(????)\\% Processor Time" ?

    Thank you for your help.

    Thursday, March 17, 2011 7:13 AM

All replies

  • Nobody knows... :( 

    I solve a problem. Very helpfull are two articles:

    http://support.microsoft.com/kb/287157

    and

    http://support.microsoft.com/kb/287159

    Both articles gives full information about the task... Most interesting is localization problem (2d article)... Take that into account if you want your program works fine worldwide.

     

     

    Friday, March 18, 2011 4:11 PM
  • Another question, looks unsolvable... 

    If I have two instances of my application, The unumeration of thread gives same names of the application for both instances. So, when I retrive thread info for for one of the instance, I always recieve data for first instance - how I can get info for second instance?

    For example:

     

    when I call PdhEnumObjectItems - I got info for both instances

    SHStudio/0 // first instance
    SHStudio/1
    SHStudio/2
    SHStudio/3
    SHStudio/4
    SHStudio/5
    SHStudio/0 // second instance
    SHStudio/1
    SHStudio/2
    SHStudio/3
    but when I call PdhCollectQueryData - I always got data only for first instance ((((

     

     

    Thread\Context Switches/sec\SHStudio/0 : [161.692] // always for first instance

    where SHStudio - name of my application 

     

    have anybody idea how to solve a problem?

     

    Monday, March 21, 2011 6:12 AM
  • Another question into the void... 

     

    I've got results for Thread\% Processor Time - and the number is quite different from results of procexp.exe... Anybody knows why? Is it PCW absolutely useless interface? 

    May be somebody knows other methods to determine % Processo time for the threads (i.e. what method used in procexp.exe) ?

     

    Monday, March 21, 2011 1:24 PM
  • procexp is probably using undocumented APIs. I don't think you can accomplish without breaking a lot of compatibility. If you really want to know I suggest you to join the discussions in http://forum.sysinternals.com

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    Tuesday, March 22, 2011 12:07 AM
  • Already joined - but silence, as it's here...

     

    Most interesting question is - How to measure threads for second instance of application, seems solution must be...

    Second question - what is "% Processor Time" for the thread - looks like it's not a processor %%, but core... Some threads show 100%, and it's looks reasonable..

     

    Tuesday, March 22, 2011 6:09 AM
  • look in the perfmon when you have multiple instance of same process #number is added in the last of the process name. For example: Notepad#1 for instance of the notepad and notepad#2 for the second instance of the notepad. You can do exactly same way in the code too. Its easy to differentiate instances of the same process.


    My current phone is Windows Phone 7 and my current browser is IE 9. Check IE9 testing center
    Tuesday, June 7, 2011 2:14 PM