Skip to content
Snippets Groups Projects
Commit ad3f8487 authored by Harout Hedeshian's avatar Harout Hedeshian
Browse files

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
parent e21de8dc
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment