michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #ifdef XP_WIN michael@0: #include michael@0: #define getpid _getpid michael@0: #else michael@0: #include michael@0: #endif michael@0: michael@0: #ifndef mozilla_IntentionalCrash_h michael@0: #define mozilla_IntentionalCrash_h michael@0: michael@0: namespace mozilla { michael@0: michael@0: inline void michael@0: NoteIntentionalCrash(const char* processType) michael@0: { michael@0: char* f = getenv("XPCOM_MEM_BLOAT_LOG"); michael@0: michael@0: if (!f) michael@0: return; michael@0: michael@0: fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f); michael@0: michael@0: std::string bloatLog(f); michael@0: michael@0: bool hasExt = false; michael@0: if (bloatLog.size() >= 4 && michael@0: 0 == bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4)) { michael@0: hasExt = true; michael@0: bloatLog.erase(bloatLog.size() - 4, 4); michael@0: } michael@0: michael@0: std::ostringstream bloatName; michael@0: bloatName << bloatLog << "_" << processType << "_pid" << getpid(); michael@0: if (hasExt) michael@0: bloatName << ".log"; michael@0: michael@0: fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str()); michael@0: michael@0: FILE* processfd = fopen(bloatName.str().c_str(), "a"); michael@0: fprintf(processfd, "==> process %d will purposefully crash\n", getpid()); michael@0: fclose(processfd); michael@0: } michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_IntentionalCrash_h