Crouching tiger, coding monkey

We’re gonna need a bigger boat. (Or a practical example of Apple Shark usage.)

Filed under: Apple, Profiling, Shark — Grant April 27, 2007 @ 9:40 am

Every few years we rent a beach house on a island off of North Carolina and meet up with a bunch of friends from college. During the last trip a group was off body surfing and during one of the wave breaks they noticed something that ended the surfing and started the on shore Corona drinking.

Yep, it was a shark.

Apparently it was just a little guy, only a few feet long, but there is really no bigger incentive to get out the water than one of those. Thank you very much for that Steven Spielberg.

Jaws

“Where’s all this rambling going?” you’re probably asking yourself at this point. Well, its actually a crude play on words tie-in to an application that seriously helped out yesterday.

Apple Shark

I was sitting at my desk, innocently minding my own business, when one of the TestTrack guys came over and asked if I could run a test for him. Apparently some code they were working on was running ok on Windows, only taking a few seconds, but on the Mac it was chewing up like five minutes.

WhatchyoutalkinaboutWillis? That’s not good.

A quick sanity check run showed that indeed that section was running with all the speed of a Geo Metro in a strong headwind. Dejected, the TestTrack guy started to walk off to try to find out what the heck was going on.

Me: “Hey hold on, we’ll sic the Shark on it and find out what’s up.”

TestTrack Guy: “Greg Norman?”

The Shark

Me: “No, not Greg Norman. And if you say Jabber Jaw next we’re going to have to have words.”

Jabber Jaw

So I fire up TestTrack again but this time I attach to it using Apple’s Shark profiling application. We hit the slow spot, let it crank for a little bit, then stop our sampling. Shark then chews (ha!) over the results for a minute and spits out (get it, chew, then spit out, double ha!) the timing graph of our sample. Looking down the result list things don’t seem so bad:

Result list

We keep scrolling down and notice a percentage jump between a call from our code to the Qt code. A sizable percentage jump too, we’ve found our first clue.

Percentage jump

Following the highlighted items to the right (I’ve had to cut down the screenshot to fit in this post) we see that slowdown is happening in CTTLookup::GetText. This is a method that we use get text to be rendered on the screen, which means it is called about a bazillion times.

CTTLookup

Double clicking on the CTTLookup::GetText string Shark opens up the source file with some percentage listings of how much time was spent processing on each line. Using those, and noticing in our call stack that the Qt locale code was running all over the place in Apple’s system libraries we found our slow spot.

Slow spot

Some quick refactoring to make sure that locale call only happens once instead of every call, a new compile, and presto the Mac TestTrack client is now running just as fast as the other platforms. Total time from Shark start to fixed code was probably five minutes. And we didn’t even need a shark cage, or a caddy, to do it.

Grant.JinxedSelf() == true

Filed under: .Net, C# — Grant April 11, 2007 @ 10:05 am

Not even ten hours after I complimented ASP.Net it has already come back to haunt me.

This morning I was rolling out a new version of the old implementation of the FTL Drive Guidance Transmogrifier and try as I might IIS kept spitting out error after error. It turns out that the production server was running .Net 2.0 BETA instead of the released version like everywhere else.

“Not to worry,” I thought “everything else went so smoothly a simple upgrade will fix this all up.”

Stupid.

Stupid.

Stupid.

Installing the release version of .Net 2.0 required the uninstall of the beta which, naturally, doesn’t really uninstall everything. This meant manual registry cleanup, in particular the obviously named HKEY_CLASSES_ROOT\CLSID\{7D23CCC6-A390-406E-AB67-2F8B7558F6F6} key.

After all that was done I re-registered ASP.Net by hand and finally was up and running. *Sigh*

cylonnelson.png

.Net web service moving faster than light

Filed under: .Net, C#, Web service — Grant April 10, 2007 @ 11:31 pm

So yesterday I got an email from Matt the CIO saying that he needed me to swing by to see him. I didn’t really think that much about it except that I was SUPER glad that I had decided not to host a bunch of bootleg DVD torrents on my corporate computer.

I had taken a day of vacation so this morning I rolled down to his office to see what was going on.

Me (pointing at his desk): That looks like a router right there.

Matt: It’s a switch.

Me: I don’t think it’s going to do much sitting right there.

Matt: I’m still configuring it.

Me: You should just make it dumb hub, this switch business is just a fad.

Matt: We don’t let you configure much on the network do we?

Me: Notsomuch.

Matt: *Nods approvingly* So anyway, we need to update the FTL Drive Guidance Transmogrifier to run as a web service so we can use it from a few different places.

Me: Just running it as a DLL like we have it currently isn’t going to work?

Matt: No, we’ll want to centralize it, use this network we have to its potential.

Me: But putting something critical like the FTL Drive Guidance Transmogrifier on the network is suicide! Don’t you remember that’s how the Cylons penetrated the fleet’s defenses?

Matt: That was a TV show you realize?

Me: Frak you man! This is all crazy talk!

Matt: If that’s how you feel I can disconnect your ports from the internet, just so the fake shiny robots don’t infiltrate your computer.

Me: I’ll go ahead start making the code changes.

Now, the last time I wrote a web service it was in C++, and really basic C++ at that. So there was no fancy schmancy integrated toolkits just a heaping helping of pain in the arse.

But, since this was all on Windows and Microsoft has been pushing .Net web services as the greatest thing since DCOM, err I mean CORBA, I figured it should be snap. Plus I’d get to use C# so I could just new, new, new as much as I wanted. It would be the digital equivalent of eating french fries wrapped in bacon without having to worry about a massive cardiac incident.

It turns out it was that easy, just a new project, some incredibly straightforward glue code to tie the new service to the existing DLL and I was rolling. I haven’t got the client code written yet but the .Net debugger interface shows it all working like a champ. (What I wouldn’t have given for that for that C++ web service. I would have given up both the fries and the bacon without thinking about it.)

I’m sure somewhere in California a tear is running down the cheek of a certain black mock turtleneck wearing executive because of my .Net/C#/web service praise. At the same time I’m also sure that somewhere else there is an evil looking robot with a red eye pulsing in anticipation. Too bad that the side that is happy has loads of nuclear weapons. Frak.

cylon.png