Profile XBAP memory in production ?

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
adm123
Posts: 4
Joined: Thu Sep 09, 2010 11:35 am

Profile XBAP memory in production ?

Post by adm123 » Thu Sep 09, 2010 12:19 pm

Is it possible to use .NET Memory Profiler to memory profile an XBAP application in production ?

I need to check for memory leaks in a .NET 3.5 XBAP application in production (i.e. not in VisualStudio). That is, launched via a URL in internet explorer e.g. http://SomeServer:9876/MyApp/MyXbap.xbap.
If I choose Profile WPF Browser Application and enter a URL, I get an error "The specific browser applicaation does not exist".

adm123
Posts: 4
Joined: Thu Sep 09, 2010 11:35 am

Re: Profile XBAP memory in production ?

Post by adm123 » Thu Sep 09, 2010 2:23 pm

After installing the Debugging Tools for Windows, I can attach to the PresentationHost.exe (which represents the XBAP inside IE), but the tabs for Types, Type Details and Instance Details are all blank - only the Native Memory tab has any content. That does list the various .NET DLLs, but the Managed Heaps is showing 0Kb. It seems I can't see "inside the XBAP", to see the .NET memory usage.

Is profiling XBAPs running in IE something that's possible ?

adm123
Posts: 4
Joined: Thu Sep 09, 2010 11:35 am

Re: Profile XBAP memory in production ?

Post by adm123 » Fri Sep 10, 2010 10:01 am

Some further investigation - I have some success with XBAPs using this approach:

- Run Memory Profiler as Administrator - if I didn't do this I got error "Profiled process terminated while connecting"
- Select Profile Application
- Enter Internet Explorer as the executable: "C:\Program Files\Internet Explorer\iexplore.exe"
- Enter the URL as the command line arguments e.g. http://SomeServer:9876/MyApp/MyXbap.xbap

Note: I'm using using IE7. Another post suggests if using IE8, need to include -noframemerging before the URL.
http://memprofiler.com/forum/viewtopic.php?f=3&t=1299
The profiler then shows data in the Types and Real-time tabs, but the Type Details and Instance Details tabs remain blank.

Is this the correct approach to be using ?
Is there a way to get the Type Details and Instance Details tabs to populate with data ?

Andreas Suurkuusk
Posts: 1028
Joined: Wed Mar 02, 2005 7:53 pm

Re: Profile XBAP memory in production ?

Post by Andreas Suurkuusk » Fri Sep 10, 2010 4:27 pm

It is currently not possible to profile an XBAP application that is not accessible locally through a file. We use the -debug parameter when starting the PresentationHost process, and the -debug parameter cannot be combined with an URI (see MSDN). However, we're investigating the possibility of running PresentationHost.exe without the -debug parameter.

You should be able to attach to the PresentationHost process using the Attach command, but when I tested this, it didn't work. This is something we will look into immediately. I will get back to you when I have some more information.

Profiling Internet Explorer will not give you memory information about the XBAP application, since the actual application is run in the PresentationHost process. You do get some information related to rendering of and interaction with the application, though.
Due to the way Internet Explorer uses processes, it's a bit difficult to run it under the profiler (without getting the "Profiled process terminated while connecting" message). When you start IE,it will try to reuse a running IE "frame process". To get around this, you can use the -noframemerging parameter under IE8. I don't think this works with IE7, so you will need to make sure that all IE windows are closed before starting IE under the profiler. When you run as an administrator, there is no existing process to reuse (at the same elevation level), which explains why it worked better for you when you ran the profiler as an administrator.

You also mention that the Type details and Instance details views are empty. These views will show data when you select a specific Type or Instance in another view, e.g. by double-clicking a type in the Types view. Is the Types view still empty if you double-click a type in the Types list (or select View->Show type details)?
Best regards,

Andreas Suurkuusk
SciTech Software AB

adm123
Posts: 4
Joined: Thu Sep 09, 2010 11:35 am

Re: Profile XBAP memory in production ?

Post by adm123 » Mon Sep 13, 2010 8:36 am

For the Type Details/Instance details - those do show data if I select a specific Type in the Types view, and double click to drill into the details view (my lack of understanding I think! - apologies). Profiling IE7 as administrator does seem to be showing what looks like memory leaks. In Types Window, Show hierarchical - after opening/closing a window I see the instances count for a known class increments by 1 but doesnt decrease. Not sure how that corresponds to what you say about profiling IE not working - would this information be reliable, or is it only part of the picture ?

I don't quite understand the instance details tab though, to know where the leak is happening (lost in the information!). I need to read up on that more to understand things.

Andreas Suurkuusk
Posts: 1028
Joined: Wed Mar 02, 2005 7:53 pm

Re: Profile XBAP memory in production ?

Post by Andreas Suurkuusk » Tue Sep 14, 2010 10:16 pm

To support scenarios like Silverlight profiling, .NET Memory Profiler was recently modified so that it connects to the first (child) process that loads the .NET runtime, even though that process is not the one originally launched by the profiler. In your case, IExplore launches PresentationHost and PresentationHost loads the .NET runtime before IExplore loads the runtime, so you will actually profile PresentationHost instead of the launched IExplore process and the information presented will be collected from your XBAP application. This does allow you to profile a production XBAP, but it requires that IExplore does not load the .NET runtime prior to PresentationHost.

If you have a class with new instances that you believe shouldn't exist, you can get information about why it has not been GCed by looking at the instance details. In this case you are mainly interested in the root paths of the instance, as they will tell you why the instance has not been collected. If you need help interpreting the root paths, you can attach one ore more of them to a post and I will see if I can provide you with some hints.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 21 guests