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

Differential Revision: https://phabricator.services.mozilla.com/D176971
This commit is contained in:
Andrew McCreight 2023-05-03 13:59:55 +00:00
parent 41613af3eb
commit 2529901815
2 changed files with 37 additions and 0 deletions

View File

@ -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);

View File

@ -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