Our Initial Trace Implementation

Our intent was to have the trace object log event messages such as entering a function, leaving a function, and possibly other information of interest between those two events.

int myFunction(int x)
    string name = "myFunction";
    Trace t(name);
    string moreInfo = "more interesting info";
};  // Trace destructor logs exit event to an output stream

To enable this usage we started out with the following Trace implementation:

class Trace {
    Trace (const string &name);
    ~Trace ();
    void debug (const string &msg);

    static bool traceIsActive;
    string theFunctionName;

The Trace constructor stores the function's name.

 inline Trace::Trace(const string &name) : theFunctionName(name) ...

Get Efficient C++ Performance Programming Techniques now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.