Added pvm hooks and ifdefs.
[dyninst.git] / paradynd / src / main.C
1 /*
2  * Main loop for the default paradynd.
3  *
4  * $Log: main.C,v $
5  * Revision 1.5  1994/02/28 05:09:42  markc
6  * Added pvm hooks and ifdefs.
7  *
8  * Revision 1.4  1994/02/25  13:40:55  markc
9  * Added hooks for pvm support.
10  *
11  * Revision 1.3  1994/02/24  04:32:33  markc
12  * Changed header files to reflect igen changes.  main.C does not look at the number of command line arguments now.
13  *
14  * Revision 1.2  1994/02/01  18:46:52  hollings
15  * Changes for adding perfConsult thread.
16  *
17  * Revision 1.1  1994/01/27  20:31:27  hollings
18  * Iinital version of paradynd speaking dynRPC igend protocol.
19  *
20  *
21  */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <sys/types.h>
25 #include <sys/time.h>
26 #include <assert.h>
27
28 #include "util/h/list.h"
29 #include "rtinst/h/rtinst.h"
30
31 #include "symtab.h"
32 #include "process.h"
33 #include "inst.h"
34 #include "instP.h"
35 #include "ast.h"
36 #include "util.h"
37 #include "dyninstP.h"
38 #include "metric.h"
39 #include "dyninstRPC.SRVR.h"
40
41 dynRPC *tp;
42 extern void controllerMainLoop();
43 extern void initLibraryFunctions();
44
45 static dynRPC *init_pvm_code();
46
47 main(int argc, char *argv[])
48 {
49     int i, family, type, well_known_socket, flag;
50     char *machine;
51     metricList stuff;
52
53     initLibraryFunctions();
54
55     // process command line args passed in
56     // flag == 1 --> started by paradyn
57     assert (RPC_undo_arg_list (argc, argv, &machine, family, type,
58                        well_known_socket, flag) == 0);
59
60 #ifdef PARADYND_PVM
61     tp = init_pvm_code();
62 #else
63     tp = new dynRPC(0, NULL, NULL);
64 #endif
65
66     //
67     // tell client about our metrics.
68     //
69     stuff = getMetricList();
70     for (i=0; i < stuff->count; i++) {
71         tp->newMetricCallback(stuff->elements[i].info);
72     }
73
74     controllerMainLoop();
75 }
76
77 void dynRPC::addResource(String parent, String name)
78 {
79     resource pr;
80     extern resource findResource(char*);
81
82     pr = findResource(parent);
83     if (pr) (void) newResource(pr, NULL, name, 0.0);
84 }
85
86 void dynRPC::coreProcess(int pid)
87 {
88     process *proc;
89
90     proc = processList.find((void *) pid);
91     dumpCore(proc);
92 }
93
94 String dynRPC::getStatus(int pid)
95 {
96     process *proc;
97     extern char *getProcessStatus(process *proc);
98
99     proc = processList.find((void *) pid);
100     return(getProcessStatus(proc));
101 }
102
103 //
104 // NOTE: This version of getAvailableMetrics assumes that new metrics are
105 //   NOT added during execution.
106 //
107 metricInfo_Array dynRPC::getAvailableMetrics(void)
108 {
109     int i;
110     static int inited;
111     static metricInfo_Array metInfo;
112
113     if (!inited) {
114         metricList stuff;
115
116         stuff = getMetricList();
117         metInfo.count = stuff->count;
118         metInfo.data = (metricInfo*) calloc(sizeof(metricInfo), metInfo.count);
119         for (i=0; i < metInfo.count; i++) {
120             metInfo.data[i] = stuff->elements[i].info;
121         }
122         inited = 1;
123     }
124     return(metInfo);
125 }
126
127 double dynRPC::getPredictedDataCost(String_Array focusString, String metric)
128 {
129     metric m;
130     double val;
131     resourceList l;
132
133     m = findMetric(metric);
134     l = findFocus(focusString.count, focusString.data);
135     if (!l) return(0.0);
136     val = guessCost(l, m);
137
138     return(val);
139 }
140
141 void dynRPC::disableDataCollection(int mid)
142 {
143     metricInstance mi;
144     extern void printResourceList(resourceList);
145
146     printf("disable of %s for RL =", getMetricName(mi->met));
147     printResourceList(mi->resList);
148     printf("\n");
149
150     mi = allMIs.find((void *) mid);
151     mi->disable();
152     allMIs.remove(mi);
153     delete(mi);
154 }
155
156 int dynRPC::enableDataCollection(String_Array foucsString,String metric)
157 {
158     int id;
159     metric m;
160     resourceList l;
161
162     m = findMetric(metric);
163     l = findFocus(foucsString.count, foucsString.data);
164     if (!l) return(-1);
165     id = startCollecting(l, m);
166     return(id);
167 }
168
169 //
170 // not implemented yet.
171 //
172 void dynRPC::setSampleRate(double sampleInterval)
173 {
174     return;
175 }
176
177 Boolean dynRPC::detachProgram(int program,Boolean pause)
178 {
179     return(detachProcess(program, pause));
180 }
181
182 //
183 // Continue program.  We really should make this work on a single pid.
184 //
185 void dynRPC::continueProgram(int program)
186 {
187     continueApplication();
188 }
189 //
190 // We really should make this work on a single pid.
191 //
192 Boolean dynRPC::pauseProgram(int program)
193 {
194     return(pauseApplication());
195 }
196
197 Boolean dynRPC::startProgram(int program)
198 {
199     continueApplication();
200     return(False);
201 }
202
203 //
204 // This is not implemented yet.
205 //
206 Boolean dynRPC::attachProgram(int pid)
207 {
208     return(FALSE);
209 }
210
211 //
212 // start a new program for the tool.
213 //
214 int dynRPC::addExecutable(int argc,String_Array argv)
215 {
216     return(addProcess(argc, argv.data));
217 }
218
219 #ifdef PARADYND_PVM
220 dynRPC *
221 init_pvm_code()
222 {
223   dynRPC *temp;
224
225   extern int PDYN_initForPVM (char **, char *, int, int, int, int);
226   extern int PDYN_initFds (dynRPC*);
227
228   assert (PDYN_initForPVM (argv, machine, family, type, well_known_socket,
229                            flag) == 0);
230
231   // connect to paradyn
232   if (flag == 1)
233     tp = new dynRPC(0, NULL, NULL);
234   else
235     {
236       tp = new dynRPC(family, well_known_socket, type, machine, NULL, NULL);
237       tp->reportSelf (machine, argv[0], getpid());
238       }
239 PDYN_initFds(tp);
240 }
241 #endif
242