diff options
author | Manuel Luis SanmartĂn Rozada | 2014-07-25 19:43:29 +0200 |
---|---|---|
committer | Pim van den Berg | 2014-07-25 20:35:54 +0200 |
commit | 8a1e2c64bf0679004a8b38d5f9ac62859b3f8cc2 (patch) | |
tree | dfca21be49b23428eba5e113de424dbe141abc4d | |
parent | jsrrdgraph: Fix ident. Thanks to Poil (diff) | |
download | apt-panopticon_cgp-8a1e2c64bf0679004a8b38d5f9ac62859b3f8cc2.zip apt-panopticon_cgp-8a1e2c64bf0679004a8b38d5f9ac62859b3f8cc2.tar.gz apt-panopticon_cgp-8a1e2c64bf0679004a8b38d5f9ac62859b3f8cc2.tar.bz2 apt-panopticon_cgp-8a1e2c64bf0679004a8b38d5f9ac62859b3f8cc2.tar.xz |
jsrrdgraph: Upgrade to javascriptrrd ver 1.1.1
Diffstat (limited to '')
-rw-r--r-- | js/binaryXHR.js | 69 | ||||
-rw-r--r-- | js/rrdFile.js | 159 |
2 files changed, 143 insertions, 85 deletions
diff --git a/js/binaryXHR.js b/js/binaryXHR.js index d91ad72..e4e7515 100644 --- a/js/binaryXHR.js +++ b/js/binaryXHR.js | |||
@@ -37,6 +37,8 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
37 | var doubleMantExpLo=Math.pow(2,-52); | 37 | var doubleMantExpLo=Math.pow(2,-52); |
38 | var doubleMantExpFast=Math.pow(2,-20); | 38 | var doubleMantExpFast=Math.pow(2,-20); |
39 | 39 | ||
40 | var switch_endian = false; | ||
41 | |||
40 | this.getRawData = function() { | 42 | this.getRawData = function() { |
41 | return data; | 43 | return data; |
42 | } | 44 | } |
@@ -57,6 +59,13 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
57 | throw new InvalidBinaryFile("Unsupported type " + (typeof strData)); | 59 | throw new InvalidBinaryFile("Unsupported type " + (typeof strData)); |
58 | } | 60 | } |
59 | 61 | ||
62 | this.getEndianByteAt = function(iOffset,width,delta) { | ||
63 | if (this.switch_endian) | ||
64 | return this.getByteAt(iOffset+width-delta-1); | ||
65 | else | ||
66 | return this.getByteAt(iOffset+delta); | ||
67 | } | ||
68 | |||
60 | this.getLength = function() { | 69 | this.getLength = function() { |
61 | return dataLength; | 70 | return dataLength; |
62 | } | 71 | } |
@@ -70,7 +79,7 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
70 | } | 79 | } |
71 | 80 | ||
72 | this.getShortAt = function(iOffset) { | 81 | this.getShortAt = function(iOffset) { |
73 | var iShort = (this.getByteAt(iOffset + 1) << 8) + this.getByteAt(iOffset) | 82 | var iShort = (this.getEndianByteAt(iOffset,2,1) << 8) + this.getEndianByteAt(iOffset,2,0) |
74 | if (iShort < 0) iShort += 65536; | 83 | if (iShort < 0) iShort += 65536; |
75 | return iShort; | 84 | return iShort; |
76 | } | 85 | } |
@@ -82,10 +91,10 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
82 | return iUShort; | 91 | return iUShort; |
83 | } | 92 | } |
84 | this.getLongAt = function(iOffset) { | 93 | this.getLongAt = function(iOffset) { |
85 | var iByte1 = this.getByteAt(iOffset), | 94 | var iByte1 = this.getEndianByteAt(iOffset,4,0), |
86 | iByte2 = this.getByteAt(iOffset + 1), | 95 | iByte2 = this.getEndianByteAt(iOffset,4,1), |
87 | iByte3 = this.getByteAt(iOffset + 2), | 96 | iByte3 = this.getEndianByteAt(iOffset,4,2), |
88 | iByte4 = this.getByteAt(iOffset + 3); | 97 | iByte4 = this.getEndianByteAt(iOffset,4,3); |
89 | 98 | ||
90 | var iLong = (((((iByte4 << 8) + iByte3) << 8) + iByte2) << 8) + iByte1; | 99 | var iLong = (((((iByte4 << 8) + iByte3) << 8) + iByte2) << 8) + iByte1; |
91 | if (iLong < 0) iLong += 4294967296; | 100 | if (iLong < 0) iLong += 4294967296; |
@@ -117,14 +126,14 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
117 | 126 | ||
118 | // Added | 127 | // Added |
119 | this.getDoubleAt = function(iOffset) { | 128 | this.getDoubleAt = function(iOffset) { |
120 | var iByte1 = this.getByteAt(iOffset), | 129 | var iByte1 = this.getEndianByteAt(iOffset,8,0), |
121 | iByte2 = this.getByteAt(iOffset + 1), | 130 | iByte2 = this.getEndianByteAt(iOffset,8,1), |
122 | iByte3 = this.getByteAt(iOffset + 2), | 131 | iByte3 = this.getEndianByteAt(iOffset,8,2), |
123 | iByte4 = this.getByteAt(iOffset + 3), | 132 | iByte4 = this.getEndianByteAt(iOffset,8,3), |
124 | iByte5 = this.getByteAt(iOffset + 4), | 133 | iByte5 = this.getEndianByteAt(iOffset,8,4), |
125 | iByte6 = this.getByteAt(iOffset + 5), | 134 | iByte6 = this.getEndianByteAt(iOffset,8,5), |
126 | iByte7 = this.getByteAt(iOffset + 6), | 135 | iByte7 = this.getEndianByteAt(iOffset,8,6), |
127 | iByte8 = this.getByteAt(iOffset + 7); | 136 | iByte8 = this.getEndianByteAt(iOffset,8,7); |
128 | var iSign=iByte8 >> 7; | 137 | var iSign=iByte8 >> 7; |
129 | var iExpRaw=((iByte8 & 0x7F)<< 4) + (iByte7 >> 4); | 138 | var iExpRaw=((iByte8 & 0x7F)<< 4) + (iByte7 >> 4); |
130 | var iMantHi=((((((iByte7 & 0x0F) << 8) + iByte6) << 8) + iByte5) << 8) + iByte4; | 139 | var iMantHi=((((((iByte7 & 0x0F) << 8) + iByte6) << 8) + iByte5) << 8) + iByte4; |
@@ -141,10 +150,10 @@ function BinaryFile(strData, iDataOffset, iDataLength) { | |||
141 | // added | 150 | // added |
142 | // Extracts only 4 bytes out of 8, loosing in precision (20 bit mantissa) | 151 | // Extracts only 4 bytes out of 8, loosing in precision (20 bit mantissa) |
143 | this.getFastDoubleAt = function(iOffset) { | 152 | this.getFastDoubleAt = function(iOffset) { |
144 | var iByte5 = this.getByteAt(iOffset + 4), | 153 | var iByte5 = this.getEndianByteAt(iOffset,8,4), |
145 | iByte6 = this.getByteAt(iOffset + 5), | 154 | iByte6 = this.getEndianByteAt(iOffset,8,5), |
146 | iByte7 = this.getByteAt(iOffset + 6), | 155 | iByte7 = this.getEndianByteAt(iOffset,8,6), |
147 | iByte8 = this.getByteAt(iOffset + 7); | 156 | iByte8 = this.getEndianByteAt(iOffset,8,7); |
148 | var iSign=iByte8 >> 7; | 157 | var iSign=iByte8 >> 7; |
149 | var iExpRaw=((iByte8 & 0x7F)<< 4) + (iByte7 >> 4); | 158 | var iExpRaw=((iByte8 & 0x7F)<< 4) + (iByte7 >> 4); |
150 | var iMant=((((iByte7 & 0x0F) << 8) + iByte6) << 8) + iByte5; | 159 | var iMant=((((iByte7 & 0x0F) << 8) + iByte6) << 8) + iByte5; |
@@ -190,10 +199,17 @@ function FetchBinaryURL(url) { | |||
190 | } | 199 | } |
191 | request.send(null); | 200 | request.send(null); |
192 | 201 | ||
193 | var response=request.responseBody; | 202 | var response=this.responseText; |
194 | if (response==undefined){ // responseBody is non standard, but the only way to make it work in IE | 203 | try { |
195 | response=request.responseText; | 204 | // for older IE versions, the value in responseText is not usable |
205 | if (IEBinary_getLength(this.responseBody)>0) { | ||
206 | // will get here only for older verson of IE | ||
207 | response=this.responseBody; | ||
208 | } | ||
209 | } catch (err) { | ||
210 | // not IE, do nothing | ||
196 | } | 211 | } |
212 | |||
197 | var bf=new BinaryFile(response); | 213 | var bf=new BinaryFile(response); |
198 | return bf; | 214 | return bf; |
199 | } | 215 | } |
@@ -208,10 +224,17 @@ function FetchBinaryURL(url) { | |||
208 | function FetchBinaryURLAsync(url, callback, callback_arg) { | 224 | function FetchBinaryURLAsync(url, callback, callback_arg) { |
209 | var callback_wrapper = function() { | 225 | var callback_wrapper = function() { |
210 | if(this.readyState == 4) { | 226 | if(this.readyState == 4) { |
211 | var response=this.responseBody; | 227 | var response=this.responseText; |
212 | if (response==undefined){ // responseBody is non standard, but the only way to make it work in IE | 228 | try { |
213 | response=this.responseText; | 229 | // for older IE versions, the value in responseText is not usable |
230 | if (IEBinary_getLength(this.responseBody)>0) { | ||
231 | // will get here only for older verson of IE | ||
232 | response=this.responseBody; | ||
233 | } | ||
234 | } catch (err) { | ||
235 | // not IE, do nothing | ||
214 | } | 236 | } |
237 | |||
215 | var bf=new BinaryFile(response); | 238 | var bf=new BinaryFile(response); |
216 | if (callback_arg!=null) { | 239 | if (callback_arg!=null) { |
217 | callback(bf,callback_arg); | 240 | callback(bf,callback_arg); |
diff --git a/js/rrdFile.js b/js/rrdFile.js index 870c88e..eabebc7 100644 --- a/js/rrdFile.js +++ b/js/rrdFile.js | |||
@@ -5,7 +5,7 @@ | |||
5 | * Igor Sfiligoi, isfiligoi@ucsd.edu | 5 | * Igor Sfiligoi, isfiligoi@ucsd.edu |
6 | * | 6 | * |
7 | * Original repository: http://javascriptrrd.sourceforge.net/ | 7 | * Original repository: http://javascriptrrd.sourceforge.net/ |
8 | * | 8 | * |
9 | * MIT License [http://www.opensource.org/licenses/mit-license.php] | 9 | * MIT License [http://www.opensource.org/licenses/mit-license.php] |
10 | * | 10 | * |
11 | */ | 11 | */ |
@@ -17,10 +17,10 @@ | |||
17 | * | 17 | * |
18 | * This software can be used to read files produced by the RRDTool | 18 | * This software can be used to read files produced by the RRDTool |
19 | * but has been developed independently. | 19 | * but has been developed independently. |
20 | * | 20 | * |
21 | * Limitations: | 21 | * Limitations: |
22 | * | 22 | * |
23 | * This version of the module assumes RRD files created on linux | 23 | * This version of the module assumes RRD files created on linux |
24 | * with intel architecture and supports both 32 and 64 bit CPUs. | 24 | * with intel architecture and supports both 32 and 64 bit CPUs. |
25 | * All integers in RRD files are suppoes to fit in 32bit values. | 25 | * All integers in RRD files are suppoes to fit in 32bit values. |
26 | * | 26 | * |
@@ -33,7 +33,7 @@ | |||
33 | 33 | ||
34 | /* | 34 | /* |
35 | * Dependencies: | 35 | * Dependencies: |
36 | * | 36 | * |
37 | * The data provided to this module require an object of a class | 37 | * The data provided to this module require an object of a class |
38 | * that implements the following methods: | 38 | * that implements the following methods: |
39 | * getByteAt(idx) - Return a 8 bit unsigned integer at offset idx | 39 | * getByteAt(idx) - Return a 8 bit unsigned integer at offset idx |
@@ -89,13 +89,16 @@ RRDDS.prototype.getMax = function() { | |||
89 | // ============================================================ | 89 | // ============================================================ |
90 | // RRD RRA Info class | 90 | // RRD RRA Info class |
91 | function RRDRRAInfo(rrd_data,rra_def_idx, | 91 | function RRDRRAInfo(rrd_data,rra_def_idx, |
92 | rrd_align,row_cnt,pdp_step,my_idx) { | 92 | int_align,row_cnt,pdp_step,my_idx) { |
93 | this.rrd_data=rrd_data; | 93 | this.rrd_data=rrd_data; |
94 | this.rra_def_idx=rra_def_idx; | 94 | this.rra_def_idx=rra_def_idx; |
95 | this.rrd_align=rrd_align; | 95 | this.int_align=int_align; |
96 | this.row_cnt=row_cnt; | 96 | this.row_cnt=row_cnt; |
97 | this.pdp_step=pdp_step; | 97 | this.pdp_step=pdp_step; |
98 | this.my_idx=my_idx; | 98 | this.my_idx=my_idx; |
99 | |||
100 | // char nam[20], uint row_cnt, uint pdp_cnt | ||
101 | this.rra_pdp_cnt_idx=rra_def_idx+Math.ceil(20/int_align)*int_align+int_align; | ||
99 | } | 102 | } |
100 | 103 | ||
101 | RRDRRAInfo.prototype.getIdx = function() { | 104 | RRDRRAInfo.prototype.getIdx = function() { |
@@ -110,10 +113,7 @@ RRDRRAInfo.prototype.getNrRows = function() { | |||
110 | // Get number of slots used for consolidation | 113 | // Get number of slots used for consolidation |
111 | // Mostly for internal use | 114 | // Mostly for internal use |
112 | RRDRRAInfo.prototype.getPdpPerRow = function() { | 115 | RRDRRAInfo.prototype.getPdpPerRow = function() { |
113 | if (this.rrd_align==32) | 116 | return this.rrd_data.getLongAt(this.rra_pdp_cnt_idx); |
114 | return this.rrd_data.getLongAt(this.rra_def_idx+24,20); | ||
115 | else | ||
116 | return this.rrd_data.getLongAt(this.rra_def_idx+32,20); | ||
117 | } | 117 | } |
118 | 118 | ||
119 | // Get RRA step (expressed in seconds) | 119 | // Get RRA step (expressed in seconds) |
@@ -158,7 +158,7 @@ function RRDRRA(rrd_data,rra_ptr_idx, | |||
158 | } | 158 | } |
159 | } else { | 159 | } else { |
160 | throw RangeError("Row idx ("+ row_idx +") out of range [0-" + this.row_cnt +")."); | 160 | throw RangeError("Row idx ("+ row_idx +") out of range [0-" + this.row_cnt +")."); |
161 | } | 161 | } |
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
@@ -199,43 +199,89 @@ RRDRRA.prototype.getElFast = function(row_idx,ds_idx) { | |||
199 | function RRDHeader(rrd_data) { | 199 | function RRDHeader(rrd_data) { |
200 | this.rrd_data=rrd_data; | 200 | this.rrd_data=rrd_data; |
201 | this.validate_rrd(); | 201 | this.validate_rrd(); |
202 | this.load_header(); | ||
203 | this.calc_idxs(); | 202 | this.calc_idxs(); |
204 | } | 203 | } |
205 | 204 | ||
206 | // Internal, used for initialization | 205 | // Internal, used for initialization |
207 | RRDHeader.prototype.validate_rrd = function() { | 206 | RRDHeader.prototype.validate_rrd = function() { |
207 | if (this.rrd_data.getLength()<1) throw new InvalidRRD("Empty file."); | ||
208 | if (this.rrd_data.getLength()<16) throw new InvalidRRD("File too short."); | ||
208 | if (this.rrd_data.getCStringAt(0,4)!=="RRD") throw new InvalidRRD("Wrong magic id."); | 209 | if (this.rrd_data.getCStringAt(0,4)!=="RRD") throw new InvalidRRD("Wrong magic id."); |
209 | 210 | ||
210 | this.rrd_version=this.rrd_data.getCStringAt(4,5); | 211 | this.rrd_version=this.rrd_data.getCStringAt(4,5); |
211 | if ((this.rrd_version!=="0003")&&(this.rrd_version!=="0004")) { | 212 | if ((this.rrd_version!=="0003")&&(this.rrd_version!=="0004")&&(this.rrd_version!=="0001")) { |
212 | throw new InvalidRRD("Unsupported RRD version "+this.rrd_version+"."); | 213 | throw new InvalidRRD("Unsupported RRD version "+this.rrd_version+"."); |
213 | } | 214 | } |
214 | 215 | ||
215 | if (this.rrd_data.getDoubleAt(12)==8.642135e+130) { | 216 | this.float_width=8; |
216 | this.rrd_align=32; | 217 | if (this.rrd_data.getLongAt(12)==0) { |
217 | } else if (this.rrd_data.getDoubleAt(16)==8.642135e+130) { | 218 | // not a double here... likely 64 bit |
218 | this.rrd_align=64; | 219 | this.float_align=8; |
220 | if (! (this.rrd_data.getDoubleAt(16)==8.642135e+130)) { | ||
221 | // uhm... wrong endian? | ||
222 | this.rrd_data.switch_endian=true; | ||
223 | } | ||
224 | if (this.rrd_data.getDoubleAt(16)==8.642135e+130) { | ||
225 | // now, is it all 64bit or only float 64 bit? | ||
226 | if (this.rrd_data.getLongAt(28)==0) { | ||
227 | // true 64 bit align | ||
228 | this.int_align=8; | ||
229 | this.int_width=8; | ||
230 | } else { | ||
231 | // integers are 32bit aligned | ||
232 | this.int_align=4; | ||
233 | this.int_width=4; | ||
234 | } | ||
235 | } else { | ||
236 | throw new InvalidRRD("Magic float not found at 16."); | ||
237 | } | ||
219 | } else { | 238 | } else { |
220 | throw new InvalidRRD("Unsupported platform."); | 239 | /// should be 32 bit alignment |
240 | if (! (this.rrd_data.getDoubleAt(12)==8.642135e+130)) { | ||
241 | // uhm... wrong endian? | ||
242 | this.rrd_data.switch_endian=true; | ||
243 | } | ||
244 | if (this.rrd_data.getDoubleAt(12)==8.642135e+130) { | ||
245 | this.float_align=4; | ||
246 | this.int_align=4; | ||
247 | this.int_width=4; | ||
248 | } else { | ||
249 | throw new InvalidRRD("Magic float not found at 12."); | ||
250 | } | ||
221 | } | 251 | } |
222 | } | 252 | this.unival_width=this.float_width; |
253 | this.unival_align=this.float_align; | ||
223 | 254 | ||
224 | // Internal, used for initialization | 255 | // process the header here, since I need it for validation |
225 | RRDHeader.prototype.load_header = function() { | 256 | |
226 | if (this.rrd_align==32) { | 257 | // char magic[4], char version[5], double magic_float |
227 | this.ds_cnt=this.rrd_data.getLongAt(20,false); | 258 | |
228 | this.rra_cnt=this.rrd_data.getLongAt(24,false); | 259 | // long ds_cnt, long rra_cnt, long pdp_step, unival par[10] |
229 | this.pdp_step=this.rrd_data.getLongAt(28,false); | 260 | this.ds_cnt_idx=Math.ceil((4+5)/this.float_align)*this.float_align+this.float_width; |
230 | // 8*10 unused values follow | 261 | this.rra_cnt_idx=this.ds_cnt_idx+this.int_width; |
231 | this.top_header_size=112; | 262 | this.pdp_step_idx=this.rra_cnt_idx+this.int_width; |
232 | } else { | 263 | |
233 | //get only the low 32 bits, the high 32 should always be 0 | 264 | //always get only the low 32 bits, the high 32 on 64 bit archs should always be 0 |
234 | this.ds_cnt=this.rrd_data.getLongAt(24,false); | 265 | this.ds_cnt=this.rrd_data.getLongAt(this.ds_cnt_idx); |
235 | this.rra_cnt=this.rrd_data.getLongAt(32,false); | 266 | if (this.ds_cnt<1) { |
236 | this.pdp_step=this.rrd_data.getLongAt(40,false); | 267 | throw new InvalidRRD("ds count less than 1."); |
237 | // 8*10 unused values follow | 268 | } |
238 | this.top_header_size=128; | 269 | |
270 | this.rra_cnt=this.rrd_data.getLongAt(this.rra_cnt_idx); | ||
271 | if (this.ds_cnt<1) { | ||
272 | throw new InvalidRRD("rra count less than 1."); | ||
273 | } | ||
274 | |||
275 | this.pdp_step=this.rrd_data.getLongAt(this.pdp_step_idx); | ||
276 | if (this.pdp_step<1) { | ||
277 | throw new InvalidRRD("pdp step less than 1."); | ||
278 | } | ||
279 | |||
280 | // best guess, assuming no weird align problems | ||
281 | this.top_header_size=Math.ceil((this.pdp_step_idx+this.int_width)/this.unival_align)*this.unival_align+10*this.unival_width; | ||
282 | var t=this.rrd_data.getLongAt(this.top_header_size); | ||
283 | if (t==0) { | ||
284 | throw new InvalidRRD("Could not find first DS name."); | ||
239 | } | 285 | } |
240 | } | 286 | } |
241 | 287 | ||
@@ -243,43 +289,29 @@ RRDHeader.prototype.load_header = function() { | |||
243 | RRDHeader.prototype.calc_idxs = function() { | 289 | RRDHeader.prototype.calc_idxs = function() { |
244 | this.ds_def_idx=this.top_header_size; | 290 | this.ds_def_idx=this.top_header_size; |
245 | // char ds_nam[20], char dst[20], unival par[10] | 291 | // char ds_nam[20], char dst[20], unival par[10] |
246 | this.ds_el_size=120; | 292 | this.ds_el_size=Math.ceil((20+20)/this.unival_align)*this.unival_align+10*this.unival_width; |
247 | 293 | ||
248 | this.rra_def_idx=this.ds_def_idx+this.ds_el_size*this.ds_cnt; | 294 | this.rra_def_idx=this.ds_def_idx+this.ds_el_size*this.ds_cnt; |
249 | // char cf_nam[20], uint row_cnt, uint pdp_cnt, unival par[10] | 295 | // char cf_nam[20], uint row_cnt, uint pdp_cnt, unival par[10] |
250 | this.row_cnt_idx; | 296 | this.row_cnt_idx=Math.ceil(20/this.int_align)*this.int_align; |
251 | if (this.rrd_align==32) { | 297 | this.rra_def_el_size=Math.ceil((this.row_cnt_idx+2*this.int_width)/this.unival_align)*this.unival_align+10*this.unival_width; |
252 | this.rra_def_el_size=108; | ||
253 | this.row_cnt_idx=20; | ||
254 | } else { | ||
255 | this.rra_def_el_size=120; | ||
256 | this.row_cnt_idx=24; | ||
257 | } | ||
258 | 298 | ||
259 | this.live_head_idx=this.rra_def_idx+this.rra_def_el_size*this.rra_cnt; | 299 | this.live_head_idx=this.rra_def_idx+this.rra_def_el_size*this.rra_cnt; |
260 | // time_t last_up, int last_up_usec | 300 | // time_t last_up, int last_up_usec |
261 | if (this.rrd_align==32) { | 301 | this.live_head_size=2*this.int_width; |
262 | this.live_head_size=8; | ||
263 | } else { | ||
264 | this.live_head_size=16; | ||
265 | } | ||
266 | 302 | ||
267 | this.pdp_prep_idx=this.live_head_idx+this.live_head_size; | 303 | this.pdp_prep_idx=this.live_head_idx+this.live_head_size; |
268 | // char last_ds[30], unival scratch[10] | 304 | // char last_ds[30], unival scratch[10] |
269 | this.pdp_prep_el_size=112; | 305 | this.pdp_prep_el_size=Math.ceil(30/this.unival_align)*this.unival_align+10*this.unival_width; |
270 | 306 | ||
271 | this.cdp_prep_idx=this.pdp_prep_idx+this.pdp_prep_el_size*this.ds_cnt; | 307 | this.cdp_prep_idx=this.pdp_prep_idx+this.pdp_prep_el_size*this.ds_cnt; |
272 | // unival scratch[10] | 308 | // unival scratch[10] |
273 | this.cdp_prep_el_size=80; | 309 | this.cdp_prep_el_size=10*this.unival_width; |
274 | 310 | ||
275 | this.rra_ptr_idx=this.cdp_prep_idx+this.cdp_prep_el_size*this.ds_cnt*this.rra_cnt; | 311 | this.rra_ptr_idx=this.cdp_prep_idx+this.cdp_prep_el_size*this.ds_cnt*this.rra_cnt; |
276 | // uint cur_row | 312 | // uint cur_row |
277 | if (this.rrd_align==32) { | 313 | this.rra_ptr_el_size=1*this.int_width; |
278 | this.rra_ptr_el_size=4; | 314 | |
279 | } else { | ||
280 | this.rra_ptr_el_size=8; | ||
281 | } | ||
282 | |||
283 | this.header_size=this.rra_ptr_idx+this.rra_ptr_el_size*this.rra_cnt; | 315 | this.header_size=this.rra_ptr_idx+this.rra_ptr_el_size*this.rra_cnt; |
284 | } | 316 | } |
285 | 317 | ||
@@ -325,7 +357,7 @@ RRDHeader.prototype.getDSbyIdx = function(idx) { | |||
325 | return new RRDDS(this.rrd_data,this.ds_def_idx+this.ds_el_size*idx,idx); | 357 | return new RRDDS(this.rrd_data,this.ds_def_idx+this.ds_el_size*idx,idx); |
326 | } else { | 358 | } else { |
327 | throw RangeError("DS idx ("+ idx +") out of range [0-" + this.ds_cnt +")."); | 359 | throw RangeError("DS idx ("+ idx +") out of range [0-" + this.ds_cnt +")."); |
328 | } | 360 | } |
329 | } | 361 | } |
330 | RRDHeader.prototype.getDSbyName = function(name) { | 362 | RRDHeader.prototype.getDSbyName = function(name) { |
331 | for (var idx=0; idx<this.ds_cnt; idx++) { | 363 | for (var idx=0; idx<this.ds_cnt; idx++) { |
@@ -344,20 +376,23 @@ RRDHeader.prototype.getRRAInfo = function(idx) { | |||
344 | if ((idx>=0) && (idx<this.rra_cnt)) { | 376 | if ((idx>=0) && (idx<this.rra_cnt)) { |
345 | return new RRDRRAInfo(this.rrd_data, | 377 | return new RRDRRAInfo(this.rrd_data, |
346 | this.rra_def_idx+idx*this.rra_def_el_size, | 378 | this.rra_def_idx+idx*this.rra_def_el_size, |
347 | this.rrd_align,this.rra_def_row_cnts[idx],this.pdp_step, | 379 | this.int_align,this.rra_def_row_cnts[idx],this.pdp_step, |
348 | idx); | 380 | idx); |
349 | } else { | 381 | } else { |
350 | throw RangeError("RRA idx ("+ idx +") out of range [0-" + this.rra_cnt +")."); | 382 | throw RangeError("RRA idx ("+ idx +") out of range [0-" + this.rra_cnt +")."); |
351 | } | 383 | } |
352 | } | 384 | } |
353 | 385 | ||
354 | // ============================================================ | 386 | // ============================================================ |
355 | // RRDFile class | 387 | // RRDFile class |
356 | // Given a BinaryFile, gives access to the RRD archive fields | 388 | // Given a BinaryFile, gives access to the RRD archive fields |
357 | // | 389 | // |
358 | // Arguments: | 390 | // Arguments: |
359 | // bf must be an object compatible with the BinaryFile interface | 391 | // bf must be an object compatible with the BinaryFile interface |
360 | function RRDFile(bf) { | 392 | // file_options - currently no semantics... introduced for future expandability |
393 | function RRDFile(bf,file_options) { | ||
394 | this.file_options=file_options; | ||
395 | |||
361 | var rrd_data=bf | 396 | var rrd_data=bf |
362 | 397 | ||
363 | this.rrd_header=new RRDHeader(rrd_data); | 398 | this.rrd_header=new RRDHeader(rrd_data); |
@@ -396,7 +431,7 @@ function RRDFile(bf) { | |||
396 | } | 431 | } |
397 | 432 | ||
398 | this.getRRA = function(idx) { | 433 | this.getRRA = function(idx) { |
399 | var rra_info=this.rrd_header.getRRAInfo(idx); | 434 | rra_info=this.rrd_header.getRRAInfo(idx); |
400 | return new RRDRRA(rrd_data, | 435 | return new RRDRRA(rrd_data, |
401 | this.rrd_header.rra_ptr_idx+idx*this.rrd_header.rra_ptr_el_size, | 436 | this.rrd_header.rra_ptr_idx+idx*this.rrd_header.rra_ptr_el_size, |
402 | rra_info, | 437 | rra_info, |