2 * Main loop for the default paradynd.
5 * Revision 1.12 1994/05/16 22:31:50 hollings
6 * added way to request unique resource name.
8 * Revision 1.11 1994/04/12 15:29:19 hollings
9 * Added samplingRate as a global set by an RPC call to control sampling
12 * Revision 1.10 1994/04/09 18:34:54 hollings
13 * Changed {pause,continue}Application to {pause,continue}AllProceses, and
14 * made the RPC interfaces use these. This makes the computation of pause
17 * Revision 1.9 1994/04/06 21:35:39 markc
18 * Added correct machine name reporting.
20 * Revision 1.8 1994/04/01 20:06:41 hollings
21 * Added ability to start remote paradynd's
23 * Revision 1.7 1994/03/31 01:57:27 markc
24 * Added support for pauseProcess, continueProcess. Added pvm interface code.
26 * Revision 1.6 1994/03/20 01:53:09 markc
27 * Added a buffer to each process structure to allow for multiple writers on the
28 * traceStream. Replaced old inst-pvm.C. Changed addProcess to return type
31 * Revision 1.5 1994/02/28 05:09:42 markc
32 * Added pvm hooks and ifdefs.
34 * Revision 1.4 1994/02/25 13:40:55 markc
35 * Added hooks for pvm support.
37 * Revision 1.3 1994/02/24 04:32:33 markc
38 * Changed header files to reflect igen changes. main.C does not look at the number of command line arguments now.
40 * Revision 1.2 1994/02/01 18:46:52 hollings
41 * Changes for adding perfConsult thread.
43 * Revision 1.1 1994/01/27 20:31:27 hollings
44 * Iinital version of paradynd speaking dynRPC igend protocol.
50 #include <sys/types.h>
54 #include "util/h/list.h"
55 #include "rtinst/h/rtinst.h"
65 #include "dyninstRPC.SRVR.h"
68 extern void controllerMainLoop();
69 extern void initLibraryFunctions();
72 static dynRPC *init_pvm_code(char *argv[], char *machine, int family,
73 int type, int well_known_socket, int flag);
74 static char machine_name[80];
79 // default to once a second.
80 float samplingRate = 1.0;
82 main(int argc, char *argv[])
84 int i, family, type, well_known_socket, flag;
88 initLibraryFunctions();
90 // process command line args passed in
91 // flag == 1 --> started by paradyn
92 assert (RPC_undo_arg_list (argc, argv, &machine, family, type,
93 well_known_socket, flag) == 0);
96 tp = init_pvm_code(argv, machine, family, type, well_known_socket, flag);
109 tp = new dynRPC(family, well_known_socket, type, machine,
111 } else if (pid > 0) {
112 printf("PARADYND %d\n", pid);
120 // already setup on this FD.
121 tp = new dynRPC(0, NULL, NULL);
126 // tell client about our metrics.
128 stuff = getMetricList();
129 for (i=0; i < stuff->count; i++) {
130 tp->newMetricCallback(stuff->elements[i].info);
131 if (tp->callErr < 0) {
132 printf("RPC error\n");
137 controllerMainLoop();
140 void dynRPC::addResource(String parent, String name)
143 extern resource findResource(char*);
145 pr = findResource(parent);
146 if (pr) (void) newResource(pr, NULL, name, 0.0, FALSE);
149 void dynRPC::coreProcess(int pid)
153 proc = processList.find((void *) pid);
157 String dynRPC::getStatus(int pid)
160 extern char *getProcessStatus(process *proc);
163 proc = processList.find((void *) pid);
166 sprintf (ret, "PID:%d not found for getStatus\n", pid);
170 return(getProcessStatus(proc));
174 // NOTE: This version of getAvailableMetrics assumes that new metrics are
175 // NOT added during execution.
177 metricInfo_Array dynRPC::getAvailableMetrics(void)
181 static metricInfo_Array metInfo;
186 stuff = getMetricList();
187 metInfo.count = stuff->count;
188 metInfo.data = (metricInfo*) calloc(sizeof(metricInfo), metInfo.count);
189 for (i=0; i < metInfo.count; i++) {
190 metInfo.data[i] = stuff->elements[i].info;
197 double dynRPC::getPredictedDataCost(String_Array focusString, String metric)
203 m = findMetric(metric);
204 l = findFocus(focusString.count, focusString.data);
206 val = guessCost(l, m);
211 void dynRPC::disableDataCollection(int mid)
214 extern void printResourceList(resourceList);
216 printf("disable of %s for RL =", getMetricName(mi->met));
217 printResourceList(mi->resList);
220 mi = allMIs.find((void *) mid);
226 int dynRPC::enableDataCollection(String_Array foucsString,String metric)
232 m = findMetric(metric);
233 l = findFocus(foucsString.count, foucsString.data);
235 id = startCollecting(l, m);
240 // not implemented yet.
242 void dynRPC::setSampleRate(double sampleInterval)
244 samplingRate = sampleInterval;
248 Boolean dynRPC::detachProgram(int program,Boolean pause)
250 return(detachProcess(program, pause));
254 // Continue all processes
256 void dynRPC::continueApplication()
258 continueAllProcesses();
262 // Continue a process
264 void dynRPC::continueProgram(int program)
266 struct List<process *> curr;
268 for (curr = processList; *curr; curr++) {
269 if ((*curr)->pid == pid) break;
272 continueProcess(*curr);
274 printf("Can't continue PID %d\n", program);
278 // Stop all processes
280 Boolean dynRPC::pauseApplication()
287 // Stop a single process
289 Boolean dynRPC::pauseProgram(int program)
291 struct List<process *> curr;
293 for (curr = processList; *curr; curr++) {
294 if ((*curr)->pid == program) break;
297 printf("Can't pause PID %d\n", program);
305 Boolean dynRPC::startProgram(int program)
307 continueAllProcesses();
312 // This is not implemented yet.
314 Boolean dynRPC::attachProgram(int pid)
320 // start a new program for the tool.
322 int dynRPC::addExecutable(int argc,String_Array argv)
324 return(addProcess(argc, argv.data));
329 init_pvm_code(char *argv[], char *machine, int family,
330 int type, int well_known_socket, int flag)
333 extern int PDYN_initForPVM (char **, char *, int, int, int, int);
335 assert(PDYN_initForPVM (argv, machine, family, type, well_known_socket,
338 assert(!gethostname(machine_name, 99));
340 // connect to paradyn
342 temp = new dynRPC(0, NULL, NULL);
345 temp = new dynRPC(family, well_known_socket, type, machine, NULL, NULL);
346 temp->reportSelf (machine_name, argv[0], getpid());
353 PDYND_report_to_paradyn (int pid, int argc, char **argv)
361 tp->newProgramCallbackFunc(pid, argc, sa, machine_name);