Merge "adb: turn darwin/windows builds back on, hopefully fix them." into klp-dev am: b19b5fe08c am: 50fb0a1f11 am: 85b6b13175 am: 4775e66996 am: 750b4c3c5f am: 667e9f92d4 am: c88a4dc090 am: 3b0772f718 am: 53a345a063 am: e3e5ea98b9 am: 9d7e954e22 am: 1a7f21d108 am: 62d55cdc90
am: b928a3485a
Change-Id: I103114547136457dd076e73f34b4c0e305c68e69
diff --git a/toolbox/top.c b/toolbox/top.c
index 6fda132..e70ea31 100644
--- a/toolbox/top.c
+++ b/toolbox/top.c
@@ -31,6 +31,7 @@
#include <ctype.h>
#include <dirent.h>
+#include <errno.h>
#include <grp.h>
#include <inttypes.h>
#include <pwd.h>
@@ -38,6 +39,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
+#include <time.h>
#include <unistd.h>
#include <cutils/sched_policy.h>
@@ -180,6 +182,11 @@
new_procs = old_procs = NULL;
read_procs();
+
+ // Pause 250ms to get better data and avoid divide by zero later (http://b/32478213).
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 250000000 };
+ TEMP_FAILURE_RETRY(nanosleep(&ts, &ts));
+
while ((iterations == -1) || (iterations-- > 0)) {
old_procs = new_procs;
num_old_procs = num_new_procs;