Commit 25299018 authored by Andrew McCreight's avatar Andrew McCreight
Browse files

Bug 1831006 - Add a way to enable refcount logging whenever. r=xpcom-reviewers,nika

parent 41613af3
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -1176,6 +1176,36 @@ void nsTraceRefcnt::SetActivityIsLegal(bool aLegal) {
  PR_SetThreadPrivate(gActivityTLS, reinterpret_cast<void*>(!aLegal));
}

void nsTraceRefcnt::StartLoggingClass(const char* aClass) {
  gLogging = FullLogging;

  if (!gTypesToLog) {
    gTypesToLog = new CharPtrSet(256);
  }

  fprintf(stdout, "### StartLoggingClass %s\n", aClass);
  if (!gTypesToLog->Contains(aClass)) {
    gTypesToLog->PutEntry(aClass);
  }

  // We are deliberately not initializing gSerialNumbers here, because
  // it would cause assertions. gObjectsToLog can't be used because it
  // relies on serial numbers.

#ifdef XP_WIN
#  define ENVVAR(x) u"" x
#else
#  define ENVVAR(x) x
#endif

  if (!gRefcntsLog) {
    InitLog(ENVVAR("XPCOM_MEM_LATE_REFCNT_LOG"), "refcounts", &gRefcntsLog,
            XRE_GetProcessTypeString());
  }

#undef ENVVAR
}

#ifdef MOZ_ENABLE_FORKSERVER
void nsTraceRefcnt::ResetLogFiles(const char* aProcType) {
  AutoRestore<LoggingType> saveLogging(gLogging);
+7 −0
Original line number Diff line number Diff line
@@ -23,6 +23,13 @@ class nsTraceRefcnt {
   */
  static void SetActivityIsLegal(bool aLegal);

  /**
   * Start refcount logging aClass. If refcount logging has not already begun,
   * it will use the environment variable XPCOM_MEM_LATE_REFCNT_LOG to decide
   * where to make the log, in a similar way as the other nsTraceRefcnt logs.
   */
  static void StartLoggingClass(const char* aClass);

#ifdef MOZ_ENABLE_FORKSERVER
  static void ResetLogFiles(const char* aProcType = nullptr);
#endif