Bug 838625 - Add hal::ProcessPriorityToString and use it in ProcessPriorityManager logging. r=cjones
authorJustin Lebar <justin.lebar@gmail.com>
Fri, 08 Feb 2013 14:32:23 +0000
changeset 121324 35cc0b94300be461d5f0b4d10018e9003707706f
parent 121323 41ce5bbd68593ab6a92984a39a3763c2c529c5ca
child 121325 fd0993e9805b10d79bf397d2cb3f10f2512e66d6
push id22685
push userjlebar@mozilla.com
push dateFri, 08 Feb 2013 14:37:00 +0000
treeherdermozilla-inbound@75899c659a0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs838625
milestone21.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 838625 - Add hal::ProcessPriorityToString and use it in ProcessPriorityManager logging. r=cjones
dom/ipc/ProcessPriorityManager.cpp
hal/Hal.cpp
hal/HalTypes.h
--- a/dom/ipc/ProcessPriorityManager.cpp
+++ b/dom/ipc/ProcessPriorityManager.cpp
@@ -396,31 +396,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
@@ -841,16 +841,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