(file) Return to cimperf.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Clients / cimperf

File: [Pegasus] / pegasus / src / Clients / cimperf / cimperf.cpp (download)
Revision: 1.20, Mon Feb 13 20:05:14 2006 UTC (18 years, 4 months ago) by w.white
Branch: MAIN
CVS Tags: TASK_PEP233_EmbeddedInstSupport-merge_out_trunk, TASK_BUG_5314_IPC_REFACTORING_ROOT, TASK_BUG_5314_IPC_REFACTORING_BRANCH, TASK_BUG_5314_IPC_REFACTORING-V1, TASK_BUG_5191_QUEUE_CONSOLIDATION_ROOT, TASK_BUG_5191_QUEUE_CONSOLIDATION_BRANCH, TASK-TASK-BUG4011_WinLocalConnect-branch-New-root, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_out_to_branch, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_out_from_trunk, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_in_to_trunk, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_in_from_branch, TASK-TASK-BUG4011_WinLocalConnect-branch-New-branch, TASK-PEP268_SSLClientCertificatePropagation-root, TASK-PEP268_SSLClientCertificatePropagation-merged_out_to_branch, TASK-PEP268_SSLClientCertificatePropagation-merged_out_from_trunk, TASK-PEP268_SSLClientCertificatePropagation-merged_in_to_trunk, TASK-PEP268_SSLClientCertificatePropagation-merged_in_from_branch, TASK-PEP268_SSLClientCertificatePropagation-branch, TASK-PEP267_SLPReregistrationSupport-root, TASK-PEP267_SLPReregistrationSupport-merging_out_to_branch, TASK-PEP267_SLPReregistrationSupport-merging_out_from_trunk, TASK-PEP267_SLPReregistrationSupport-merged_out_to_branch, TASK-PEP267_SLPReregistrationSupport-merged_out_from_trunk, TASK-PEP267_SLPReregistrationSupport-merged_in_to_trunk, TASK-PEP267_SLPReregistrationSupport-merged_in_from_branch, TASK-PEP267_SLPReregistrationSupport-branch, TASK-PEP250_RPMProvider-root, TASK-PEP250_RPMProvider-merged_out_to_branch, TASK-PEP250_RPMProvider-merged_out_from_trunk, TASK-PEP250_RPMProvider-merged_in_to_trunk, TASK-PEP250_RPMProvider-merged_in_from_branch, TASK-PEP250_RPMProvider-branch, TASK-PEP245_CimErrorInfrastructure-root, TASK-PEP245_CimErrorInfrastructure-merged_out_to_branch, TASK-PEP245_CimErrorInfrastructure-merged_out_from_trunk, TASK-PEP245_CimErrorInfrastructure-merged_in_to_trunk, TASK-PEP245_CimErrorInfrastructure-merged_in_from_branch, TASK-PEP245_CimErrorInfrastructure-branch, TASK-PEP241_OpenPegasusStressTests-root, TASK-PEP241_OpenPegasusStressTests-merged_out_to_branch, TASK-PEP241_OpenPegasusStressTests-merged_out_from_trunk, TASK-PEP241_OpenPegasusStressTests-merged_in_to_trunk, TASK-PEP241_OpenPegasusStressTests-merged_in_from_branch, TASK-PEP241_OpenPegasusStressTests-branch, TASK-Bugs5690_3913_RemoteCMPI-root, TASK-Bugs5690_3913_RemoteCMPI-merged_out_to_branch, TASK-Bugs5690_3913_RemoteCMPI-merged_out_from_trunk, TASK-Bugs5690_3913_RemoteCMPI-merged_in_to_trunk, TASK-Bugs5690_3913_RemoteCMPI-merged_in_from_branch, TASK-Bugs5690_3913_RemoteCMPI-branch, TASK-Bug2021_RemoteCMPIonWindows-root, TASK-Bug2021_RemoteCMPIonWindows-merged_out_to_branch, TASK-Bug2021_RemoteCMPIonWindows-merged_out_from_trunk, TASK-Bug2021_RemoteCMPIonWindows-merged_in_to_trunk, TASK-Bug2021_RemoteCMPIonWindows-merged_in_from_branch, TASK-Bug2021_RemoteCMPIonWindows-branch, TASK-Bug2021_RCMPIonWindows-root, TASK-Bug2021_RCMPIonWindows-merged_out_to_branch, TASK-Bug2021_RCMPIonWindows-merged_out_from_trunk, TASK-Bug2021_RCMPIonWindows-merged_in_to_trunk, TASK-Bug2021_RCMPIonWindows-merged_in_from_branch, TASK-Bug2021_RCMPIonWindows-branch, TASK-BUG4011_WinLocalConnect-root, TASK-BUG4011_WinLocalConnect-merged_out_to_branch, TASK-BUG4011_WinLocalConnect-merged_out_from_trunk, TASK-BUG4011_WinLocalConnect-merged_in_to_trunk, TASK-BUG4011_WinLocalConnect-merged_in_from_branch, TASK-BUG4011_WinLocalConnect-branch-New, TASK-BUG4011_WinLocalConnect-branch, RELEASE_2_6_0-FC, RELEASE_2_5_5-RC2, RELEASE_2_5_5-RC1, RELEASE_2_5_5, RELEASE_2_5_4-RC2, RELEASE_2_5_4-RC1, RELEASE_2_5_4, RELEASE_2_5_3-RC1, RELEASE_2_5_3, RELEASE_2_5_2-RC1, RELEASE_2_5_2, RELEASE_2_5_1-RC1, RELEASE_2_5_1, RELEASE_2_5-root, RELEASE_2_5-branch
Changes since 1.19: +4 -2 lines
BUG#: 3450

TITLE:cimperf defaults to remote connection

DESCRIPTION: checking in fix

//%2006////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
// IBM Corp.; EMC Corporation, The Open Group.
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
// EMC Corporation; VERITAS Software Corporation; The Open Group.
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
// EMC Corporation; Symantec Corporation; The Open Group.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//==============================================================================
//
// Author: Karl Schopmeyer (k.schopmeyer@opengroup.org)
//
// Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
//                (carolann_graves@hp.com)
//              Amit K Arora (amita@in.ibm.com) for Bug# 1081 (mofFormat())
//              Willis White (whiwill@us.ibm.com)
//              Josephine Eskaline Joyce (jojustin@in.ibm.com) for Bug#3449
//              Aruran, IBM(ashanmug@in.ibm.com) for Bug# 3684
//              Melvin Solomon, IBM(msolomon@in.ibm.com) for Bug# 3866
//
//%/////////////////////////////////////////////////////////////////////////////

/* This is a simplistic display program for the CIMOM performance characteristics.
    This version simply gets the instances of the performace class and displays
    the resulting average counts.
    TODO  KS
    1. Convert to use the correct class when it is available.
    2. Get the header information from the class, not fixed.
    3. Keep history and present so that there is a total
    4. Do Total so that we have overall counts.
    5. Do percentages
*/
#include <Pegasus/Common/Config.h>
#include <Pegasus/Common/PegasusAssert.h>
#include <stdlib.h>
#include <Pegasus/Client/CIMClient.h>
#include <Pegasus/Common/HTTPConnector.h>
#include <Pegasus/Common/OptionManager.h>
#include <Pegasus/Common/FileSystem.h>
#include <Pegasus/Common/CIMDateTime.h>
#include <Pegasus/Common/PegasusVersion.h>

PEGASUS_USING_PEGASUS;
PEGASUS_USING_STD;

const String DEFAULT_NAMESPACE = "root/cimv2";

//------------------------------------------------------------------------------
//
// _indent()
//
//------------------------------------------------------------------------------

static void _indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentSize)
{
    Uint32 n = level * indentSize;
    if (n > 50)
    {
        cout << "Jumped Ship " << level << " size " << indentSize << endl;
        exit(1);
    }

    for (Uint32 i = 0; i < n; i++)
        os << ' ';
}

void mofFormat(
    PEGASUS_STD(ostream)& os,
    const char* text,
    Uint32 indentSize)
{
    char* var = new char[strlen(text)+1];
    char* tmp = strcpy(var, text);
    Uint32 count = 0;
    Uint32 indent = 0;
    Boolean quoteState = false;
    Boolean qualifierState = false;
    char c;
    char prevchar='\0';
    while ((c = *tmp++) != '\0')
    {
        count++;
        // This is too simplistic and must move to a token based mini parser
        // but will do for now. One problem is tokens longer than 12 characters that
        // overrun the max line length.
        switch (c)
        {
            case '\n':
                os << Sint8(c);
                prevchar = c;
                count = 0 + (indent * indentSize);
                _indent(os, indent, indentSize);
                break;

            case '\"':   // quote
                os << Sint8(c);
                prevchar = c;
                quoteState = !quoteState;
                break;

            case ' ':
                os << Sint8(c);
                prevchar = c;
                if (count > 66)
                {
                    if (quoteState)
                    {
                        os << "\"\n";
                        _indent(os, indent + 1, indentSize);
                        os <<"\"";
                    }
                    else
                    {
                        os <<"\n";
                        _indent(os, indent + 1,  indentSize);
                    }
                    count = 0 + ((indent + 1) * indentSize);
                }
                break;
            case '[':
                if (prevchar == '\n')
                {
                    indent++;
                    _indent(os, indent,  indentSize);
                    qualifierState = true;
                }
                os << Sint8(c);
                prevchar = c;
                break;

            case ']':
                if (qualifierState)
                {
                    if (indent > 0)
                        indent--;
                    qualifierState = false;
                }
                os << Sint8(c);
                prevchar = c;
                break;

            default:
                os << Sint8(c);
                prevchar = c;
        }
    }
    delete [] var;
}

/* method to build an OptionManager object - which holds and organizes options and the properties */

void GetOptions(
    OptionManager& om,
    int& argc,
    char** argv,
    const String& testHome)
{
    static const char* outputFormats[] = { "xml", "mof", "txt"};
    static const Uint32 NUM_OUTPUTFORMATS = sizeof(outputFormats) /
        sizeof(outputFormats[0]);

    static struct OptionRow optionsTable[] =
    //The values in the OptionRows below are:
    //optionname, defaultvalue, is required, type, domain, domainsize, flag, hlpmsg
    {
        {"port", "5988", false, Option::INTEGER, 0, 0, "p",
                "specifies port"},

        {"location", "localhost", false, Option::STRING, 0, 0, "h",
                "specifies hostname of system"},

        {"version", "false", false, Option::BOOLEAN, 0, 0, "-version",
                "Displays software Version "},

        {"help", "false", false, Option::BOOLEAN, 0, 0, "-help",
                "Prints help message with command line options "},

        {"user name","",false,Option::STRING, 0, 0, "u",
                "specifies user loging in"},

        {"password","",false,Option::STRING, 0, 0, "w",
                "login password for user"},

    };
    const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]);

    om.registerOptions(optionsTable, NUM_OPTIONS);

    //We want to make this code common to all of the commands

    String configFile = "/CLTest.conf";

    if (FileSystem::exists(configFile))
    {
        om.mergeFile(configFile);
    }

    om.mergeCommandLine(argc, argv);

    om.checkRequiredOptions();
}

int main(int argc, char** argv)
{

    // Get options (from command line and from configuration file); this
    // removes corresponding options and their arguments from the command
    // line.

    OptionManager om;

    try
    {
        String testHome = ".";
        GetOptions(om, argc, argv, testHome);
        // om.print();
    }
    catch (Exception& e)
    {
        cerr << argv[0] << ": " << e.getMessage() << endl;
        String header = "Usage ";
        String trailer = "";
        om.printOptionsHelpTxt(header, trailer);
        exit(1);
    }

    // Establish the namespace from the input parameters
    String nameSpace = "root/cimv2";

    // Check to see if user asked for help (--help option)
    if (om.valueEquals("help", "true"))
    {
        String header = "Usage ";
        String trailer = "";
        om.printOptionsHelpTxt(header, trailer);
        exit(0);
    }
    else if (om.valueEquals("version", "true"))
    {
        cerr << "Version " << PEGASUS_PRODUCT_VERSION << endl;
        exit(0);
    }

    //Get hostname form (option manager) command line if none use default
    String location;
    om.lookupValue("location", location);

    // Get port number from (option manager) command line; if none use the
    // default.  The lookup will always be successful since the optionTable
    // has a default value for this option.
    String str_port;
    Uint32 port = 0;
    if (om.lookupValue("port", str_port))
    {
        port = (Uint32) atoi(str_port.getCString());
    }

    //Get user name and password
    String userN;
    String passW;
    om.lookupValue("user name", userN);
    om.lookupValue("pass word", passW);

    /*
    The next section of code connects to the server and enumerates all the 
    instances of the CIM_CIMOMStatisticalData class. The instances are held in
    an Array named "instances". The output of cimperf is a table of averages.
    */


    String className = "CIM_CIMOMStatisticalData";
    CIMClient client;

    try
    {   if(String::equal(location,"localhost"))
            client.connectLocal();
        else
            client.connect(location, port, userN, passW);
    }

    catch (Exception& e)
    {
        cerr << argv[0] << " Exception connecting to : " << location << endl;
        cerr << e.getMessage() << endl;
        exit(1);
    }


    try
    {
        Boolean localOnly = false;
        Boolean deepInheritance = false;
        Boolean includeQualifiers = false;
        Boolean includeClassOrigin = false;

        Array<CIMInstance> instances;
        instances = client.enumerateInstances(nameSpace,
            className,
            deepInheritance,
            localOnly,
            includeQualifiers,
            includeClassOrigin);

        // First print the header for table of values
        printf("%-25s%10s %10s %10s %10s %10s\n",
    "Operation", "Number of", "Server", "Provider", "Request", "Response");

	printf("%-25s%10s %10s %10s %10s %10s\n",
    "Type", "Requests", "Time", "Time", "Size", "Size");

	printf("%-25s%10s %10s %10s %10s %10s\n",
    " ", " ", "(usec)", "(usec)", "(bytes)", "(bytes)");

        printf("%-25s\n", "-------------------------------------------------------------------------------");

        // This section of code loops through all the instances of 
        // CIM_CIMOMStatisticalData (one for each intrinsic request type) and
        // gathers the NumberofOperations, CIMOMElapsedTime, 
        // ProviderElapsedTime, ResponseSize and RequestSize for each instance.
        // Averages are abtained by dividing times and sizes by 
        // NumberofOperatons.

        for (Uint32 inst = 0; inst < instances.size(); inst++)
        {
            CIMInstance instance = instances[inst];

            // Get the request type property for this instance.
            // Note that for the moment it is simply an integer.
            Uint32 pos;
            CIMProperty p;
            String statName;
            CIMValue v;

            if ((pos = instance.findProperty("ElementName")) != PEG_NOT_FOUND)
            {
                p = (instance.getProperty(pos));
                v = p.getValue();
                if (v.getType() == CIMTYPE_STRING)
                {
                    v.get(statName);
                }
            }
            else
            {
                statName = "UNKNOWN";
            }

            // Get number of requests property - "NumberofOperations"
            Uint64 numberOfRequests = 0;
            if ((pos = instance.findProperty("NumberOfOperations")) != PEG_NOT_FOUND)
            {

                p = (instance.getProperty(pos));
                v = p.getValue();

                if (v.getType() == CIMTYPE_UINT64)
                {
                    v.get(numberOfRequests);

                }
                else
                {
                    cerr << "NumberofOperations was not a CIMTYPE_SINT64 and should be" << endl;
                }
            }
            else
            {
                cerr << "Could not find NumberofOperations" << endl;
            }

            // Get the total CIMOM Time property "CIMOMElapsedTime"
            // in order to calculate the averageCimomTime.
            CIMDateTime totalCimomTime;
            Sint64 averageCimomTime = 0;
            Uint64 totalCT = 0;

            if ((pos = instance.findProperty("CimomElapsedTime")) != PEG_NOT_FOUND)
            {
                p = (instance.getProperty(pos));
                v = p.getValue();

                if (v.getType() == CIMTYPE_DATETIME)
                {
                    v.get(totalCimomTime);
                    totalCT = totalCimomTime.toMicroSeconds();
                }
                else
                {
                    cerr << "Error Property value " << "CimomElapsedTime" << endl;
                }
            }
            else
            {
                cerr << "Error Property " << "CimomElapsedTime" << endl;
            }

            if (numberOfRequests != 0)
            {
                averageCimomTime = totalCT / numberOfRequests;
            }

            // Get the total Provider Time property "ProviderElapsedTime"
            CIMDateTime totalProviderTime;
            Uint64 averageProviderTime = 0;
            Uint64 totalPT = 0;

            if ((pos = instance.findProperty("ProviderElapsedTime")) != PEG_NOT_FOUND)
            {
                p = (instance.getProperty(pos));
                v = p.getValue();
                if (v.getType() == CIMTYPE_DATETIME)
                {
                    v.get(totalProviderTime);
                    totalPT = totalProviderTime.toMicroSeconds();
                }
                else
                {
                    cerr << "Error Property Vlaue " << "ProviderElapsedTime" << endl;
                }
            }
            else
            {
                cerr << "Error Property " << "ProviderElapsedTime" << endl;
            }

            if (numberOfRequests != 0)
            {
                averageProviderTime = totalPT / numberOfRequests;
            }

            // Get the total Response size property "ResponseSize"
            Uint64 totalResponseSize = 0;
            Uint64 averageResponseSize = 0;

            if ((pos = instance.findProperty("ResponseSize")) != PEG_NOT_FOUND)
            {
                p = (instance.getProperty(pos));
                v = p.getValue();

                if (v.getType() == CIMTYPE_UINT64)
                {
                    v.get(totalResponseSize);
                }
                else
                {
                    cerr << "RequestSize is not of type CIMTYPE_SINT64" << endl ;
                }
            }
            else
            {
                cerr << "Could not find ResponseSize property" << endl;
            }

            if (numberOfRequests != 0)
            {
                averageResponseSize =  totalResponseSize / numberOfRequests;
            }

            //Get the total request size property "RequestSize"
            Uint64 totalRequestSize = 0;
            Uint64 averageRequestSize = 0;

            if ((pos = instance.findProperty("RequestSize")) != PEG_NOT_FOUND)
            {
                p = (instance.getProperty(pos));
                v = p.getValue();

                if (v.getType() == CIMTYPE_UINT64)
                {
                    v.get(totalRequestSize);
                }
                else
                {
                    cerr << "RequestSize is not of type CIMTYPE_SINT64" << endl ;
                }
            }
            else
            {
                cerr << "Could not find RequestSize property" << endl;
            }

            if (numberOfRequests != 0)
            {
                averageRequestSize = totalRequestSize / numberOfRequests;
            }

            //if StatisticalData::copyGSD is FALSE this will only return 0's

            printf("%-25s"
                "%10"  PEGASUS_64BIT_CONVERSION_WIDTH "u"
                "%11" PEGASUS_64BIT_CONVERSION_WIDTH "u"
                "%11" PEGASUS_64BIT_CONVERSION_WIDTH "u"
                "%11" PEGASUS_64BIT_CONVERSION_WIDTH "u"
                "%11" PEGASUS_64BIT_CONVERSION_WIDTH "u\n",
                (const char*)statName.getCString(),
                numberOfRequests, averageCimomTime,
                averageProviderTime, averageRequestSize,
                averageResponseSize);
        }
    }
    catch (Exception& e)
    {
        cerr << argv[0] << "Exception : " << e.getMessage() << endl;
        exit(1);
    }

    return 0;
}



No CVS admin address has been configured
Powered by
ViewCVS 0.9.2