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