📄 benchmarktest.cpp
字号:
client.setTimeout( _timeout ); try { _connectToServer( client, outPrintWriter); isConnected = true; Boolean deepInheritance = true; Boolean localOnly = false; Boolean includeQualifiers = false; Boolean includeClassOrigin = false; Array<CIMInstance> cimNInstances = client.enumerateInstances(OSINFO_NAMESPACE, OSINFO_CLASSNAME, deepInheritance, localOnly, includeQualifiers, includeClassOrigin ); // while we only have one instance (the running OS), we can take the // first instance. When the OSProvider supports installed OSs as well, // will need to select the runningOS instance if (cimNInstances.size() != 1) { client.disconnect(); return; } CIMObjectPath instanceRef = cimNInstances[0].getPath(); if ( !(instanceRef.getClassName().equal(OSINFO_CLASSNAME)) ) { errPrintWriter << "Returned ClassName = " << instanceRef.getClassName().getString() << endl; errPrintWriter << "Expected ClassName = " << OSINFO_CLASSNAME.getString() << endl; errorExit(errPrintWriter, "enumerateInstances failed. Incorrect class name returned."); } for (Uint32 j = 0; j < cimNInstances[0].getPropertyCount(); j++) { CIMName propertyName = cimNInstances[0].getProperty(j).getName(); if (propertyName.equal(CIMName("CSName"))) { outPrintWriter << "Computer System Name = " << cimNInstances[0].getProperty(j).getValue().toString() << endl; } if (propertyName.equal(CIMName("Version"))) { outPrintWriter << "Version = " << cimNInstances[0].getProperty(j).getValue().toString() << endl; } } } // end try catch(...) { if (isConnected) client.disconnect(); return; } client.disconnect();}void benchmarkTestCommand::_getSystemConfiguration( ostream& outPrintWriter, ostream& errPrintWriter){ benchmarkTestCommand::_getOSInfo(outPrintWriter, errPrintWriter); benchmarkTestCommand::_getCSInfo(outPrintWriter, errPrintWriter); outPrintWriter << endl << endl;}void benchmarkTestCommand::_getTestConfiguration( ostream& outPrintWriter, ostream& errPrintWriter){ Boolean isConnected = false; CIMClient client; client.setTimeout( _timeout ); try { _connectToServer( client, outPrintWriter); isConnected = true; Boolean deepInheritance = true; Array<CIMName> classNames = client.enumerateClassNames( NAMESPACE, CIMName(), deepInheritance); Uint32 numberOfProperties; Uint32 sizeOfPropertyValue; Uint32 numberOfInstances; for (Uint32 i = 0, n = classNames.size(); i < n; i++) { if (CIM_ERR_SUCCESS == test.getConfiguration(classNames[i], numberOfProperties, sizeOfPropertyValue, numberOfInstances)) { _testClassNames.append (classNames[i]); } } } // end try catch (const Exception&) { if (isConnected) client.disconnect(); throw; } catch (const exception&) { if (isConnected) client.disconnect(); throw; } client.disconnect();}CIMObjectPath benchmarkTestCommand::_buildObjectPath( const CIMName& className, CIMValue Identifier){ Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("Identifier", Identifier.toString(), CIMKeyBinding::NUMERIC)); return CIMObjectPath(String(),CIMNamespaceName(NAMESPACE),className,keys);}Boolean benchmarkTestCommand::_invokeProviderModuleMethod( const String& moduleName, const CIMName& methodName, ostream& outPrintWriter, ostream& errPrintWriter){ CIMClient client; Boolean isConnected = false; Sint16 retValue = -1; client.setTimeout( _timeout ); CIMObjectPath moduleRef; try { _connectToServer( client, outPrintWriter); isConnected = true; // // disable the module // moduleRef.setNameSpace(PEGASUS_NAMESPACENAME_PROVIDERREG); moduleRef.setClassName(PEGASUS_CLASSNAME_PROVIDERMODULE); CIMKeyBinding kb1(CIMName ("Name"), moduleName, CIMKeyBinding::STRING); Array<CIMKeyBinding> keys; keys.append(kb1); moduleRef.setKeyBindings(keys); Array<CIMParamValue> inParams; Array<CIMParamValue> outParams; CIMValue ret_value = client.invokeMethod( PEGASUS_NAMESPACENAME_PROVIDERREG, moduleRef, methodName, inParams, outParams); ret_value.get(retValue); client.disconnect(); } catch (const Exception&) { if (isConnected) client.disconnect(); throw; } if ((retValue == 0) || (retValue == 1)) return true; else return false;}void benchmarkTestCommand::dobenchmarkTest1( Uint32 testID, ostream& outPrintWriter, ostream& errPrintWriter){ CIMClient client; client.setTimeout( _timeout ); try { Stopwatch stopwatchTime; stopwatchTime.start(); for (Uint32 i = 0; i < _iterations; i++) { _connectToServer( client, outPrintWriter); client.disconnect(); } stopwatchTime.stop(); double elapsedTime = stopwatchTime.getElapsed(); outPrintWriter << testID; outPrintWriter << ": Benchmark Test #1: Connect/Disconnect Test" << endl; outPrintWriter << _iterations << " requests processed in " << stopwatchTime.getElapsed() << " Seconds " << "(Average Elapse Time = " << elapsedTime/_iterations << ")" << endl << endl; if (_resultsFileHandle != NULL) { fprintf(_resultsFileHandle, "Connect/Disconnect\t%f\t", elapsedTime); } } // end try catch(const Exception& e) { errorExit(errPrintWriter, e.getMessage()); }}void benchmarkTestCommand::dobenchmarkTest2( Uint32 testID, const CIMName& className, ostream& outPrintWriter, ostream& errPrintWriter){ CIMClient client; client.setTimeout( _timeout ); try { Stopwatch stopwatchTime; stopwatchTime.start(); _connectToServer(client, outPrintWriter); stopwatchTime.stop(); double connectTime = stopwatchTime.getElapsed(); stopwatchTime.reset(); stopwatchTime.start(); if (_invokeProviderModuleMethod(MODULENAME, CIMName("stop"), outPrintWriter, errPrintWriter)) { _invokeProviderModuleMethod(MODULENAME, CIMName("start"), outPrintWriter, errPrintWriter); } stopwatchTime.stop(); double _unloadModuleTime = stopwatchTime.getElapsed(); stopwatchTime.reset(); stopwatchTime.start(); CIMObjectPath reference = benchmarkTestCommand::_buildObjectPath(className, CIMValue(99)); CIMInstance cimInstance = client.getInstance(NAMESPACE, reference); CIMObjectPath instanceRef = cimInstance.getPath(); if ( !(instanceRef.getClassName().equal(className))) { outPrintWriter << "Returned ClassName = " << instanceRef.getClassName().getString() << endl; outPrintWriter << "Expected ClassName = " << className.getString() << endl; errorExit(errPrintWriter, "getInstance failed. Incorrect class name returned."); } stopwatchTime.stop(); double elapsedTime = stopwatchTime.getElapsed(); outPrintWriter << testID << ": Benchmark Test #2: Load Provider Test on class " << className.getString() << endl; outPrintWriter << "Connect time = " << connectTime << endl; outPrintWriter << "Unload Module time = " << _unloadModuleTime << endl; outPrintWriter << "First getInstance request processed in " << elapsedTime << " Seconds " << endl << endl; if (_resultsFileHandle != NULL) { fprintf(_resultsFileHandle, "Load/Unload\t%f\t", elapsedTime); } client.disconnect(); } // end try catch(const Exception& e) { errorExit(errPrintWriter, e.getMessage()); }}void benchmarkTestCommand::dobenchmarkTest3( Uint32 testID, const CIMName& className, ostream& outPrintWriter, ostream& errPrintWriter){ CIMClient client; client.setTimeout( _timeout ); try { Stopwatch stopwatchTime; stopwatchTime.reset(); stopwatchTime.start(); _connectToServer( client, outPrintWriter); stopwatchTime.stop(); double connectTime = stopwatchTime.getElapsed(); Uint32 numberOfProperties; Uint32 sizeOfPropertyValue; Uint32 expectedNumberOfInstances; test.getConfiguration(className, numberOfProperties, sizeOfPropertyValue, expectedNumberOfInstances); stopwatchTime.reset(); stopwatchTime.start(); CIMObjectPath reference = benchmarkTestCommand::_buildObjectPath(className, CIMValue(99)); for (Uint32 i = 0; i < _iterations; i++) { CIMInstance cimInstance = client.getInstance(NAMESPACE, reference); CIMObjectPath instanceRef = cimInstance.getPath(); if ( !(instanceRef.getClassName().equal(className))) { outPrintWriter << "Returned ClassName = " << instanceRef.getClassName().getString() << endl; outPrintWriter << "Expected ClassName = " << className.getString() << endl; errorExit(errPrintWriter, "getInstance failed. Incorrect class name returned."); } if ( cimInstance.getPropertyCount() != numberOfProperties+1) { errorExit(errPrintWriter, "getInstance failed. " "Incorrect number of properties returned."); } } stopwatchTime.stop(); double elapsedTime = stopwatchTime.getElapsed(); outPrintWriter << testID << ": Benchmark Test #3: getInstance Test on " << className.getString() << endl; outPrintWriter << "Connect time = " << connectTime << endl; outPrintWriter << "Number of Non-Key Properties Returned = " << numberOfProperties << endl << "Size of Each Non-Key Property Returned = " << sizeOfPropertyValue << endl << "Number of Instances Returned = " << 1 << endl; outPrintWriter << _iterations << " requests processed in " << elapsedTime << " Seconds " << "(Average Elapse Time = " << elapsedTime/_iterations << ")" << endl << endl; if (_resultsFileHandle != NULL) { fprintf(_resultsFileHandle,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -