KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > analyser > View


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2003 France Telecom R&D
4 * Copyright (C) 2003 INRIA
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * CLIF $Name: $
21 *
22 * Contact: clif@objectweb.org
23 */

24
25
26 /**
27  *
28  * @author Damien Croizer
29  */

30
31
32 package org.objectweb.clif.analyser;
33
34 import java.io.*;
35 import java.util.*;
36 import org.objectweb.clif.analyser.api.AnalyserControl;
37
38
39 public class View
40 {
41
42     // a View contain all the data of th archive.clif, according to 7 parameters: the testId, the blade,
43
//the virtual client (numthread), two parameters for the type of the data (paramX for X axis representation...), and two dates.
44
//a View also take a name and got a result which is a string that's is written under the graph in the manual analyzer GUI
45
private String JavaDoc name;
46     private String JavaDoc testId;
47     private String JavaDoc blade;
48     private int numthread;
49     private String JavaDoc paramX;
50     private String JavaDoc paramY;
51     private long datedebut;
52     private long datefin;
53     private String JavaDoc result;
54     private int option;
55     
56     public View()
57     {
58     }
59
60     public View(String JavaDoc name,String JavaDoc testId,String JavaDoc bladename,int numthread,String JavaDoc paramX,String JavaDoc paramY,long datedebut, long datefin)
61     {
62     }
63
64  
65     // the creation of an object View produce a file named "name.view" in a repertory "vues"
66
public View(String JavaDoc name,String JavaDoc testId,String JavaDoc bladename,int numthread,String JavaDoc paramX,String JavaDoc paramY,long datedebut, long datefin, int option){
67     //creation of the object
68
this.name=name;
69     this.testId=testId;
70     this.blade=bladename;
71     this.numthread=numthread;
72     this.paramX=paramX;
73     this.paramY=paramY;
74     this.datedebut=datedebut;
75     this.datefin=datefin;
76     this.result = "" ;
77     this.option = option;
78     //creation of the file
79
//for this moment, only graphs with testing time on the X axis is allowed
80
if(paramX.equals("Testing time")) CreerfctTesttime(name,testId,bladename,numthread,paramX,paramY,datedebut,datefin,option);
81     }
82
83     public String JavaDoc getName() { return this.name; }
84     public String JavaDoc getTestId() { return this.testId; }
85     public String JavaDoc getNommachine() { return this.blade; }
86     public int getNumthread() { return this.numthread; }
87     public String JavaDoc getParamX() { return this.paramX; }
88     public String JavaDoc getParamY() { return this.paramY; }
89     public long getDatedebut() { return this.datedebut; }
90     public long getDatefin() { return this.datefin; }
91     public String JavaDoc getResult() { return this.result; }
92
93     public void setName(String JavaDoc name) { this.name = name; }
94     public void setTestId(String JavaDoc testId) { this.testId = testId; }
95     public void setNommachine(String JavaDoc bladename) { this.blade = bladename; }
96     public void setNumthread(int numthread) { this.numthread = numthread; }
97     public void setParamX(String JavaDoc paramX) { this.paramX = paramX; }
98     public void setParamY(String JavaDoc paramY) { this.paramY = paramY; }
99     public void setDatedebut(long datedebut) { this.datedebut = datedebut; }
100     public void setDatefin(long datefin) { this.datefin = datefin; }
101     public void setResult(String JavaDoc result) { this.result = this.result +"\n" +result; }
102
103
104
105
106
107
108     //this function extract from the archive.clif the data corresponding to the user selection
109
//the file "name.view" contain 3 columns of values representing values of the X parameter selected by the user
110
//(only testing time at this time), the values of the Y parameters chosen by the user (action, cpu, ...),
111
//and the date of the registration of each values in the third column.
112
public void CreerfctTesttime(String JavaDoc name,String JavaDoc testId,String JavaDoc bladename,int numthread,String JavaDoc paramX,String JavaDoc paramY,long datedebut, long datefin, int option)
113     {
114
115     FileInputStream fileInput;
116     FileOutputStream fileoutput;
117         BufferedReader file ;
118     PrintStream fileout;
119     StringTokenizer st;
120     String JavaDoc line = null ;
121     int[] numColonne = new int[8];
122     int i=0;
123     int[] regul = new int[2];
124     long tempdate =0;
125     String JavaDoc tempstring1 = null;
126     int tempint = 0;
127     String JavaDoc entete = null;
128     long unitoftime = 0;
129     long temptime = 0;
130     int compteur=0;
131
132     
133     if(option == 1) unitoftime = 1000; //means counting the number paramY in 1 second
134
else if(option == 2) unitoftime = 10000; //means counting the number paramY in 10 second
135
else if(option == 3) unitoftime = 60000; //means counting the number paramY in 1 minute
136
else if(option == 4) unitoftime = -1; //means return the field response time of each paramY
137

138     try {
139         
140         fileInput = new FileInputStream("report/"+testId + "/archive.clif");
141         fileoutput = new FileOutputStream("report/"+testId + "/vues/" + name + ".view");
142         file = new BufferedReader(new InputStreamReader(fileInput));
143         fileout = new PrintStream(fileoutput);
144
145
146         //each file "name.view" begins with the following line that permit to retrieve all the object view by their file
147
entete = "#|"+name+"|"+testId+"|testing time|"+paramY+"|"+bladename+"|"+numthread+"|"+datedebut+"|"+datefin ;
148         fileout.println(entete);
149         line = file.readLine() ;
150         while(line != null)
151         {
152             st = new StringTokenizer(line,";") ;
153             tempdate = (new Integer JavaDoc(st.nextToken())).intValue() ;
154             if ((tempdate >= datedebut)&&(tempdate <= datefin))
155             {
156                 if( (unitoftime!=-1) && (tempdate > unitoftime + temptime) )
157                 {
158                     if(temptime!=0)
159                     {
160                         fileout.println(tempdate +"\t"+ compteur + "\t" +tempdate);
161                         compteur=0;
162                     }
163                     temptime = tempdate;
164
165                 }
166                 tempstring1 = st.nextToken() ;
167                 if(tempstring1.equals("action"))
168                 {
169                     tempstring1 = st.nextToken() ;
170                     if(tempstring1.matches(bladename))
171                     {
172                         tempint = (new Integer JavaDoc(st.nextToken())).intValue() ;
173                         if((numthread == -1) || (tempint == numthread))
174                         {
175                             st.nextToken();st.nextToken();st.nextToken();
176                             tempint = (new Integer JavaDoc(st.nextToken())).intValue();
177                             if(st.nextToken().matches(paramY)){
178                             if(option==4){
179                                 fileout.println(tempdate +"\t"+ tempint + "\t" +tempdate);
180                             }
181                             else compteur++;
182                             }
183                         }
184                     }
185                     
186                 }
187             
188             }
189                         
190             line = file.readLine() ;
191         }
192     }
193     catch (Exception JavaDoc e) {
194         e.printStackTrace() ;
195         System.exit(0) ;
196     }
197
198
199     }
200
201
202
203     //this function is not used at the moment
204
//it's the generic function that permit to create the file "name.view" with the good data, when
205
//the param X is not the testing time
206
//TO DO ... adapt the graph Panel for the representation of "nuages de points"
207
public void Creerfct_generic(String JavaDoc name,String JavaDoc testId,String JavaDoc servername,int numthread,int paramX,int paramY,long datedebut, long datefin)
208     {
209
210     FileInputStream fileInput;
211     FileOutputStream fileoutput;
212         BufferedReader file ;
213     PrintStream fileout;
214     StringTokenizer st;
215     String JavaDoc line = null ;
216     int[] numColonne = new int[8];
217     int i=0;
218     int[] regul = new int[2];
219     long tempdate =0;
220     String JavaDoc tempstring = null;
221     int tempint = 0;
222     String JavaDoc entete = null;
223     
224     try {
225         
226         fileInput = new FileInputStream(testId + "_rapport/archive.clif");
227         fileoutput = new FileOutputStream(testId + "_rapport/vues/" + name + ".view");
228         file = new BufferedReader(new InputStreamReader(fileInput));
229         fileout = new PrintStream(fileoutput);
230
231         entete = "#|"+name+"|"+testId+"|0|"+paramY+"|"+servername+"|"+numthread+"|"+datedebut+"|"+datefin ;
232         fileout.println(entete);
233         line = file.readLine() ;
234         while(line != null)
235         {
236             st = new StringTokenizer(line,";") ;
237             tempdate = (new Integer JavaDoc(st.nextToken())).intValue() ;
238             if ((tempdate >= datedebut)&&(tempdate <= datefin))
239             {//ladate du fichier est dans l'intervalle d'etude
240
tempint = (new Integer JavaDoc(st.nextToken())).intValue() ;
241                 if(tempint == paramY)
242                 {//l'index correspond et on traite la ligne courante
243
tempstring = st.nextToken() ;
244                     if(true)//(servername == "toutes") || (tempstring == servername))
245
{ // la machine correspond a l'intervale d'etude
246
tempint = (new Integer JavaDoc(st.nextToken())).intValue() ;
247                         if((numthread == -1) || (tempint == numthread))
248                         { // le numero du thread correspond a l'intervale d'etude
249
//on construit le string a ecrire
250
tempstring = regul[0]+"\t";
251                             if(paramY == 4) {st.nextToken(); st.nextToken();}
252                             if(paramY == 7) st.nextToken();
253                             tempint = (new Integer JavaDoc(st.nextToken())).intValue() ;
254                             tempstring = tempstring + tempint + "\t" +tempdate;
255                             fileout.println(tempstring);
256                             regul[1] = tempint;
257                         }
258                     }
259                     
260                 }
261                 else if(tempint == paramX)
262                 {//l'index correspond et on traite la ligne courante
263
tempstring = st.nextToken() ;
264                     if(true)//(servername == "toutes") || (tempstring == servername))
265
{ // la machine correspond a l'intervale d'etude
266
tempint = (new Integer JavaDoc(st.nextToken())).intValue() ;
267                         if((numthread == -1) || (tempint == numthread))
268                         { // le numero du thread correspond a l'intervale d'etude
269
//on construit le string a ecrire
270
if(paramX == 4) {st.nextToken(); st.nextToken();}
271                             if(paramX == 7) st.nextToken();
272                             tempint = (new Integer JavaDoc(st.nextToken())).intValue() ;
273                             tempstring = tempint + "\t"+regul[1]+"\t" +tempdate;
274                             fileout.println(tempstring);
275                             regul[0] = tempint;
276                         }
277                     }
278                 }
279             }
280                         
281             line = file.readLine() ;
282         }
283     }
284     catch (Exception JavaDoc e) {
285         e.printStackTrace() ;
286         System.exit(0) ;
287     }
288
289
290     }
291
292
293
294
295
296     //this function is not used at this time
297
//it's the one which count the number of connected users
298
//TO DO... the use of alarms can indicate to the storage system all connection and deconnection of virtual users
299
// possible options : nbUser by 1 second, by ten second or by minute
300

301     public void CreerfctTesttime_Nbuser(String JavaDoc name,String JavaDoc testId,String JavaDoc servername,int numthread,long datedebut,long datefin)
302     {
303
304     FileInputStream fileInput;
305     FileOutputStream fileoutput;
306         BufferedReader file ;
307     PrintStream fileout;
308     StringTokenizer st;
309     String JavaDoc line = null ;
310     int i=0;
311     int compteur = 0;
312     long tempdate =0;
313     String JavaDoc tempstring = null;
314     String JavaDoc templine = null;
315     int tempint = 0;
316     String JavaDoc entete = null;
317
318        
319
320
321     try {
322         
323         fileInput = new FileInputStream(testId + "_rapport/archive.clif");
324         fileoutput = new FileOutputStream(testId + "_rapport/vues/" + name + ".view");
325
326         file = new BufferedReader(new InputStreamReader(fileInput));
327         fileout = new PrintStream(fileoutput);
328
329         entete = "#|"+name+"|"+testId+"|0|2|"+"|"+servername+"|"+numthread+"|"+datedebut+"|"+datefin ;
330         fileout.println(entete);
331         line = file.readLine() ;
332         while(line != null)
333         {
334
335             st = new StringTokenizer(line,";") ;
336             tempdate = (new Integer JavaDoc(st.nextToken())).intValue() ;
337             if ((tempdate >= datedebut)&&(tempdate <= datefin))
338             {//ladate du fichier est dans l'intervalle d'etude
339
tempint = (new Integer JavaDoc(st.nextToken())).intValue() ;
340                 if(tempint == 2)//index pour les notifications d'actions
341
{//l'index correspond et on traite la ligne courante
342
tempstring = st.nextToken() ;
343                     if(true)//(servername.equalsIgnoreCase("toutes")) || (tempstring == servername))
344
{ // la machine correspond a l'intervale d'etude
345
tempint = (new Integer JavaDoc(st.nextToken())).intValue() ;
346                         if((numthread == -1) || (tempint == numthread))
347                         { // le numero du thread correspond a l'intervale d'etude
348
//on construit le string a ecrire
349
templine = tempdate+"\t" ;
350                             st.nextToken();
351                             tempstring = st.nextToken();
352                             if(tempstring.equalsIgnoreCase("connection")) compteur++;
353                             if(tempstring.equalsIgnoreCase("deconnection")) compteur--;
354                             templine = templine + compteur + "\t" + tempdate;
355                             fileout.println(templine);
356
357                         }
358                     }
359                 }
360             }
361                         
362             line = file.readLine() ;
363         }
364     }
365     catch (Exception JavaDoc e) {
366         e.printStackTrace() ;
367         System.exit(0) ;
368     }
369     }
370
371 }
372
Popular Tags