Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. instance name from thread id?

instance name from thread id?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    ben2
    wrote on last edited by
    #1

    Instance name from Thread Id? Hi, I'm using pdh to generate Performace data for a thread in my multithreaded program. The counter should be like "\\Thread(App/3)\\% Processor Time" here App/3 is the name of the instance for the thread. My question is: I know the thread Id for my thread, how do I find the instance name of the thread from my program? Please help

    B 1 Reply Last reply
    0
    • B ben2

      Instance name from Thread Id? Hi, I'm using pdh to generate Performace data for a thread in my multithreaded program. The counter should be like "\\Thread(App/3)\\% Processor Time" here App/3 is the name of the instance for the thread. My question is: I know the thread Id for my thread, how do I find the instance name of the thread from my program? Please help

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      See the MSDN topic for SetThreadName. Since you must set the thread's name, how could you not know it when the thread is running? Otherwise, this is just some default name the system gave your thread, and I would encourage you to give it a meaningful name yourself, when it starts up.

      B 1 Reply Last reply
      0
      • B Blake Miller

        See the MSDN topic for SetThreadName. Since you must set the thread's name, how could you not know it when the thread is running? Otherwise, this is just some default name the system gave your thread, and I would encourage you to give it a meaningful name yourself, when it starts up.

        B Offline
        B Offline
        ben2
        wrote on last edited by
        #3

        I tried your suggestion, but that thread name is not shown in the perfmon Thread instance list. Seems like it is still showing as one of App/0, App/1 etc. Please suggest any other method

        B B 2 Replies Last reply
        0
        • B ben2

          I tried your suggestion, but that thread name is not shown in the perfmon Thread instance list. Seems like it is still showing as one of App/0, App/1 etc. Please suggest any other method

          B Offline
          B Offline
          ben2
          wrote on last edited by
          #4

          sorry it is giving error for except. I included windows.h, excpt.h..still // // Usage: SetThreadName (-1, "MainThread"); // typedef struct tagTHREADNAME_INFO { DWORD dwType; // must be 0x1000 LPCSTR szName; // pointer to name (in user addr space) DWORD dwThreadID; // thread ID (-1=caller thread) DWORD dwFlags; // reserved for future use, must be zero } THREADNAME_INFO; void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName) { THREADNAME_INFO info; info.dwType = 0x1000; info.szName = szThreadName; info.dwThreadID = dwThreadID; info.dwFlags = 0; __try { RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info ); } except(EXCEPTION_CONTINUE_EXECUTION) { } }

          B 1 Reply Last reply
          0
          • B ben2

            sorry it is giving error for except. I included windows.h, excpt.h..still // // Usage: SetThreadName (-1, "MainThread"); // typedef struct tagTHREADNAME_INFO { DWORD dwType; // must be 0x1000 LPCSTR szName; // pointer to name (in user addr space) DWORD dwThreadID; // thread ID (-1=caller thread) DWORD dwFlags; // reserved for future use, must be zero } THREADNAME_INFO; void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName) { THREADNAME_INFO info; info.dwType = 0x1000; info.szName = szThreadName; info.dwThreadID = dwThreadID; info.dwFlags = 0; __try { RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info ); } except(EXCEPTION_CONTINUE_EXECUTION) { } }

            B Offline
            B Offline
            ben2
            wrote on last edited by
            #5

            I used __except, compiled. But still I cant see the name of the thread in the list of perfmon

            1 Reply Last reply
            0
            • B ben2

              I tried your suggestion, but that thread name is not shown in the perfmon Thread instance list. Seems like it is still showing as one of App/0, App/1 etc. Please suggest any other method

              B Offline
              B Offline
              Blake Miller
              wrote on last edited by
              #6

              I do not know any other mechanism. Perhaps the PerfMon is just enumerating the threads somehow, and it just assigns each one a number based upon its order of being returned or indexed. It might not necessarily be using a thread 'name' so much as appending thread number after name of process. Have you seen any other application with decorated thread names? Or are all processes using the same scheme? I was not able to readily locate any further information relating performance monitor and threads.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups