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