Show thread name on threads list, if available.#60
Show thread name on threads list, if available.#60CyberShadow merged 2 commits intoVerySleepy:masterfrom
Conversation
Find if GetThreadDescription() is available in Kernel32.dll (it's available from the Win10 Creators update onwards). If it is, add another column "Thread Name" to the list of threads shown when selecting which thread(s) to profile. If this function is unavailable, don't show this extra column at all. If it is available, we rely on the application being profiled to have called SetThreadDescription(), but if it has not, we just show "-" instead.
CyberShadow
left a comment
There was a problem hiding this comment.
LGTM aside the Fn identifier.
Worth noting that there is another, older way to "set" the thread name (by raising and catching an exception, which would be caught by a debugger).
src/profiler/threadinfo.cpp
Outdated
| } | ||
|
|
||
| typedef HRESULT( WINAPI *Fn )(HANDLE, PWSTR*); | ||
| static Fn GetThreadDescription = reinterpret_cast<Fn>(GetProcAddress( GetModuleHandle( TEXT( "Kernel32.dll" ) ), "GetThreadDescription" )); |
There was a problem hiding this comment.
Please pick a more unique global-scope identifier than Fn, e.g. GetThreadDescriptionFunc.
src/wxProfilerGUI/threadlist.cpp
Outdated
|
|
||
| return L"-"; | ||
| } | ||
|
|
|
We used that older way to set a thread name before the new API in our code but as far as I could figure out, it was only available inside the debugger. I had a quick search there but can't see any way that we could add code to read it. Otherwise I would be happy to add something in for this too. |
Yes, that's right. Theoretically, Very Sleepy could capture it if the program would set it while it was being profiled. There is some code for "debugging", for the purpose of profiling new threads as they are created, however it is not currently finished, so it would take some work to get it that far. |
|
Thank you for submitting this improvement. |
Find if GetThreadDescription() is available in Kernel32.dll (it's available from the Win10 Creators update onwards). If it is, add another column "Thread Name" to the list of threads shown when selecting which thread(s) to profile. If this function is unavailable, don't show this extra column at all. If it is available, we rely on the application being profiled to have called SetThreadDescription(), but if it has not, we just show "-" instead.