@cryptotaxi247 / netdata-1 / commits / 4b953be4b

minor fix for timings

Costa Tsaousis (ktsaou) committed Feb 25, 2017 at 04:04 UTC 4b953be4b3c87204f00509ed0c7042ccae034d03
2 files changed +22 -14
conf.d/aggregated_hosts.conf
+1 -1
@@ -92,6 +92,6 @@
92 # The memory mode of the database
93 # memory mode = save
94
95 - # Health / alarms control
95 + # Health / alarms control: yes | no | auto
96 # health enabled = yes
97
src/rrdset.c
+21 -13
@@ -215,11 +215,16 @@ inline long align_entries_to_pagesize(RRD_MEMORY_MODE mode, long entries) {
215 return entries;
216 }
217
218 -static inline void timeval_align(struct timeval *tv, int update_every) {
218 +static inline void last_collected_time_align(struct timeval *tv, int update_every) {
219 tv->tv_sec -= tv->tv_sec % update_every;
220 tv->tv_usec = 500000;
221 }
222
223 +static inline void last_updated_time_align(struct timeval *tv, int update_every) {
224 + tv->tv_sec -= tv->tv_sec % update_every;
225 + tv->tv_usec = 0;
226 +}
227 +
228 // ----------------------------------------------------------------------------
229 // RRDSET - free a chart
230
@@ -398,7 +403,8 @@ RRDSET *rrdset_create(RRDHOST *host, const char *type, const char *id, const cha
403
404 // make sure the database is aligned
405 if(st->last_updated.tv_sec)
401 - timeval_align(&st->last_updated, update_every);
406 + last_updated_time_align(&st->last_updated, update_every);
407 +
408
409 // make sure we have the right memory mode
410 // even if we cleared the memory
@@ -543,15 +549,17 @@ inline void rrdset_next_usec(RRDSET *st, usec_t microseconds) {
549
550 if(unlikely(since_last_usec < 0)) {
551 // oops! the database is in the future
546 - error("Database for chart '%s' on host '%s' is %lld microseconds in the future.", st->id, st->rrdhost->hostname, -since_last_usec);
547 - memcpy(&st->last_collected_time, &now, sizeof(struct timeval));
548 - st->last_collected_time.tv_sec -= st->update_every;
552 + error("Database for chart '%s' on host '%s' is %lld microseconds in the future. Adjusting it to current time.", st->id, st->rrdhost->hostname, -since_last_usec);
553 +
554 + st->last_collected_time.tv_sec = now.tv_sec - st->update_every;
555 + st->last_collected_time.tv_usec = now.tv_usec;
556 + last_collected_time_align(&st->last_collected_time, st->update_every);
557
550 - memcpy(&st->last_updated, &now, sizeof(struct timeval));
551 - timeval_align(&st->last_updated, st->update_every);
552 - st->last_updated.tv_sec -= st->update_every;
558 + st->last_updated.tv_sec = now.tv_sec - st->update_every;
559 + st->last_updated.tv_usec = now.tv_usec;
560 + last_updated_time_align(&st->last_updated, st->update_every);
561
554 - microseconds = st->update_every * USEC_PER_SEC;
562 + microseconds = st->update_every * USEC_PER_SEC;
563 since_last_usec = st->update_every * USEC_PER_SEC;
564 }
565
@@ -589,7 +597,7 @@ inline void rrdset_next_usec(RRDSET *st, usec_t microseconds) {
597
598 static inline void rrdset_init_last_collected_time(RRDSET *st) {
599 now_realtime_timeval(&st->last_collected_time);
592 - timeval_align(&st->last_collected_time, st->update_every);
600 + last_collected_time_align(&st->last_collected_time, st->update_every);
601 }
602
603 static inline usec_t rrdset_update_last_collected_time(RRDSET *st) {
@@ -602,9 +610,9 @@ static inline usec_t rrdset_update_last_collected_time(RRDSET *st) {
610
611 static inline void rrdset_init_last_updated_time(RRDSET *st) {
612 // copy the last collected time to last updated time
605 - memcpy(&st->last_updated, &st->last_collected_time, sizeof(struct timeval));
606 - timeval_align(&st->last_updated, st->update_every);
607 - st->last_updated.tv_usec = 0;
613 + st->last_updated.tv_sec = st->last_collected_time.tv_sec;
614 + st->last_updated.tv_usec = st->last_collected_time.tv_usec;
615 + last_updated_time_align(&st->last_updated, st->update_every);
616 }
617
618 static inline void rrdset_done_push_exclusive(RRDSET *st) {