UnsafeNativeMethods.PostMessage-Transition to unmanaged code
setter
Posts: 5
I'm trying to profile a section of the code that ANTS says %5 of CPU time.
It's reported as
UnsafeNativeMethods.PostMessage > Transition to unmanaged code
In the call graph, all the callers using a pattern like this:
However mostly SomethingHappenedHandler is null.
Unfortunately profiler doesn't tell me what line is about "Transition to unmanaged code" so I'm guess this is the line as all 3 callers got something like this. Another code that might be related is this:
Most of these events later on handled in the GUI and then GUI uses InvokeRequired and BeginInvokes something.
How can I understand which code leads to "Transition to unmanaged code"? And what does it actually mean?
Another similar one exactly same but this time original method is "SetNativeMethods.GetWindowThreadProcessId" again it's linked to "Transition to unmanaged code" and I can't find which calls actually calls it as there is no line indicators.
Thanks,
It's reported as
UnsafeNativeMethods.PostMessage > Transition to unmanaged code
In the call graph, all the callers using a pattern like this:
if (SomethingHappenedHandler != null) { SomethingHappenedHandler(something); }
However mostly SomethingHappenedHandler is null.
Unfortunately profiler doesn't tell me what line is about "Transition to unmanaged code" so I'm guess this is the line as all 3 callers got something like this. Another code that might be related is this:
Interlocked.Increment(ref _DCount);
Most of these events later on handled in the GUI and then GUI uses InvokeRequired and BeginInvokes something.
How can I understand which code leads to "Transition to unmanaged code"? And what does it actually mean?
Another similar one exactly same but this time original method is "SetNativeMethods.GetWindowThreadProcessId" again it's linked to "Transition to unmanaged code" and I can't find which calls actually calls it as there is no line indicators.
Thanks,
Comments
Still it's not possible to spot this from the source code as profiler doesn't mark it up or show any time allocation on that line, so it's a bit of guess work.
You're only going to see "transition to managed code" on the tree view as it's probably going to be difficult to wedge it into the source code view. However, the managed method name invoking the unmanaged code should be directly below the "transition" entry in the tree view. For instance: Where GetVersionFromProcess is a pInvoke defined as...
I think the "time with children" on the "transition" is not very useful - it seems to include the run-time of the unmanaged methods, too. The "time %" seems more sane (in my case <0.001).
I'm told that if computing resources are low this may affect the reported time in transition. So you may want to turn down the detail level (for instance do not profile with line-level timings on).