Lower profiler saver thread priority.

Spotted while looking at bug reports. Doesn't hurt, and better
be safe than sorry.

bug:37446669
bug:36631902
test:manual, looking at bugreports

(cherry picked from commit 23caed84eba735b2615f5962b5161f6dc9e8bd4e)

Change-Id: I47723e368f3a7d863a9ed2e85c223e6e242508d5
(cherry picked from commit c84073db8e919a000cdb923f34697fd5f17a1b30)
diff --git a/runtime/jit/profile_saver.cc b/runtime/jit/profile_saver.cc
index e2bd1cb..60f7b6e 100644
--- a/runtime/jit/profile_saver.cc
+++ b/runtime/jit/profile_saver.cc
@@ -16,6 +16,7 @@
 
 #include "profile_saver.h"
 
+#include <sys/resource.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -431,6 +432,16 @@
       pthread_create,
       (&profiler_pthread_, nullptr, &RunProfileSaverThread, reinterpret_cast<void*>(instance_)),
       "Profile saver thread");
+
+#if defined(ART_TARGET_ANDROID)
+  // At what priority to schedule the saver threads. 9 is the lowest foreground priority on device.
+  static constexpr int kProfileSaverPthreadPriority = 9;
+  int result = setpriority(
+      PRIO_PROCESS, pthread_gettid_np(profiler_pthread_), kProfileSaverPthreadPriority);
+  if (result != 0) {
+    PLOG(ERROR) << "Failed to setpriority to :" << kProfileSaverPthreadPriority;
+  }
+#endif
 }
 
 void ProfileSaver::Stop(bool dump_info) {