Bug 1259428 - part 1 - don't call Log methods of generated method classes; r=jld
authorNathan Froyd <froydnj.com>
Fri, 25 Mar 2016 17:02:38 -0400
changeset 291444 234de0ccd39ba2cf18cf9da6e55a0ccb6033fa58
parent 291443 690bbfa6023c01347647b139ebdd2a00272477c4
child 291445 1349ec62f2411520c6c1120d00f6ea7e957f7ad1
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjld
bugs1259428
milestone48.0a1
Bug 1259428 - part 1 - don't call Log methods of generated method classes; r=jld The first step to eliminating all the generated Message subclasses the IPDL compiler spits out is to move the functionality of their Log methods someplace else. In addition to eliminating the need for the Log methods, this change has the welcome effect of moving a bunch of code that would be generated hundreds of times into a single place, which should reduce code size a bit (debug builds only). We don't actually remove the generation of the Log methods; that change will be done for a future patch.
ipc/glue/ProtocolUtils.cpp
ipc/glue/ProtocolUtils.h
ipc/ipdl/ipdl/lower.py
--- a/ipc/glue/ProtocolUtils.cpp
+++ b/ipc/glue/ProtocolUtils.cpp
@@ -311,16 +311,34 @@ void AnnotateSystemError()
   if (error) {
     CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("SystemError"),
                                        nsPrintfCString("%lld", error));
   }
 }
 #endif
 
 void
+LogMessageForProtocol(const char* aTopLevelProtocol, base::ProcessId aOtherPid,
+                      const char* aContextDescription,
+                      const char* aMessageDescription,
+                      MessageDirection aDirection)
+{
+  nsPrintfCString logMessage("[time: %" PRId64 "][%d%s%d] [%s] %s %s\n",
+                             PR_Now(), base::GetCurrentProcId(),
+                             aDirection == MessageDirection::eReceiving ? "<-" : "->",
+                             aOtherPid, aTopLevelProtocol,
+                             aContextDescription,
+                             aMessageDescription);
+#ifdef ANDROID
+  __android_log_write(ANDROID_LOG_INFO, "GeckoIPC", logMessage.get());
+#endif
+  fputs(logMessage.get(), stderr);
+}
+
+void
 ProtocolErrorBreakpoint(const char* aMsg)
 {
     // Bugs that generate these error messages can be tough to
     // reproduce.  Log always in the hope that someone finds the error
     // message.
     printf_stderr("IPDL protocol error: %s\n", aMsg);
 }
 
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -291,16 +291,27 @@ LoggingEnabledFor(const char *aTopLevelP
         return false;
     }
     return strcmp(filter, "1") == 0 || strcmp(filter, aTopLevelProtocol) == 0;
 #else
     return false;
 #endif
 }
 
+enum class MessageDirection {
+    eSending,
+    eReceiving,
+};
+
+MOZ_NEVER_INLINE void
+LogMessageForProtocol(const char* aTopLevelProtocol, base::ProcessId aOtherPid,
+                      const char* aContextDescription,
+                      const char* aMessageDescription,
+                      MessageDirection aDirection);
+
 MOZ_NEVER_INLINE void
 ProtocolErrorBreakpoint(const char* aMsg);
 
 MOZ_NEVER_INLINE void
 FatalError(const char* aProtocolName, const char* aMsg,
            base::ProcessId aOtherPid, bool aIsParent);
 
 struct PrivateIPDLInterface {};
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -5375,22 +5375,26 @@ class _GenerateProtocolActorCode(ipdl.as
             ret=Type.BOOL)
         if md.decl.type.isCtor():
             decl.ret = md.actorDecl().bareType(self.side)
         return decl
 
     def logMessage(self, md, msgptr, pfx, actor=None, receiving=False):
         actorname = _actorName(self.protocol.name, self.side)
 
-        topLevel = self.protocol.decl.type.toplevel().name()
-        return _ifLogging(ExprLiteral.String(topLevel), [ StmtExpr(ExprCall(
-            ExprSelect(msgptr, '->', 'Log'),
-            args=[ ExprLiteral.String('['+ actorname +'] '+ pfx),
-                   self.protocol.callOtherPid(actor),
-                   ExprLiteral.TRUE if receiving else ExprLiteral.FALSE ])) ])
+        return _ifLogging(ExprLiteral.String(actorname),
+                          [ StmtExpr(ExprCall(
+                              ExprVar('mozilla::ipc::LogMessageForProtocol'),
+                              args=[ ExprLiteral.String(actorname),
+                                     self.protocol.callOtherPid(actor),
+                                     ExprLiteral.String(pfx),
+                                     ExprCall(ExprSelect(msgptr, '->', 'name')),
+                                     ExprVar('mozilla::ipc::MessageDirection::eReceiving'
+                                             if receiving
+                                             else 'mozilla::ipc::MessageDirection::eSending') ])) ])
 
     def profilerLabel(self, tag, msgname):
         return StmtExpr(ExprCall(ExprVar('PROFILER_LABEL'),
                                  [ ExprLiteral.String('IPDL::' + self.protocol.name),
                                    ExprLiteral.String(tag + msgname),
                                    ExprVar('js::ProfileEntry::Category::OTHER') ]))
 
     def saveActorId(self, md):