diff options
author | Peter Wu | 2014-08-02 12:51:57 +0200 |
---|---|---|
committer | Pim van den Berg | 2014-11-14 00:09:51 +0100 |
commit | b75430280f5bfc61b5c7d4576cda1b2608aa4422 (patch) | |
tree | 08535232792e9ab49cee73f1b52bc555a484c94b | |
parent | jsrrdgraph: Fix undefined value issue in RrdDataFile (diff) | |
download | apt-panopticon_cgp-b75430280f5bfc61b5c7d4576cda1b2608aa4422.zip apt-panopticon_cgp-b75430280f5bfc61b5c7d4576cda1b2608aa4422.tar.gz apt-panopticon_cgp-b75430280f5bfc61b5c7d4576cda1b2608aa4422.tar.bz2 apt-panopticon_cgp-b75430280f5bfc61b5c7d4576cda1b2608aa4422.tar.xz |
jsrrdgraph: Improve performance for graphs in the future
The RRD file has finer details for more recent data points. When looking
for a match for a graph past the last update ("the future"), a RRA would
be picked which has a step size of 1. As we know that no data points are
available, optimise this and return earlier with the full range set to
NaN.
-rw-r--r-- | js/RrdDataFile.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/js/RrdDataFile.js b/js/RrdDataFile.js index 08cc3ae..4f96234 100644 --- a/js/RrdDataFile.js +++ b/js/RrdDataFile.js | |||
@@ -49,6 +49,7 @@ RrdDataFile.prototype = { | |||
49 | var rows; | 49 | var rows; |
50 | var rra; | 50 | var rra; |
51 | var i, ii; | 51 | var i, ii; |
52 | var last_update = rrd.getLastUpdate(); | ||
52 | 53 | ||
53 | var cf_idx = gdp.cf; | 54 | var cf_idx = gdp.cf; |
54 | var ds_cnt = rrd.getNrDSs(); | 55 | var ds_cnt = rrd.getNrDSs(); |
@@ -57,12 +58,23 @@ RrdDataFile.prototype = { | |||
57 | for (i = 0; i < ds_cnt; i++) | 58 | for (i = 0; i < ds_cnt; i++) |
58 | gdp.ds_namv[i] = rrd.rrd_header.getDSbyIdx(i).getName(); | 59 | gdp.ds_namv[i] = rrd.rrd_header.getDSbyIdx(i).getName(); |
59 | 60 | ||
61 | /* if the requested graph starts after the last available data point, | ||
62 | * return one big NaN instead of taking the finest (step=1) RRA */ | ||
63 | if (gdp.start > last_update) { | ||
64 | ft_step = gdp.end - gdp.start; | ||
65 | gdp.ds_cnt = ds_cnt; | ||
66 | gdp.data = []; | ||
67 | for (ii = 0; ii < ds_cnt; ii++) | ||
68 | gdp.data[ii] = Number.NaN; | ||
69 | return ft_step; | ||
70 | } | ||
71 | |||
60 | for (i = 0; i < rra_cnt; i++) { | 72 | for (i = 0; i < rra_cnt; i++) { |
61 | rra = rrd.getRRAInfo(i); | 73 | rra = rrd.getRRAInfo(i); |
62 | if (RrdGraphDesc.cf_conv(rra.getCFName()) === cf_idx) { | 74 | if (RrdGraphDesc.cf_conv(rra.getCFName()) === cf_idx) { |
63 | /* covered seconds in this RRA */ | 75 | /* covered seconds in this RRA */ |
64 | var range_secs = rra.getStep(); | 76 | var range_secs = rra.getStep(); |
65 | cal_end = rrd.getLastUpdate() - (rrd.getLastUpdate() % range_secs); | 77 | cal_end = last_update - (last_update % range_secs); |
66 | cal_start = cal_end - (range_secs * rra.row_cnt); | 78 | cal_start = cal_end - (range_secs * rra.row_cnt); |
67 | full_match = gdp.end - gdp.start; | 79 | full_match = gdp.end - gdp.start; |
68 | 80 | ||
@@ -101,7 +113,7 @@ RrdDataFile.prototype = { | |||
101 | gdp.ds_cnt = ds_cnt; | 113 | gdp.ds_cnt = ds_cnt; |
102 | data_ptr = 0; | 114 | data_ptr = 0; |
103 | 115 | ||
104 | var rra_end_time = (rrd.getLastUpdate() - (rrd.getLastUpdate() % ft_step)); | 116 | var rra_end_time = (last_update - (last_update % ft_step)); |
105 | var rra_start_time = (rra_end_time - (ft_step * (rra_info.row_cnt - 1))); | 117 | var rra_start_time = (rra_end_time - (ft_step * (rra_info.row_cnt - 1))); |
106 | /* here's an error by one if we don't be careful */ | 118 | /* here's an error by one if we don't be careful */ |
107 | var start_offset = (gdp.start + ft_step - rra_start_time) / ft_step; | 119 | var start_offset = (gdp.start + ft_step - rra_start_time) / ft_step; |