| Author |
Message |
setter
Joined: 08 Nov 2011 Posts: 3
|
Posted: Tue Nov 08, 2011 6:59 pm Post subject: UnsafeNativeMethods.PostMessage-Transition to unmanaged code |
|
|
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:
| Code: |
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:
| Code: |
| 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, |
|
| Back to top |
|
 |
setter
Joined: 08 Nov 2011 Posts: 3
|
Posted: Wed Nov 09, 2011 12:32 pm Post subject: |
|
|
OK, I figured that "Transition to unmanaged code" is referring to marshalling in UI thread due to invokes.
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. |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6369 Location: Red Gate Software
|
Posted: Wed Nov 09, 2011 2:28 pm Post subject: |
|
|
Hi,
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:
| Code: |
Microsoft.Samples.Debugging.CorDebug.CorDebuggerVersion.GetDebuggerVersionFromPid(int pid)
-> Transition to unmanaged code...
->Microsoft.Samples.Debugging.CorDebug.NativeMethods.GetVersionFromProcess(ProcessSafeHandle hProcess, StringBuilder versionString, int bufferSize, out int dwLength)
|
Where GetVersionFromProcess is a pInvoke defined as...
| Code: |
[DllImport("mscoree.dll", CharSet=CharSet.Unicode, PreserveSig=true)]
public static extern void GetVersionFromProcess(ProcessSafeHandle hProcess, StringBuilder versionString,
Int32 bufferSize, out Int32 dwLength); |
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). _________________ Brian Donahue
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
|
|
All times are GMT + 1 Hour
|
| Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group