Debian Codegraph @

tcl/ex/empweb/modelCDF

raw
1 #!/usr/bin/perl -w
2
3 open(IDLEI,"> idle.in.dat");
4 open(IDLEO,"> idle.out.dat");
5 open(REQI,"> request.in.dat");
6 open(REQO,"> request.out.dat");
7 open(NUMPAGEI,"> numpage.in.dat");
8 open(NUMPAGEO,"> numpage.out.dat");
9 open(PAGESIZEI,"> pagesize.in.dat");
10 open(PAGESIZEO,"> pagesize.out.dat");
11 open(SESSINTERI,"> sessinter.in.dat");
12 open(SESSINTERO,"> sessinter.out.dat");
13 open(SERVER,"> server.dat");
14 open(SERVERCDF,"> server.dat.cdf");
15
16
17 $numServer = 0;
18 $oldtimeI = 0;
19 $oldtimeO = 0;
20 $oldT = 0;
21 $oldclnt = "";
22
23 print "start processing model output\n";
24 while (<>) {
25 ($type,$fld1,$fld2,$fld3,$fld4,$fld5,$fld6,$fld7,$fld8,$fld9) = split(' ',$_);
26
27 $fld3="";
28 $fld7="";
29
30 if ($type eq "req") {
31 if ($fld2 eq $oldclnt) {
32 $idle = $fld5 - $oldT;
33 if ($fld4 eq "7") {
34 print IDLEI "$idle\n";
35 } else {
36 print IDLEO "$idle\n";
37 }
38 }
39 if ($fld4 eq "7") {
40 print REQI "$fld8\n";
41 print PAGESIZEI "$fld9\n";
42 } else {
43 print REQO "$fld8\n";
44 print PAGESIZEO "$fld9\n";
45 $server[$numServer] = $fld4;
46 $numServer++;
47 }
48 $oldclnt = $fld2;
49 $oldT = $fld5;
50 }
51 if ($type eq "Session") {
52 if ($fld1 eq "Inbound") {
53 print NUMPAGEI "$fld4\n";
54 $inter = $fld6 - $oldtimeI;
55 print SESSINTERI "$inter\n";
56 $oldtimeI = $fld6;
57 }
58 if ($fld1 eq "Outbound") {
59 print NUMPAGEO "$fld4\n";
60 $inter = $fld6 - $oldtimeO;
61 print SESSINTERO "$inter\n";
62 $oldtimeO = $fld6;
63 }
64 }
65 }
66
67 print "sort array\n";
68 @serverSorted = sort @server;
69 print "done sorting\n";
70
71 $old = "";
72 $serverCnt = 1;
73 $ns = 0;
74 $nsSum = 0;
75 foreach $j (0 .. $#serverSorted) {
76 if ($serverSorted[$j] ne $old) {
77 if ($old ne "") {
78 print SERVER "$serverCnt\n";
79 $svr[$ns] = $serverCnt;
80 $ns++;
81 $nsSum = $nsSum + $serverCnt;
82 $serverCnt = 1;
83 }
84 }
85 else {
86 $serverCnt++;
87 }
88 $old = $serverSorted[$j];
89 }
90 print SERVER "$serverCnt\n";
91 $svr[$ns] = $serverCnt;
92 $nsSum = $nsSum + $serverCnt;
93
94 @svrS = sort numerically @svr;
95
96 $tmp = 0;
97 foreach $j (0 .. $#svrS) {
98 $tmp = $tmp + $svrS[$j];
99 $prob = $tmp/$nsSum;
100 $j1 = $j+1;
101 print SERVERCDF "$j1 $tmp $prob\n";
102 }
103
104 close(IDLEI);
105 close(IDLEO);
106 close(REQI);
107 close(REQO);
108 close(NUMPAGEI);
109 close(NUMPAGEO);
110 close(PAGESIZEI);
111 close(PAGESIZEO);
112 close(SESSINTERI);
113 close(SESSINTERO);
114 close(SERVER);
115 close(SERVERCDF);
116
117 #compute CDF
118 &outputCDF(1,1,1,"request.in.dat");
119 &outputCDF(1,1,1,"request.out.dat");
120 &outputCDF(1,1,1,"numpage.in.dat");
121 &outputCDF(1,1,1,"numpage.out.dat");
122 &outputCDF(1,1,1,"pagesize.in.dat");
123 &outputCDF(1,1,1,"pagesize.out.dat");
124 &outputCDF(0,0.01,1,"sessinter.in.dat");
125 &outputCDF(0,0.01,1,"sessinter.out.dat");
126 &outputCDF(1,0.1,1,"idle.in.dat");
127 &outputCDF(1,0.1,1,"idle.out.dat");
128
129 sub numerically { $a <=> $b; }
130
131
132 sub outputCDF {
133
134 local($cur_epoch,$incr,$dividend,$tfile) = @_;
135
136 local(@data);
137 local(@dataS);
138 local(@epoch);
139 local(@cum);
140
141 open(ORIG,$tfile);
142 $tfileS = join('.',$tfile,"cdf");
143 $newtfile = join(' ',">",$tfileS);
144 open(CDF,$newtfile);
145
146 $count = 0;
147 $cur_time = 0;
148
149 $i = 0;
150 while ($line = <ORIG>) {
151 chop $line;
152 $data[$i] = $line;
153 $i++;
154 }
155
156 close(ORIG);
157
158 if ($i eq 0) { exit; }
159
160
161 @dataS = sort numerically @data;
162
163 $i = 0;
164 $sum = 0;
165
166 foreach $j (0 .. $#dataS) {
167
168 $cur_time = $dataS[$j];
169
170 if ($cur_time > $cur_epoch) {
171 while ($cur_epoch < $cur_time) {
172
173 $epoch[$i] = $cur_epoch;
174 $sum = $sum + $count;
175 $cum[$i] = $sum;
176 $i++;
177
178 $cur_epoch = $cur_epoch + $incr;
179 $count=0;
180 }
181 if ($cur_time <= $cur_epoch) {
182 $count = 1;
183 } else {
184 $count = 0;
185 }
186 } else {
187 $count++;
188 }
189
190 }
191
192 $epoch[$i] = $cur_epoch;
193 $sum = $sum + $count;
194 $cum[$i] = $sum;
195
196 $oldcum = 0;
197 foreach $j (0 .. $#epoch) {
198 $prob = $cum[$j]/$cum[$#cum];
199 $e = $epoch[$j]/$dividend;
200 if ($cum[$j] ne $oldcum) {
201 print CDF "$e $cum[$j] $prob\n";
202 }
203 $oldcum = $cum[$j];
204 }
205
206 close(CDF);
207 }
208