Tuesday 14 May 2013

Ever a duh! moment

So, after coming up with a great design I rode off into the sunset.

Of course, after the sunset there's always a sunrise. This particular sunrise caught me merrily peppering logging statements all over my SSH code, basking in the warm light of my brilliant design. Or maybe it was the warm light of the sunrise, I tend to get confused about which is which. And, suddenly (isn't that always the case?), something went click, like a brain cell waking up.

I'm using POCO Logger's poco_* macros. Convenient little buggers, actually. Here, take a look at one of them:

#define poco_debug(logger, msg) \
    if ((logger).debug()) (logger).debug(msg, __FILE__, __LINE__); \
    else (void) 0

Note the __FILE__ and __LINE__. Cool, heh? And now, note how my brilliant design cunningly takes advantage of it:

2013-05-14 13:26:18.228 [Debug] ... [../Logger/logger.h:46] LibClassSupport ctor ID: 11
2013-05-14 13:26:18.250 [Debug] ... [../Logger/logger.h:46] LibClassUtility1 ctor ID: 1
2013-05-14 13:26:18.283 [Debug] ... [../Logger/logger.h:46] LibClassSupport ctor ID: 21
2013-05-14 13:26:18.306 [Debug] ... [../Logger/logger.h:46] LibClassUtility2 ctor ID: 1
2013-05-14 13:26:18.412 [Debug] ... [../Logger/logger.h:46] LibClassMain ctor ID: 1
2013-05-14 13:26:18.474 [Debug] ... [../Logger/logger.h:46] LibClassSupport ctor ID: 12
2013-05-14 13:26:18.508 [Debug] ... [../Logger/logger.h:46] LibClassUtility1 ctor ID: 2
2013-05-14 13:26:18.541 [Debug] ... [../Logger/logger.h:46] LibClassSupport ctor ID: 22
2013-05-14 13:26:18.574 [Debug] ... [../Logger/logger.h:46] LibClassUtility2 ctor ID: 2
2013-05-14 13:26:18.608 [Debug] ... [../Logger/logger.h:46] LibClassMain ctor ID: 2


Yep, looking from this log excerpt, one would get the impression my code spends an awful lot of time in line 46 of logger.h (a definite performance bottleneck, if I ever saw one). One would be forgiven for such an impression, even though one would be wrong; in case you're wondering, this last one would be me.

Ah, well, back to the old drawing board. Still, if it wasn't for mistakes, how would I learn, right?

Hey, if it happens to Wile E. Coyote, super-genius, why wouldn't it happen to me?

No comments:

Post a Comment