[PATCH v4] Backtrace via call detail

Alexander Monakov amonakov at ispras.ru
Mon May 13 05:34:49 PDT 2013



On Mon, 13 May 2013, José Fonseca wrote:

> No, it was not intentional. I removed by mistake, and somehow thought that
> it was only used in Android. I've re-added backtrace_is_needed() now.

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<pstring> pset;
-    char* buf;
-private:
+
     void addPrefix(char* startbuf, int n) {
         std::set<pstring>::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);


More information about the apitrace mailing list