Previous section.

Systems Management: Application Response Measurement (ARM) API
Copyright © 1998 The Open Group

Examples

C/C++ (all platforms) Sample 1

Sample 1 uses standard ARM API calls, not advanced functions.

/*******************************************************************/
/* sample1.c                                                       */
/* This program provides examples of how to use the features       */
/* provided by version 1.0 and 2.0 of the ARM API.                 */
/*******************************************************************/

#include <stdio.h>
#include "arm.h"

int32 appl_id = -1;  /* Define an identifer for the application id */
int32 simple_tran_id = -1; /* Define a unique identifier for each  */
int32 long_tran_id_1 = -1; /* TRANSACTION */
int32 long_tran_id_2 = -1;
int32 sub_tran_id_1 = -1;
int32 sub_tran_id_2 = -1;

/*******************************************************************/
/* init                                                            */
/*******************************************************************/

void init()
{
    appl_id=arm_init("ARM sample program", /* application name */
                     "*",                  /* use default user */
                     0,0,0);

simple_tran_id = arm_getid(appl_id,
                   "Simple_transaction_1", /* transaction name */
                   "First Transaction in Sample program",
                   0,0,0);

if (simple_tran_id < 0)
    printf("Simple_transaction_1 is not registered.");

long_tran_id_1 = arm_getid(appl_id,
                  "Long_transaction_1",    /* transaction name */
                  "A long transaction using arm_update",
                  0,0,0);

if (long_tran_id_1 < 0)
    printf("Long_transaction_1 is not registered.");

long_tran_id_2 = arm_getid(appl_id,
                  "Long_transaction_2",    /* transaction name */
                  "A long transaction using sub transactions",
                  0,0,0);

if (long_tran_id_2 < 0)
    printf("Long_transaction_2 is not registered.");

sub_tran_id_1 = arm_getid(appl_id,
                 "Sub_tran1_of_long_tran_2", /* transaction name */
                 "Subtransaction 1 of Long_trans2",
                 0,0,0);

if (sub_tran_id_1 < 0)
    printf("Sub_tran_of_long_tran_2 is not registered.");

sub_tran_id_2 = arm_getid(appl_id,
                 "Sub_tran2_of_long_tran_2", /* transaction name */
                 "Subtransaction 2 of Long_trans2",
                 0,0,0);

if (sub_tran_id_2 < 0)
    printf("Sub_tran_of_long_tran_2 is not registered.");

} /* init */

/*****************************************************************/
/* simple_trans1                                                 */
/*****************************************************************/

void simple_trans1()
{
    int32 tran_handle;

    tran_handle = arm_start(simple_tran_id, /* transaction id    */
                                            /* from arm_getid    */
                            0,0,0);

    /**********************************************/
    /* Perform actual transaction processing here */
    /**********************************************/

    arm_stop(tran_handle, /* transaction handle from arm_start */
               ARM_GOOD,  /* successful completion define = 0  */
               0,0,0);
    return;
} /* simple_trans1 */

/*****************************************************************/
/* long_trans_using_update                                       */
/* arm_update can show the progress of an iterative process      */
/*****************************************************************/

void long_trans_using_update()
{

#define MAX_COUNT 1000000
#define UPDATE_COUNT 100000    /* call update every 100,000 iterations */

    int32 tran_handle;
    int i;
    tran_handle = arm_start(long_tran_id_1, /* trans id from arm_getid */
                            0,0,0);

    for (i=1;i<=MAX_COUNT;i++)
    {
        /* your processing goes here */

        if (i%UPDATE_COUNT == 0)
            arm_update(tran_handle,    /* update based on UPDATE_COUNT */
                       0,0,0);
    }
    arm_stop(tran_handle,         /* transaction handle from arm_start */
             ARM_GOOD             /* successful completion define = 0  */
             0,0,0);
    return;

}   /* long_trans_using_update */

/*******************************************************************/
/* long_trans_using_sub_trans                                      */
/* Sub-transactions can show the progress of the steps of a long   */
/* transaction                                                     */
/*******************************************************************/

void long_trans_using_sub_trans()
{
    int32 tran_handle;
    int32 sub_tran_handle1;
    int32 sub_tran_handle2;

    /* record the overall transaction processing (optional) */

    tran_handle = arm_start(long_tran_id_2, /* trans id from*/
                                            /* arm_getid    */
                            0,0,0);

    /* start recording the first step of the long transaction */
    sub_tran_handle1 = arm_start(sub_tran_id_1,
                                 0,0,0);

    /**************************************/
    /* Process step 1 on this transaction */
    /**************************************/

    /* record the completion of the first step */

    arm_stop(sub_tran_handle1, /* transaction handle from arm_start */
             ARM_GOOD,         /* successful completion define = 0 */
             0,0,0);

    /* start recording the second step of the long transaction */
    sub_tran_handle2 = arm_start(sub_tran_id_2,
                                 0,0,0);

    /**************************************/
    /* Process step 2 on this transaction */
    /**************************************/

    /* record the completion of the second step */

    arm_stop(sub_tran_handle2, /* transaction handle from arm_start */
             ARM_GOOD,         /* successful completion define = 0 */
             0,0,0);

    /* record the completion of the overall transaction */
    arm_stop(tran_handle, /* transaction handle from arm_start */
             ARM_GOOD,    /* successful completion define = 0 */
             0,0,0);
    return;
} /* long_trans_using_sub_trans */

/***************************************************************/
/* main                                                        */
/***************************************************************/

main()
{

    int continue_processing = 1;

    init();

    while (continue_processing)
    {
        simple_trans1();
        long_trans_using_update();
        long_trans_using_sub_trans();

        continue_processing = 0;
    }

    arm_end(appl_id,           /* application id from arm_init */
            0,0,0);

    return(0);

}


C/C++ (all platforms) Sample 2

Sample 2 uses the advanced functions of application-defined metrics and transaction correlation.

/****************************************************************/
/* Sample2.c                                                    */
/* This program provides examples of how to use two of the new  */
/* features provided by version 2.0 of the ARM API:             */
/* - user defined metrics and correlation. For simplicity,      */
/* this sample program does not perform any error checking.     */
/****************************************************************/

#include <stdio.h>
#include "arm.h"

int32 client_appl_id = -1; /* application id */
int32 client_tran_id = -1; /* transaction id */

int32 metric_appl_id = -1; /* application id */
int32 metric_tran_id = -1; /* transaction id */

/****************************************************************/
/* server_application                                           */
/* This routine is included here to simplify this example.      */
/* In a real life situation, this piece of code would likely be */
/* running on a separate system.                                */
/****************************************************************/

void server_application(arm_app_correlator_t client_correlator)

{
    int32 server_appl_id = -1;        /* unique application id  */
    int32 server_tran_id = -1;        /* unique transaction id  */
    int32 server_tran_handle = -1;    /* transaction instance   */

    arm_user_data1_t *buf_ptr, buf = {
        1,                            /* header */
        {ARM_CorrPar_f, 0, 0, 0},     /* flags  */
        };

    int32 buf_sz;

    int i, data_len;

    server_appl_id=arm_init("Server_Application", /* application name */
                            "*",                  /* use default user */
                            0,0,0);               /* reserved */

    server_tran_id = arm_getid(server_appl_id, /* appl_id from arm_init */
                       "Server_transaction",   /* transaction name */
                       "First Transaction in Server program",
                       0,                      /* data buffer */
                       0,0);                   /* buffer pointer & size */

    /* Pass the parent correlator received from the client    */
    /* application to the ARM agent using the arm_start call. */

    buf_ptr = &buf;
    buf_ptr->flags[0] = ARM_CorrPar_f;

    buf_ptr->correlator.length = client_correlator.length;
    data_len = (client_correlator.length 
                 - sizeof(client_correlator.length));
    for (i = 0; i < data_len; i++)
      buf_ptr->correlator.agent_data[i] = client_correlator.agent_data[i];

    buf_sz = (sizeof(buf)-sizeof(client_correlator) 
               + client_correlator.length);

    server_tran_handle = arm_start(server_tran_id,    /* tran_id from */
                                                      /* arm_getid */
                                   0,                 /* reserved */
                                   (char *)buf_ptr,
                                   buf_sz);

    /**********************************************/
    /* Perform actual transaction processing here */
    /**********************************************/

    arm_stop(server_tran_handle, /* transaction handle from arm_start */

            ARM_GOOD,            /* successful completion define = 0 */
            0,                   /* reserved for future use          */
            0,0);                /* buffer pointer & buffer size     */

    arm_end(server_appl_id,      /* application id from arm_init     */
            0,0,0);              /* reserved for future use          */

    return;

}   /* server_application() */


/*********************************************************************/
/* client_transaction                                                */
/*********************************************************************/

void client_transaction()
{

    int32 client_tran_handle = -1; /* transaction start handle */

    arm_user_data1_t *buf_ptr, buf = {
        1, /* Header */
        };

    int32 buf_sz;

    arm_app_correlator_t correlator = {
        0, /* correlator length */
        0, /* agent data */
        };

    int i, data_len;

    buf_ptr = &buf;
    buf_sz = sizeof(buf);

    /* The client application requests a correlator from the ARM Agent */

    buf_ptr->flags[0] = ARM_CorrReq_f;
    client_tran_handle = arm_start(client_tran_id,     /* tran_id from */
                                                       /* arm_getid    */
                                  0,        /* reserved for future use */
                                  (char *)buf_ptr,  /* metrics buf ptr */
                                  buf_sz);  /* user metric buffer size */

    /* If the ARM Agent returns a correlator, determine the size of    */
    /* the agent specific data in the correlator and pass the data,    */
    /* along with the correlator length, to the server application.    */

    if ((buf_ptr->flags[0] & ARM_CorrGen_f) == ARM_CorrGen_f) {
        correlator.length = buf_ptr->correlator.length;
        data_len = (correlator.length - sizeof(buf_ptr->correlator.length));
        for (i = 0; i < data_len; i++)
            correlator.agent_data[i] = buf_ptr->correlator.agent_data[i];
    }

    server_application(correlator);

    arm_stop(client_tran_handle, /* transaction handle from arm_start */
             ARM_GOOD,           /* successful completion define = 0  */
             0,                  /* reserved for future use           */
            0,0);                /* buffer pointer & buffer size      */

    return;

}   /* client_transaction() */

/******************************************************************/
/* init_client_application                                        */
/******************************************************************/

void init_client_application()

{

    client_appl_id=arm_init("Client_Application", /* application name */
                            "*",                  /* use default user */
                            0,0,0);        /* reserved for future use */

    client_tran_id = arm_getid(client_appl_id, /* appl_id from arm_init */
                              "Client_transaction", /* transaction name */
                              "First transaction in Client application",
                              0,                            /* reserved */
                              0,0);            /* buffer pointer & size */

    return;

}   /* init_client_application */

/******************************************************************/
/* metric_transaction                                             */
/******************************************************************/

void metric_transaction()

{
    int32 metric_tran_handle = -1; /* transaction start handle */

    arm_user_data1_t *buf_ptr, buf = {
        1,                                           /* Header */
        {0, ARM_AllMetrics_f | ARM_String1_f, 0, 0}, /* Flags  */
        };

    int32 buf_sz;

    buf_ptr = &buf;
    buf_sz = sizeof(buf);

    buf_ptr->metric[0].counter32 = 0x32;
    buf_ptr->metric[1].gauge32 = 0x32;
    buf_ptr->metric[2].counter64.upper = 0x01234567;
    buf_ptr->metric[2].counter64.lower = 0x76543210;
    strcpy(buf_ptr->metric[3].string8, "String 8");
    buf_ptr->metric[4].cntrdivr32.count = 0x32;
    buf_ptr->metric[4].cntrdivr32.divisor = 0x32;
    buf_ptr->metric[5].numericid64.upper = 0x01234567;
    buf_ptr->metric[5].numericid64.lower = 0x76543210;
    strcpy(buf_ptr->string32,"This is a 32 character string ");

    metric_tran_handle = arm_start(metric_tran_id, /* tran_id from */
                                                   /* arm_getid    */
                               0,                  /* reserved     */
                               (char *)buf_ptr, /* metrics buf ptr */
                               buf_sz); /* user metric buffer size */

    /********************************/
    /* Perform some processing here */
    /********************************/

    arm_update(metric_tran_handle,  /* trans handle from arm_start */
               0,                   /* reserved for future use     */
               (char *)buf_ptr,     /* user metrics buffer pointer */
               buf_sz);             /* user metric buffer size     */

    /*************************************/
    /* Perform some more processing here */
    /*************************************/

    arm_stop(metric_tran_handle, /* transaction handle from arm_start */
             ARM_GOOD,           /* successful completion define = 0  */
             0,                  /* reserved for future use           */
             (char *)buf_ptr,    /* user metrics buffer pointer       */
             buf_sz);            /* user metric buffer size           */

    return;

}   /* metric_transaction() */

/*****************************************************************/
/* init_metric_application                                       */
/*****************************************************************/

void init_metric_application()
{
arm_user_data101_t *buf_ptr, buf = {
    101,
    {0, ARM_AllMetrics_f | ARM_String1_f, 0, 0},
    {{1, "Metric #1 - Type 1 is a COUNTER32         "},
    {4, "Metric #2 - Type 4 is a GAUGE32            "},
    {2, "Metric #3 - Type 2 is a COUNTER64          "},
    {9, "Metric #4 - Type 9 is a STRING8            "},
    {3, "Metric #5 - Type 3 is a COUNTER32/DIVISOR32"},
    {8, "Metric #6 - Type 8 is a NUMERICID64        "}
    {10, "The last field is always a STRING32       "}
    }};

int32 buf_sz;

buf_ptr = &buf;
buf_sz = sizeof(buf);

metric_appl_id=arm_init("Metric_Application", /* application name */
                        "*",                  /* use default user */
                        0,0,0);               /* reserved         */

metric_tran_id = arm_getid(metric_appl_id, /* appl_id from arm_init */
                      Metric_transaction", /* transaction name      */
                      "First transaction in Metric application",
                       0,                  /* reserved              */
                       (char *)buf_ptr,    /* buffer                */
                       buf_sz);            /* buffer size           */

    return;

} /* init_metric_application */

/*****************************************************************/
/* Main                                                          */
/*****************************************************************/

main()
{

    int continue_processing = 1;

    init_client_application();

    init_metric_application();

while (continue_processing)
{
    client_transaction();
    metric_transaction();
    continue_processing = 0;
}

arm_end(client_appl_id,     /* application id from arm_init */
        0,0,0);             /* reserved for future use      */

arm_end(metric_appl_id,     /* application id from arm_init */
        0,0,0);             /* reserved for future use      */
    return(0);



Why not acquire a nicely bound hard copy?
Click here to return to the publication details or order a copy of this publication.

Contents Next section Index