Boost logo

Boost :

From: Alan Stokes (A.Stokes_at_[hidden])
Date: 2002-04-10 04:00:56


We have something very similar. However, we've defined the ShouldTrace
function as in inline function that first checks a global boolean flag that
indicates whether any tracing is turned on at all; if it is then it calls a
second non-inline function that decides whether tracing should be turned on
for the supplied Topic and Level.

The result is that in a normal production system when all tracing is off,
the performance impact is a single read and test of a static variable, which
is pretty minimal. We've never had any performance problems as a result (we
keep tracing out of inner loops, just to be safe). And we can still
dynamically turn tracing on whenever we need to - which is incredibly
useful.

(This assumes that the read of the bool is atomic; it is on the platforms we
currently use.)

Regards,

Alan

> From: "Wyss, Felix" <FelixW_at_[hidden]>
>
> In our tracing library, we use the following approach:
>
> #define TRACE(Topic, Level) \
> if(!ShouldTrace((Topic), (Level))) { } else
> TraceMessage((Topic), __FILE__, __LINE__).Stream()
>
> This macro is then used as follows:
>
> TRACE(MyTopic, LEVEL_STATUS) << "SessionID=" << SessionID <<
> ", State=" << State << ...;
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk