summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--datatop/src/Android.mk1
-rw-r--r--datatop/src/Makefile.am2
-rw-r--r--datatop/src/datatop.c8
-rw-r--r--datatop/src/datatop_gen_poll.c4
-rw-r--r--datatop/src/datatop_stat_poll.c3
5 files changed, 15 insertions, 3 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);
diff --git a/datatop/src/datatop_gen_poll.c b/datatop/src/datatop_gen_poll.c
index 457cc35..c3eb09d 100644
--- a/datatop/src/datatop_gen_poll.c
+++ b/datatop/src/datatop_gen_poll.c
@@ -69,6 +69,10 @@ static int get_number_of_values(struct dtop_data_point_gatherer *dpg)
read = dt_read_file(dpg->file, &data, DTOP_GEN_SIZE);
line_len = dt_read_line(line, DTOP_GEN_LINE, data, DTOP_GEN_SIZE, 0);
+ if (read == 0) {
+ return 0;
+ }
+
if (line_len < 1) {
dt_free(&data);
return 0;
diff --git a/datatop/src/datatop_stat_poll.c b/datatop/src/datatop_stat_poll.c
index 3eadaeb..88320b5 100644
--- a/datatop/src/datatop_stat_poll.c
+++ b/datatop/src/datatop_stat_poll.c
@@ -219,7 +219,7 @@ static void construct_stat_file_dpg(struct dtop_data_point
*/
int dtop_stat_search(struct dtop_stat_vars *storage)
{
- int i, k, n, sum;
+ int i, n, sum;
char *data;
int *line_len = malloc(sizeof(int) * storage->line_count);
int read;
@@ -297,7 +297,6 @@ int dtop_stat_search(struct dtop_stat_vars *storage)
count++;
}
}
- k = 0;
/* Calls dpg constructor, dpg will point to the dp struct */
construct_stat_file_dpg(data_points, storage, dp_count);