From 63fe89bd2e1d31636adb8ac12458f0f6edfbd71d Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Fri, 25 Mar 2016 17:02:38 -0400 Subject: [PATCH] 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 | 18 ++++++++++++++++++ ipc/glue/ProtocolUtils.h | 11 +++++++++++ ipc/ipdl/ipdl/lower.py | 16 ++++++++++------ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/ipc/glue/ProtocolUtils.cpp b/ipc/glue/ProtocolUtils.cpp index e359170e3bdd..ff979b451383 100644 --- a/ipc/glue/ProtocolUtils.cpp +++ b/ipc/glue/ProtocolUtils.cpp @@ -315,6 +315,24 @@ void AnnotateSystemError() } #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) { diff --git a/ipc/glue/ProtocolUtils.h b/ipc/glue/ProtocolUtils.h index cdd7498aeb80..0935fb65c607 100644 --- a/ipc/glue/ProtocolUtils.h +++ b/ipc/glue/ProtocolUtils.h @@ -296,6 +296,17 @@ LoggingEnabledFor(const char *aTopLevelProtocol) #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); diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 619663d5f377..018cc3888f91 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -5380,12 +5380,16 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): 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'),