Bug 1301022 - Add an API for annotating pending IPC messages. r?ted draft
authorTing-Yu Chou <janus926@gmail.com>
Tue, 20 Sep 2016 14:10:43 +0800
changeset 419974 c3cf6fe5e1ba243f29bb0d976ac395439c6f0886
parent 415258 c9971be9e98150ef99d4ef80c6f800ec5915b1ac
child 532689 06d5e805252bfebd3a5e1e29ec9cdf642d4fa0b7
push id31058
push userbmo:janus926@gmail.com
push dateMon, 03 Oct 2016 02:45:49 +0000
reviewersted
bugs1301022
milestone52.0a1
Bug 1301022 - Add an API for annotating pending IPC messages. r?ted MozReview-Commit-ID: GiAMUnjYjvI
ipc/glue/MessageChannel.h
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/crashreporter/nsExceptionHandler.h
--- a/ipc/glue/MessageChannel.h
+++ b/ipc/glue/MessageChannel.h
@@ -502,22 +502,17 @@ class MessageChannel : HasResultCodes
           }
           // In case the last type is the top one.
           if (curCount > topCount) {
             topName = curName;
             topType = curType;
             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));
         }
         return static_cast<T*>(p);
       }
       void deallocate(T* p, size_t n) {
         ::operator delete(p);
       }
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -567,16 +567,32 @@ void AnnotateOOMAllocationSize(size_t si
 
 static size_t gTexturesSize = 0;
 
 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)
 {
   const int kBufSize = 4096;
   int fdfrom = sys_open(from, O_RDONLY, 0);
   if (fdfrom < 0) {
     return false;
@@ -868,16 +884,29 @@ bool MinidumpCallback(
     XP_STOA(gOOMAllocationSize, oomAllocationSizeBuffer, 10);
   }
 
   char texturesSizeBuffer[32] = "";
   if (gTexturesSize) {
     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;
 #ifdef XP_LINUX
   struct kernel_timeval tv;
   sys_gettimeofday(&tv, nullptr);
   crashTime = tv.tv_sec;
 #else
@@ -1016,16 +1045,33 @@ bool MinidumpCallback(
       WriteAnnotation(eventFile, "OOMAllocationSize", oomAllocationSizeBuffer);
     }
 
     if (texturesSizeBuffer[0]) {
       WriteAnnotation(apiData, "TextureUsage", texturesSizeBuffer);
       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");
     }
   }
 
 #ifdef XP_WIN
   if (!doReport) {
@@ -1297,16 +1343,42 @@ PrepareChildExceptionTimeAnnotations()
 
   if (oomAllocationSizeBuffer[0]) {
     WriteAnnotation(apiData, "OOMAllocationSize", oomAllocationSizeBuffer);
   }
 
   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
 static void
 ReserveBreakpadVM()
 {
   if (!gBreakpadReservedVM) {
     gBreakpadReservedVM = VirtualAlloc(nullptr, kReserveSize, MEM_RESERVE,
--- a/toolkit/crashreporter/nsExceptionHandler.h
+++ b/toolkit/crashreporter/nsExceptionHandler.h
@@ -72,21 +72,24 @@ nsresult SetMinidumpPath(const nsAString
 nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data);
 nsresult RemoveCrashReportAnnotation(const nsACString& key);
 nsresult AppendAppNotesToCrashReport(const nsACString& data);
 
 // NOTE: If you change this definition, also change the definition in Assertions.h
 // 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);
 bool GetLastRunCrashID(nsAString& id);
 
 // Registers an additional memory region to be included in the minidump
 nsresult RegisterAppMemory(void* ptr, size_t length);
 nsresult UnregisterAppMemory(void* ptr);