Dynamic Probe Class Library

Dynamic Probe Class Library Programming Guide


Chapter 6. Connecting to or starting the target application processes

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:


Connecting to the target application

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
  1. creating a Process object that identifies the target application process, and
  2. calling the Process::bconnect or Process::connect function.
For complete instructions, refer to Connecting to a serial application. For sample code, refer to Example: Connecting to a serial application.
A parallel application (non-POE)
  1. Creating Process objects that identify the target application processes,
  2. grouping the Process class objects under an Application object, and
  3. calling the Application::connect or Application::bconnect function.
For complete instructions, refer to Connecting to a non-POE parallel application. For sample code, refer to Example: Connecting to a non-POE parallel application.
A POE Application
  1. Creating an empty PoeAppl object,
  2. initializing the PoeAppl object to contain Process objects representing the POE target application processes, and
  3. calling the Application::connect or Application::bconnect function. (The PoeAppl class is derived from the Application class, so these functions are available to the PoeAppl object.)
For complete instructions, refer to Connecting to a POE application. For sample code, refer to Example: Connecting to a POE application.

Connecting to a serial application

To connect to a serial application, the analysis tool must:

  1. instantiate a Process object that Identifies the target application process, and
  2. call the Process::bconnect or Process::connect function.

The following steps describe these tasks in greater detail. For sample code, see Example: Connecting to a serial application.

Step 1: Instantiate a Process object that identifies the target application process

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:

  1. Identify the host and process ID of the target application process, and
  2. using this information, instantiate the Process object

The following substeps describe these tasks in greater detail.

Step 1a: Identify the host and process ID of the target application process

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.

Step 1b: Instantiate a Process object for the target application process

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

Step 2: Connect to the target application process

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
To connect to a single target application process (Process object): Do this:
Using the blocking function bconnect
sts = P.bconnect();

    check_status("P.bconnect()", sts);

    printf("  %s: connected to pid:%d\n", toolname,  P.get_pid());


Using the asynchronous function connect
AisStatus sts = p->connect(connect_cb, GCBTagType(0));

    check_status("p->connect(connect_cb, GCBTagType(0))", sts);

 

 

//

// callback to be called after the connect completes

//

void connect_cb(GCBSysType sys, GCBTagType tag, GCBObjType obj, GCBMsgType msg)

{

 

     // code within callback routine 

     // can check the status of the 

     // operation and respond to its 

     // completion by, for example, 

     // continuing with other work

 

}


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.

Example: Connecting to a serial application

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());

.

.

.

 

Connecting to a parallel application

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)
  1. instantiating Process objects that identify the target application processes
  2. grouping the Process class objects under an Application object, and
  3. calling the Application::connect or Application::bconnect function.
For complete instructions, refer to Connecting to a non-POE parallel application. For sample code, refer to Example: Connecting to a non-POE parallel application.
A POE application
  1. Creating an empty PoeAppl object,
  2. initializing the PoeAppl object to contain Process objects representing the POE target application processes, and
  3. calling the Application::connect or Application::bconnect function. (The PoeAppl class is derived from the Application class, so these functions are available to the PoeAppl object.)
For complete instructions, refer to Connecting to a POE application. For sample code, refer to Example: Connecting to a POE application.

Connecting to a non-POE parallel application

To connect to a non-POE parallel application, the analysis tool must:

  1. instantiate Process objects that identify the target application processes,
  2. group the Process objects under an Application object, and
  3. call the Application::connect or Application::bconnect function.

The following steps describe these tasks in greater detail. For sample code, see Example: Connecting to a non-POE parallel application.

Step 1: Instantiate Process objects that identify the target application processes

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:

  1. Identify the host and process ID of each target application process, and
  2. instantiate a Process object for each process in the target application.

The following substeps describe these tasks in more detail.

Step 1a: Identify the host and process ID of each process in the target application

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.

Step 1b: Instantiate a Process object for each process in the target application

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.

Step 2: Group Process objects under an Application object

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:

  1. Instantiate an Application object, and
  2. add the Process objects to the Application object.

The following substeps describe these tasks in greater detail.

Step 2a: Instantiate an Application object

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.

Step 2b: Add the Process objects to the Application object

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.

Step 2: Connect to the target application processes
Applicationdefaulhat I>grouping the Process objects that repres of the target application pr objes tos toder to connechineset of pros this usingng the blocking functi Application::bconnetructor, targ the asynchronous functihe Application::conne.h.

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

Example: Connecting to a non-POE parallel applicatect

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

 work
AisStatusA->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

 

Connecting to a POE application

To connecin the P llel Operating Envi (l (non-POE) applicesses, the analysis tool must:

    nr to instantiate an empty PoeAppl object,
  1. inealizing the PoeAppl object to contain Process objects representing the POE target application processes, and
  2. Application::connect or Application::bconnect function. (The PoeAppl class is derived from the Application class, so these functions are available to the PoeAppl object.) For more informatPOEnctions, refer in thet wiin the P rating Envi ftStep 1: Instantie cation object

    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>
  3. inealiziie cationobjes that repres ng the POE target appl object
  4. In order to connect ng the POE target application procbject, the armatiysis too evenI>

  5. inealiziate an empty PoeAppl sbes inti>defaulhat chon all Process objects representing the POE target applent the procDo precois tooene avai from the analysis tt to manip>StII>
  6. inealiziie cation obje,able to the PoeAppcationprovidtans tvenis Resss fu objectene avai from the analysis ,ocessewere a a DPCL functi,nit. To instantiate Process oructoodt grouilable to the PoeApon oTcribehavvenis Re these fun">What n. (The ::nI> f daemo> oer the blocequivale c tantbnI>s fu t. Note, howeses, the analysis toot muste user identify tht name and ssStep 1a: Identify the host and process ID ng th havme and ication.

    Step 1a: Identify the host and process ID ng th havme and icatect
    nextllowing ng step (StII>
  7. inealiziie cation objechapter describes how an analysis tenI>
  8. ineaan. (The PoeAppl sbes inti> aulhat chon all Process and e is ree grouping all oo the processes ng the POE target appl valuesct. In order tobehavvenis Re these funs intohat supply >
  9. in applicat Note, howeses, the analysis tooe user ile code: