summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarout Hedeshian <harouth@codeaurora.org>2015-06-02 14:43:23 -0600
committerHarout Hedeshian <harouth@codeaurora.org>2015-06-17 13:35:59 -0600
commitad3f8487ff9baaeedfa71a1e216c4ac28c3316a1 (patch)
treefd215aceedec27c2978ba0c0a31b9cf802611b1c
parente21de8dcb916d32b8dcce6d6316603811bbc408b (diff)
downloadandroid_vendor_qcom_opensource_dataservices-ad3f8487ff9baaeedfa71a1e216c4ac28c3316a1.tar.gz
android_vendor_qcom_opensource_dataservices-ad3f8487ff9baaeedfa71a1e216c4ac28c3316a1.tar.bz2
android_vendor_qcom_opensource_dataservices-ad3f8487ff9baaeedfa71a1e216c4ac28c3316a1.zip
datatop: polling interval change
Make dtop_poll_periodically wait the time it takes to poll so that the polling times are more accurate to the second. Change-Id: I3253deb79c60b76bc7c0fa8823678832979d2ed0
-rw-r--r--datatop/src/Android.mk1
-rw-r--r--datatop/src/Makefile.am2
-rw-r--r--datatop/src/datatop.c8
3 files changed, 10 insertions, 1 deletions
diff --git a/datatop/src/Android.mk b/datatop/src/Android.mk
index f4b4b43..51d062a 100644
--- a/datatop/src/Android.mk
+++ b/datatop/src/Android.mk
@@ -21,6 +21,7 @@ LOCAL_SRC_FILES += datatop_value_only_poll.c
LOCAL_CFLAGS := -Wall -Wextra -Werror -pedantic
LOCAL_CFLAGS += -DVERSION="\"1.0.4"\"
LOCAL_CFLAGS += -DHAVE_STRL_FUNCTIONS
+LOCAL_CFLAGS += -D _BSD_SOURCE
LOCAL_C_INCLUDES := $(LOCAL_PATH)
diff --git a/datatop/src/Makefile.am b/datatop/src/Makefile.am
index 554b40c..5dd0469 100644
--- a/datatop/src/Makefile.am
+++ b/datatop/src/Makefile.am
@@ -2,7 +2,7 @@
CFLAGS := -std=c99 # Target c99 for portability
CFLAGS += -Wall -Wextra -Werror -pedantic # Strict code quality enforcement
-CFLAGS += -g # Enable debugging
+CFLAGS += -g -D _BSD_SOURCE # Enable debugging and BSD time functions
bin_PROGRAMS = datatop
datatop_SOURCES := datatop.c
diff --git a/datatop/src/datatop.c b/datatop/src/datatop.c
index 984de05..82022a3 100644
--- a/datatop/src/datatop.c
+++ b/datatop/src/datatop.c
@@ -45,6 +45,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <unistd.h>
#include <string.h>
#include <errno.h>
+#include <time.h>
#include "datatop_interface.h"
#include "datatop_linked_list.h"
#include "datatop_opt.h"
@@ -94,6 +95,7 @@ int dtop_poll_periodically(struct dtop_linked_list *dpg_list, FILE *fw)
int inp, quit;
struct dtop_linked_list *curr_ptr = dpg_list;
struct dtop_data_point_gatherer *dpset;
+ struct timeval ftime, itime, polltime;
gettimeofday(&tv, NULL);
curtime = tv.tv_sec;
@@ -113,6 +115,7 @@ int dtop_poll_periodically(struct dtop_linked_list *dpg_list, FILE *fw)
return FILE_ERROR;
dtop_print_interactive_opts();
+ gettimeofday(&itime, NULL);
/* periodically poll the datapoints and print in csv format */
while (curtime < endtime
|| usr_cl_opts.poll_time == POLL_NOT_SPECIFIED) {
@@ -120,7 +123,12 @@ int dtop_poll_periodically(struct dtop_linked_list *dpg_list, FILE *fw)
FD_SET(0, &rfds);
timeout.tv_sec = usr_cl_opts.poll_per;
timeout.tv_usec = 0;
+ //ftime is right before timeout calculations for most acurate calculations
+ gettimeofday(&ftime, NULL);
+ timersub(&ftime, &itime, &polltime);
+ timersub(&timeout,&polltime, &timeout);
inp = select(1, &rfds, NULL, NULL, &timeout);
+ gettimeofday(&itime, NULL);
if (inp) {
char s[4];
scanf("%s", s);