DO NOT MERGE:Add missing SOCK_CLOEXEC flag when opening socket am: a7ba9ff00b am: 4f3df4e131 am: ccfb7619f4 -s ours am: 3bd49af10b -s ours am: af7dbf4d7a am: b01cb2a926 -s ours am: 778fff4ae8 am: 4e37d97d61 am: 0735bfdd3a am: d540186b0d -s ours am: f6e21cb1f8 am: dd11742510 am: 4f99cb9cb9
am: 268bdfb840
Change-Id: Id36deba08c80717920291c4c00113348abba18e8
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;