*** empty log message ***
[dyninst.git] / visi / test / client1.C
1 #include "../h/visithread.h"
2
3 #define TESTMETRIC      "blah,blah blah,metric 3,metric 4,last metric"
4 #define TESTRESOURCE    "resource1/blah1/foo1,resource2/foo2,resource3"
5
6
7 main(int argc,char *argv[]){
8
9 int i=0;
10 int fd,pid;
11 visualizationUser *vup;
12 char **arg_list;
13 char temp[128], temp2[128];
14 int wch;
15
16 int done;
17 metricType *metrics;
18 metricType_Array mets;
19 resourceType *resources;
20 resourceType_Array res;
21 dataValue   *data;
22 dataValue_Array blah;
23 int mId,rId,bNum,nval;
24 float num,num2;
25 int nMets,nRes;
26 float bWidth;
27
28
29   if(argc < 2){
30     fprintf(stdout,"incorrect num arguments: client1 server_executable\n");
31     exit(-1);
32   }
33   fprintf(stderr,"in client\n");
34   arg_list = new char*[argc+1];
35   arg_list[i++] = strdup(argv[1]);
36   if(argc > 2){ 
37     sprintf(temp,"%s",TESTMETRIC);
38     arg_list[i++] = strdup(temp);
39     sprintf(temp,"%s",TESTRESOURCE);
40     arg_list[i++] = strdup(temp);
41   }
42   arg_list[i++] = 0;
43
44
45   fprintf(stderr,"in client before RPCprocessCreate\n");
46   fd = RPCprocessCreate(&pid, "localhost", "", argv[1],arg_list);
47   if (fd < 0) {
48     perror("process Create");
49     exit(-1);
50   }
51
52   
53   fprintf(stderr,"in client before new visualizationUser\n");
54   vup = new visualizationUser(fd,NULL,NULL);
55
56   fprintf(stderr,"in client before while loop\n");
57   done = 0;
58   while(!done){
59
60       // check for upcall
61       // these don't do anything yet 
62       if(RPC_readReady(fd))
63         vup->awaitResponce(-1);
64
65       wch = -1;
66       while((wch < 0) || (wch > 7)){
67         fprintf(stdout,"\n---------------------------------------------\n");
68         fprintf(stdout,"enter number of operation to perform:\n");
69         fprintf(stdout,"---------------------------------------------\n");
70         fprintf(stdout,"0:data values  1:fold    2:invalid m/r  3:add m/r\n");
71         fprintf(stdout,"4:new m/r      5:phase       6:print    7:quit\n");
72         fprintf(stdout,"---------------------------------------------\n\n");
73         scanf("%d",&wch);
74       }
75       switch(wch){
76         case 0:
77             fprintf(stdout,"\nSend Data values to server process:\n");   
78             fprintf(stdout,"enter number of dataValues\n");
79             scanf("%d",&nval);
80             data = (dataValue *)malloc(sizeof(dataValue)*nval);
81             for(i=0;i<nval;i++){
82               fprintf(stdout,"enter metricId (int)\n");   
83               scanf("%d",&data[i].metricId);
84               fprintf(stdout,"enter resourceId (int)\n");   
85               scanf("%d",&data[i].resourceId);
86               fprintf(stdout,"enter bucketNum (int)\n");   
87               scanf("%d",&data[i].bucketNum);
88               fprintf(stdout,"enter data value (float)\n");   
89               scanf("%f",&num);
90               data[i].data = num;
91             }
92
93             blah.data = data;
94             blah.count = nval;
95             vup->Data(blah);
96             free(data);
97             break;
98         case 1:
99             fprintf(stdout,"\nFold:\n");   
100             fprintf(stdout,"enter new bucket width value (float)\n");
101             scanf("%f",&num);
102             vup->Fold(num);
103             break;
104         case 2:
105             fprintf(stdout,"\nInvalidate Metric and Resources:\n");   
106             fprintf(stdout,"enter metricId (int)\n");   
107             scanf("%d",&mId);
108             fprintf(stdout,"enter resourceId (int)\n");   
109             scanf("%d",&rId);
110             vup->InvalidMR(mId,rId);
111             break;
112         case 3:
113             fprintf(stdout,"\nAdd Metrics and Resorces:\n");   
114             fprintf(stdout,"enter number of metrics (int)\n");
115             scanf("%d",&nMets);
116             metrics = (metricType *)malloc(sizeof(metricType)*nMets);
117             for(i=0;i<nMets;i++){
118              fprintf(stdout,"enter metric name (string), Id (int), units (string), and aggregate(0 or 1)\n");
119              scanf("%s%d%s%d",temp,&metrics[i].Id,temp2,&metrics[i].aggregate);
120              metrics[i].name = strdup(temp);
121              metrics[i].units = strdup(temp2);
122             }
123             mets.count = nMets;
124             mets.data = metrics;
125             fprintf(stdout,"enter number of resources  (int)\n");
126             scanf("%d",&nRes);
127             resources = (resourceType *)malloc(sizeof(resourceType)*nRes);
128             for(i=0;i<nRes;i++){
129              fprintf(stdout,"enter resources name (string), Id (int)\n");
130              scanf("%s%d",temp,&resources[i].Id);
131              resources[i].name = strdup(temp);
132             }
133             res.count = nRes;
134             res.data = resources;
135             fprintf(stdout,"enter numBuckets (int)\n");
136             scanf("%d",&bNum);
137             fprintf(stdout,"enter bucket width (float)\n");
138             scanf("%f",&bWidth);
139             vup->AddMetricsResources(mets,res,bWidth,bNum);
140             for(i=0;i<nMets;i++){
141               free(metrics[i].name);
142               free(metrics[i].units);
143             }
144             for(i=0;i<nRes;i++){
145               free(resources[i].name);
146             }
147             free(metrics);
148             free(resources);
149             break;
150         case 4:
151             fprintf(stdout,"\nNew Metrics and Resorces: not currently supported\n");   
152             fprintf(stdout,"enter number of metrics (int)\n");
153             scanf("%d",&nMets);
154             metrics = (metricType *)malloc(sizeof(metricType)*nMets);
155             for(i=0;i<nMets;i++){
156              fprintf(stdout,"enter metric name(string), Id (int), units(string), and aggregate (int 0 or 1)\n");
157              scanf("%s%d%s%d",temp,&metrics[i].Id,temp2,&metrics[i].aggregate);
158              metrics[i].name = strdup(temp);
159              metrics[i].units = strdup(temp2);
160             }
161             mets.count = nMets;
162             mets.data = metrics;
163             fprintf(stdout,"enter number of resources (int)\n");
164             scanf("%d",&nRes);
165             resources = (resourceType *)malloc(sizeof(resourceType)*nRes);
166             for(i=0;i<nRes;i++){
167              fprintf(stdout,"enter resources name (string), Id (int)\n");
168              scanf("%s%d",temp,&resources[i].Id);
169              resources[i].name = strdup(temp);
170             }
171             res.count = nRes;
172             res.data = resources;
173             vup->NewMetricsResources(mets,res);
174             for(i=0;i<nMets;i++){
175               free(metrics[i].name);
176               free(metrics[i].units);
177             }
178             for(i=0;i<nRes;i++){
179               free(resources[i].name);
180             }
181             free(metrics);
182             free(resources);
183             break;
184         case 5:
185             fprintf(stdout,"\nPhase:\n");   
186             fprintf(stdout,"enter phase name(string), begin(float), end(float)\n"); 
187             scanf("%s%f%f",temp,&num,&num2);
188             vup->Phase(num,num2,temp);
189             break;
190         case 6:
191             vup->Phase(3.4,4.5,"blah");
192             break;
193         case 7:
194             done = 1;
195             break;
196
197       }
198
199   }
200   for(i=0;i<argc;i++)
201     free(arg_list[i]);
202   delete [] arg_list;
203   delete(vup);
204
205 }