1 #! @PERL@
3 #makes things work when run without install
4 use lib qw( ../bindings/perl-piped/blib/lib ../lib/perl );
6 #makes programm work AFTER install
7 use lib qw( @prefix@/lib/perl );
9 use RRDp;
11 # this simpulates a standard mrtg-2.x setup ... we can use this to
12 # compare performance ...
14 $main::DEBUG=0;
15 $STEP = 300;
16 $RUNS = 12*24*30*6;
17 $GRUNS = 20;
18 $RRD = "piped-demo.rrd";
19 $SVG = "piped-demo.svg";
20 $PNG = "piped-demo.png";
22 # some magic to find the correct rrdtol executable
23 if ( -x "@prefix@/bin/rrdtool") {
24 RRDp::start "@prefix@/bin/rrdtool";
25 } elsif ( -x "../bin/rrdtool") {
26 RRDp::start "../bin/rrdtool";
27 } else {
28 RRDp::start "../src/rrdtool";
29 }
31 print "* Creating RRD with properties equivalent to mrtg-2.x logfile\n\n";
33 $START = time()-$RUNS*$STEP;
35 RRDp::cmd "create $RRD -b $START -s $STEP
36 DS:in:GAUGE:400:U:U
37 DS:out:GAUGE:400:U:U
38 RRA:AVERAGE:0.5:1:600
39 RRA:AVERAGE:0.5:6:600
40 RRA:MAX:0.5:6:600
41 RRA:AVERAGE:0.5:24:600
42 RRA:MAX:0.5:24:600
43 RRA:AVERAGE:0.5:144:600
44 RRA:MAX:0.5:144:600";
46 $answer = RRDp::read;
47 ($user,$sys,$real) = ($RRDp::user,$RRDp::sys,$RRDp::real);
49 print "* Filling RRD with $RUNS Values. One moment please ...\n";
50 print " If you are running over NFS this will take *MUCH* longer\n\n";
52 for ($i=$START+1;
53 $i<$START+$STEP*$RUNS;
54 $i+=$STEP+int((rand()-0.5)*7)){
56 $line = "update $RRD $i:".int(rand(100000)).":".int(rand(100000));
57 RRDp::cmd $line;
58 $answer = RRDp::read;
59 }
61 ($user1,$sys1,$real1) = ($RRDp::user,$RRDp::sys,$RRDp::real);
63 printf "-- performance analysis Update test\n".
64 " usr/upd: %1.5fs sys/upd: %1.5fs real/upd: %1.5fs upd/sec: %1.0f\n",
65 ($user1-$user)/($RUNS), ($sys1-$sys)/($RUNS),
66 ($real1-$real)/($RUNS), ($RUNS)/($real1-$real);
67 print "\n";
68 # creating some graphs
70 print "* Creating $GRUNS SVG graphs: $SVG\n\n";
71 $now = time;
72 $localtime = scalar localtime(time);
73 $localtime = s/:/\\:/g;
74 for ($i=0;$i<$GRUNS;$i++) {
75 RRDp::cmd "graph $SVG ", "--title 'Test GRAPH' ",
76 "--imgformat SVG --height 150 --vertical-label 'Dummy Units' ".
77 "--start now".(-$RUNS*$STEP),
78 "--color ARROW#bfbfbf",
79 "DEF:alpha=$RRD:in:AVERAGE",
80 "DEF:beta=$RRD:out:AVERAGE",
81 "CDEF:calc=alpha,beta,+,1.5,/",
82 "AREA:alpha#0022e9:Alpha",
83 "STACK:beta#00b871:Beta",
84 "STACK:calc#ff0091:Calc\\j",
85 "PRINT:alpha:AVERAGE:'Average Alpha\\: %1.2lf %S'",
86 "PRINT:alpha:MIN:'Min Alpha\\: %1.2lf %S'",
87 "PRINT:alpha:MAX:'Max Alpha\\: %1.2lf %S'",
88 "GPRINT:calc:AVERAGE:'Average calc\\: %1.2lf %S\\r'",
89 "GPRINT:calc:MIN:'Min calc\\: %1.2lf %S'",
90 "GPRINT:calc:MAX:'Max calc\\: %1.2lf %S'",
91 "VRULE:".($now-3600)."#008877:'60 Minutes ago'",
92 "COMMENT:'\\s'",
93 "COMMENT:'Graph created on\\: ".$localtime."\\c'";
95 $answer = RRDp::read;
96 }
97 ($user2,$sys2,$real2) = ($RRDp::user,$RRDp::sys,$RRDp::real);
99 print "ANSWER:\n$$answer";
101 printf "\n-- average Time for one Graph\n".
102 " usr/grf: %1.5fs sys/grf: %1.5fs real/grf: %1.5fs graphs/sec: %1.2f\n",
103 ($user2-$user1)/$GRUNS,
104 ($sys2-$sys1)/$GRUNS,
105 ($real2-$real1)/$GRUNS,
106 $GRUNS/($real2-$real1);
108 print "\n\n* Creating $GRUNS PNG graphs: $PNG\n\n";
110 $now = time;
111 ($user1,$sys1,$real1) = ($RRDp::user,$RRDp::sys,$RRDp::real);
112 for ($i=0;$i<$GRUNS;$i++) {
113 RRDp::cmd "graph $PNG ", "--title 'Test GRAPH' ",
114 "--imgformat PNG --height 150 --vertical-label 'Dummy Units' ".
115 "--start now".(-$RUNS*$STEP),
116 "--color ARROW#bfbfbf",
117 "DEF:alpha=$RRD:in:AVERAGE",
118 "DEF:beta=$RRD:out:AVERAGE",
119 "CDEF:calc=alpha,beta,+,1.5,/",
120 "AREA:alpha#0022e9:Alpha",
121 "STACK:beta#00b871:Beta",
122 "STACK:calc#ff0091:Calc\\j",
123 "PRINT:alpha:AVERAGE:'Average Alpha\\: %1.2lf %S'",
124 "PRINT:alpha:MIN:'Min Alpha\\: %1.2lf %S'",
125 "PRINT:alpha:MAX:'Max Alpha\\: %1.2lf %S'",
126 "GPRINT:calc:AVERAGE:'Average calc\\: %1.2lf %S\\r'",
127 "GPRINT:calc:MIN:'Min calc\\: %1.2lf %S'",
128 "GPRINT:calc:MAX:'Max calc\\: %1.2lf %S'",
129 "VRULE:".($now-3600)."#008877:'60 Minutes ago'",
130 "COMMENT:'\\s'",
131 "COMMENT:'Graph created on\\: ".localtime(time())."\\c'";
133 $answer = RRDp::read;
134 }
135 ($user2,$sys2,$real2) = ($RRDp::user,$RRDp::sys,$RRDp::real);
137 print "ANSWER:\n$$answer";
139 printf "\n-- average Time for one PNG Graph\n".
140 " usr/grf: %1.5fs sys/grf: %1.5fs real/grf: %1.5fs".
141 " graphs/sec: %1.2f\n\n",
142 ($user2-$user1)/$GRUNS,
143 ($sys2-$sys1)/$GRUNS,
144 ($real2-$real1)/$GRUNS,
145 $GRUNS/($real2-$real1);
147 RRDp::end;