From ad3f8487ff9baaeedfa71a1e216c4ac28c3316a1 Mon Sep 17 00:00:00 2001 From: Harout Hedeshian Date: Tue, 2 Jun 2015 14:43:23 -0600 Subject: 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 --- datatop/src/Android.mk | 1 + datatop/src/Makefile.am | 2 +- datatop/src/datatop.c | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) 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 #include #include +#include #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); -- cgit v1.2.3