Search

Tuesday, August 26, 2008

Team Foundation Server tool dump workspace details

Bangalore airport

I juggle around with a lot of workspaces. The reason is .NET Compact Framework is consumed in a whole bunch of things like Windows Mobile, Xbox, Zune, Nokia and most of them are on different source branches. On top of this active feature work happens in feature branches and there are other service branches to frequently peek into.

So the net effect is I need to sometime go to different folders and see what it's source control workspace mapping is or I need to dump details of workspaces on other computers and see if I can use that workspace as a template to create a new workspace.

The thing I hate here is to run cd to that folder and do a tf workspace to bring up the GUI and then dismiss the UI. I don't like GUI when things can be done equally well on the console. So I quickly hacked up a tool that dumps workspace details onto the console, something as below

d:\>workspace.exe NETCF\F01
Name: ABHINAB2_S60
Server: TfsServer01
Owner: Abhinaba
Computer: ABHINAB2

Comment:

Working folders:

Active $/NetCF/F01/tools d:\NETCF\F01\tools
Active $/NetCF/F01/source d:\NETCF\F01\source



-


This tool can be used either to see the mapping of a folder or given a workspace name and owner dump it details. It uses the exact same format as show in the tf workspace UI.


Source


The source and a build binary is linked below. It is a single source file (Program.cs) and you should be able to pull it into any version of Visual Studio and even build it from the command line using CSC



  1. Source
  2. Binary

Using the tool

Build it or use the pre-built binary and edit the .config file to point it to your TFS server and you are all set to go.

Wednesday, August 20, 2008

Obsession with desktop continues

Desktop

This is my new office setup. I have been pushing around a lot of code lately and felt I needed more real-estate to effectively do what I'm doing. So I hooked up another monitor. All  3 are standard HP LP1965 19" monitors.

However, since none of my video cards support 3 monitors and I have a whole bunch of computers to hook up I had to do some complex wiring around :). If I number the screens 1,2,3 from left to right this is how it works out

  • 1 and 2 is connected to my main dev box (machine1)
  • 2 and 3 is connected to the machine I use for emails and browsing (machine 2)
  • 2 actually goes through a 4-port KVM switch using which it can circle through machine1, machine2 and two other less used machines
  • 1 also goes through a 2 port KVM switch and connects a xbox and machine 1
  • I don't use the laptop at work directly, I connect to it using remote desktop.

Sweet :)

It's not as complex as it sounds. For my normal flow I just use the KVM to switch between machine-1 and machine-2. I rarely need to switch between the xbox and machine1.

PS: Don't try to make much sense of the Vintage books on the shelve, I plan to keep them for some more time before handing them off to some historian.

Sunday, August 17, 2008

Back to Basic: Using a System.Threading.Interlocked is a great idea

Bound to give you diabetes :)

I just saw some code which actually takes a lock to do a simple set operation. This is bad because taking locks are expensive and there is an easy alternative. The System.Threading.Interlocked class and its members can get the same job done and much faster.

I wrote the following two methods which increments a variable a million times. The first method does that by taking a lock and the other uses the Interlocked.Increment API.

static int IncrementorLock()
{
int val = 0;
object lockObject = new object();
for (int i = 0; i < 1000000; ++i)
{
lock (lockObject)
{
val++;
}
}

return val;
}

static int IncrementorInterlocked()
{
int val = 0;
for (int i = 0; i < 1000000; ++i)
{
System.Threading.
Interlocked.Increment(ref val);
}

return val;
}

-


I then used the Visual Studio Team System Profiler (instrumented profiling) and got the following performance data.















Function NameElapsed Inclusive TimeApplication Inclusive Time
IncrementorInterlocked()1,363.45134.43
IncrementorLock()4,374.23388.69


Even though this is a micro benchmark and uses a completely skewed scenario, it still drives the simple point that using the interlocked class is way faster.


The reason the interlocked version is faster is because instead of using .NET locks it directly calls Win32 apis like InterlockedIncrement which ensures atomic updation to variables at the OS scheduler level.


These Interlocked APIs complete depend on the support of the underlying OS. This is the reason you'd see that all the APIs are not available uniformly across all versions of .NET (e.g. there is no uniform coverage over WinCE and Xbox). While implementing these for the Nokia platform (S60) we are hitting some scenarios where there is no corresponding OS API.