Tools
Materials from HDC09 – Testing With Mocks Talk
Oct 18th
Below is a link to download the Testing With Mocks lightning round talk that I gave at the Heartland Developers Conference this last week.
In order to get the samples to run you will need to have TypeMock Isolator installed. If you do not own a license you can download an evaluation for free here.
The download includes full buildable source and the presentation.
Download: TestingWithMocks_HDC09.zip (~15MB)
Presentation Settings for Visual Studio
Apr 3rd
Unfortunately most presenters do not think about font size until about 10 _after_ they show code to an audience. Its usually followed by the confirmation question from the presenter that goes something like this: “Hey, can you guys see the code?”
Most of the time the answer is… “No, bigger font please … ”. 2 minutes later the font is larger, but usually its only the code editor window. What about the solution explorer, output window, menu’s, etc? Nope, it is still an 8pt font that strains your audiences eyes.
Big Font to the Rescue
I have a Visual Studio Settings file that I call “WowThatsABigFont.vssettings” that I use when I’m presenting. I’m going to attach to this post so you can use it in the future.
Here is what it looks like (click to see full res picture):
These settings are at 16 pt Lucinda Console (for most everything) and 14pt Consolas for the environment.
You have no idea how much this improves your presentation. People can read the screen! This coupled with ZoomIt makes it super easy on your audiences eyes.
Enjoy.
Download
WowThatsABigFont.vssettings (~375kb)
Castle ActiveRecord – NonUniqueObjectException
Mar 29th
Ran into a small issue this morning. Posting the solution here should help me find it next time in a jiffy.
I was performing some database validation – I needed to ensure that x object with y name does not already exist in the DB before submitting it, and more stuff, etc. I have to query the DB to see if this value exists or not. I’m using Castle Active Record and I’m using the Repository pattern to wrap my Active Record calls. I’m also utilizing the ActiveRecordMediator<T> class to help keep the AR (Active Record) DB calls out of the AR storage classes.
If everything was golden, I’d update the record using ActiveRecordMediator’s Update call. Otherwise some error handling took place. When the record was updated I had to hit the DB again. When this happened I got this exception:
NonUniqueObjectException: a different object with the same identifier value was already associated with the session
Oh boy. Fun.
Anyway, this seems to be a scoping issue as once my validation was occuring I was able to grab onto a record and then NHibernate cached that for me. Unfortunately when I went out of scope, NHibernate supposedly cleans up and gets rid of this cached object (from what I’ve read – if anyone had any more info on this please reply). However, later in the method call I perform a very similar call, and at this point the exception is thrown.
I fixed this by evicting the object directly after I used it. I just needed to check one value on the object and I never needed it again until (if and only if) I’d then update it.
The code to do this was as such:
ActiveRecordMediator<T>.Evict(instance);
Where the instance was the instance that i needed to cleanup.
After I performed an eviction from the session, the update worked perfectly.
Here is one link that helped me get started down this path to the solution.
The Importance of Incremental Builds
Oct 15th
With continuous integration being integrated into Team Foundation Server 2008 we can sometimes run into unexpected results. Such as extended build times. By default the build file is set up to inform the TFS Build Agent that it should perform a “Full Build”.
What is a “Full Build”?
By default, when TFS performs a build the following events happen:
- Clean – When Team Foundation Build performs a full build, it cleans the files in the intermediate build folder and sources folder in Clean target.
- Workspace Initialization – As a part of a full build, Team Foundation Build deletes the old, and recreates a new workspace to clean and synchronize the source files.
- Get – In the Get task, Team Foundation Build by default retrieves new source files and overwrites the existing files in the build workspace.
A Possible Issue
A full build can have consequences that can be considered “non-optimal” (this is very subjective in many circles), but in my opinion coming from a Cruise Control .NET background, I DO NOT want full builds.
If my source code repository is very large, cleaning the files, re-creating the workspace and then getting all the files again can be a real pain in the “time” category. I’ve had builds on my local dev machine (which is in a VPC) take 15-20 seconds to build using Visual Studio. I’ve even run the same build from the command line using MSBuild using the .proj file and its taken less than 15 seconds for he same build (~15 Visual Studio Projects in the solution).
However, this same build using TFS would take nearly 20+ minutes!
Wowzers… The reason the build took so long in TFS is because it was utilizing the FULL Build.
Core Concept
One of the core concepts is “Keep The Build Fast“. We’re looking for frequent feedback. 20 minutes (IMO) is not quick feedback (if the build takes 15-20 seconds on my machine). We should be able to get this down to under 10 minutes at the worst, but my goal is to get it well under 5 minutes (closer to 2 minutes).
Enabling TFS 2008 Incremental Builds
In Team Foundation Server 2008, we can change this behavior with a simple change in the TfsBuild.proj file under the TeamBuildTypes directory in TFS. Here’s how:
- Open the TfsBuild.proj file for the build in question
- Add the following XML:
This will enable Team Build to treat this build as an incremental build.
What does this exactly do behind the scenes?
IncrementalBuild is a convenience property that sets SkipClean to true, SkipInitializeWorkspace to true, and ForceGet to false.
Since clean is skipped, the files will not be deleted. Since SkipInitailizeWorkspace is skipped, the workspace will not be deleted and recreated and since ForceGet is disabled, the files will not be overwritten with the files from Source Control. What this will do is perform a regular “Get” on the existing workspace which will only get the changed files.
Result
A huge performance improvement. The previous ~20 minute build dropped to about 4 minutes. There are some other improvements I could do to improve the performance,but at this time its 5 times as fast. Excellent.
Why did it improve this much? Simple: Less disk I/O. Disk I/O = slow.
Disclaimer: This may not be desired. For example, build that is specified for “Production” you might want a “Full Build” in order to simulate a production release. You may have tasks in your build file that need a clean build. But for Continuous integration on the project, this setting is highly desirable.
Why Windows Task Manager Sucks
Sep 17th
It never fails… I’ll boot up, start a program, walk away, log back into my PC and all of a sudden the disk light on my laptop or desktop is lit up like a Christmas tree for the next 10 minutes. The computer is rendered useless until its done “working”. I can’t do anything at this point but wait. A WASTE OF MY FLIPPING TIME.
The Problem With Task Manager
The problem is: I can’t do anything while the disk is tripping on a couple of tabs of electric ecstasy … opening task manager shows me… WELL… nothing. Task Manager says not a single process is utilizing CPU, and not a single process is over utilizing memory. Then I look at Disk I/O (which is presented in Read/Write/Other fashion) and It provides no valuable information at quick glance.
565234 Reads
88723412 Writes
WTF!?!
What I Want
When I look at task manager I want to see what tasks are my computer doing and what affects do each of these issues present. Right now I can only determine if something is a memory hog, or a CPU hog. I may see that SVCHOST.exe is running at 79% CPU utilization, but what the hell is running under the svchost context?!?!! Since svchost is a general host process name for services that from DLL’s, I can’t determine WHO is causing my pain.
So please tell me… Mr. Task Manager. WHO THE @#%! is spinning my disk. THAT IS WHAT I WANT TO KNOW.
You would think that after hmm…. 13 or so years of Windows OS’s, Microsoft would have implemented this functionality. Its fairly rudimentary and actually VERY helpful in troubleshooting.
What I Did About It
Fortunately this exact problem is something that other companies have recognized and have since developed an application I use regularly. Since I recently set up my PC I forgot to load this tool and I decided to write about it.
<Disclaimer>No, I’m not getting paid to write this about this product.</Disclaimer>
When I want to see what is going on in my PC I use Anvir’s Task Manager Free Portable App (download link on the bottom). I bring it with me on my portable drive and flash sticks. Being a consultant who works on many machines, servers, or VPC’s its nice to see what’s going on.
Anvir has many features, but the one feature that I use it for the most is the “Disk Load”. It shows exactly what is utilizing your disk and at what rate. You can sort on this column, therefore when your disk is playing Twinkle Twinkle Little Staryou can see what is causing it.
Here’s a screen shot of what I’m talking about: (Click for larger)
I can now look at what is causing my disk to spin (as long as I can get AnVir open)! Anvir also allows me to see the processes under the svchost as well as look at startup items, processes, services, etc. It has a much more interactive and feature rich set of tools that you can use to help diagnose your troubles.
I’ve written about portable apps before – and I’ll say it again – the nice part about this being a portable application is that I can use it on anyone’s machine without having to install a thing. That’s a thing of beauty. I can log into my mothers machine via SharedView and utilize it on her machine to see what her issues may be. Or even have her run it and tell me what she sees. Instead of seeing “svchost” I can now navigate to the service that svchost is working with. FINALLY.
I realize this may not be the BEST tool for this type of use, and if you have one that you feel is better, please leave a comment.