Using CLR Profiler 2.0 with XNA 4.0

September 6, 2010 by Dave
Filed under: C#, XNA 4.0 

By default (at least on my computer, running Windows 7), CLR Profiler 2 won’t work with new XNA apps since they utilize the new .NET framework.  It looks like it’s working when you try it, but when it shows the final statistics window it’s empty.  Fortunately, it’s possible to enable support using the new profiler compatibility settings functionality, which for this case involves simply setting the COMPLUS_ProfAPI_ProfilerCompatibilitySetting environment variable before running CLR Profiler.

Here’s what I did:

Create a batch file called start_clr_profiler.bat with this content, save it in Documents or wherever:


c:
cd "\program files (x86)\clrprofiler\binaries\x86
set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler
clrprofiler

It goes without saying that you’ll need to change the drive and path to where you have CLR Profiler installed.

Once you have this file, create a shortcut  to it on your desktop.  Right click on the shortcut, select Properties, click the Advanced button and check “Run as Administrator”.  Click OK a couple of times, and you’re good to go. Just start the profiler with the batch file and the environment variable will be set, and the profiling magic will happen.

You could also set that environment variable at the user or machine level so it’s set all the time, but I don’t know what ramifications that has so prefer setting it just when needed. Happy garbage collecting!

Comments

9 Comments on Using CLR Profiler 2.0 with XNA 4.0

  1. Brandson Henry on Tue, 14th Sep 2010 5:45 am
  2. THANK YOU THANK YOU THANK YOU!!!

    been desperately needing a free CLR profiler for a large XNA 4.0 project I’ve been working on. it’s been heart wrenching to find no solutions on google or the xna community forums. thanks for this =]

  3. Nathaniel Troutman on Mon, 11th Oct 2010 12:43 pm
  4. Thanks! This worked great.

  5. John Hampson on Tue, 9th Nov 2010 6:46 am
  6. Yes, thanks a lot for this. I too have been missing the CLR profiler since upgrading to XNA 4.0

  7. DragonSix on Sun, 14th Nov 2010 3:14 am
  8. Thank you.

  9. Jonathan Harbour on Thu, 2nd Dec 2010 1:40 pm
  10. Looks great, congrats on a nice game!

  11. Peter Leahy on Thu, 19th May 2011 7:06 am
  12. Cheers mate, helped me nail a nasty new GC bug

  13. Jason Doucette on Wed, 8th Jun 2011 12:48 am
  14. Thanks, I got CLR Profiler 2.0 to work with XNA 4.0 in this manner. However, it only worked for the x86 version, not the 64-bit version, which is strange.

    Also, I’d like to know why CLR Profiler 4.0 doesn’t work with XNA 4.0 as-is. Do you have any suggestions on how to make it work? It shouldn’t require any help.

    Jason

  15. Jason Doucette on Wed, 8th Jun 2011 1:00 am
  16. Weird, the x86 version of 4.0 seems to work fine now…

  17. Dave on Wed, 8th Jun 2011 1:22 am
  18. One thing I noticed is that I have to have Allocations and/or Calls checked before I start my app. If I check them after the app starts (if I’m trying to just profile a certain part of the app for example) then I never get any data. So I always make sure those are checked, leave Profiling Active unchecked, start the app, navigate to where I want, then check Profiling Active. Other than that, as long as I run it as administrator, and set the working directory in File/Set Parameters everything seems to work pretty well with it.

Tell me what you're thinking...