Bug 962344 - Log messages in IPDL should contain from/to information; Log message should go to logcat on Gonk devices. r=bent
authorTed Clancy <tclancy@mozilla.com>
Mon, 03 Feb 2014 14:11:50 +0100
changeset 178052 8cd50b4ce64bf60b2f7006ae73c6c758e15947ca
parent 178051 3876aee7eb393f1ef86e12386b8e060d62c26a9b
child 178053 ab06f04ddb3d5571e7bc8299efea203b645a9dd6
push id5439
push userffxbld
push dateMon, 17 Mar 2014 23:08:15 +0000
treeherdermozilla-aurora@c0befb3c8038 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs962344
milestone30.0a1
Bug 962344 - Log messages in IPDL should contain from/to information; Log message should go to logcat on Gonk devices. r=bent
ipc/glue/ProtocolUtils.h
ipc/ipdl/ipdl/lower.py
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -17,16 +17,20 @@
 #include "IPCMessageStart.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/ipc/FileDescriptor.h"
 #include "mozilla/ipc/Shmem.h"
 #include "mozilla/ipc/Transport.h"
 #include "mozilla/ipc/MessageLink.h"
 #include "mozilla/LinkedList.h"
 
+#if defined(ANDROID) && defined(DEBUG)
+#include <android/log.h>
+#endif
+
 // WARNING: this takes into account the private, special-message-type
 // enum in ipc_channel.h.  They need to be kept in sync.
 namespace {
 // XXX the max message ID is actually kuint32max now ... when this
 // changed, the assumptions of the special message IDs changed in that
 // they're not carving out messages from likely-unallocated space, but
 // rather carving out messages from the end of space allocated to
 // protocol 0.  Oops!  We can get away with this until protocol 0
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -1820,50 +1820,66 @@ def _generateMessageClass(clsname, msgid
                                        ExprVar('IPC::Message::PRIORITY_NORMAL'),
                                        compression,
                                        ExprLiteral.String(prettyName) ]) ])
     cls.addstmts([ ctor, Whitespace.NL ])
 
     # generate a logging function
     # 'pfx' will be something like "[FooParent] sent"
     pfxvar = ExprVar('__pfx')
-    outfvar = ExprVar('__outf')
+    otherprocess = ExprVar('__otherProcess')
+    receiving = ExprVar('__receiving')
     logger = MethodDefn(MethodDecl(
         'Log',
         params=([ Decl(Type('std::string', const=1, ref=1), pfxvar.name),
-                  Decl(Type('FILE', ptr=True), outfvar.name) ]),
+                  Decl(Type('base::ProcessHandle'), otherprocess.name),
+                  Decl(Type('bool'), receiving.name) ]),
         const=1))
     # TODO/cjones: allow selecting what information is printed to 
     # the log
     msgvar = ExprVar('__logmsg')
     logger.addstmt(StmtDecl(Decl(Type('std::string'), msgvar.name)))
 
     def appendToMsg(thing):
         return StmtExpr(ExprCall(ExprSelect(msgvar, '.', 'append'),
                                  args=[ thing ]))
     logger.addstmts([
         StmtExpr(ExprCall(
             ExprVar('StringAppendF'),
             args=[ ExprAddrOf(msgvar),
-                   ExprLiteral.String('[time:%" PRId64 "][%d]'),
+                   ExprLiteral.String('[time:%" PRId64 "][%d%s%d]'),
                    ExprCall(ExprVar('PR_Now')),
-                   ExprCall(ExprVar('base::GetCurrentProcId')) ])),
+                   ExprCall(ExprVar('base::GetCurrentProcId')),
+                   ExprConditional(receiving, ExprLiteral.String('<-'),
+                                   ExprLiteral.String('->')),
+                   otherprocess ])),
         appendToMsg(pfxvar),
         appendToMsg(ExprLiteral.String(clsname +'(')),
         Whitespace.NL
     ])
 
     # TODO turn this back on when string stuff is sorted
 
     logger.addstmt(appendToMsg(ExprLiteral.String('[TODO])\\n')))
 
+    logger.addstmts([
+        CppDirective('ifdef', 'ANDROID'),
+        StmtExpr(ExprCall(
+            ExprVar('__android_log_write'),
+            args=[ ExprVar('ANDROID_LOG_INFO'),
+                   ExprLiteral.String('GeckoIPC'),
+                   ExprCall(ExprSelect(msgvar, '.', 'c_str')) ])),
+        CppDirective('endif')
+    ])
+
     # and actually print the log message
     logger.addstmt(StmtExpr(ExprCall(
         ExprVar('fputs'),
-        args=[ ExprCall(ExprSelect(msgvar, '.', 'c_str')), outfvar ])))
+        args=[ ExprCall(ExprSelect(msgvar, '.', 'c_str')),
+               ExprVar('stderr') ])))
 
     cls.addstmt(logger)
 
     return cls
 
 ##--------------------------------------------------
 
 class _ComputeTypeDeps(TypeVisitor):
@@ -4924,17 +4940,17 @@ class _GenerateProtocolActorCode(ipdl.as
         sendok, sendstmts = self.sendBlocking(md, msgvar, replyvar, actorvar)
         method.addstmts(
             stmts
             + [ Whitespace.NL,
                 StmtDecl(Decl(Type('Message'), replyvar.name)) ]
             + sendstmts)
 
         destmts = self.deserializeReply(
-            md, ExprAddrOf(replyvar), self.side, errfnSend)
+            md, ExprAddrOf(replyvar), self.side, errfnSend, actorvar)
         ifsendok = StmtIf(ExprLiteral.FALSE)
         ifsendok.addifstmts(destmts)
         ifsendok.addifstmts([ Whitespace.NL,
                               StmtExpr(ExprAssn(sendok, ExprLiteral.FALSE, '&=')) ])
 
         method.addstmt(ifsendok)
 
         if self.protocol.decl.type.hasReentrantDelete:
@@ -5160,17 +5176,18 @@ class _GenerateProtocolActorCode(ipdl.as
             # are forwarding the message name (yuck) or making the
             # IPDL|*Channel abstraction leak more
             StmtExpr(ExprCall(
                 ExprSelect(
                     ExprCast(msgvar, Type('Message', ref=1), const=1),
                     '.', 'set_name'),
                 args=[ ExprLiteral.String(md.prettyMsgName(self.protocol.name
                                                            +'::')) ])),
-            self.logMessage(md, md.msgCast(msgexpr), 'Received '),
+            self.logMessage(md, md.msgCast(msgexpr), 'Received ',
+                            receiving=True),
             self.profilerLabel('Recv', md.decl.progname),
             Whitespace.NL
         ])
 
         if 0 == len(md.params):
             return stmts
 
         start, decls, reads = 0, [], []
@@ -5195,20 +5212,20 @@ class _GenerateProtocolActorCode(ipdl.as
                                          msgexpr, ExprAddrOf(itervar),
                                          errfn, p.bareType(side).name)
                         for p in md.params[start:] ]
             + [ self.endRead(msgvar, itervar) ]))
 
         return stmts
 
 
-    def deserializeReply(self, md, replyexpr, side, errfn):
+    def deserializeReply(self, md, replyexpr, side, errfn, actor=None):
         stmts = [ Whitespace.NL,
                    self.logMessage(md, md.replyCast(replyexpr),
-                                   'Received reply ') ]
+                                   'Received reply ', actor, receiving=True) ]
         if 0 == len(md.returns):
             return stmts
 
         itervar = self.itervar
         stmts.extend(
             [ Whitespace.NL,
               StmtDecl(Decl(Type.VOIDPTR, itervar.name),
                        init=ExprLiteral.NULL) ]
@@ -5221,34 +5238,34 @@ class _GenerateProtocolActorCode(ipdl.as
 
         return stmts
 
     def sendAsync(self, md, msgexpr, actor=None):
         sendok = ExprVar('__sendok')
         return (
             sendok,
             ([ Whitespace.NL,
-               self.logMessage(md, msgexpr, 'Sending '),
+               self.logMessage(md, msgexpr, 'Sending ', actor),
                self.profilerLabel('AsyncSend', md.decl.progname) ]
             + self.transition(md, 'out', actor)
             + [ Whitespace.NL,
                 StmtDecl(Decl(Type.BOOL, sendok.name),
                          init=ExprCall(
                              ExprSelect(self.protocol.channelVar(actor),
                                         self.protocol.channelSel(), 'Send'),
                              args=[ msgexpr ]))
             ])
         )
 
     def sendBlocking(self, md, msgexpr, replyexpr, actor=None):
         sendok = ExprVar('__sendok')
         return (
             sendok,
             ([ Whitespace.NL,
-               self.logMessage(md, msgexpr, 'Sending '),
+               self.logMessage(md, msgexpr, 'Sending ', actor),
                self.profilerLabel('Send', md.decl.progname) ]
             + self.transition(md, 'out', actor)
             + [ Whitespace.NL,
                 StmtDecl(
                     Decl(Type.BOOL, sendok.name),
                     init=ExprCall(ExprSelect(self.protocol.channelVar(actor),
                                              self.protocol.channelSel(),
                                              _sendPrefix(md.decl.type)),
@@ -5307,23 +5324,24 @@ class _GenerateProtocolActorCode(ipdl.as
             params=md.makeCxxParams(paramsems='in', returnsems='out',
                                     side=self.side, implicit=implicit),
             warn_unused=(self.side == 'parent'),
             ret=Type.BOOL)
         if md.decl.type.isCtor():
             decl.ret = md.actorDecl().bareType(self.side)
         return decl
 
-    def logMessage(self, md, msgptr, pfx):
+    def logMessage(self, md, msgptr, pfx, actor=None, receiving=False):
         actorname = _actorName(self.protocol.name, self.side)
-        return _ifLogging([
-            StmtExpr(ExprCall(
-                ExprSelect(msgptr, '->', 'Log'),
-                args=[ ExprLiteral.String('['+ actorname +'] '+ pfx),
-                       ExprVar('stderr') ])) ])
+
+        return _ifLogging([ StmtExpr(ExprCall(
+            ExprSelect(msgptr, '->', 'Log'),
+            args=[ ExprLiteral.String('['+ actorname +'] '+ pfx),
+                   self.protocol.callOtherProcess(actor),
+                   ExprLiteral.TRUE if receiving else ExprLiteral.FALSE ])) ])
 
     def profilerLabel(self, tag, msgname):
         return StmtExpr(ExprCall(ExprVar('PROFILER_LABEL'),
                                  [ ExprLiteral.String('IPDL::' + self.protocol.name),
                                    ExprLiteral.String(tag + msgname) ]))
 
     def saveActorId(self, md):
         idvar = ExprVar('__id')