📄 cimperf.cpp
字号:
break; case 24: opName = _OPERATION_NAME[StatisticalData::DELETE_QUALIFIER]; break; case 25: opName = _OPERATION_NAME[StatisticalData::ENUMERATE_QUALIFIERS]; break; case 26: opName = _OPERATION_NAME[StatisticalData::INDICATION_DELIVERY]; break; case 1: opName = _OPERATION_NAME[StatisticalData::INVOKE_METHOD]; break; default: //Invalid type opName = "Dummy Response"; } return opName;}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; // Operation Type is decoded as const char*, hence type has // changed from string to const char* const char* statName = NULL; CIMValue v; Uint16 type; if ((pos = instance.findProperty("OperationType")) != PEG_NOT_FOUND) { p = (instance.getProperty(pos)); v = p.getValue(); if (v.getType() == CIMTYPE_UINT16) { v.get(type); statName = opTypeToOpName(type); } } 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", statName, numberOfRequests, averageCimomTime, averageProviderTime, averageRequestSize, averageResponseSize); } } catch (Exception& e) { cerr << argv[0] << "Exception : " << e.getMessage() << endl; exit(1); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -