views:

210

answers:

1

Does anyone know of a way I can code-profile my Windows Sidebar Gadget?

I've played around with the code-profiling tool in IE8's "Developer Tools" and the code-profiling included in Visual Studio 2010, but I can't find a way to include the System.* API, which my gadget relies on (as it is standard in the Sidebar environment). The gadget also relies on cross-domain AJAX requests; which is normally permitted in the Sidebar environment.

By code-profiling I primarily mean:

  • Function call count
  • Function execution time

I've tried the following using Visual Studio 2010 and the Performance Wizard:

  • Using "Instrumentation" mode with the "An ASP.NET or JavaScript application" selected. However the gadget opens in Internet Explorer instead of Windows Sidebar
  • Using "Instrumentation" mode with the "An executable" option selected, and selecting Sidebar.exe. However, I get the error "Error VSP1030: Invalid, mismatched, or no PDB file was found for C:\Users\Matt\Desktop\Windows Sidebar\sidebar.exe"
  • Using "CPU Sampling" mode with the "An ASP.NET or JavaScript application" selected. However the gadget opens in Internet Explorer instead of Windows Sidebar

When using the "Attach to Process" option in the Analyse -> Profiler menu, I can successfully attach to the sidebar.exe process, but the profiler returns data about the actual Sidebar process, and no information about my Gadget.

I don't have a Project/Solution file for my Gadget.

Regards, Matt

+1  A: 

I'm on the VS Profiler team, so feel free to ask any clarifying questions.

If you want exact metrics (execution time, call counts), then you should use instrumentation. With instrumentation, the profiler will show you data for any binaries you instrument as well as one level of callees (e.g. if you call string.Concat directly from your instrumented binary, the profiler will show you how many times you called it and how long (in aggregate) the calls took). The profiler will not show you data for binaries that you don't instrument.

Have you tried instrumentation profiling? What sort of data are you seeing?

If you want, you can also try a statistical approach to profiling: sampling. Sampling is lighter-weight than instrumentation and is often good as a first pass to figure out, at a high level, where your CPU is doing the most work. With sampling, the profiler takes snapshots of the call stack at specified intervals (this is similar to breaking into the debugger to see what's currently executing). It then aggregates the snapshots to create a call tree.

If you give me a better idea of how you're trying to profile, I can help you more. Are you using the profiler from VS or from the command-line? Do you have a VS solution/project for your Sidebar Gadget?

You can also check out our blog or our MSDN documentation for more info.


Update:

The profiler's JavaScript profiling functionality was primarily targeted at IE8, so I'm not sure if it will collect data against another process like sidebar.exe that (I'm assuming) hosts the IE JavaScript engine. Still, you should at least be able to use the profiler to collect data against your managed code.

For instrumentation, you will want to go with your second option ("An executable"), and in the Performance Explorer, you will want to have two targets:

  1. sidebar.exe, not instrumented (since you don't have the PDB) - you can right-click the target and uncheck the "Instrument" option to suppress instrumentation
  2. foo.dll (whatever your Gadget DLL is called), instrumented - you might have to manually add this target (right-click on the Targets folder, select "Add Target Binary..."), but be sure to enable the "Instrument" option and ensure that its PDB is sitting next to it

To understand more about performance targets, see this blog post. With this setup, just click the "Start Profiling" button. Instrumentation should succeed and you should get trace profiling data for your Gadget.

For sampling, you can either launch or attach to the process. Attaching to the process only works if:

  • The process is running on the v4 CLR; or
  • The process has the correct profiling environment variables set (see below for what this means)

Profiling a pre-v4 CLR process requires some environment variables be set in the target process. Essentially, you will need to kill the sidebar.exe process and then re-launch it using the profiler's command-line tools. A walkthrough of how to do this is available on MSDN.

The other option, sampling launch, can be done from the command-line (refer again to the MSDN article), or from the VS UI. Choose "CPU Sampling" with "An executable (.EXE file)", then shutdown any currently running instances of sidebar.exe, right-click on the newly-created target in the Performance Explorer, choose "Properties", and modify the command-line arguments as needed. Launching the profiler should then work.

Let me know if you hit any more issues. Sorry this isn't easier.

Chris Schmich
Hi Chris, many thanks for your help so far. I've updated the question to answer your questions. Thanks.
Matt