In order for your analysis tool to be able to dynamically insert probes into a target application process, it must have established a communication connection to that process. This "communication connection" is achieved though a socket connection from the analysis tool to the DPCL communication daemon, and shared-memory communication between the DPCL communication daemon and the target application process. There are two ways an analysis tool may establish such a connection to a process -- either by calling a DPCL function to explicitly connect to the process, or by calling a DPCL function to actually create the process (which will implicitly establish the necessary connection). This chapter describes how an analysis tool can:
Before an analysis tool can install and execute probes within a target application process, it must first establish a connection to that process. Connecting to a target application process on a particular host machine creates two DPCL daemon processes on that host -- a DPCL superdaemon process, and a DPCL communication daemon process.
The DPCL superdaemon creates the DPCL communication daemon and is responsible for ensuring that only one communication daemon per user exists on the remote host. Although the DPCL superdaemon establishes the initial connection to the target application process, it passes this connection to the DPCL communication daemon. It is then the DPCL communication daemon that handles the communication between the analysis tool and the target application process. It is also the DPCL communication daemon that performs much of the actual work requested, via DPCL function calls, by the analysis tool. For more information on the DPCL daemon processes, refer to What are the DPCL daemons?.
The procedure for connecting to the target application differs depending on
whether you are connecting to a serial application, a parallel (non-POE)
application, or a parallel POE application.
If the target application is: | The analysis tool connects to it by: |
---|---|
A serial application |
|
A parallel application (non-POE) |
|
A POE Application |
|
To connect to a serial application, the analysis tool must:
The following steps describe these tasks in greater detail. For sample code, see Example: Connecting to a serial application.
In order to connect to the target application process, the analysis tool must instantiate a Process object that represents the process. To do this, the analysis tool must:
The following substeps describe these tasks in greater detail.
In order to instantiate a Process object that represents the target application process, the analysis tool must have some way of identifying the host running this process and the process ID on that host. The analysis tool could accomplish this in a number of ways; it could, for example, prompt the user to supply this information to standard input, or it could read a configuration file that contains the information.
In order to connect to the target application process, the analysis tool
must instantiate a Process object that represents the
process. The Process class is defined in the header file
Process.h. To assign the host name and process ID to
a Process object, you can use a non-default constructor, a
non-default constructor with a copy constructor, or the default constructor
with an assignment operator. Say the target application process is
currently executing on a host machine whose IP host name is
"myhost.xyz.edu", and the process ID is 12345.
Table 17. Instantiating a Process object
To instantiate a Process class object, the analysis tool can: | For example: |
---|---|
Use a default constructor and an assignment operator to assign values to the Process object. |
Process p; p = Process("myhost.xyz.edu", 12345); |
Use a non-default constructor to directly assign values to the Process object. |
Process p("myhost.xyz.edu", 12345); |
Use a non-default constructor and a copy constructor to assign values to the Process object. |
Process p = Process("myhost.xyz.edu", 12345); |
When you assign a host name and process ID to a Process object (as shown in the preceding table), the Process object is in an unconnected state. In other words, it is just an object allocated by the analysis tool process; it does not yet have a connection to the particular process indicated by its host and process ID values. In fact, the DPCL system does not at this point even know if the Process object's host and process ID values are valid. This unconnected state is represented by the enumeration constant PRC_unconnected of the Process class' ConnectState enumeration type. The analysis tool can query a Process object's state by calling the Process::query_state function.
For more information on the Process class constructor, refer to the DPCL Class Reference
Once the analysis tool has a Process object that represents
the target application, it can connect to it using either the blocking
function Process::bconnect, or the asynchronous
function Process::connect.
Table 18. Connecting to a target application process
By using the Process::connect or Process::bconnect function, the analysis tool creates a connection to the Process indicated by the Process object's host and process ID values. When the DPCL system has established a connection between the analysis tool and a target application process, the analysis tool can instrument it with probes. This connected state is represented by the enumeration constant PRC_connected of the Process class' ConnectState enumeration type. The analysis tool can query a Process object's state by calling the Process::query_state function.
For more information on the Process::bconnect and Process::connect functions, refer to their UNIX man pages, or their entries in the DPCL Class Reference.
The following example code:
main(int argc, char *argv[]) { Process P(argv[1], atoi(argv[2])); Ais_initialize(); printf("Connecting to process %s on node %s\n", argv[2], argv[1]); AisStatus sts = P.bconnect(); printf ("connect status = %d\n", (int)sts); if ( (int)sts != 0) printf("%s\n", sts.status_name()); . . .
The procedure for connecting to a parallel application differs
depending on whether or not the application is designed to run in the Parallel
Operating Environment.
If the target application is: | The analysis tool connects to it by: |
---|---|
A parallel application (non-POE) |
|
A POE application |
|
To connect to a non-POE parallel application, the analysis tool must:
The following steps describe these tasks in greater detail. For sample code, see Example: Connecting to a non-POE parallel application.
In order to connect to the target application processes in the parallel application, the analysis tool must instantiate Process objects that represent the processes. Later, the analysis tool will organize these Process objects under an Application object so that it may treat all the processes as if they were a single unit. To instantiate Process objects to represent the processes, the analysis tool must:
The following substeps describe these tasks in more detail.
In order to instantiate Process objects that represent the target application processes, the analysis tool must have some way of identifying the host running, and the process ID for, each target application process. The analysis tool could accomplish this in a number of ways; it could, for example, prompt the user to supply this information to standard input, or it could read a configuration file that contains this information.
In order to connect to the processes in the target application, the
analysis tool must instantiate Process objects that represent the
processes. The Process class is defined in the header file
Process.h. To assign the host name and process ID to
a Process object, the analysis tool can use a non-default
constructor, a non-default constructor with a copy constructor, or the default
constructor with an assignment operator. Say one of the target
application processes is currently executing on a host machine whose IP host
name is "myhost.xyz.edu", and the process ID is 12345.
Table 19. Instantiating Process objects for multiple target application processes
To instantiate a Process class object, the analysis tool can: | For example: |
---|---|
Use a default constructor and an assignment operator to assign values to the Process object. |
Process p[128]; p = Process("myhost.xyz.edu", 12345); |
Use a non-default constructor to directly assign values to the Process object. |
Process p[0]("myhost.xyz.edu", 12345); |
Use a non-default constructor and a copy constructor to assign values to the Process object. |
Process p[0] = Process("myhost.xyz.edu", 12345); |
When you assign a host name and process ID to a Process object (as shown in the preceding table), the Process object is in an unconnected state. In other words, it is just an object allocated by the analysis tool process; it does not yet have a connection to the particular process indicated by its host and process ID values. In fact, the DPCL system does not at this point even know if the Process object's host and process ID values are valid. This unconnected state is represented by the enumeration constant PRC_unconnected of the Process class' ConnectState enumeration type. The analysis tool can query a Process object's state by calling the Process::query_state function.
For more information on the Process class constructor, refer to the DPCL Class Reference.
By grouping a set of Process objects under an Application object, the analysis tool is able to treat the set of Process objects as a single unit. In other words, it need only make a single call to an Application class member function to act upon all Process objects managed by that Application object. In this case, we are grouping all of the parallel target application's Process objects under the Application object. Note, however, that an Application object can be any grouping of Process objects that the analysis tool needs to manipulate as a single unit.
To group a set of Process objects under an Application object, the analysis tool must:
The following substeps describe these tasks in greater detail.
In order to manipulate different processes in a parallel application, the
analysis tool must group them into an Application object.
The Application class is defined in the header file
Application.h.
Table 20. Instantiating an Application object (for connecting to multiple processes)
To instantiate a Application class object, the analysis tool can: | For example: |
---|---|
Use a default constructor: |
Application app1; |
Use a copy constructor: |
Application app2 = app1; |
For more information on the Application class constructor, refer to the DPCL Class Reference.
The preceding step (Step 2a: Instantiate an Application object) showed how the analysis tool can use the Application class constructor to instantiate an empty Application object. In order to use this object to manipulate a set of processes as a single unit, the analysis tool now needs to add the Process objects to the Application object. It does this using the Application::add_process function. This function takes, as a parameter, the Process object to be added to the Application object. For example, the following line of code adds the Process object p to the Application object app1.
for (i=0; i<128; i++){ app1.add_process(p[i]); }
For more information on the Application::add_processs function >Applicnlica, mand inputsr theyentries in the DPCss< Class Reference.
1able 18. Connectts for multiple target application processes
To connellfferent processn target appli(t upon all Process objects manao into an Application object): | Do this: |
---|---|
Using the asynchronous function connect |
AisStatusaatus("p->connect(conneaType(0)); check_saatus("p->connect(conneaType(0))", sts); // // callback to be called after the connect completes // void connect_cb(GCBSysType sys, GCBTagType tag, GCBObjType obj, GCBMsgType msg) { // code within callback { // can check the status { // operation and respond { // completion by, for e { // continuing with oth er work } |
Using the blocking function bconnect |
|
By using the Application::connect or Application::bconnect f object, the analysis t tool chave a consconnect to the proce/TT> indicated ject's host and proes ss ID ng all variynchon all Process objects managed to the Application oTcribehave a conscctionn" is aageion th queough a socket connection from the analysis tool to the DPCL commun tion daemqueo, and shared-memory communication between the DPCL communicationz.edu", ent the target application values. When the DPCL sysst have estableates a connection to the prorocess represented by the Processsject tcts managediate an Application oocess, the analysis tool can inschieveineset of proent it with pFbject for each , passes this connected s and e is represented by the enumeration c tant PRC_connected set of Process ass' ConnectState enumchieation type. The analysis tool can by the Process's anject's state by call the Process::query_stasss fuunction.
For more information on the Application::connect and Application::bconnect functions, refer to theject t man pages, or their entries in the DPCL Class Reference. 5
The following example code:
for (i=0np; ++its[]) p repring te ho: ") = a thes(ng te ho)", sts); p repriPID: ") = a thes(pidstrint)sts); diffid8];gv[1]pidstrint)sts);dd the PP(ng te ho,ffidint)sts);A-> app1.add_p&Pint)sts}ork workAisStatusA->us("p->connect(conneAint)s check_sA->us("p->connect(conneAiype(0))", sts); // // callback to be called after the connect completes es // void connect_cb(GCBSysType sys, GCBTagType tag, GCBObjType obj, GCBMsgTys[]) // code within callback r // can check the status // operat]) on and respond // completion by, for ex // continuing with other work
To connecin the P llel Operating Envi (l (non-POE) applicesses, the analysis tool must:
In order to connect to the g to a POE appl object, the analysis tonit. To instaaing the PoeAppl object that represe g t target appli Dss is defined in the heading the ication,lues to th PoeAppl class is derived from the Application daemonprovidtantddiApplasis tvenis Re these funspecificconng t target applrocessee, the following line illustrnstancribes how an armatiysis tool ca instaaing the PoeAppl rocess usior the default consp1.
app2 = app The prelowing line wor itbeunction to cmchiate an empty PoeAppl object apps tool. For more infoit neable to the PoeAppcation class constructor, refer in the DPCss< Class Reference.SII>
- inealiziie cationobjes that repres ng the POE target appl object
In order to connect ng the POE target application procbject, the armatiysis too evenI>
For more informatPOEnctions, refer in thet wiin the P rating Envi ft.
2.tII>