Wednesday, November 18, 2009

LINQ To SQL Profiler And How To Swing It

[warning: technical post]

My friend showed me a cool profiler the other day by the smart chaps at Hibernating Rhinos which lets you see what is going on behind the scenes of the magic black box known as "LINQ To SQL" (L2S). I've been using LINQ to SQL for almost 2 years now and while it's far from perfect it makes my job (life!) much easier. Unfortunately by hiding the inner workings away from the developer by the time you come to look at the performance of your website (or desktop app) you're pretty much left in the dark. That's where L2SProf comes in. It hooks into your datacontext and gives you a great view of what's happening back there...


Now, the set up is pretty straightforward with L2SProf and involves adding a reference to a single DLL into your app (web or otherwise) then copying and pasting a single line of code into your startup method (e.g. Application_Start in global.asax for a website). Once you've done that you restart your application, crack open the included L2SProf.exe and voila, your LINQ to SQL datacontext's secrets are no longer secret... unless you're me. I got a big fat nothing.

After trying to sort it out with my friend and failing I jumped onto the support forums and posted a quick message asking for help. There was a bit of to-ing and fro-ing over email with not much accomplished. Then Oren Eini (AKA Ayende Rahien) popped onto the scene (then Skype) to give me some help.

First we tried writing the profiler data to a text file (a slight modification to that single line of code I mentioned earlier) and while the log file was created, nothing was written to it. Next we created a brand new web application from scratch and everything worked with the profiler showing my single datacontext call and its corresponding SQL code. Oren looked over the web.config from my original website and decided the problem wasn't in there. After fiddling around some more we came across a little bit of code I'd put in place to stop Visual Studio from trying to read my connection string from the data model project's app.config. This was our "aha" moment.

Normally you'd either have your DBML file (LINQ to SQL datacontext) in your website or if it's out in another project in your solution, you'd let Visual Studio control the database connections by dropping them into the app.config, that's not how I had it set up. This is the method I had in place in my DataContext.cs...

public MyDataContext() : base(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString)
{
OnCreated();
}


I'll let Oren explain what was going on here...

"The problem with doing it this way is that you are forcing L2S to build a new model every time that you create a data context, that is quite expensive, from a perf point of view. L2S have to use reflection to get the values each and every time. A side affect of that is that it also kills the way L2S Prof works. Here is how to make it both performance and work with L2S Prof:"

public MyDataContext() : base(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}


Once we did this everything fell into place, data access information pouring out of my website. So there you go, once again proving that if you don't do what Visual Studio wants you to do you can get into trouble.

Thanks a lot to Oren for his help and patience in helping me solve this problem. Now I need to go see how badly my website is performing.

Monday, October 19, 2009

Using Microsoft Ajax Minifier with Deployment Projects

It's been a while since I did a post here but this is worth it. Yesterday Microsoft's Scott Guthrie announced the new Microsoft Ajax Library (Preview 6) and the Microsoft Ajax Minifier. While I haven't checked out the new Ajax library I have had a bit of a play with the minifier.

Seeing as I was on the look out for a Javascript minifier for my current project this came at quite an opportune time. I found Stephen Walther's immensely helpful blog post about setting the Ajax Minifier to run automatically each time you build your project (you should go read that now before continuing here). The only problem with Stephen's sample is my current ASP.NET solution is set up in such a way as my website is a Website, not a Web Application so I don't have a .csproj file to edit.

Fear not! For I have found that I can simply transpose Stephen's sample code over to my deployment project's .csproj file with similar results. The following is the required markup from my deployment project's csproj file to generate minified scripts on the fly after deploying my website. I placed this at the very end of the markup, just before the closing </Project> tag.

CODE:


<PropertyGroup>
<BuildDependsOn>
$(BuildDependsOn);
MinifyJs
</BuildDependsOn>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" />
<Target Name="MinifyJs">
<ItemGroup>
<JS Include="$(OutputPath)\js\*.js" Exclude="$(OutputPath)\js\*.min.js" />
</ItemGroup><AjaxMin SourceFiles="@(JS)" SourceExtensionPattern="\.js$" TargetExtension=".min.js" />
</Target>


Should look something like this:


The big difference here is the min.js files are generated on the fly in the DEPLOYED website (that'd be the $(OutputPath) location. Also, but not as important, my javascript files are in a folder called "js" unlike Stephen's which sit in the root of the site.

So there you go, minified Javascript files in your target site.

Sunday, April 5, 2009

Monsters vs Aliens' Monster Cast

I took my eight year old daughter out this morning to see the 10am session of Monsters vs Aliens, Dreamwork's latest 3D animated feature. I picked a few of the voices but when I saw the credits roll past at the end (GIANT credits I might add!) I knew almost all the names. It was this that lead me to make this list characters-to-actors so you too can see just who was in the film. You should go and see it by the way, quite entertaining with plenty of monster movie/sci fi in-jokes (there's even a Wilhelm Scream) including a hilarious Close Encounters homage with a genuine Yamaha DX/7 synth.

Susan Murphy/Ginormica - voiced by Reese Witherspoon



B.O.B - voiced by Seth Rogen


Dr. Cockroach Ph.D. - voiced by Hugh Laurie


The Missing Link - voiced by Will Arnett


General W.R. Monger - voiced by Kiefer Sutherland


Gallaxhar - voiced by Rainn Wilson


President Hathaway - voiced by Stephen Colbert


Derek Dietl - voiced by Paul Rudd


Wendy Murphy - voiced by Julie White


Carl Murphy - voiced by Jeffrey Tambor


Spaceship Computer - voiced by Amy Poehler


News Reporter - voiced by Ed Helms


Katie - voiced by Renée Zellweger


Cuthbert - voiced by John Krasinski


This is the 3D Super Bowl trailer for the film:

Wednesday, March 4, 2009

Retweet @mottey: Terminator Salvation Trailer


Retweeting @mottey

"The new Terminator Salvation trailer looks awesome! http://is.gd/lwK3"

NIN's track The Day The World Went Away + awesome footage = WIN!

Thursday, February 26, 2009

The king of the Vampires is a US Marine

Due to its long episode running time (1+ hour each) I've slowly been catching up on the excellent modern war TV mini series Generation Kill. It originally aired about 8 months ago and during that time I've watched quite a few other shows. This has lead to not one, but two instances where an actor I originally saw in Generation Kill is more familiar to me from another series which I'd started watching after GK. So when I watch a new GK episode I have an odd mix of deja vu and the feeling of recognising someone but not being able to remember where from (is there a word for that?).

The following are two actors who I originally saw in Generation Kill back in July of 2008 but have since become more familiar through other shows, namely The Mentalist and True Blood.

Example 1 (Generation Kill vs True Blood): Alexander SkarsgĂ¥rd


Sgt. Brad “Iceman” Colbert from Generation Kill


Eric “King of the vampires” Northman from True Blood

Example 2 (Generation Kill vs The Mentalist vs Sarah Connor Chronicles): Owain Yeoman


Sgt. Eric Kocher (right) from Generation Kill with "Captain America"


CBI detective Wayne Rigsby (left) from The Mentalist (with Simon Baker)


Terminator "Cromartie" from Terminator: The Sarah Connor Chronicles (Pilot episode only)

Monday, February 9, 2009

Hot As Hell: Australia's Worst Natural Disaster

By now you'll have heard of the fires that screamed through Victoria, Australia at the weekend. Currently the official death toll is at 131 with the final grisly number expected to be much higher as emergency workers sort through the rubble making this the worst natural disaster ever in Australia.

One of the towns totally destroyed by the fire was Marysville where I visited only a few months ago. Finding the following photo is what prompted me to write this post as I have an almost identical photo from November last year. What was a luscious green country town is now a smoking heap as you can see here...

Before (November 16, 2008)


After (February 8, 2009)


My hometown of Warragul and its neighbouring town Drouin were both on alert on Saturday but were given the all clear later on Sunday. I'm just thankful that my family is OK even though my brother said burning embers were landing in his backyard in Drouin.

The ABC website has a page where you can ask or offer help. We've given clothes and food and have offered housing if anyone needs it.

It seems to be a time to break records with Melbourne recording its hottest 3-day streak last week with a 43c+ (109.4f) hat trick and its hottest day on record on the day of the fires where it got up to a horrible 46.4c (115.4f). Throw in gale-force winds and pyromaniacs and you have the perfect recipe for disaster.

Today, Prime Minister Kevin Rudd said that if the Victorian fires had been deliberately lit it would amount to "mass murder". Later, Attorney-General Robert McClelland agreed saying, "Anyone who lights fires deliberately, with reckless disregard for the safety of their fellow Australians, in our view establishes the requisite criminal intent that would sustain a charge of murder." ...so say we all.

Tuesday, February 3, 2009

Does It Offend You, Yeah? My Drinking?

I may be a little late to the party but I've just picked up Does It Offend You, Yeah's album "You Have No Idea What You're Getting Yourself Into" after hearing their track We Are Rockstars in the new Fast and Furious trailer.

Of the band Wikipedia has this to say, "Does It Offend You, Yeah? have been compared to dance-oriented acts like Daft Punk, Justice and Digitalism. NME also compares them to bands like Muse due to their heavier, more "live" sound. The group is known for their raucous live shows, which often end in stage diving and broken instruments."

Personally I reckon they're like Daft Punk mashed with The Prodigy but whatever they are, they rock!


We Are Rockstars video clip (sorry for the bad quality audio but this is the old YouTube here).

Some history...

Band Name
“Everybody thinks the name is some kind of statement but it's a quote from David Brent in an episode of The Office. "When me and James Rushent first started writing music together we decided to put it up on MySpace. We needed a name to put as our profile name so just put what was the first thing that was said on TV, we switched it on and Ricky Gervais said "Does it offend you, yeah? My drinking?" so we just went with that. No thought went into it whatsoever.[8]”

Album Name

“The name of the album was decided just as spontaneously as the name of the band - the album's title is a direct quote from Robin Williams' character in the film Jumanji.”

Tuesday, January 27, 2009

Still Here, Wish You Were

Yes, I'm still here, just not blogging most of my "shared hyperlink" posts which are being pushed along the Twitter lines these days. Did I mention I'm tweeting? Yes... follow me at http://twitter.com/mrated. I highly recommend installing Twhirl for all your Twitter needs, it makes so much more sense that way.

Sunday, January 18, 2009

How To Have An 18 Movie Marathon In 2 Hours

Today my 3.5 year old was restless and scratchy so I started playing Shrek on my PC for him while I was updating Mood Stones. I saw the other 2 Shrek movies sitting there on my media hard drive and thought I'd try a little experiment.

What you see here is a screenshot of 18 movies playing at the same time on my dual monitor setup (2 x 4:3 CRTs). The system tray shows I had 21 windows open but the other three were hidden underneath somewhere and I couldn't get to their play buttons. My PC had no problems playing all 18 movies and even mixed the various audio streams out through to my 5.1 speakers with the AC3 (Dolby Digital) outputs even mixing correctly. I was a little surprised with that one. This would sure be an easy way to have an 18 film marathon... you'd be done in a few hours.

My next test was to see how my PC would handle multiple HD videos. I kicked in all 6 Star Wars movies which I just happen to have in 720p and they played with no troubles at all, again with the 6 distinct audio streams being mixed nicely.



(click for full size images, excuse the JPEG compression)



Just a few years ago you'd have struggled to play one high definition video now you can play six HD or 18 SD videos ACROSS THE NETWORK all at once and still have spare CPU for solitaire in another window.

I was running low on free RAM with the 18 videos playing (plus 3 more loaded ready to play) but the 6 HD videos didn't seem to worry Vista much. When I install Windows 7 on my PC I'll have to retry my experiment, especially seeing as MPEG4 decoding is now part of the OS.

FYI, my hardware specs:

CPU: Intel Core 2 Quad Q6600 (not overclocked)
RAM: 4GB
LAN: 1,000Mb/1Gb Ethernet
OS: Windows Vista 64
Video: ATI Radeon HD 4850 512MB
Audio: Onboard Realtek HD Audio
Codec: K-Lite Standard pack using WMP Classic.


Thursday, January 15, 2009

Wednesday, January 14, 2009

American Muscle, Old Vs New

There's been a trend in recent years for US car manufacturers to return to the glory days of the late 1960s and early 1970s with their super powerful gas guzzling muscle cars. The retro designs are very American and tend to invoke strong feelings for or against them.

I personally like the look of the new cars although the Mustang's rear end looks odd and the Challenger's big chin is worrisome. At the 2009 Detroit auto show the Camaro Black was looking like a superstar, makes me want to burn dinosaurs!

To show how similar/dissimilar the "new" designs are from the old designs I've put together this easy to see side-by-side comparison. Enjoy. (click for larger images)

Dodge Challenger


Ford Mustang



Chevy Camaro


Here's the Camaro Black in all its hotness, thanks Autoblog!

Tuesday, January 13, 2009

Editing ID3 Tags With Vista

I'm not sure how widely documented this feature of Windows Vista is but I use it frequently and thought I'd pass on the info.

I sometimes acquire MP3s in various formats and more often than not the ID3 tags are either incomplete, incorrect or just not there. ID3 tags are metadata stored with the audio data as part of the MP3 file and include information such as the track name, the artist name(s), the cover art and plenty of other things.

Well, before Vista you had to edit the tags with third party software, through Winamp or Windows Media Player (WMP) or whatever media player you use which wasn't too bad, so long as the software updated the files then and there. Winamp does this but you can only edit one file at a time while WMP lets you edit multiple files at once (e.g. album title) but it delays updating the physical files until later which is a pain if you want to transfer them to an external device for example.

So here are my simple steps on cleaning up ID3 tags using Windows Explorer in Vista and finally adding album art of a decent size using Windows Media Player.

Step 1

Firstly, make sure you can see the ID3 tag information in Explorer. Go to the folder with your MP3 files, select "Detail View" then right-click the titles of the columns. You can click on the "More..." option to get the complete list as shown in this screenshot. I like to select "#" (the track number), "Name" (the file name), "Size" (file size), "Type" (what type of file it is), "Title" (the song title), "Artists" (the album artist), "Album" (the album title), "Bit rate" (the bitrate of the MP3 file), "Genre" (the genre of the music) and "Year" (the year released).



Step 2

Now you can select the files in the list and edit the general information such as the Album Title, Album Artist, Genre and Year. To do this, just select the files and you'll see the aggregated details in the information bar at the bottom of the window. Clicking in any of these fields allows you to edit then save the details. Be careful you don't overwrite the track number, track title etc. as it will update all the files at once. If you want to edit a single file, just select the one you want and follow the same steps.



Step 3

Before adding album art, just check to see if the files already have them. In Windows Explorer set your view to Large Icons. If the files just have the default blue musical note icon instead of album art follow these steps to add it in. This will embed the image into the MP3 so when you transfer it around to various places you'll get the cover art. I usually get a 500x500 pixel image from Google Images, just search by artist name and album title, to serve as the cover art as WMP's 200x200 images are too small and badly compressed for my liking.

This is where we head over to Windows Media Player. Right click your folder and select "Add to Windows Media Player list" or "Play with Windows Media Player". Once you have WMP open go to the Library tab then select Now Playing in the left tree view. If the files haven't been added to your music library yet you'll see the Rating stars are grey, wait until they're all solid before continuing or you could get yourself into trouble (I've had WMP crash if it's trying to add cover art while adding tracks to the library).



Now select all the files, right click any one of them and select "Advanced Tag Editor". Once that's open go to the Pictures tab and press "Add...". Select the JPEG you'd like to use as cover art making sure you set it as "Cover (front)" then hit OK. It may take a few seconds to update all the files and if one of them is playing (or was the previous track played) WMP will do it's whacky postponed update.



Head back over to Windows Explorer and hit refresh, you should now see each file has the cover art as its icon. If you want you can delete the system files that were generated (selected in the screenshot below). I like to keep folder.jpg so when I view the folder in icon view I get a nice image instead of a pile of images.



Done!

I know this isn't the only way to do it but it's the way I do it... hopefully it doesn't change too drastically in Windows 7.