Saturday, August 23, 2008

Visual Studio Profiler Tips

Here are some random tips for the Visual Studio 2008 Profiler that I have found useful recently:

Adding Marks Programatically

You can add marks to a profile log through the IDE's Data Collection Control pane, but this is a bit inaccurate and tedious. To add them programmatically you can use the Microsoft.VisualStudio.Profiler.DataCollection class in the Microsoft.VisualStudio.Profiler library.

One great advantage of the profile marks is that you can filter the analysis results to focus on a particular phase.

System Library Calls

By default there is no symbol information for interop libraries, so all calls to a particular DLL are treated as a single function call. For instance, profiler could report that 50% of the time was spent in [mscorwks.dll] and the functions that called into this DLL would appear in a single list. This is not very useful for working out how to reduce the number of calls.

To fix this, add the symbol table as follows:

1. Go to Tools > Options > Debugging > Symbols
2. Add http://msdl.microsoft.com/download/symbols to the search path

Now the calls to mscorwks.dll will resolve to things like _JIT_DblRem@16 (fmod in the C math library). Most importantly, the callers of that function are resolved properly rather than being lumped together with every other interop call, so there is some hope of optimization.

UPDATE: Visual Studio 2008 Service Pack 1

Upgrading to SP1 caused me some stress. It appears that all of the symbols are now available from the Microsoft Servers through a single URL and via the press of a magic button. The Reference Source Server Discussion is the place to go for more information.

I had a couple of problems getting [mscorwks.dll] to work in the profiler and the debugger. The solution involved the following:

1. Launch the process unattached and then attach with Managed and Native debugging active. This forces it to do this in future for all processes and makes [mscorwks.dll] visible to the IDE (important for the next step).
2. When the process is attached and running, go to Tools > Options > Debugging > Symbols and press the "Load symbols from Microsoft symbol servers" magic button.

When the magic button is pressed, symbols are downloaded for any libraries you have loaded AT THAT TIME - this is important to note. This can take a while, but is a reliable way of getting the right symbols for the library versions you are actually using. Alternatively you can download the source code and point at it, but I found this unreliable.

If you follow this method you should not even need to set the search path manually, although I wouldn't swear to it and I can't be bothered to use a virgin machine to find out - comments welcome.

Monday, August 11, 2008

IT News by Yoda

After reading this rather speculative piece of journalism about Google buying Sprint, I noticed a similar piece in my Google Alerts, but this time read by Yoda.

My guess is that this is the product of double translation (English > Jedi > English), which garbles the text enough to make it unique, but it still looks like English to a computer (almost by definition). This makes the search engine favour it, and puts eyeballs on the adverts. Either that or it makes perfect sense and I am having a stroke.

A good example of double translation mishaps is the Hungarian Madonna interview, which I find out now is actually a spoof, but still worth a look.



As an illustration, here is this blog post sent to Japanese and back via Google Translate:

I read the piece rather speculative buying after the sprint Google about journalism, I have my work is similar to Google Alerts, however, at this point, read by Yoda.

My guess is that this is the product of the double translation (English> Jedi> English), which garbles the text enough to make it unique, but still follows English to a computer (roughly defined by) . As a result, the search engine in favor of the ad by the eyeball search. One sense, or is it makes perfect and I am a stroke.

A good example of the accident, Hungarian double translation of an interview with Madonna, it is actually a spoof now discovered that I still want to look at your value.


To be fair, it does a great job and is almost perfect for European languages.