2 * dataManager.h - exported services of the Data Mgr thread of paradyn.
4 * Revision 1.79 1997/04/14 19:54:00 zhichen
5 * Added memoryInfoCallback, getMemoryBounds, newMemoryDefined
6 * Revision 1.78 1997/01/30 17:55:09 tamches
7 * added "afterAttach" param to attach()
9 * Revision 1.77 1997/01/16 21:56:16 tamches
10 * bumped up version number
12 * Revision 1.76 1997/01/16 21:55:24 tamches
13 * extra params to attach()
15 * Revision 1.75 1997/01/15 00:04:57 tamches
18 * Revision 1.74 1996/05/06 17:14:02 newhall
19 * added disableDataAndClearPersistentData, and added phase_persistent_data flag
20 * to enableDataRequest routines
22 * Revision 1.73 1996/05/02 19:52:15 karavan
23 * removed obsolete parameters from predicted cost callback defn
25 * Revision 1.72 1996/05/01 18:06:31 newhall
26 * added param to predicted cost routines
28 * Revision 1.71 1996/04/30 18:57:37 newhall
29 * changes to enableDataCollection calls and upcalls
31 * Revision 1.70 1996/04/22 17:56:40 newhall
32 * minor change to predictedDataCost
39 #include "util/h/list.h"
40 #include "util/h/sys.h"
41 #include "dyninstRPC.xdr.h"
43 #include "util/h/aggregation.h"
44 #include "util/h/stringPool.h"
45 #include "paradyn/src/DMthread/DMinclude.h"
46 #include "paradyn/src/DMthread/DVbufferpool.h"
48 typedef enum {Global, Phase, All} SaveRequestType;
50 typedef enum { Trace, Sample } dataType;
53 * error handler call back.
56 typedef void (*errorHandler)(int errno, char *message);
59 * Handler that gets called when new sample data is delivered.
61 * handle - a performance stream handle from createPerformanceStream
62 * mi - a metricInstance returned by enableDataCollection
63 * buckets - array of sampleValue filled by the DM
64 * first - the first bucket value
65 * count - number of bucket values in buckets
68 typedef void (*sampleDataCallbackFunc)(vector<dataValueType> *data,
69 u_int num_data_values);
72 * Handler that gets called when new trace data is available.
74 * handle - a performance stream handle from createPerformanceStream
75 * mi - a metricInstance returned by enableDataCollection
76 * time - time of the event.
77 * eventSize - size of the event specific data.
78 * eventData - event specific data.
80 typedef void (*traceDataCallbackFunc)(perfStreamHandle handle,
81 metricInstanceHandle mi,
87 * union to hold two types of data callback.
91 sampleDataCallbackFunc sample;
92 traceDataCallbackFunc trace;
95 typedef union dataCallback dataCallback;
98 * Handler that gets called when a new metric is defined.
100 * handle - a performance stream handle from createPerformanceStream
101 * metricInfo - info about metric, client is resp. for deleting this struct
104 typedef void (*metricInfoCallback)(perfStreamHandle,
110 dm_MetUnitsType units_type);
113 * Handler that gets called when a new resource is defined.
115 * handle - a performance stream handle from createPerformanceStream
116 * parent - parent of new resource
117 * newResource - new resource being created
118 * name - name of the new resource, client must delete
121 typedef void (*resourceInfoCallback)(perfStreamHandle handle,
122 resourceHandle parent,
123 resourceHandle newResource,
125 const char *abstraction);
126 typedef void (*memoryInfoCallback)(perfStreamHandle handle,
127 const char *data_structure,
131 resourceHandle parent,
132 vector<resourceHandle> *newResources) ;
134 typedef enum batchMode { batchStart, batchEnd };
136 typedef void (*resourceBatchModeCallback)(perfStreamHandle, batchMode mode);
138 typedef void (*histFoldCallback)(perfStreamHandle, timeStamp width, phaseType);
140 typedef enum appState { appRunning, appPaused, appExited };
142 typedef void (*appStateChangeCallback)(perfStreamHandle, appState state);
144 typedef void (*newPhaseCallback)(perfStreamHandle handle,
154 * Handler that gets called when there is a response to a
155 * getPredictedDataCost call
157 * m_handle - the metricHandle assoc. with the request
158 * rl_handle - the resourceListHandle assoc. with the request
159 * cost - the cost of enabling the metric/focus pair
160 * clientId - the identifier passed by the calling thread
162 typedef void (*predDataCostCallbackFunc)(u_int clientId,
166 * Handler that gets called when there is a response to an enableData request
168 * response - vector of responses to enable request one element for each
169 * element in the vector passed by client to enableData request
170 * request_id - identifier that client thread associated with this call
171 * (passed to DM on enableDataRequest)
173 typedef void (*enableDataCallbackFunc)(vector<metricInstInfo> *response,
176 struct controlCallback {
177 metricInfoCallback mFunc;
178 resourceInfoCallback rFunc;
179 resourceBatchModeCallback bFunc;
180 histFoldCallback fFunc;
181 appStateChangeCallback sFunc;
182 newPhaseCallback pFunc;
183 predDataCostCallbackFunc cFunc;
184 enableDataCallbackFunc eFunc;
185 memoryInfoCallback xFunc;
188 typedef struct controlCallback controlCallback;
190 $remote dataManager {
195 // Start a paradyn daemon
197 bool addDaemon (const char *machine,
202 // Define a daemon in the daemon dictionary
203 // command = command line to exec
204 // dir = directory to use as working directory
205 // login = user name to execute as
206 // name = name of dictionary entry, for matching
207 // flavor = programming environment (metPVM, metCM5, metUNIX)
208 // machine = machine to run this daemon on
210 // Note - arguments that are not used should be passed in
211 // as null, anything else will be assumed to be a
213 bool defineDaemon (const char *command,
221 // Define a program to run.
222 // machine = name of machine to run on
223 // login = user to run as
224 // name = name of daemon to run with, matches dictionary entry
225 // dir = working directory to use
227 // Note - arguments that are not used should be passed in
228 // as null, anything else will be assumed to be a
230 bool addExecutable(const char *machine,
234 const vector<string> *argv);
236 // Attach is the other way to start a process...newly implemented with v1.2
237 bool attach(const char *machine,
241 const char *daemonName,
242 int afterAttach // 1 --> pause, 2 --> run, 0 --> leave as is
246 // Find out if an application has been defined yet.
248 bool applicationDefined();
251 // Start an application running (This starts the actual execution).
253 bool startApplication();
256 // Stop all processes associted with the application.
258 // Pause an application (I am not sure about this but I think we want it).
259 // - Does this force buffered data to be delivered?
260 // - Does a paused application respond to enable/disable commands?
262 bool pauseApplication();
265 // Pause a process in an application
266 // - Does this force buffered data to be delivered?
267 // - Does a paused application respond to enable/disable commands?
269 bool pauseProcess(int pid);
272 // Continue a paused application.
274 bool continueApplication();
277 // Continue a paused process in an application.
279 bool continueProcess(int pid);
282 // Disconnect the tool from the process.
283 // pause - leave the process in a stopped state.
285 bool detachApplication(bool pause);
288 // write all global data to files created in the dirname directory
290 $async void saveAllData (const char *dirname, SaveRequestType optionFlag);
293 // write all resource information to a file created in dirname
295 $async void saveAllResources (const char *dirname);
298 // Create a performanceStream. This a flow of performance information
301 // dataType - Sample or Trace
302 // dataCallback - Function to call when new data arrives
303 // controlCallback - Function to call when new structure info arrives
305 perfStreamHandle createPerformanceStream(dataType,
310 // Destroy a performance Stream.
312 // perfStreamHandle - a handle returned by createPerformanceStream
314 int destroyPerformanceStream(perfStreamHandle);
317 // Routines to control data collection on a performance Stream.
321 // Request to enable a set of metric/focus pairs
322 // ps_handle - the perfStreamHandle of the calling thread
323 // pt_handle - the perfTraceStreamHandle of the calling thread
324 // request - vector of metic/focus pairs to enable
325 // request_Id - identifier passed by calling thread
326 // type - which phase type to enable data for
327 // phaseId - the identifier of the phase for which data is requested
328 // persistent_data - if set data is not distroyed on last disable
329 // persistent_collection - if set data collection isn't stoped on disable
330 // phase_persistent_data - like persistent_data, but only valid for curr
333 $async void enableDataRequest(perfStreamHandle ps_handle,
334 perfStreamHandle pt_handle,
335 vector<metric_focus_pair> *request,
339 u_int persistent_data,
340 u_int persistent_collection,
341 u_int phase_persistent_data);
342 // getMemoryBounds: get the bounds of shared-memory for
344 $async void getMemoryBounds(perfStreamHandle ps_handle,
345 vector<metric_focus_pair> *request) ;
348 // same as enableDataRequest, but with diff type request
350 $async void enableDataRequest2(perfStreamHandle ps_handle,
351 vector<metricRLType> *request,
355 u_int persistent_data,
356 u_int persistent_collection,
357 u_int phase_persistent_data);
361 // stop collecting data for the named metricInstance.
362 // perfStreamHandle - a handle returned by createPerformanceStream
363 // metricInstance - a metricInstance returned by enableDataCollection.
364 // phaseType - specifies either global or current phase data
366 $async void disableDataCollection(perfStreamHandle,
367 metricInstanceHandle,
371 // stop collecting data for the named metricInstance and clear the
372 // persistent data flag(s) before disabling
373 // ps_handle - a handle returned by createPerformanceStream
374 // mi_handle - a metricInstance returned by enableDataCollection.
375 // p_type - specifies either global or current phase data
376 // clear_persistent_data - if true, clear persistent_data flag
377 // clear_phase_persistent_data - if true, clear phase_persistent_data flag
379 $async void disableDataAndClearPersistentData(perfStreamHandle ps_handle,
380 metricInstanceHandle mi_handle,
382 bool clear_persistent_data,
383 bool clear_phase_persistent_data);
385 // This routine returns a list of foci which are the result of combining
386 // each child of resource rh with the remaining resources that make up rlh
387 // if the resource rh is a component of the focus rlh, otherwise returns 0
389 vector<rlNameId> *magnify(resourceHandle rh,
390 resourceListHandle rlh);
393 // returns a list of foci each of which is the result of combining a child
394 // of one of the resources with the remaining resource components of rlh,
395 // this routine returns 0 if no resource components of rlh have children
397 vector<rlNameId> *magnify2(resourceListHandle rlh);
400 // if resource rh is a decendent of a component of the focus, return a new
401 // focus consisting of rh replaced with it's corresponding entry in rlh,
402 // otherwise return the focus rlh
404 resourceListHandle *constrain(resourceHandle rh, resourceListHandle rlh);
407 // like constrain, except it returns 0 on failure
409 resourceListHandle *morespecific(resourceHandle rh, resourceListHandle rlh);
412 // returns true if seppressSearch is true for this focus
414 bool isSuppressed(resourceListHandle rlh);
417 // returns the name for the focus associated with this MI
418 // returns 0 on error
420 const char *getFocusNameFromMI(metricInstanceHandle mi);
423 // returns the name for the focus associated with this resourceHandle
425 const char *getFocusName(const vector<resourceHandle>*);
428 // returns the name for the focus associated with this resourceListHandle
429 // returns 0 on error
431 const char *getFocusNameFromHandle(resourceListHandle rlh);
434 // change the persistent_collection flag value for the assoc. MI
436 $async void setPersistentCollection(metricInstanceHandle);
437 $async void clearPersistentCollection(metricInstanceHandle);
440 // change the persistent_data flag value for the assoc. MI
442 $async void setPersistentData(metricInstanceHandle);
445 // this clears both persistent_data and phase_persistent_data flags of MI
447 $async void clearPersistentData(metricInstanceHandle);
450 // Return the expected cost of collecting performance data for a single
451 // metric at a given focus. The value returned is the fraction of
452 // perturbation expected (i.e. 0.10 == 10% slow down expected).
453 // perfStreamHandle and u_int are idetifiers for the request
455 $async void getPredictedDataCost(perfStreamHandle,
461 // Histogram/timebase information
463 timeStamp getCurrentBucketWidth();
466 // Histogram/timebase information
468 timeStamp getGlobalBucketWidth();
473 u_int getCurrentPhaseId();
474 timeStamp getCurrentStartTime();
479 // Resource utility functions.
483 // returns handle for root resource, returns NULL on error
485 resourceHandle *getRootResource();
488 // returns handles of root resources, returns NULL on error
490 vector<resourceHandle> *getRootResources();
493 // create a new resource and return it's handle
495 resourceHandle newResource(resourceHandle parent,
500 // converts from a vector of resourceHandles to a resourceListHandle
502 resourceListHandle getResourceList(const vector<resourceHandle>*);
505 // converts from a resourceListHandle to a vector of resourceHandles
506 // client is responsible for deleting vector<resourceHandle>*
508 vector<resourceHandle> *getResourceHandles(resourceListHandle);
511 // converts from a resource name to a resourceHandle
512 // the resource name must be the full name ie. "/Code/blah.c/foo"
513 // returns NULL if conversion fails
515 resourceHandle *findResource(const char *name);
518 // returns name of resource (this is not a unique representation of
519 // the name instead it is the unique name trunctated)
520 // so for "/Code/blah.c/foo" this routine will return "foo"
522 const char *getResourceLabelName(resourceHandle);
526 // returns full name of a resource ie. "/Code/blah.c/foo"
528 const char *getResourceName(resourceHandle);
531 // converts from a focus name to a resourceListHandle
532 // returns NULL if convertion fails
534 resourceListHandle *findResourceList(const char *name);
537 // don't search the SHG for this node.
539 void setResourceSearchSuppress(resourceHandle res_handle, bool newValue);
542 // don't search the SHG for children of this node.
544 void setResourceSearchChildrenSuppress(resourceHandle res_handle,
548 // consider this resource a black box (applies to modules/procedures now).
550 void setResourceInstSuppress(resourceHandle res_handle, bool newValue);
553 // returns a vector of metric names
554 // client is responsible for deleting these
556 vector<string> *getAvailableMetrics(bool all);
559 // returns a vector of metric name and id pairs
560 // client is responsible for deleting these
562 vector<met_name_id> *getAvailableMetInfo(bool all);
565 // looks for a specifc metric instance
566 // returns NULL if search is unsuccessful
568 metricHandle *findMetric(const char *name);
571 // Metric utility functions.
573 const char *getMetricName(metricHandle);
576 // get the supporting info about a metric.
578 T_dyninstRPC::metricInfo *getMetricInfo(metricHandle);
580 // TODO: these shouldn't be necessary
581 // Get metric out of a metric instance.
583 metricHandle *getMetric(metricInstanceHandle);
584 const char *getMetricNameFromMI(metricInstanceHandle);
587 // Get the value of a metric.
589 sampleValue getMetricValue(metricInstanceHandle);
592 // fill the passed array of buckets with the histogram sample from the
593 // passed metricInstance.
594 // mi metric instance to use
595 // buckets array of buckets to fill
596 // numberOfBuckets max number of buckets to fill
597 // first first bin to fill (i.e. what bin goes into
599 // phase specifies either curr. or global phase data
601 int getSampleValues(metricInstanceHandle mi,
602 sampleValue *buckets,
608 // fill the passed array of buckets with the archived histogram values
609 // of the passed metricInstance
610 // mi which metric instance
611 // phase_id which phase
613 int getArchiveValues(metricInstanceHandle mi,
614 sampleValue *buckets,
617 phaseHandle phase_id);
620 // Get the total value of a metric.
621 // (ie. do not divide by time enabled)
623 sampleValue getTotValue(metricInstanceHandle);
627 // start_Time: would allow a phase to be specified for some time
628 // in the future, this would be useful for using phase
629 // information from a config. file
630 // a default value of -1.0 would be equivalent to now
631 // name: would be an optional user defined identifier for the phase
632 // each phase would still have a system defined unique id
633 // with_new_pc: flag that indicates if new instance of PC should be
634 // started with this phase (DM just takes value of flag
635 // and passes it back on newPhaseCallbacks)
636 // with_visis: flag that indicates if new instance of curr. phase
637 // visis should be started with the new phase (this
638 // option is not currently supported....the DM would
639 // have to keep curr. phase MI's enabled for the new
640 // phase by setting collection flags for the MI's
641 // and calling a VM routine to start new versions of
642 // all curr. phase visis with a pre-defined list of
643 // MI's for each one)
645 $async void StartPhase(timeStamp start_Time, const char *name,
646 bool with_new_pc, bool with_visis);
650 // returns a list of all currently defined phases in the system
651 // the caller is responsible for freeing the space associated with
654 vector<T_visi::phase_info> *getAllPhaseInfo();
658 // Debugger style calls.
661 void printResources();
663 void coreProcess(int pid);
666 // probably temporary call, show defined daemons
672 // daemonStartInfo: prints a message with the command line to start a
673 // daemon manually (needed if a rshd is not available on a remote machine)
675 void printDaemonStartInfo();
678 // return a list of daemon names
680 vector<string> *getAvailableDaemons();
683 // upcalls for indications of events.
685 $upcall $async void newMetricDefined(metricInfoCallback,
692 dm_MetUnitsType units_type);
694 $upcall $async void newMemoryDefined(memoryInfoCallback,
700 resourceHandle p_handle,
701 vector<resourceHandle> *handles) ;
703 $upcall $async void newResourceDefined(resourceInfoCallback,
705 resourceHandle parent,
706 resourceHandle newResource,
710 $upcall $async void changeResourceBatchMode(resourceBatchModeCallback,
714 // $upcall $async void newPerfData(sampleDataCallbackFunc,
715 $upcall $async void newPerfData(sampleDataCallbackFunc sampleFunc,
716 vector<dataValueType> *data,
717 u_int num_data_values);
719 // trace data streams
720 $upcall $async void newTracePerfData(traceDataCallbackFunc traceFunc,
721 vector<traceDataValueType> *traceData,
722 u_int num_traceData_values);
724 $upcall $async void predictedDataCost(predDataCostCallbackFunc func,
725 metricHandle m_handle,
726 resourceListHandle rl_handle,
731 // response to enableDataRequest call
732 // func - callback function registered by client thread on createPerfStream
733 // response - vector of enable reponses to enable
734 // request_id - identifier passed by client to enableDataRequest
736 $upcall $async void enableDataCallback(enableDataCallbackFunc func,
737 vector<metricInstInfo> *response,
741 $upcall $async void histFold(histFoldCallback,
746 $upcall $async void changeState(appStateChangeCallback,
751 // Info. about a new phase that was created
753 $upcall $async void newPhaseInfo(newPhaseCallback,
755 const char *, // name
756 phaseHandle, // unique id
757 timeStamp, // start time
758 timeStamp, // end time
759 float, // bucketwidth
766 static bool DM_sequential_init(const char*);
767 static int DM_post_thread_create_init(int);
768 static dataManager *dm; // need this so can call setTid which is
769 // not a static function, otherwise could
770 // just define all DM functions as static