2 * @brief implementation of tracing functionality.
4 * @copyright © Copyright 2008 by Intra2net AG
9 * @note This module is not thread safe!
10 * @todo make this module thread safe (only useful when we can use threads...)
13 #include "tracefunc.hpp"
25 using Logger::GlobalLogger;
31 typedef std::list< ScopeTracker* > ScopeTrackerList;
33 ScopeTrackerList scope_tracker_list;
36 std::vector< std::string > indents;
40 * @brief ensures indent level string to exist up to the desired level.
41 * @param level the desired indent level.
43 void ensure_indent_level(int level)
45 while (indents.size() <= level)
47 indents.push_back( indents.back() + " " );
49 } // eo ensure_indent_level(int)
53 * @brief module initializer.
60 // pre initialize indent strings:
63 indents.push_back("");
66 indents.push_back( indents.back() + " " );
72 } // eo namespace <anonymous>
76 ** implementation of ScopeTracker
80 * @brief constructor. initializes object with a source location and emits a ENTER message.
81 * @param loc the source location.
83 * the message is indented according to the current depth of nested ScopeTracker instances.
85 ScopeTracker::ScopeTracker(
86 const SourceLocation& loc)
91 if (!scope_tracker_list.empty())
93 ScopeTracker* last_tracker= scope_tracker_list.back();
96 if (last_tracker->Location
97 && last_tracker->Location.File == Location.File
98 && last_tracker->Location.FunctionName == Location.FunctionName)
100 FuncDepth= last_tracker->FuncDepth+1;
103 Depth= last_tracker->Depth + 1;
105 ensure_indent_level(Depth);
106 scope_tracker_list.push_back(this);
108 std::ostringstream ostr;
109 if (Location.FunctionName.empty())
111 ostr << "<unknown> (global scope?)";
115 ostr << Location.FunctionName;
118 ostr << "#" << FuncDepth+1;
124 if (Logger::has_log_level(Logger::LogLevel::Debug))
126 GlobalLogger.debug() << indents[Depth] << "ENTER " << Tag;
128 } // eo ScopeTrcaker::ScopeTracker(const SourceLocation&)
132 * @brief destructor. emits a LEAVE message.
136 ScopeTracker::~ScopeTracker()
139 if (Logger::has_log_level(Logger::LogLevel::Debug))
141 GlobalLogger.debug() << indents[Depth] << "LEAVE " << Tag;
143 if (scope_tracker_list.empty())
147 if (scope_tracker_list.back() == this)
149 scope_tracker_list.pop_back();
153 // oh hell, this should never be the case!
155 GlobalLogger.error() << "inconsistency detected in scope tracker";
157 } // eo ScopeTracker::~ScopeTracker()
162 } // eo namespace Tracer
163 } // eo namespace I2n