@cryptotaxi247 / netdata-1 / commits / e880807f0

made the main JSON generation loop more accurate

Costa Tsaousis (ktsaou) committed May 2, 2014 at 10:05 UTC e880807f057bbe2a827c397cfa3347ebfb02c1c4
1 file changed +4 -7
netdata.c
+4 -7
@@ -1289,7 +1289,6 @@ void rrd_stats_done(RRD_STATS *st)
1289
1290 st->last_updated.tv_sec = now.tv_sec;
1291 st->last_updated.tv_usec = now.tv_usec;
1292 -
1292 st->counter++;
1293
1294 pthread_mutex_unlock(&st->mutex);
@@ -1765,9 +1764,7 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1764 else if(current_entry >= st->entries) current_entry = st->entries - 1;
1765
1766 // find the oldest entry of the round-robin
1768 - long stop_entry = current_entry + 1;
1769 - if(stop_entry >= st->entries) stop_entry = 0;
1770 - if(st->counter < st->entries) stop_entry = 0;
1767 + long max_entries = (st->counter <= st->entries) ? st->counter - 1 : st->entries;
1768
1769 if(before == 0) before = st->last_updated.tv_sec;
1770 if(after == 0) after = rrd_stats_first_entry_t(st);
@@ -1819,7 +1816,7 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1816 // checks for debuging
1817
1818 if(st->debug) {
1822 - debug(D_RRD_STATS, "%s first_entry_t = %lu, last_entry_t = %lu, duration = %lu, after = %lu, before = %lu, duration = %lu, entries_to_show = %lu, group = %lu, stop_entry = %ld"
1819 + debug(D_RRD_STATS, "%s first_entry_t = %lu, last_entry_t = %lu, duration = %lu, after = %lu, before = %lu, duration = %lu, entries_to_show = %lu, group = %lu, max_entries = %ld"
1820 , st->id
1821 , rrd_stats_first_entry_t(st)
1822 , st->last_updated.tv_sec
@@ -1829,7 +1826,7 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1826 , before - after
1827 , entries_to_show
1828 , group
1832 - , stop_entry
1829 + , max_entries
1830 );
1831
1832 if(before < after)
@@ -1872,7 +1869,7 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1869 unsigned long long time_usec = st->last_updated.tv_sec * 1000000ULL + st->last_updated.tv_usec;
1870 long t, count, printed, group_count;
1871
1875 - for (count = printed = group_count = 0, t = current_entry; t != stop_entry ; time_usec -= st->timediff[t], t--) {
1872 + for (count = printed = group_count = 0, t = current_entry; max_entries ; time_usec -= st->timediff[t], t--, max_entries--) {
1873 if(t < 0) t = st->entries - 1;
1874
1875 if(st->debug)