📄 benchmarktest.cpp
字号:
"getInstance\t%s\t%f\t", (const char *)className.getString().getCString(), elapsedTime/_iterations); } client.disconnect(); } // end try catch(const Exception& e) { errorExit(errPrintWriter, e.getMessage()); }}void benchmarkTestCommand::dobenchmarkTest4( 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); Uint32 numberInstances; stopwatchTime.reset(); stopwatchTime.start(); for (Uint32 i = 0; i < _iterations; i++) { Array<CIMObjectPath> cimInstanceNames = client.enumerateInstanceNames(NAMESPACE, className); numberInstances = cimInstanceNames.size(); if (numberInstances != expectedNumberOfInstances) { errorExit(errPrintWriter, "enumerateInstanceNames failed. " "Incorrect number of instances returned."); } for (Uint32 j = 0; j < numberInstances; j++) { if ( !(cimInstanceNames[j].getClassName().equal(className))) { errorExit(errPrintWriter, "enumerateInstanceNames failed. " "Incorrect class name returned."); } } // end for looping through instances } stopwatchTime.stop(); double elapsedTime = stopwatchTime.getElapsed(); outPrintWriter << testID << ": Benchmark Test #4: enumerateInstanceNames Test on class " << className.getString() << endl; outPrintWriter << "Connect time = " << connectTime << endl; outPrintWriter << "Number of Non-Key Properties Returned = " << 0 << endl << "Number of Instances Returned = " << expectedNumberOfInstances << endl; outPrintWriter << _iterations << " requests processed in " << elapsedTime << " Seconds " << "(Average Elapse Time = " << elapsedTime/_iterations << ")" << endl << endl; if (_resultsFileHandle != NULL) { fprintf(_resultsFileHandle, "enumerateInstanceNames\t%s\t%f\t", (const char *)className.getString().getCString(), elapsedTime/_iterations); } client.disconnect(); } // end try catch(const Exception& e) { errorExit(errPrintWriter, e.getMessage()); }}void benchmarkTestCommand::dobenchmarkTest5( 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); Uint32 numberInstances; stopwatchTime.reset(); stopwatchTime.start(); Boolean deepInheritance = true; Boolean localOnly = false; Boolean includeQualifiers = false; Boolean includeClassOrigin = false; for (Uint32 i = 0; i < _iterations; i++) { Array<CIMInstance> cimNInstances = client.enumerateInstances(NAMESPACE, className, deepInheritance, localOnly, includeQualifiers, includeClassOrigin ); numberInstances = cimNInstances.size(); if (numberInstances != expectedNumberOfInstances) { errorExit(errPrintWriter, "enumerateInstances failed. " "Incorrect number of instances returned."); } for (Uint32 j = 0; j < numberInstances; j++) { CIMObjectPath instanceRef = cimNInstances[j].getPath (); if ( !(instanceRef.getClassName().equal(className))) { errorExit(errPrintWriter, "enumerateInstances failed. " "Incorrect class name returned."); } if ( cimNInstances[j].getPropertyCount() != numberOfProperties+1) { errorExit(errPrintWriter, "enumerateInstances failed. " "Incorrect number of properties returned."); } } // end for looping through instances } stopwatchTime.stop(); double elapsedTime = stopwatchTime.getElapsed(); outPrintWriter << testID << ": Benchmark Test #5: enumerateInstances Test on class " << 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 = " << expectedNumberOfInstances << endl; outPrintWriter << _iterations << " requests processed in " << elapsedTime << " Seconds " << "(Average Elapse Time = " << elapsedTime/_iterations << ")" << endl << endl; if (_resultsFileHandle != NULL) { fprintf(_resultsFileHandle, "enumerateInstances\t%s\t%f\t", (const char *)className.getString().getCString(), elapsedTime/_iterations); } client.disconnect(); } // end try catch(const Exception& e) { errorExit(errPrintWriter, e.getMessage()); }}/** Executes the command and writes the results to the PrintWriters. @param outPrintWriter the ostream to which output should be written @param errPrintWriter the ostream to which error output should be written @return 0 if the command is successful 1 if an error occurs in executing the command */Uint32 benchmarkTestCommand::execute (ostream& outPrintWriter, ostream& errPrintWriter){ benchmarkDefinition test; if (_resultsDirectory != String::EMPTY) { String resultsFile = _resultsDirectory; resultsFile.append("/benchmarkTestResults0001.txt"); _resultsFileHandle = fopen(resultsFile.getCString(), "a+"); } else { _resultsFileHandle = NULL; } if (_resultsFileHandle != NULL) { _startTime = System::getCurrentASCIITime().getCString(); fprintf(_resultsFileHandle, "%s\t", (const char *)_startTime.getCString()); } try { if (_debugOption1) { Tracer::setTraceFile("benchmarkTest.trc"); Tracer::setTraceComponents("ALL"); Tracer::setTraceLevel(Tracer::LEVEL4); } Uint32 testID = 0; if (_generateReport) { benchmarkTestCommand::_getSystemConfiguration( outPrintWriter, errPrintWriter); } benchmarkTestCommand::_getTestConfiguration(outPrintWriter, errPrintWriter); testID++; if (!_testIDSet || (testID == _testID)) { benchmarkTestCommand::dobenchmarkTest1( testID, outPrintWriter, errPrintWriter); } testID++; if (!_testIDSet || (testID == _testID)) { benchmarkTestCommand::dobenchmarkTest2( testID, _testClassNames[0], outPrintWriter, errPrintWriter); } for (Uint32 i = 0, n = _testClassNames.size(); i < n; i++) { if ((_resultsFileHandle != NULL) && ((i+1) % 10) == 0) { fclose(_resultsFileHandle); String resultsFile = _resultsDirectory; char s[40]; sprintf(s, "/benchmarkTestResults%.4u.txt", (i/10)+1); resultsFile.append(s); _resultsFileHandle = fopen(resultsFile.getCString(), "a+"); if (_resultsFileHandle != NULL) { fprintf(_resultsFileHandle, "%s\t", (const char *)_startTime.getCString()); } } testID++; if (!_testIDSet || (testID == _testID)) { benchmarkTestCommand::dobenchmarkTest3(testID, _testClassNames[i], outPrintWriter, errPrintWriter); } testID++; if (!_testIDSet || (testID == _testID)) { benchmarkTestCommand::dobenchmarkTest4(testID, _testClassNames[i], outPrintWriter, errPrintWriter); } testID++; if (!_testIDSet || (testID == _testID)) { benchmarkTestCommand::dobenchmarkTest5(testID, _testClassNames[i], outPrintWriter, errPrintWriter); } } } catch (const benchmarkTestException& e) { errPrintWriter << benchmarkTestCommand::COMMAND_NAME << ": " << e.getMessage () << endl; return (RC_ERROR); } catch (const Exception& e) { errPrintWriter << benchmarkTestCommand::COMMAND_NAME << ": " << e.getMessage () << endl; return (RC_ERROR); } catch (const exception& e) { errPrintWriter << benchmarkTestCommand::COMMAND_NAME << ": " << e.what () << endl; return (RC_ERROR); } if (_resultsFileHandle != NULL) { fprintf(_resultsFileHandle, "\n"); fclose(_resultsFileHandle); } return (RC_SUCCESS);}/** Parses the command line, and executes the command. @param argc the number of command line arguments @param argv the string vector of command line arguments @return 0 if the command is successful 1 if an error occurs in executing the command */PEGASUS_NAMESPACE_END// exclude main from the Pegasus NamespacePEGASUS_USING_PEGASUS;PEGASUS_USING_STD;int main (int argc, char* argv []){ benchmarkTestCommand command = benchmarkTestCommand (); int rc; try { command.setCommand (argc, argv); } catch (const CommandFormatException& cfe) { cerr << benchmarkTestCommand::COMMAND_NAME << ": " << cfe.getMessage () << endl; cerr << command.getUsage () << endl; exit (Command::RC_ERROR); } rc = command.execute (cout, cerr); return (rc);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -