Bug 901597, part 2 - Add environment var to CC log only main or worker threads. r=smaug
authorAndrew McCreight <continuation@gmail.com>
Wed, 19 Feb 2014 13:27:15 -0800
changeset 169956 b4fcc34583e47b51aa4ac38fb64ed6c5803ec3bf
parent 169955 efa4c77cfa5f5fdef61e3fffc1539601db2f4d53
child 169957 fc5ea4b0b1147ddf5e011dc920fee261be8aa39f
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerssmaug
bugs901597
milestone30.0a1
Bug 901597, part 2 - Add environment var to CC log only main or worker threads. r=smaug
xpcom/base/nsCycleCollector.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -198,16 +198,21 @@ using namespace mozilla;
 #define NORMAL_SHUTDOWN_COLLECTIONS 2
 
 // Cycle collector environment variables
 //
 // MOZ_CC_LOG_ALL: If defined, always log cycle collector heaps.
 //
 // MOZ_CC_LOG_SHUTDOWN: If defined, log cycle collector heaps at shutdown.
 //
+// MOZ_CC_LOG_THREAD: If set to "main", only automatically log main thread
+// CCs. If set to "worker", only automatically log worker CCs. If set to "all",
+// log either. The default value is "all". This must be used with either
+// MOZ_CC_LOG_ALL or MOZ_CC_LOG_SHUTDOWN for it to do anything.
+//
 // MOZ_CC_ALL_TRACES_AT_SHUTDOWN: If defined, any cycle collector
 // logging done at shutdown will be WantAllTraces, which disables
 // various cycle collector optimizations to give a fuller picture of
 // the heap.
 //
 // MOZ_CC_RUN_DURING_SHUTDOWN: In non-DEBUG or builds, if this is set,
 // run cycle collections at shutdown.
 //
@@ -225,27 +230,37 @@ CC_AbortIfNull(void *ptr)
 // Various parameters of this collector can be tuned using environment
 // variables.
 
 struct nsCycleCollectorParams
 {
     bool mLogAll;
     bool mLogShutdown;
     bool mAllTracesAtShutdown;
+    bool mLogThisThread;
 
     nsCycleCollectorParams() :
         mLogAll      (PR_GetEnv("MOZ_CC_LOG_ALL") != nullptr),
         mLogShutdown (PR_GetEnv("MOZ_CC_LOG_SHUTDOWN") != nullptr),
-        mAllTracesAtShutdown (PR_GetEnv("MOZ_CC_ALL_TRACES_AT_SHUTDOWN") != nullptr)
+        mAllTracesAtShutdown (PR_GetEnv("MOZ_CC_ALL_TRACES_AT_SHUTDOWN") != nullptr),
+        mLogThisThread(true)
     {
+        const char* logThreadEnv = PR_GetEnv("MOZ_CC_LOG_THREAD");
+        if (logThreadEnv && !!strcmp(logThreadEnv, "all")) {
+            if (NS_IsMainThread()) {
+                mLogThisThread = !strcmp(logThreadEnv, "main");
+            } else {
+                mLogThisThread = !strcmp(logThreadEnv, "worker");
+            }
+        }
     }
 
     bool LogThisCC(bool aIsShutdown)
     {
-        return mLogAll || (aIsShutdown && mLogShutdown);
+        return (mLogAll || (aIsShutdown && mLogShutdown)) && mLogThisThread;
     }
 };
 
 #ifdef COLLECT_TIME_DEBUG
 class TimeLog
 {
 public:
     TimeLog() : mLastCheckpoint(TimeStamp::Now()) {}