[Development] QLog ( Work on qDebug and friends)

Lincoln Ramsay lincoln.ramsay at nokia.com
Thu Feb 16 05:00:03 CET 2012


On 02/16/2012 02:14 AM, ext BRM wrote:
>> This fails the "do nothing quickly" test so the cost of leaving
>> such statements in shipping code is high, even when the categories
>> are disabled.
>>
>> This works fine though.
>>
>> qLog(category1)<< "message for category1";
>> qLog(category2)<< "message for category2";
>
> No more than the Macro.
>
> Yes, it would need to read all the strings; but then it could just
> read them instead. The macro fails in the same respect.

I don't think I get where you're going here.

qLog expands to:

if (do_nothing) /*NOP*/; else qDebug() << "your message";

Why? Because the category check must be done first and it must be done 
quickly. That means things like no string operations in the "common" 
case (where we already know that the category is disabled). Sure, if you 
don't know if the category should be disabled you're going to have to do 
some calculations but that's the exception, not the norm.

Filtering out either at the QDebug object level or the message handler 
level means that all of the code after the << _must_ be executed even if 
the resulting strings are going to be dropped on the floor. This could 
be hundreds of instructions which may not be noticeable on a desktop but 
will cripple any slower device.

So...

This code can quickly do nothing:
qLog(category1) << "message for category1";
qLog(category2) << "message for category2";

This code cannot:
qDebug() << category1 << "message for category1"
          << category2 << "message for category2";

Is the second syntax really that much better to justify the large 
performance hit? I just don't see it.

-- 
Lincoln Ramsay - Senior Software Engineer
Qt Development Frameworks, Nokia - http://qt.nokia.com/



More information about the Development mailing list