14 * rrd_tool.h includes config.h, but at least on Ubuntu Breezy Badger
15 * 5.10 with gcc 4.0.2, the C preprocessor picks up Perl's config.h
16 * which is included from the Perl includes and never reads rrdtool's
17 * config.h. Without including rrdtool's config.h, this module does
18 * not compile, so include it here with an explicit path.
20 * Because rrdtool's config.h redefines VERSION which is originally
21 * set via Perl's Makefile.PL and passed down to the C compiler's
22 * command line, save the original value and reset it after the
25 #define VERSION_SAVED VERSION
28 #include "../../rrd_config.h"
30 #include "../../src/rrd_tool.h"
32 #define VERSION VERSION_SAVED
35 #define rrdcode(name) \
36 argv = (char **) malloc((items+1)*sizeof(char *));\
38 for (i = 0; i < items; i++) { \
40 char *handle= SvPV(ST(i),len);\
41 /* actually copy the data to make sure possible modifications \
42 on the argv data does not backfire into perl */ \
43 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \
44 strcpy(argv[i+1],handle); \
47 RETVAL=name(items+1,argv); \
48 for (i=0; i < items; i++) {\
53 if (rrd_test_error()) XSRETURN_UNDEF;
55 #define hvs(VAL) hv_store_ent(hash, sv_2mortal(newSVpv(data->key,0)),VAL,0)
57 #define rrdinfocode(name) \
58 /* prepare argument list */ \
59 argv = (char **) malloc((items+1)*sizeof(char *)); \
61 for (i = 0; i < items; i++) { \
63 char *handle= SvPV(ST(i),len); \
64 /* actually copy the data to make sure possible modifications \
65 on the argv data does not backfire into perl */ \
66 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \
67 strcpy(argv[i+1],handle); \
70 data=name(items+1, argv); \
71 for (i=0; i < items; i++) { \
75 if (rrd_test_error()) XSRETURN_UNDEF; \
79 /* the newSV will get copied by hv so we create it as a mortal \
80 to make sure it does not keep hanging round after the fact */ \
81 switch (data->type) { \
83 if (isnan(data->value.u_val)) \
86 hvs(newSVnv(data->value.u_val)); \
89 hvs(newSViv(data->value.u_int)); \
92 hvs(newSViv(data->value.u_cnt)); \
95 hvs(newSVpv(data->value.u_str,0)); \
98 hvs(newSVpv(data->value.u_blo.ptr,data->value.u_blo.size)); \
103 rrd_info_free(save); \
104 RETVAL = newRV_noinc((SV*)hash);
107 * should not be needed if libc is linked (see ntmake.pl)
110 #define malloc malloc
111 #define realloc realloc
116 MODULE = RRDs PACKAGE = RRDs PREFIX = rrd_
119 #ifdef MUST_DISABLE_SIGFPE
120 signal(SIGFPE,SIG_IGN);
122 #ifdef MUST_DISABLE_FPMASK
129 if (! rrd_test_error()) XSRETURN_UNDEF;
130 RETVAL = newSVpv(rrd_get_error(),0);
202 argv = (char **) malloc((items+1)*sizeof(char *));
204 for (i = 0; i < items; i++) {
206 char *handle = SvPV(ST(i),len);
207 /* actually copy the data to make sure possible modifications
208 on the argv data does not backfire into perl */
209 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
210 strcpy(argv[i+1],handle);
213 rrd_graph(items+1,argv,&calcpr,&xsize,&ysize,NULL,&ymin,&ymax);
214 for (i=0; i < items; i++) {
219 if (rrd_test_error()) {
221 for(i=0;calcpr[i];i++)
222 rrd_freemem(calcpr[i]);
227 for(i=0;calcpr[i];i++){
228 av_push(retar,newSVpv(calcpr[i],0));
229 rrd_freemem(calcpr[i]);
234 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
235 PUSHs(sv_2mortal(newSViv(xsize)));
236 PUSHs(sv_2mortal(newSViv(ysize)));
243 unsigned long step, ds_cnt,i,ii;
244 rrd_value_t *data,*datai;
247 AV *retar,*line,*names;
249 argv = (char **) malloc((items+1)*sizeof(char *));
251 for (i = 0; i < items; i++) {
253 char *handle= SvPV(ST(i),len);
254 /* actually copy the data to make sure possible modifications
255 on the argv data does not backfire into perl */
256 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
257 strcpy(argv[i+1],handle);
260 rrd_fetch(items+1,argv,&start,&end,&step,&ds_cnt,&ds_namv,&data);
261 for (i=0; i < items; i++) {
265 if (rrd_test_error()) XSRETURN_UNDEF;
266 /* convert the ds_namv into perl format */
268 for (ii = 0; ii < ds_cnt; ii++){
269 av_push(names,newSVpv(ds_namv[ii],0));
270 rrd_freemem(ds_namv[ii]);
272 rrd_freemem(ds_namv);
273 /* convert the data array into perl format */
276 for (i = start+step; i <= end; i += step){
278 for (ii = 0; ii < ds_cnt; ii++){
279 av_push(line,(isnan(*datai) ? &PL_sv_undef : newSVnv(*datai)));
282 av_push(retar,newRV_noinc((SV*)line));
286 PUSHs(sv_2mortal(newSViv(start+step)));
287 PUSHs(sv_2mortal(newSViv(step)));
288 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
289 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
292 rrd_times(start, end)
296 rrd_time_value_t start_tv, end_tv;
297 char *parsetime_error = NULL;
298 time_t start_tmp, end_tmp;
301 if ((parsetime_error = rrd_parsetime(start, &start_tv))) {
302 rrd_set_error("start time: %s", parsetime_error);
305 if ((parsetime_error = rrd_parsetime(end, &end_tv))) {
306 rrd_set_error("end time: %s", parsetime_error);
309 if (rrd_proc_start_end(&start_tv, &end_tv, &start_tmp, &end_tmp) == -1) {
313 PUSHs(sv_2mortal(newSVuv(start_tmp)));
314 PUSHs(sv_2mortal(newSVuv(end_tmp)));
322 unsigned long step, col_cnt,row_cnt,i,ii;
323 rrd_value_t *data,*ptr;
324 char **argv,**legend_v;
325 AV *retar,*line,*names;
327 argv = (char **) malloc((items+1)*sizeof(char *));
329 for (i = 0; i < items; i++) {
331 char *handle = SvPV(ST(i),len);
332 /* actually copy the data to make sure possible modifications
333 on the argv data does not backfire into perl */
334 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
335 strcpy(argv[i+1],handle);
338 rrd_xport(items+1,argv,&xsize,&start,&end,&step,&col_cnt,&legend_v,&data);
339 for (i=0; i < items; i++) {
343 if (rrd_test_error()) XSRETURN_UNDEF;
345 /* convert the legend_v into perl format */
347 for (ii = 0; ii < col_cnt; ii++){
348 av_push(names,newSVpv(legend_v[ii],0));
349 rrd_freemem(legend_v[ii]);
351 rrd_freemem(legend_v);
353 /* convert the data array into perl format */
356 for (i = start+step; i <= end; i += step){
358 for (ii = 0; ii < col_cnt; ii++){
359 av_push(line,(isnan(*ptr) ? &PL_sv_undef : newSVnv(*ptr)));
362 av_push(retar,newRV_noinc((SV*)line));
367 PUSHs(sv_2mortal(newSViv(start+step)));
368 PUSHs(sv_2mortal(newSViv(end)));
369 PUSHs(sv_2mortal(newSViv(step)));
370 PUSHs(sv_2mortal(newSViv(col_cnt)));
371 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
372 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
378 rrd_info_t *data,*save;
383 rrdinfocode(rrd_info);
391 rrd_info_t *data,*save;
396 rrdinfocode(rrd_update_v);
404 rrd_info_t *data,*save;
409 rrdinfocode(rrd_graph_v);
432 rrdcode(rrd_restore);
445 rrdcode(rrd_flushcached);