Merge "DO NOT MERGE:Add missing SOCK_CLOEXEC flag when opening socket" into lmp-dev am: 40138b630c -s ours am: 65e59a4960 am: fb3d3904d0 -s ours am: 4b9c44dcf7 am: cc236b7e94 am: 76af41ef0a am: 18b8b0f168 -s ours am: 3ef91bbffa am: 0da14e91c6 am: 5e10383130
am: 80dc7605b9
Change-Id: I32d058b21874b1685ee24b1cd4195331a2584254
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;