From 7d65559dd1a236e86614a8ba6600aa5d2c793e5b Mon Sep 17 00:00:00 2001 From: Ting-Yu Chou Date: Tue, 20 Sep 2016 14:10:43 +0800 Subject: [PATCH] Bug 1301022 - Add an API for annotating pending IPC messages. r=ted MozReview-Commit-ID: GiAMUnjYjvI --HG-- extra : rebase_source : a40f81a4878205b5edb71ca8ec2f24dc35c677eb --- ipc/glue/MessageChannel.h | 7 +- toolkit/crashreporter/nsExceptionHandler.cpp | 72 ++++++++++++++++++++ toolkit/crashreporter/nsExceptionHandler.h | 7 +- 3 files changed, 78 insertions(+), 8 deletions(-) diff --git a/ipc/glue/MessageChannel.h b/ipc/glue/MessageChannel.h index 73e593f66238..b7ec18cfc265 100644 --- a/ipc/glue/MessageChannel.h +++ b/ipc/glue/MessageChannel.h @@ -507,12 +507,7 @@ class MessageChannel : HasResultCodes topCount = curCount; } - CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("NumberOfPendingIPC"), - nsPrintfCString("%zu", q.size())); - CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("TopPendingIPCCount"), - nsPrintfCString("%u", topCount)); - CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("TopPendingIPCName"), - nsPrintfCString("%s(0x%x)", topName, topType)); + CrashReporter::AnnotatePendingIPC(q.size(), topCount, topName, topType); mozalloc_handle_oom(n * sizeof(T)); } diff --git a/toolkit/crashreporter/nsExceptionHandler.cpp b/toolkit/crashreporter/nsExceptionHandler.cpp index 2e0f4d0bbb79..c34dea284725 100644 --- a/toolkit/crashreporter/nsExceptionHandler.cpp +++ b/toolkit/crashreporter/nsExceptionHandler.cpp @@ -579,6 +579,22 @@ void AnnotateTexturesSize(size_t size) gTexturesSize = size; } +static size_t gNumOfPendingIPC = 0; +static uint32_t gTopPendingIPCCount = 0; +static const char* gTopPendingIPCName = nullptr; +static uint32_t gTopPendingIPCType = 0; + +void AnnotatePendingIPC(size_t aNumOfPendingIPC, + uint32_t aTopPendingIPCCount, + const char* aTopPendingIPCName, + uint32_t aTopPendingIPCType) +{ + gNumOfPendingIPC = aNumOfPendingIPC; + gTopPendingIPCCount = aTopPendingIPCCount; + gTopPendingIPCName = aTopPendingIPCName; + gTopPendingIPCType = aTopPendingIPCType; +} + #ifndef XP_WIN // Like Windows CopyFile for *nix bool copy_file(const char* from, const char* to) @@ -880,6 +896,19 @@ bool MinidumpCallback( XP_STOA(gTexturesSize, texturesSizeBuffer, 10); } + char numOfPendingIPCBuffer[32] = ""; + char topPendingIPCCountBuffer[32] = ""; + char topPendingIPCTypeBuffer[11] = "0x"; + if (gNumOfPendingIPC) { + XP_STOA(gNumOfPendingIPC, numOfPendingIPCBuffer, 10); + if (gTopPendingIPCCount) { + XP_STOA(gTopPendingIPCCount, topPendingIPCCountBuffer, 10); + } + if (gTopPendingIPCType) { + XP_STOA(gTopPendingIPCType, &topPendingIPCTypeBuffer[2], 16); + } + } + // calculate time since last crash (if possible), and store // the time of this crash. time_t crashTime; @@ -1028,6 +1057,23 @@ bool MinidumpCallback( WriteAnnotation(eventFile, "TextureUsage", texturesSizeBuffer); } + if (numOfPendingIPCBuffer[0]) { + WriteAnnotation(apiData, "NumberOfPendingIPC", numOfPendingIPCBuffer); + WriteAnnotation(eventFile, "NumberOfPendingIPC", numOfPendingIPCBuffer); + if (topPendingIPCCountBuffer[0]) { + WriteAnnotation(apiData, "TopPendingIPCCount", topPendingIPCCountBuffer); + WriteAnnotation(eventFile, "TopPendingIPCCount", topPendingIPCCountBuffer); + } + if (gTopPendingIPCName) { + WriteAnnotation(apiData, "TopPendingIPCName", gTopPendingIPCName); + WriteAnnotation(eventFile, "TopPendingIPCName", gTopPendingIPCName); + } + if (topPendingIPCTypeBuffer[2]) { + WriteAnnotation(apiData, "TopPendingIPCType", topPendingIPCTypeBuffer); + WriteAnnotation(eventFile, "TopPendingIPCType", topPendingIPCTypeBuffer); + } + } + if (memoryReportPath) { WriteLiteral(apiData, "ContainsMemoryReport=1\n"); WriteLiteral(eventFile, "ContainsMemoryReport=1\n"); @@ -1314,6 +1360,32 @@ PrepareChildExceptionTimeAnnotations() if (gMozCrashReason) { WriteAnnotation(apiData, "MozCrashReason", gMozCrashReason); } + + char numOfPendingIPCBuffer[32] = ""; + char topPendingIPCCountBuffer[32] = ""; + char topPendingIPCTypeBuffer[11] = "0x"; + if (gNumOfPendingIPC) { + XP_STOA(gNumOfPendingIPC, numOfPendingIPCBuffer, 10); + if (gTopPendingIPCCount) { + XP_STOA(gTopPendingIPCCount, topPendingIPCCountBuffer, 10); + } + if (gTopPendingIPCType) { + XP_STOA(gTopPendingIPCType, &topPendingIPCTypeBuffer[2], 16); + } + } + + if (numOfPendingIPCBuffer[0]) { + WriteAnnotation(apiData, "NumberOfPendingIPC", numOfPendingIPCBuffer); + if (topPendingIPCCountBuffer[0]) { + WriteAnnotation(apiData, "TopPendingIPCCount", topPendingIPCCountBuffer); + } + if (gTopPendingIPCName) { + WriteAnnotation(apiData, "TopPendingIPCName", gTopPendingIPCName); + } + if (topPendingIPCTypeBuffer[2]) { + WriteAnnotation(apiData, "TopPendingIPCType", topPendingIPCTypeBuffer); + } + } } #ifdef XP_WIN diff --git a/toolkit/crashreporter/nsExceptionHandler.h b/toolkit/crashreporter/nsExceptionHandler.h index a088fdde047f..2c37266bbfc2 100644 --- a/toolkit/crashreporter/nsExceptionHandler.h +++ b/toolkit/crashreporter/nsExceptionHandler.h @@ -77,11 +77,14 @@ nsresult AppendAppNotesToCrashReport(const nsACString& data); // as it is intended to be defining this same function. void AnnotateMozCrashReason(const char* aReason); void AnnotateOOMAllocationSize(size_t size); +void AnnotateTexturesSize(size_t size); +void AnnotatePendingIPC(size_t aNumOfPendingIPC, + uint32_t aTopPendingIPCCount, + const char* aTopPendingIPCName, + uint32_t aTopPendingIPCType); nsresult SetGarbageCollecting(bool collecting); void SetEventloopNestingLevel(uint32_t level); -void AnnotateTexturesSize(size_t size); - nsresult SetRestartArgs(int argc, char** argv); nsresult SetupExtraData(nsIFile* aAppDataDirectory, const nsACString& aBuildID);