Fix ProfileEnter / ProfileLeave#88134
Conversation
These two functions can be entered in preemptive mode for UnmanagedCallersOnly methods and also on thread that was not known to runtime. This change switches to cooperative mode if the thread is known to runtime and early outs when the thread was not known.
|
Tagging subscribers to this area: @tommcdon Issue DetailsThese two functions can be entered in preemptive mode for UnmanagedCallersOnly methods and also on thread that was not known to runtime. This change switches to cooperative mode if the thread is known to runtime and early outs when the thread was not known.
|
|
The behavior of the Enter/Leave profiler callbacks on unmanaged callers only methods was discussed in #68760 .
What is the behavior that we want these callbacks to have for unmanaged callers only methods? Would it be better for the profilers if these callbacks are not issues for unmanaged callers only methods? |
The ELT hooks aren't that broadly used, but we have seen people use them to create managed shadow stacks, to do performance profiling, and for code coverage. I think most ELT users would prefer having hooks for all managed methods, but could make do with skipping UnmanagedCallersOnly methods since they are rare. Having mismatched Enter and Leave hooks would most likely break them though, we definitely want to avoid that. Could we set up the thread instead of returning in the Enter hook? |
|
The change is going to address the immediate problem that you have run into, but I think the profiler scenario as a whole (inspection of method argu,ments) is still going to be broken for the unmanagedcallersonly methods. Potential alternative is to stop issuing these callbacks for unmanagedcallersonly methods as discussed in #68760 (comment) I will leave it to @davmason to make a call on this. |
|
It is still unclear to me why we are not hitting the failures in the CI. I keep hitting this locally even without any local changes. The |
The stacktrace suggests that you have an active ETW session on your machine. For example, it can be a ETW session from VS or defender. The CI machines tend to be clean, they do not have random ETW sessions like that. |
I would like to take Jan's change as it is. I think there is value in having ELT hooks even without argument inspection. I filed #89617 against myself to track sorting out the argument inspection part - we should at a minimum return a failure HR. |
These two functions can be entered in preemptive mode for UnmanagedCallersOnly methods and also on thread that was not known to runtime. This change switches to cooperative mode if the thread is known to runtime and early outs when the thread was not known.