Add /proc/pid/task/tid/schedstat info to thread stack dumps

This lets us see whether a usually-blocked thread is actually making
progress in between stack snapshots.

Change-Id: If191627e4572457579d5f330d31bde86b8ce4ec5
diff --git a/vm/Thread.c b/vm/Thread.c
index 41562e2..f15b5dc 100644
--- a/vm/Thread.c
+++ b/vm/Thread.c
@@ -3422,6 +3422,8 @@
     int priority;               // java.lang.Thread priority
     int policy;                 // pthread policy
     struct sched_param sp;      // pthread scheduling parameters
+    char schedstatBuf[64];      // contents of /proc/[pid]/task/[tid]/schedstat
+    int schedstatFd;
 
     threadObj = thread->threadObj;
     if (threadObj == NULL) {
@@ -3483,6 +3485,19 @@
         thread->systemTid, getpriority(PRIO_PROCESS, thread->systemTid),
         policy, sp.sched_priority, schedulerGroupBuf, (int)thread->handle);
 
+    snprintf(schedstatBuf, sizeof(schedstatBuf), "/proc/%d/task/%d/schedstat",
+             getpid(), thread->systemTid);
+    schedstatFd = open(schedstatBuf, O_RDONLY);
+    if (schedstatFd >= 0) {
+        int bytes;
+        bytes = read(schedstatFd, schedstatBuf, sizeof(schedstatBuf) - 1);
+        close(schedstatFd);
+        if (bytes > 1) {
+            schedstatBuf[bytes-1] = 0;  // trailing newline
+            dvmPrintDebugMessage(target, "  | schedstat=( %s )\n", schedstatBuf);
+        }
+    }
+
 #ifdef WITH_MONITOR_TRACKING
     if (!isRunning) {
         LockedObjectData* lod = thread->pLockedObjects;