From: Christian Herdtweck Date: Wed, 25 Jan 2017 08:39:48 +0000 (+0100) Subject: Run shorten_stl_types (and a bit more) only if needed in scope tracker X-Git-Tag: v2.9~5^2 X-Git-Url: http://developer.intra2net.com/git/?p=libi2ncommon;a=commitdiff_plain;h=fdd09ae03721cc7be78bff2b2a5873779cdffa73 Run shorten_stl_types (and a bit more) only if needed in scope tracker --- diff --git a/src/tracefunc.cpp b/src/tracefunc.cpp index 4e6282a..ff03b50 100644 --- a/src/tracefunc.cpp +++ b/src/tracefunc.cpp @@ -134,31 +134,46 @@ ScopeTracker::ScopeTracker( } ensure_indent_level(PerThread, Depth); PerThread->scope_tracker_list.push_back(this); - { - std::ostringstream ostr; - if (Location.FunctionName.empty()) - { - ostr << " (global scope?)"; - } - else - { - ostr << shorten_stl_types(Location.FunctionName); - if (FuncDepth>0) - { - ostr << "#" << FuncDepth+1; - } - } - Tag= ostr.str(); - } + // spit a message if (Logger::has_log_level(Logger::LogLevel::Debug)) { - GlobalLogger.debug() << PerThread->indents[Depth] << "ENTER " << Tag; + GlobalLogger.debug() << PerThread->indents[Depth] << "ENTER " << get_tag(); } } // eo ScopeTrcaker::ScopeTracker(const SourceLocation&) /** + * @brief create Tag if empty; return reference to it + * + * Moved this from constructor into own function to avoid creating Tag if it is + * not required (i.e. log level is not DEBUG) but still create it only once and + * ensure it is available if log level changes inside tracked function + */ +std::string& ScopeTracker::get_tag() +{ + if (Tag.empty()) + { + if (Location.FunctionName.empty()) + { + Tag = " (global scope?)"; + } + else + { + std::ostringstream ostr; + ostr << shorten_stl_types(Location.FunctionName); + if (FuncDepth>0) + { + ostr << "#" << FuncDepth+1; + } + Tag= ostr.str(); + } + } + return Tag; +} + + +/** * @brief destructor. emits a LEAVE message. * * @@ -168,7 +183,7 @@ ScopeTracker::~ScopeTracker() // spit a message if (Logger::has_log_level(Logger::LogLevel::Debug)) { - GlobalLogger.debug() << PerThread->indents[Depth] << "LEAVE " << Tag; + GlobalLogger.debug() << PerThread->indents[Depth] << "LEAVE " << get_tag(); } if (PerThread->scope_tracker_list.empty()) { diff --git a/src/tracefunc.hpp b/src/tracefunc.hpp index 7f5d0df..a575bfe 100644 --- a/src/tracefunc.hpp +++ b/src/tracefunc.hpp @@ -59,7 +59,8 @@ class ScopeTracker int Depth; int FuncDepth; - std::string Tag; + std::string Tag; // might be empty + std::string &get_tag(); // returns Tag, creates it first if necessary PerThreadContainer *PerThread; }; // eo ScopeTracker