IBM Books

System Monitor Guide and Reference


Making a Snapshot Request

An invocation of db2GetSnapshot() can specify several requests (if desired).

/* Get Snapshot Data Interface Structure                                      */
typedef struct
{
        sqlma *                piSqlmaData; /* Pointer to monitor area        */
        sqlm_collected *       poCollectedData; /* Pointer to collected data  */
        void                   *poBuffer; /* Pointer to output buffer         */
        db2Uint32              iVersion; /* Snapshot version                  */
        db2Uint32              iBufferSize; /* Size of output buffer          */
        db2Uint32              iStoreResult; /* Write to file flag            */
} db2GetSnapshotData;
 
 
 
SQL_API_RC SQL_API_FN                  /* Get snapshot                        */
  db2GetSnapshot (
        db2Uint32 versionNumber,       /* Database version number             */
        void * pParamStruct,           /* In/out parameters                   */
        struct sqlca * pSqlca);        /* SQLCA                               */

The sqlma supplied as input argument to db2GetSnapshot() contains an array of sqlm_obj_struct. Each sqlm_obj_struct is an individual snapshot request.

sqlm_obj_struct is defined as follows:

typedef struct sqlm_obj_struct          /* SNAPSHOT REQUEST  */
{
   unsigned long agent_id;              /* used for requests based on agentid */
   unsigned long obj_type;              /* Snapshot Request Type (SQLMA_XXXX) */
   char          object[SQLM_OBJECT_SZ];/* used for requests based on object  */
                                 /* name, such as 'get snapshot for database' */
}sqlm_obj_struct;

Where agent_id and object are only required if applicable for the request type, and are mutually exclusive. For example: a database name is required when the type is SQLMA_DBASE_LOCKS (get snapshot for locks on database), whereas an agent_id is required when the type is SQLMA_APPL_LOCKS_AGENT_ID. Both agent_id and object are ignored for requests such as SQLMA_APPLINFO_ALL (list applications).

Note that agent_id is the application handle for an application. It does not correspond to any Operating System process Id (it is named this way for source compatibility with older releases of DB2).

The size of strings returned by DB2 are the actual string length. Strings are not NULL terminated.

Setting Up the sqlma and Issuing the Snapshot Call

The following example sets up the sqlma for a call to db2GetSnapshot() that requests two different snapshots. The first request requires an object name, the database alias, the second request requires an agent_id, the application handle:

#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "sqlutil.h"
#include "sqlmon.h"  // System Monitor interface
#include "db2ApiDf.h"
main()
{
  struct sqlca sqlca;
  int rc;
 
  db2GetSnapshotData ss_data;
 
  #define BUFFER_SZ 4096                 // Use a fixed size output buffer
  char snap_buffer[BUFFER_SZ];    // Snapshot output buffer
  sqlm_collected collected;
 
  //----------------------------------------------------------------------
  // Request SQLMA_DBASE, and SQLMA_APPL_LOCKS_AGENT_ID in the sqlma
  //----------------------------------------------------------------------
  unsigned long agent_id = 0; // STUB: Obtain by issuing 'list application'
 
  // Allocate the variable size sqlma structure
  struct sqlma* sqlma = (struct sqlma *) malloc(SQLMASIZE(2));
 
  // Request 2 different snapshots in same call
  sqlma->obj_num = 2;
  sqlma->obj_var[0].obj_type      = SQLMA_DBASE;
  strcpy(sqlma->obj_var[0].object, "SAMPLE");
 
  sqlma->obj_var[1].obj_type      = SQLMA_APPL_LOCKS_AGENT_ID;
  sqlma->obj_var[1].agent_id      = agent_id;
 
  //----------------------------------------------------------------------
  // Perform the snapshot
 //----------------------------------------------------------------------
 
  ss_data.piSqlmaData = sqlma;
  ss_data.poCollectedData = &collected;
  ss_data.poBuffer = snap_buffer;
  ss_data.iVersion = SQLM_DBMON_VERSION6;
  ss_data.iBufferSize = sizeof(snap_buffer);
  ss_data.iStoreResult = FALSE;
 
  rc = db2GetSnapshot(db2Version610,
                      ss_data,  
                      &sqlca);  
  if (sqlca.sqlcode < 0) {
      // get and display a printable error message
      char msg[1024];
      sqlaintp (msg, sizeof(msg), 60, &sqlca);
      printf("%s", msg);
  }
  free(sqlma);
  return rc;
}


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]