instance name from thread id?
-
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
-
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
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.
-
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.
-
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
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) { } }
-
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) { } }
-
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
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.