Bug 823226 - Add environment variables for controlling cycle collector logging. r=smaug
authorAndrew McCreight <amccreight@mozilla.com>
Wed, 19 Dec 2012 14:35:50 -0800
changeset 117051 d29b182e169ee1245729e2a45817e09b424df9de
parent 117050 6b81175079c5a32245b9b3000ec9931c3b4eac2b
child 117052 7457db98e2e3049a0e04c57d1e4580ee5b75a1d4
child 117054 47a6822f5e3f28436eabf6b1b065959234e02d90
push id24080
push usergkwong@mozilla.com
push dateWed, 26 Dec 2012 22:45:06 +0000
treeherdermozilla-central@d29b182e169e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs823226
milestone20.0a1
first release with
nightly linux32
d29b182e169e / 20.0a1 / 20121227030822 / files
nightly linux64
d29b182e169e / 20.0a1 / 20121227030822 / files
nightly mac
d29b182e169e / 20.0a1 / 20121227030822 / files
nightly win32
d29b182e169e / 20.0a1 / 20121227030822 / files
nightly win64
d29b182e169e / 20.0a1 / 20121227030822 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 823226 - Add environment variables for controlling cycle collector logging. r=smaug
xpcom/base/nsCycleCollector.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -162,57 +162,63 @@ using namespace mozilla;
 extern DWORD gTLSThreadIDIndex;
 #elif defined(NS_TLS)
 // Defined in nsThreadManager.cpp.
 extern NS_TLS mozilla::threads::ID gTLSThreadID;
 #else
 PRThread* gCycleCollectorThread = nullptr;
 #endif
 
-// If true, always log cycle collector graphs.
-const bool gAlwaysLogCCGraphs = false;
-
-// If true, log the cycle collector graphs during shutdown.
-const bool gLogShutdown = false;
-
-// If true, any logging done at shutdown will be AllTraces.
-const bool gAllTracesAtShutdown = false;
+// Cycle collector environment variables
+//
+// XPCOM_CC_LOG_ALL: If defined, always log cycle collector heaps.
+//
+// XPCOM_CC_LOG_SHUTDOWN: If defined, log cycle collector heaps at shutdown.
+//
+// XPCOM_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.
+//
+// XPCOM_CC_RUN_DURING_SHUTDOWN: In non-DEBUG or non-DEBUG_CC builds,
+// if this is set, run cycle collections at shutdown.
 
 MOZ_NEVER_INLINE void
 CC_AbortIfNull(void *ptr)
 {
     if (!ptr)
         MOZ_CRASH();
 }
 
 // Various parameters of this collector can be tuned using environment
 // variables.
 
 struct nsCycleCollectorParams
 {
+    bool mLogAll;
+    bool mLogShutdown;
+    bool mAllTracesAtShutdown;
     bool mDoNothing;
-    bool mLogGraphs;
 #ifdef DEBUG_CC
     bool mReportStats;
     bool mLogPointers;
     uint32_t mShutdownCollections;
 #endif
     
     nsCycleCollectorParams() :
+        mLogAll      (PR_GetEnv("XPCOM_CC_LOG_ALL") != NULL),
+        mLogShutdown (PR_GetEnv("XPCOM_CC_LOG_SHUTDOWN") != NULL),
+        mAllTracesAtShutdown (PR_GetEnv("XPCOM_CC_ALL_TRACES_AT_SHUTDOWN") != NULL),
 #ifdef DEBUG_CC
-        mDoNothing     (PR_GetEnv("XPCOM_CC_DO_NOTHING") != NULL),
-        mLogGraphs     (gAlwaysLogCCGraphs ||
-                        PR_GetEnv("XPCOM_CC_DRAW_GRAPHS") != NULL),
-        mReportStats   (PR_GetEnv("XPCOM_CC_REPORT_STATS") != NULL),
-        mLogPointers   (PR_GetEnv("XPCOM_CC_LOG_POINTERS") != NULL),
-
+        mDoNothing   (PR_GetEnv("XPCOM_CC_DO_NOTHING") != NULL),
+        mReportStats (PR_GetEnv("XPCOM_CC_REPORT_STATS") != NULL),
+        mLogPointers (PR_GetEnv("XPCOM_CC_LOG_POINTERS") != NULL),
         mShutdownCollections(DEFAULT_SHUTDOWN_COLLECTIONS)
 #else
-        mDoNothing     (false),
-        mLogGraphs     (gAlwaysLogCCGraphs)
+        mDoNothing   (false)
 #endif
     {
 #ifdef DEBUG_CC
         char *s = PR_GetEnv("XPCOM_CC_SHUTDOWN_COLLECTIONS");
         if (s)
             PR_sscanf(s, "%d", &mShutdownCollections);
 #endif
     }
@@ -2969,19 +2975,19 @@ nsCycleCollector::Shutdown()
 {
 #ifndef DEBUG
 #ifndef DEBUG_CC
     if (PR_GetEnv("XPCOM_CC_RUN_DURING_SHUTDOWN"))
 #endif
 #endif
     {
         nsCOMPtr<nsCycleCollectorLogger> listener;
-        if (mParams.mLogGraphs || gLogShutdown) {
+        if (mParams.mLogAll || mParams.mLogShutdown) {
             listener = new nsCycleCollectorLogger();
-            if (gAllTracesAtShutdown) {
+            if (mParams.mAllTracesAtShutdown) {
                 listener->SetAllTraces();
             }
         }
         Collect(false, nullptr,  SHUTDOWN_COLLECTIONS(mParams), listener);
     }
 
 #ifdef DEBUG_CC
     GCGraphBuilder builder(mGraph, mJSRuntime, nullptr, false);
@@ -3374,17 +3380,17 @@ nsCycleCollector_forgetSkippable(bool aR
 void
 nsCycleCollector_collect(bool aMergeCompartments,
                          nsCycleCollectorResults *aResults,
                          nsICycleCollectorListener *aListener)
 {
     MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
     SAMPLE_LABEL("CC", "nsCycleCollector_collect");
     nsCOMPtr<nsICycleCollectorListener> listener(aListener);
-    if (!aListener && sCollector && sCollector->mParams.mLogGraphs) {
+    if (!aListener && sCollector && sCollector->mParams.mLogAll) {
         listener = new nsCycleCollectorLogger();
     }
 
     if (sCollectorRunner) {
         sCollectorRunner->Collect(aMergeCompartments, aResults, listener);
     } else if (sCollector) {
         sCollector->Collect(aMergeCompartments, aResults, 1, listener);
     }