From: Alexander Monakov Date: Mon, 13 May 2013 14:35:44 +0000 (+0100) Subject: common: Cleanup backtrace. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=825bb152a877152c8fd77fd5edc75b5c027023f0;p=apitrace common: Cleanup backtrace. There was a bool field that was caching results of 'is_backtrace_needed' lookups. Now that field is gone, and 'is_backtrace_needed' is called repeatedly. I guess it's not that bad (it boils down to a lookup in an std::set), but that function was also printing notices for functions with enabled stack trace recording, and now those messages are printed repeatedly as well. The following patch removes the notices completely and slightly cleans up the surrounding code. --- diff --git a/common/trace_backtrace.cpp b/common/trace_backtrace.cpp index d0bdd5a..730cfef 100644 --- a/common/trace_backtrace.cpp +++ b/common/trace_backtrace.cpp @@ -70,8 +70,7 @@ struct pstring { class StringPrefixes { private: std::set pset; - char* buf; -private: + void addPrefix(char* startbuf, int n) { std::set::iterator elem = pset.find(pstring(startbuf, n)); bool replace = elem != pset.end() && n < elem->n; @@ -86,11 +85,7 @@ public: StringPrefixes(const char* source); bool contain(const char* s) { - if (pset.find(pstring(s, strlen(s) + 1)) != pset.end()) { - os::log("Backtrace for %s is enabled", s); - return true; - } - return false; + return pset.find(pstring(s, strlen(s) + 1)) != pset.end(); } }; @@ -110,7 +105,7 @@ bool backtrace_is_needed(const char* fname) { namespace trace { StringPrefixes::StringPrefixes(const char* source) { - buf = (char*)malloc(sizeof(char) * PREFIX_BUF_SIZE); + char* buf = (char*)malloc(sizeof(char) * PREFIX_BUF_SIZE); char* startbuf = buf; int n = 0; FILE* f = fopen(source, "r"); @@ -303,7 +298,7 @@ namespace trace { StringPrefixes::StringPrefixes(const char* source) { - buf = (char*)malloc(sizeof(char) * PREFIX_BUF_SIZE); + char* buf = (char*)malloc(sizeof(char) * PREFIX_BUF_SIZE); char* startbuf = buf; int n = 0; char* s = getenv(source);