Bug 838625 - Add hal::ProcessPriorityToString and use it in ProcessPriorityManager logging. r=cjones, a=bajaj
authorJustin Lebar <justin.lebar@gmail.com>
Fri, 08 Feb 2013 14:32:23 +0000
changeset 118500 d90d3cb30e065548a97be6f9185afc0c59c7fdcb
parent 118499 76904864da989a9a5a889db9a8a7cd183a4ace4c
child 118501 81305ec8beb4217082b70b3fbea3deefb20ee714
push id443
push userryanvm@gmail.com
push dateSat, 09 Feb 2013 16:25:45 +0000
reviewerscjones, bajaj
bugs838625
milestone18.0
Bug 838625 - Add hal::ProcessPriorityToString and use it in ProcessPriorityManager logging. r=cjones, a=bajaj
dom/ipc/ProcessPriorityManager.cpp
hal/Hal.cpp
hal/HalTypes.h
--- a/dom/ipc/ProcessPriorityManager.cpp
+++ b/dom/ipc/ProcessPriorityManager.cpp
@@ -389,31 +389,31 @@ ProcessPriorityManager::SetIsForeground(
 
   // Cancel the memory minimization procedure we might have started.
   nsCOMPtr<nsICancelableRunnable> runnable =
     do_QueryReferent(mMemoryMinimizerRunnable);
   if (runnable) {
     runnable->Cancel();
   }
 
-  LOG("Setting priority to FOREGROUND.");
   mProcessPriority = PROCESS_PRIORITY_FOREGROUND;
+  LOG("Setting priority to %s.", ProcessPriorityToString(mProcessPriority));
   hal::SetProcessPriority(getpid(), PROCESS_PRIORITY_FOREGROUND);
 }
 
 void
 ProcessPriorityManager::SetIsBackgroundNow()
 {
   ProcessPriority backgroundPriority = GetBackgroundPriority();
   if (mProcessPriority == backgroundPriority) {
     return;
   }
 
   mProcessPriority = backgroundPriority;
-  LOG("Setting priority to BACKGROUND (type %d)", mProcessPriority);
+  LOG("Setting priority to %s", ProcessPriorityToString(mProcessPriority));
   hal::SetProcessPriority(getpid(), mProcessPriority);
 
   // We're in the background; dump as much memory as we can.
   nsCOMPtr<nsIMemoryReporterManager> mgr =
     do_GetService("@mozilla.org/memory-reporter-manager;1");
   if (mgr) {
     nsCOMPtr<nsICancelableRunnable> runnable =
       do_QueryReferent(mMemoryMinimizerRunnable);
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -833,16 +833,37 @@ SetAlarm(int32_t aSeconds, int32_t aNano
 }
 
 void
 SetProcessPriority(int aPid, ProcessPriority aPriority)
 {
   PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority));
 }
 
+// From HalTypes.h.
+const char*
+ProcessPriorityToString(ProcessPriority aPriority)
+{
+  switch (aPriority) {
+  case PROCESS_PRIORITY_MASTER:
+    return "MASTER";
+  case PROCESS_PRIORITY_FOREGROUND:
+    return "FOREGROUND";
+  case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
+    return "BACKGROUND_PERCEIVABLE";
+  case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN:
+    return "BACKGROUND_HOMESCREEN";
+  case PROCESS_PRIORITY_BACKGROUND:
+    return "BACKGROUND";
+  default:
+    MOZ_ASSERT(false);
+    return "???";
+  }
+}
+
 static StaticAutoPtr<ObserverList<FMRadioOperationInformation> > sFMRadioObservers;
 
 static void
 InitializeFMRadioObserver()
 {
   if (!sFMRadioObservers) {
     sFMRadioObservers = new ObserverList<FMRadioOperationInformation>;
     ClearOnShutdown(&sFMRadioObservers);
--- a/hal/HalTypes.h
+++ b/hal/HalTypes.h
@@ -74,16 +74,24 @@ enum ProcessPriority {
   // Any priority greater than or equal to FOREGROUND is considered
   // "foreground" for the purposes of priority testing, for example
   // CurrentProcessIsForeground().
   PROCESS_PRIORITY_FOREGROUND,
   PROCESS_PRIORITY_MASTER,
   NUM_PROCESS_PRIORITY
 };
 
+// Convert a ProcessPriority enum value to a string.  The strings returned by
+// this function are statically allocated; do not attempt to free one!
+//
+// If you pass an unknown process priority (or NUM_PROCESS_PRIORITY), we
+// fatally assert in debug builds and otherwise return "???".
+const char*
+ProcessPriorityToString(ProcessPriority aPriority);
+
 /**
  * Used by ModifyWakeLock
  */
 enum WakeLockControl {
   WAKE_LOCK_REMOVE_ONE = -1,
   WAKE_LOCK_NO_CHANGE  = 0,
   WAKE_LOCK_ADD_ONE    = 1,
   NUM_WAKE_LOCK