-
June 16th, 2004, 05:03 PM
#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
-
June 16th, 2004, 05:36 PM
#2
-
June 16th, 2004, 11:28 PM
#3
There are a number of ways to accomplish this. A generic way would be to call GetModuleFileName(...)/GetModuleFileNameEx(...)
-
June 17th, 2004, 02:26 AM
#4
Take a look at the following FAQ...
-
June 17th, 2004, 11:39 AM
#5
correct me if I'm wrong, I think that program will return the path of the application. I don't need that, I need the name of the Thread for which I have the handle.
Please advise
-
June 17th, 2004, 11:47 AM
#6
As far as Windows is concerned, a thread doesn't have a name. it is just the address of the ThreadProc !!!
What is the purpose for wanting to know the "name". If you explain that maybe someone here will provide a solution.
-
June 17th, 2004, 11:51 AM
#7
Please look at my first post in this thread, I need the name of the thread to creat a counter for the performance monitoring using pdh.
In my application I have around 20 thread and in the perfmon they are listed as
App/0
App/1
App/2
..
App/20
etc, where App is the name of the application.
Now I want to find the %CPU for only one thread and I just know the handle for it.
Please advise.
-
June 17th, 2004, 11:55 AM
#8
Doesn't the performance monitor show the thread ID ? That is more what you need.
You could probably log the thread ID of each thread you create in the thread proc using GetCurrentThreadID()
-
June 17th, 2004, 11:58 AM
#9
Please forgive my ignorance, but
How to get the thread name from thread id?
I definitely need the name of the thread for the counter as the counters are like:
"\\Thread(App/3)\\% Processor Time"
where App/3 is the thread name.
-
June 17th, 2004, 12:05 PM
#10
Note that the name you see in the performance counter is not a thread name. It is just a friendly name that performance monitor uses for display. What is more important is the thread ID.
Given a thread, you can find the thread ID by adding a counter.
1. Select the performance object as thread. Now, you see a list of the processes and their threads in the list.
2. In the Select Counters from list, select ID Thread.
3. In the select instances from list, select the thread you are interested in.
In your code add the GetCurrentThreadID in each thread and trace out the thread ID. Compare the 2.
-
June 17th, 2004, 03:57 PM
#11
the name you are seeing is the PROCESS name.
Thread(App/3)
Thread 3, in Process App.
So again...GetModuleFileName(...)/GetModuleFileNameEx(...)
If you need the order of thread creation use Thread32First(...) in the tool help library. Or use the Native Api via NtQuerySystemInformation(...). Or WMI. The performance monitor should have a counter to enum the threads also.
Last edited by Mick; June 17th, 2004 at 04:02 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|