Removed start slash from comments
[dyninst.git] / paradyn / src / DMthread / DMpublic.C
1
2 /*
3  * dataManagerImpl.C - provide the interface methods for the dataManager thread
4  *   remote class.
5  *
6  * $Log: DMpublic.C,v $
7  * Revision 1.37  1995/02/16 19:10:44  markc
8  * Removed start slash from comments
9  *
10  * Revision 1.36  1995/02/16  08:16:42  markc
11  * Changed Bool to bool
12  * Changed igen-xdr functions to use string/vectors rather than char igen-arrays
13  *
14  * Revision 1.35  1995/01/26  17:58:23  jcargill
15  * Changed igen-generated include files to new naming convention; fixed
16  * some bugs compiling with gcc-2.6.3.
17  *
18  * Revision 1.34  1994/11/09  18:39:36  rbi
19  * the "Don't Blame Me" commit
20  *
21  * Revision 1.33  1994/11/07  08:24:37  jcargill
22  * Added ability to suppress search on children of a resource, rather than
23  * the resource itself.
24  *
25  * Revision 1.32  1994/11/04  16:30:41  rbi
26  * added getAvailableDaemons()
27  *
28  * Revision 1.31  1994/11/02  11:46:21  markc
29  * Changed shadowing nam.
30  *
31  * Revision 1.30  1994/09/30  19:17:47  rbi
32  * Abstraction interface change.
33  *
34  * Revision 1.29  1994/09/22  00:56:05  markc
35  * Added const to args to addExecutable()
36  *
37  * Revision 1.28  1994/08/22  15:59:07  markc
38  * Add interface calls to support daemon definitions.
39  *
40  * Revision 1.27  1994/08/11  02:17:42  newhall
41  * added dataManager interface routine destroyPerformanceStream
42  *
43  * Revision 1.26  1994/08/08  20:15:20  hollings
44  * added suppress instrumentation command.
45  *
46  * Revision 1.25  1994/08/05  16:03:59  hollings
47  * more consistant use of stringHandle vs. char *.
48  *
49  * Revision 1.24  1994/07/25  14:55:37  hollings
50  * added suppress resource option.
51  *
52  * Revision 1.23  1994/07/14  23:45:54  hollings
53  * added hybrid cost model.
54  *
55  * Revision 1.22  1994/07/07  03:29:35  markc
56  * Added interface function to start a paradyn daemon
57  *
58  * Revision 1.21  1994/07/02  01:43:12  markc
59  * Removed all uses of type aggregation from enableDataCollection.
60  * The metricInfo structure now contains the aggregation operator.
61  *
62  * Revision 1.20  1994/06/27  21:23:29  rbi
63  * Abstraction-specific resources and mapping info
64  *
65  * Revision 1.19  1994/06/17  22:08:00  hollings
66  * Added code to provide upcall for resource batch mode when a large number
67  * of resources is about to be added.
68  *
69  * Revision 1.18  1994/06/14  15:23:17  markc
70  * Added support for aggregation.
71  *
72  * Revision 1.17  1994/06/02  16:08:16  hollings
73  * fixed duplicate naming problem for printResources.
74  *
75  * Revision 1.16  1994/05/31  19:11:33  hollings
76  * Changes to permit direct access to resources and resourceLists.
77  *
78  * Revision 1.15  1994/05/10  03:57:38  hollings
79  * Changed data upcall to return array of buckets.
80  *
81  * Revision 1.14  1994/05/09  20:56:22  hollings
82  * added changeState callback.
83  *
84  * Revision 1.13  1994/04/21  23:24:27  hollings
85  * removed process name from calls to RPC_make_arg_list.
86  *
87  * Revision 1.12  1994/04/20  15:30:11  hollings
88  * Added error numbers.
89  * Added data manager function to get histogram buckets.
90  *
91  * Revision 1.11  1994/04/19  22:08:38  rbi
92  * Added getTotValue method to get non-normalized metric data.
93  *
94  * Revision 1.10  1994/04/18  22:28:32  hollings
95  * Changes to create a canonical form of a resource list.
96  *
97  * Revision 1.9  1994/04/06  21:26:41  markc
98  * Added "include <assert.h>"
99  *
100  * Revision 1.8  1994/04/01  20:45:05  hollings
101  * Added calls to query bucketWidth and max number of bins.
102  *
103  * Revision 1.7  1994/03/31  01:39:01  markc
104  * Added dataManager continue/pause Process.
105  *
106  * Revision 1.6  1994/03/20  01:49:49  markc
107  * Gave process structure a buffer to allow multiple writers.  Added support
108  * to register name of paradyn daemon.  Changed addProcess to return type int.
109  *
110  * Revision 1.5  1994/03/08  17:39:34  hollings
111  * Added foldCallback and getResourceListName.
112  *
113  * Revision 1.4  1994/02/24  04:36:32  markc
114  * Added an upcall to dyninstRPC.I to allow paradynd's to report information at
115  * startup.  Added a data member to the class that igen generates.
116  * Make depend differences due to new header files that igen produces.
117  * Added support to allow asynchronous starts of paradynd's.  The dataManager has
118  * an advertised port that new paradynd's can connect to.
119  *
120  * Revision 1.3  1994/02/08  17:20:29  hollings
121  * Fix to not core dump when parent is null.
122  *
123  * Revision 1.2  1994/02/03  23:26:59  hollings
124  * Changes to work with g++ version 2.5.2.
125  *
126  * Revision 1.1  1994/02/02  00:42:34  hollings
127  * Changes to the Data manager to reflect the file naming convention and
128  * to support the integration of the Performance Consultant.
129  *
130  * Revision 1.1  1994/01/28  01:34:18  hollings
131  * The initial version of the Data Management thread.
132  *
133  *
134  */
135 extern "C" {
136 #include <malloc.h>
137 }
138
139 #include "dataManager.thread.SRVR.h"
140 #include "dataManager.thread.CLNT.h"
141 #include "dyninstRPC.xdr.CLNT.h"
142 #include "DMinternals.h"
143 #include <assert.h>
144
145 // the argument list passed to paradynds
146 vector<string> paradynDaemon::args = 0;
147
148 applicationContext *dataManager::createApplicationContext(errorHandler foo)
149 {
150   appContext = new applicationContext(foo);
151   return appContext;
152 }
153
154 void dataManager::setResourceSearchSuppress(applicationContext *app,
155                                             resource *res, bool newValue)
156 {
157     if (res) res->setSuppress(newValue);
158 }
159
160 void dataManager::setResourceSearchChildrenSuppress(applicationContext *app,
161                                                     resource *res, 
162                                                     bool newValue)
163 {
164     if (res) res->setSuppressChildren(newValue);
165 }
166
167 void dataManager::setResourceInstSuppress(applicationContext *app,
168                                       resource *res, bool newValue)
169 {
170     if (res) app->setInstSuppress(res, newValue);
171 }
172
173 bool dataManager::addDaemon(applicationContext *app,
174                                char *machine, char *login, char *name)
175 {
176   return (app->getDaemon(machine, login, name));
177 }
178
179 bool dataManager::defineDaemon(applicationContext *app,
180                                   const char *command,
181                                   const char *dir,
182                                   const char *login,
183                                   const char *name,
184                                   const char *machine,
185                                   int flavor)
186 {
187   return (app->defineDaemon(command, dir, login, name, machine, flavor));
188 }
189
190 bool dataManager::addExecutable(applicationContext *app,
191                                    char  *machine,
192                                    char *login,
193                                    char *name,
194                                    char *dir,
195                                    vector<string> *argv)
196 {
197     return(app->addExecutable(machine, login, name, dir, *argv));
198 }
199
200 bool dataManager::applicationDefined(applicationContext *app)
201 {
202     return(app->applicationDefined());
203 }
204
205 bool dataManager::startApplication(applicationContext *app)
206 {
207     return(app->startApplication());
208 }
209
210 bool dataManager::pauseApplication(applicationContext *app)
211 {
212     return(app->pauseApplication());
213 }
214
215 bool dataManager::pauseProcess(applicationContext *app, int pid)
216 {
217     return(app->pauseProcess(pid));
218 }
219
220 bool dataManager::continueApplication(applicationContext *app)
221 {
222     return(app->continueApplication());
223 }
224
225 bool dataManager::continueProcess(applicationContext *app, int pid)
226 {
227     return(app->continueProcess(pid));
228 }
229
230 bool dataManager::detachApplication(applicationContext *app, bool pause)
231 {
232    return(app->detachApplication(pause));
233 }
234
235 performanceStream *dataManager::createPerformanceStream(applicationContext *ap,
236                                                         dataType dt,
237                                                         dataCallback dc,
238                                                         controlCallback cc)
239 {
240     int td;
241     performanceStream *ps;
242
243     td = getRequestingThread();
244     ps = new performanceStream(ap, dt, dc, cc, td);
245     ap->streams.add(ps);
246
247     return(ps);
248 }
249
250 int dataManager::destroyPerformanceStream(applicationContext *ap,
251                                           performanceStream *ps){
252     int ok = 1;
253     performanceStream *temp;
254
255     if(temp = ap->streams.find(ps)){
256       ok = ap->streams.remove(ps);
257     }
258     return(ok);
259 }
260
261
262
263 String_Array dataManager::getAvailableMetrics(applicationContext *ap)
264 {
265     return(ap->getAvailableMetrics());
266 }
267
268 metric *dataManager::findMetric(applicationContext *ap, char *name)
269 {
270     return(ap->findMetric(name));
271 }
272
273 resourceList *dataManager::getRootResources()
274 {
275     return(resource::rootResource->getChildren());
276 }
277
278 resource *dataManager::getRootResource()
279 {
280     return(resource::rootResource);
281 }
282
283 metricInstance *dataManager::enableDataCollection(performanceStream *ps,
284                                                   resourceList *rl,
285                                                   metric *m)
286 {
287     return(ps->enableDataCollection(rl, m));
288 }
289
290 void dataManager::disableDataCollection(performanceStream *ps, 
291                                         metricInstance *mi)
292 {
293     if (mi) ps->disableDataCollection(mi);
294 }
295
296 void dataManager::enableResourceCreationNotification(performanceStream *ps, 
297                                                         resource *r)
298 {
299     ps->enableResourceCreationNotification(r);
300 }
301
302 void dataManager::disableResourceCreationNotification(performanceStream *ps, 
303                                                          resource *r)
304 {
305     ps->disableResourceCreationNotification(r);
306 }
307
308 metric *dataManager::getMetric(metricInstance *mi)
309 {
310     return(mi->met);
311 }
312
313 stringHandle dataManager::getMetricNameFromMI(metricInstance *mi)
314 {
315     return(mi->met->getName());
316 }
317
318 stringHandle dataManager::getMetricName(metric *m)
319 {
320     return(m->getName());
321 }
322
323 float dataManager::getMetricValue(metricInstance *mi)
324 {
325     return(mi->getValue());
326 }
327
328 float dataManager::getTotValue(metricInstance *mi)
329 {
330     return(mi->getTotValue());
331 }
332
333 void dataManager::setSampleRate(performanceStream *ps, timeStamp rate)
334 {
335     ps->setSampleRate(rate);
336 }
337
338 float dataManager::getPredictedDataCost(applicationContext *a, 
339                                         resourceList *rl, 
340                                         metric *m)
341 {
342     return(a->getPredictedDataCost(rl, m));
343 }
344
345 float dataManager::getCurrentHybridCost(applicationContext *a) 
346 {
347     return(a->getCurrentHybridCost());
348 }
349
350 int dataManager::getSampleValues(metricInstance *mi,
351                                  sampleValue *buckets,
352                                  int numberOfBuckets,
353                                  int first)
354 {
355     Histogram *hist;
356
357     hist = mi->data;
358
359     if (!hist) return(-1);
360
361     return(hist->getBuckets(buckets, numberOfBuckets, first));
362 }
363
364 void dataManager::printResources()
365 {
366     printAllResources();
367 }
368
369 void dataManager::printStatus(applicationContext *appl)
370 {
371     appl->printStatus();
372 }
373
374 void dataManager::coreProcess(applicationContext *app, int pid)
375 {
376     app->coreProcess(pid);
377 }
378
379 //
380 // Now for the upcalls.  We provide code that get called in the thread that
381 //   requested the call back.
382 //
383 void dataManagerUser::newMetricDefined(metricInfoCallback cb,
384                                   performanceStream *ps,
385                                   metric *m)
386 {
387     (cb)(ps, m);
388 }
389
390 void dataManagerUser::newResourceDefined(resourceInfoCallback cb,
391                                          performanceStream *ps,
392                                          resource *parent,
393                                          resource *newResource,
394                                          stringHandle name)
395 {
396     (cb)(ps, parent, newResource, name);
397 }
398
399 void dataManagerUser::changeResourceBatchMode(resourceBatchModeCallback cb,
400                                          performanceStream *ps,
401                                          batchMode mode)
402 {
403     (cb)(ps, mode);
404 }
405
406 void dataManagerUser::histFold(histFoldCallback cb,
407                                performanceStream *ps,
408                                timeStamp width)
409 {
410     (cb)(ps, width);
411 }
412
413 void dataManagerUser::changeState(appStateChangeCallback cb,
414                                   performanceStream *ps,
415                                   appState state)
416 {
417     (cb)(ps, state);
418 }
419
420 void dataManagerUser::newPerfData(sampleDataCallbackFunc func,
421                              performanceStream *ps,
422                              metricInstance *mi,
423                              sampleValue *buckets,
424                              int count,
425                              int first)
426 {
427     (func)(ps, mi, buckets, count, first);
428 }
429
430 T_dyninstRPC::metricInfo *dataManager::getMetricInfo(metric *met) {
431     return(met->getInfo());
432 }
433
434 resource *dataManager::newResource(applicationContext *app, 
435                                    resource *res, 
436                                    const char *name)
437 {
438     resource *child;
439
440     // rbi: kludge 
441     // calls to this method should specify an abstraction,
442     // but that involves a bunch of other changes that I don't want 
443     // to make right now.
444     // the kludge works because we know that all calls to this method 
445     // are for BASE abstraction resources.  
446     child = createResource(res, name, "BASE");  
447     app->tellDaemonsOfResource((const char *) res->getFullName(), name);
448     return(child);
449 }
450
451 timeStamp dataManager::getCurrentBucketWidth()
452 {
453     return(Histogram::bucketSize);
454 }
455
456 int dataManager::getMaxBins()
457 {
458     return(Histogram::numBins);
459 }
460
461 void dataManager::printDaemons(applicationContext *app)
462 {
463   app->printDaemons();
464 }
465
466 String_Array dataManager::getAvailableDaemons(applicationContext *ap)
467 {
468     return(ap->getAvailableDaemons());
469 }
470
471 double dataManager::firstSampleTime(int program, double first) {
472   if (!firstTime)
473     firstTime = first;
474   return firstTime;
475 }
476