Bug 1143532 - Include pid in the log messages of GMPParent. r=edwin
authorJW Wang <jwwang@mozilla.com>
Sun, 15 Mar 2015 23:30:00 +0100
changeset 263560 a29d23e9d4b67cb435ba14e5b9958054bbc930c7
parent 263559 703caa5d845f02d37f98f099540a00d4f2353af6
child 263561 1d525669326e48e7bf604ba8871b9596025837ef
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin
bugs1143532
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1143532 - Include pid in the log messages of GMPParent. r=edwin
dom/media/gmp/GMPParent.cpp
dom/media/gmp/GMPParent.h
dom/media/gmp/GMPStorageParent.cpp
--- a/dom/media/gmp/GMPParent.cpp
+++ b/dom/media/gmp/GMPParent.cpp
@@ -29,51 +29,49 @@ using mozilla::dom::CrashReporterParent;
 using CrashReporter::AnnotationTable;
 using CrashReporter::GetIDFromMinidump;
 #endif
 
 #include "mozilla/Telemetry.h"
 
 namespace mozilla {
 
-#ifdef LOG
 #undef LOG
-#endif
+#undef LOGD
 
 #ifdef PR_LOGGING
 extern PRLogModuleInfo* GetGMPLog();
-
-#define LOGD(msg) PR_LOG(GetGMPLog(), PR_LOG_DEBUG, msg)
-#define LOG(level, msg) PR_LOG(GetGMPLog(), (level), msg)
+#define LOG(level, x, ...) PR_LOG(GetGMPLog(), (level), (x, ##__VA_ARGS__))
+#define LOGD(x, ...) LOG(PR_LOG_DEBUG, "GMPParent[%p|childPid=%d] " x, this, mChildPid, ##__VA_ARGS__)
 #else
-#define LOGD(msg)
-#define LOG(level, msg)
+#define LOG(level, x, ...)
+#define LOGD(x, ...)
 #endif
 
-#ifdef __CLASS__
-#undef __CLASS__
-#endif
-#define __CLASS__ "GMPParent"
-
 namespace gmp {
 
 GMPParent::GMPParent()
   : mState(GMPStateNotLoaded)
   , mProcess(nullptr)
   , mDeleteProcessOnlyOnUnload(false)
   , mAbnormalShutdownInProgress(false)
   , mAsyncShutdownRequired(false)
   , mAsyncShutdownInProgress(false)
+#ifdef PR_LOGGING
+  , mChildPid(0)
+#endif
 {
+  LOGD("GMPParent ctor");
 }
 
 GMPParent::~GMPParent()
 {
   // Can't Close or Destroy the process here, since destruction is MainThread only
   MOZ_ASSERT(NS_IsMainThread());
+  LOGD("GMPParent dtor");
 }
 
 void
 GMPParent::CheckThread()
 {
   MOZ_ASSERT(mGMPThread == NS_GetCurrentThread());
 }
 
@@ -102,18 +100,17 @@ GMPParent::Init(GeckoMediaPluginService 
   if (NS_FAILED(rv)) {
     return rv;
   }
   nsAutoString parentLeafName;
   rv = parent->GetLeafName(parentLeafName);
   if (NS_FAILED(rv)) {
     return rv;
   }
-  LOGD(("%s::%s: %p for %s", __CLASS__, __FUNCTION__, this,
-       NS_LossyConvertUTF16toASCII(parentLeafName).get()));
+  LOGD("%s: for %s", __FUNCTION__, NS_LossyConvertUTF16toASCII(parentLeafName).get());
 
   MOZ_ASSERT(parentLeafName.Length() > 4);
   mName = Substring(parentLeafName, 4);
 
   return ReadGMPMetaData();
 }
 
 void
@@ -130,52 +127,56 @@ GMPParent::LoadProcess()
   MOZ_ASSERT(mDirectory, "Plugin directory cannot be NULL!");
   MOZ_ASSERT(GMPThread() == NS_GetCurrentThread());
   MOZ_ASSERT(mState == GMPStateNotLoaded);
 
   nsAutoString path;
   if (NS_FAILED(mDirectory->GetPath(path))) {
     return NS_ERROR_FAILURE;
   }
-  LOGD(("%s::%s: %p for %s", __CLASS__, __FUNCTION__, this, path.get()));
+  LOGD("%s: for %s", __FUNCTION__, NS_ConvertUTF16toUTF8(path).get());
 
   if (!mProcess) {
     mProcess = new GMPProcessParent(NS_ConvertUTF16toUTF8(path).get());
     if (!mProcess->Launch(30 * 1000)) {
       mProcess->Delete();
       mProcess = nullptr;
       return NS_ERROR_FAILURE;
     }
 
+#ifdef PR_LOGGING
+    mChildPid = base::GetProcId(mProcess->GetChildProcessHandle());
+#endif
+
     bool opened = Open(mProcess->GetChannel(), mProcess->GetChildProcessHandle());
     if (!opened) {
-      LOGD(("%s::%s: Failed to create new child process %p", __CLASS__, __FUNCTION__, (void *)mProcess));
+      LOGD("%s: Failed to create new child process", __FUNCTION__);
       mProcess->Delete();
       mProcess = nullptr;
       return NS_ERROR_FAILURE;
     }
-    LOGD(("%s::%s: Created new child process %p", __CLASS__, __FUNCTION__, (void *)mProcess));
+    LOGD("%s: Created new child process", __FUNCTION__);
 
     bool ok = SendSetNodeId(mNodeId);
     if (!ok) {
-      LOGD(("%s::%s: Failed to send node id to child process %p", __CLASS__, __FUNCTION__, (void *)mProcess));
+      LOGD("%s: Failed to send node id to child process", __FUNCTION__);
       mProcess->Delete();
       mProcess = nullptr;
       return NS_ERROR_FAILURE;
     }
-    LOGD(("%s::%s: Sent node id to child process %p", __CLASS__, __FUNCTION__, (void *)mProcess));
+    LOGD("%s: Sent node id to child process", __FUNCTION__);
 
     ok = SendStartPlugin();
     if (!ok) {
-      LOGD(("%s::%s: Failed to send start to child process %p", __CLASS__, __FUNCTION__, (void *)mProcess));
+      LOGD("%s: Failed to send start to child process", __FUNCTION__);
       mProcess->Delete();
       mProcess = nullptr;
       return NS_ERROR_FAILURE;
     }
-    LOGD(("%s::%s: Sent StartPlugin to child process %p", __CLASS__, __FUNCTION__, (void *)mProcess));
+    LOGD("%s: Sent StartPlugin to child process", __FUNCTION__);
   }
 
   mState = GMPStateLoaded;
 
   return NS_OK;
 }
 
 void
@@ -220,36 +221,34 @@ GMPParent::EnsureAsyncShutdownTimeoutSet
     &AbortWaitingForGMPAsyncShutdown, this, timeout,
     nsITimer::TYPE_ONE_SHOT);
 }
 
 void
 GMPParent::CloseIfUnused()
 {
   MOZ_ASSERT(GMPThread() == NS_GetCurrentThread());
-  LOGD(("%s::%s: %p mAsyncShutdownRequired=%d", __CLASS__, __FUNCTION__, this,
-        mAsyncShutdownRequired));
+  LOGD("%s: mAsyncShutdownRequired=%d", __FUNCTION__, mAsyncShutdownRequired);
 
   if ((mDeleteProcessOnlyOnUnload ||
        mState == GMPStateLoaded ||
        mState == GMPStateUnloading) &&
       mVideoDecoders.IsEmpty() &&
       mVideoEncoders.IsEmpty() &&
       mDecryptors.IsEmpty() &&
       mAudioDecoders.IsEmpty()) {
 
     // Ensure all timers are killed.
     for (uint32_t i = mTimers.Length(); i > 0; i--) {
       mTimers[i - 1]->Shutdown();
     }
 
     if (mAsyncShutdownRequired) {
       if (!mAsyncShutdownInProgress) {
-        LOGD(("%s::%s: %p sending async shutdown notification", __CLASS__,
-              __FUNCTION__, this));
+        LOGD("%s: sending async shutdown notification", __FUNCTION__);
         mAsyncShutdownInProgress = true;
         if (!SendBeginAsyncShutdown() ||
             NS_FAILED(EnsureAsyncShutdownTimeoutSet())) {
           AbortAsyncShutdown();
         }
       }
     } else {
       // Any async shutdown must be complete. Shutdown GMPStorage.
@@ -260,17 +259,17 @@ GMPParent::CloseIfUnused()
     }
   }
 }
 
 void
 GMPParent::AbortAsyncShutdown()
 {
   MOZ_ASSERT(GMPThread() == NS_GetCurrentThread());
-  LOGD(("%s::%s: %p", __CLASS__, __FUNCTION__, this));
+  LOGD("%s", __FUNCTION__);
 
   if (mAsyncShutdownTimeout) {
     mAsyncShutdownTimeout->Cancel();
     mAsyncShutdownTimeout = nullptr;
   }
 
   if (!mAsyncShutdownRequired || !mAsyncShutdownInProgress) {
     return;
@@ -294,17 +293,17 @@ GMPParent::AudioDecoderDestroyed(GMPAudi
   // until after this has completed.
   nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &GMPParent::CloseIfUnused);
   NS_DispatchToCurrentThread(event);
 }
 
 void
 GMPParent::CloseActive(bool aDieWhenUnloaded)
 {
-  LOGD(("%s::%s: %p state %d", __CLASS__, __FUNCTION__, this, mState));
+  LOGD("%s: state %d", __FUNCTION__, mState);
   if (aDieWhenUnloaded) {
     mDeleteProcessOnlyOnUnload = true; // don't allow this to go back...
   }
   if (mState == GMPStateLoaded) {
     mState = GMPStateUnloading;
   }
 
   // Invalidate and remove any remaining API objects.
@@ -334,17 +333,17 @@ GMPParent::CloseActive(bool aDieWhenUnlo
   // the plugin-container until they're all safely shut down via
   // CloseIfUnused();
   CloseIfUnused();
 }
 
 void
 GMPParent::Shutdown()
 {
-  LOGD(("%s::%s: %p", __CLASS__, __FUNCTION__, this));
+  LOGD("%s", __FUNCTION__);
   MOZ_ASSERT(GMPThread() == NS_GetCurrentThread());
 
   MOZ_ASSERT(!mAsyncShutdownTimeout, "Should have canceled shutdown timeout");
 
   if (mAbnormalShutdownInProgress) {
     return;
   }
   MOZ_ASSERT(mVideoDecoders.IsEmpty() && mVideoEncoders.IsEmpty());
@@ -379,26 +378,26 @@ public:
     return NS_OK;
   }
   nsString mNodeId;
 };
 
 void
 GMPParent::DeleteProcess()
 {
-  LOGD(("%s::%s: %p", __CLASS__, __FUNCTION__, this));
+  LOGD("%s", __FUNCTION__);
 
   if (mState != GMPStateClosing) {
     // Don't Close() twice!
     // Probably remove when bug 1043671 is resolved
     mState = GMPStateClosing;
     Close();
   }
   mProcess->Delete();
-  LOGD(("%s::%s: Shut down process %p", __CLASS__, __FUNCTION__, (void *) mProcess));
+  LOGD("%s: Shut down process", __FUNCTION__);
   mProcess = nullptr;
   mState = GMPStateNotLoaded;
 
   NS_DispatchToMainThread(
     new NotifyGMPShutdownTask(NS_ConvertUTF8toUTF16(mNodeId)),
     NS_DISPATCH_NORMAL);
 
 }
@@ -649,17 +648,17 @@ GMPNotifyObservers(nsAString& aData)
     nsString temp(aData);
     obs->NotifyObservers(nullptr, "gmp-plugin-crash", temp.get());
   }
 }
 #endif
 void
 GMPParent::ActorDestroy(ActorDestroyReason aWhy)
 {
-  LOGD(("%s::%s: %p (%d)", __CLASS__, __FUNCTION__, this, (int) aWhy));
+  LOGD("%s: (%d)", __FUNCTION__, (int)aWhy);
 #ifdef MOZ_CRASHREPORTER
   if (AbnormalShutdown == aWhy) {
     Telemetry::Accumulate(Telemetry::SUBPROCESS_ABNORMAL_ABORT,
                           NS_LITERAL_CSTRING("gmplugin"), 1);
     nsString dumpID;
     GetCrashID(dumpID);
     nsString id;
     // use the parent address to identify it
@@ -1012,30 +1011,33 @@ const nsCString&
 GMPParent::GetVersion() const
 {
   return mVersion;
 }
 
 bool
 GMPParent::RecvAsyncShutdownRequired()
 {
-  LOGD(("%s::%s: %p", __CLASS__, __FUNCTION__, this));
+  LOGD("%s", __FUNCTION__);
   if (mAsyncShutdownRequired) {
     NS_WARNING("Received AsyncShutdownRequired message more than once!");
     return true;
   }
   mAsyncShutdownRequired = true;
   mService->AsyncShutdownNeeded(this);
   return true;
 }
 
 bool
 GMPParent::RecvAsyncShutdownComplete()
 {
-  LOGD(("%s::%s: %p", __CLASS__, __FUNCTION__, this));
+  LOGD("%s", __FUNCTION__);
 
   MOZ_ASSERT(mAsyncShutdownRequired);
   AbortAsyncShutdown();
   return true;
 }
 
 } // namespace gmp
 } // namespace mozilla
+
+#undef LOG
+#undef LOGD
--- a/dom/media/gmp/GMPParent.h
+++ b/dom/media/gmp/GMPParent.h
@@ -194,14 +194,18 @@ private:
   nsCOMPtr<nsIThread> mGMPThread;
   nsCOMPtr<nsITimer> mAsyncShutdownTimeout; // GMP Thread only.
   // NodeId the plugin is assigned to, or empty if the the plugin is not
   // assigned to a NodeId.
   nsAutoCString mNodeId;
 
   bool mAsyncShutdownRequired;
   bool mAsyncShutdownInProgress;
+
+#ifdef PR_LOGGING
+  int mChildPid;
+#endif
 };
 
 } // namespace gmp
 } // namespace mozilla
 
 #endif // GMPParent_h_
--- a/dom/media/gmp/GMPStorageParent.cpp
+++ b/dom/media/gmp/GMPStorageParent.cpp
@@ -34,17 +34,17 @@ extern PRLogModuleInfo* GetGMPLog();
 #else
 #define LOGD(msg)
 #define LOG(level, msg)
 #endif
 
 #ifdef __CLASS__
 #undef __CLASS__
 #endif
-#define __CLASS__ "GMPParent"
+#define __CLASS__ "GMPStorageParent"
 
 namespace gmp {
 
 // We store the records in files in the profile dir.
 // $profileDir/gmp/storage/$nodeId/
 static nsresult
 GetGMPStorageDir(nsIFile** aTempDir, const nsCString& aNodeId)
 {