Tuesday, September 30, 2008



Getting Started with Performance Testing in Visual Studio 2008


Analizing the performance of an application is not an easy task. Visual Studio 2008 Team System comes with a set of tools which make it easier to find the bottle necks of a system.



Here is a walk through for the very basic first steps.



I wrote the following program which calculates the Fibonacci number for a given number.

using System;

namespace Fibonacci
{
internal class Program
  {
  private static void Main(string[] args)
    {
    int x = 40;
      Console.WriteLine("Calculating the Fibonacci number for {0}.", x);

      int result = Fibonacci(x);
      Console.WriteLine("The Fibonacci number of {0} is {1}.",
  x,
result);
    }

    private static int Fibonacci(int x)
    {
    if (x < 0)
      {
      throw new ArgumentException("x has to be >= 0", "x");
      }
      if (x == 0)
      {
      return 0;
      }
      if (x == 1)
      {
      return 1;
      }
      return Fibonacci(x - 1) + Fibonacci(x - 2);
    }
  }
}


The calculation takes really long and I want to know where the program spends it time.



So I use the Performance Wizard of Visual Studio to get some performance number for the program.








The wizard lets me choose what to profile. I can choose almost any type of applications and libraries (even existing ones) but in this case I just go with the default selection which is my current program.



Next I have to choose the profiling method, Sampling or Instrumentation. The dialog explains the pros and cons of each method. Sampling is selected by default but I tend to use Instrumentation. For my example I use Instrumentation.


Thats it for this wizard. Just click Finish on the next page and you are ready for profiling.

The next image shows the Performance Explorer which popped up after finishing the performance wizard. For my performance session (Fibonacci) the instrumented targets (binaries) are shown and an empty report.

Next thing to do is launching my program with the profiler to get some performance data.

This first starts up the Visual Studio Performance Monitor (vsperfman.exe) and then my Fibonacci program. As the Fibonacci program is instrumented with performance probes these probes report performance data back to the Performance Monitor.

After the Fibonacci program is finished the Performance Monitor is shut down and a performance report is generated.








Monday, September 22, 2008

Referencing DLLs in Visual Studio 2008


Following problem:

In my project I have to reference the Microsoft.VisualStudio.Profiler.dll, which on my computer is at:

C:Program FilesMicrosoft Visual Studio 9.0Team ToolsPerformance Tools

As some of your developer machines use a German setup, on these machines this DLL is at:

C:ProgrammeMicrosoft Visual Studio 9.0Team ToolsPerformance Tools

So how can I tell Visual Studio to search for the DLL in different directories depending on the machine it is installed?

The solution is easy.

Just add the directory to the "Reference Path" in the projects properties.



The "Reference Path" is stored in "fooproject.csproj.user" so every user can set it differently without interfering with each other.

The downside of this is that every user has to set the "Reference Path".

It would be a better solution to be able to use the %ProgramFiles% system variable in the "Reference Path" and share this setting among all users.