1 //%2003////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 //==============================================================================
26 // Author: Karl Schopmeyer (k.schopmeyer@opengroup.org)
28 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
29 // (carolann_graves@hp.com)
31 //%/////////////////////////////////////////////////////////////////////////////
33 /* This is a simplistic display program for the CIMOM performance characteristics.
34 This version simply gets the instances of the performace class and displays
35 the resulting average counts.
37 1. Convert to use the correct class when it is available.
38 2. Get the header information from the class, not fixed.
39 3. Keep history and present so that there is a total
40 4. Do Total so that we have overall counts.
43 #include <Pegasus/Common/Config.h>
45 #include <Pegasus/Client/CIMClient.h>
46 #include <Pegasus/Common/HTTPConnector.h>
47 #include <Pegasus/Common/OptionManager.h>
48 #include <Pegasus/Common/Stopwatch.h>
49 #include <Pegasus/Common/FileSystem.h>
51 PEGASUS_USING_PEGASUS;
54 const String DEFAULT_NAMESPACE = "root/cimv2";
56 static const char * usage = "blah blah";
57 static const char * extra = "more blah";
59 //------------------------------------------------------------------------------
63 //------------------------------------------------------------------------------
65 static void _indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentSize)
67 Uint32 n = level * indentSize;
70 cout << "Jumped Ship " << level << " size " << indentSize << endl;
74 for (Uint32 i = 0; i < n; i++)
78 PEGASUS_STD(ostream)& os,
82 char* tmp = strcpy(new char[strlen(text) + 1], text);
85 Boolean quoteState = false;
86 Boolean qualifierState = false;
92 // This is too simplistic and must move to a token based mini parser
93 // but will do for now. One problem is tokens longer than 12 characters that
94 // overrun the max line length.
100 count = 0 + (indent * indentSize);
101 _indent(os, indent, indentSize);
107 quoteState = !quoteState;
118 _indent(os, indent + 1, indentSize);
124 _indent(os, indent + 1, indentSize);
126 count = 0 + ((indent + 1) * indentSize);
130 if (prevchar == '\n')
133 _indent(os, indent, indentSize);
134 qualifierState = true;
145 qualifierState = false;
163 const String& testHome)
165 static const char* outputFormats[] = { "xml", "mof", "txt"};
166 static const Uint32 NUM_OUTPUTFORMATS = sizeof(outputFormats) /
167 sizeof(outputFormats[0]);
169 static struct OptionRow optionsTable[] =
170 //optionname defaultvalue rqd type domain domainsize clname hlpmsg
172 {"location", "localhost:5988", false, Option::STRING, 0, 0, "-n",
173 "specifies system and port" },
175 {"namespace", "root/cimv2", false, Option::STRING, 0, 0, "-n",
176 "specifies namespace to use for operation" },
180 {"version", "false", false, Option::BOOLEAN, 0, 0, "v",
181 "Displays software Version "},
183 {"help", "false", false, Option::BOOLEAN, 0, 0, "h",
184 "Prints help message with command line options "},
186 {"debug", "false", false, Option::BOOLEAN, 0, 0, "d",
189 const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]);
191 om.registerOptions(optionsTable, NUM_OPTIONS);
193 //We want to make this code common to all of the commands
195 String configFile = "/CLTest.conf";
197 cout << "Config file from " << configFile << endl;
199 if (FileSystem::exists(configFile))
200 om.mergeFile(configFile);
202 om.mergeCommandLine(argc, argv);
204 om.checkRequiredOptions();
208 void printHelp(char* name, OptionManager om)
210 String header = "Usage ";
213 //om.printOptionsHelpTxt(header, trailer);
216 /* PrintHelp - This is temporary until we expand the options manager to allow
217 options help to be defined with the OptionRow entries and presented from
220 void printHelpMsg(const char* pgmName, const char* usage, const char* extraHelp,
223 cout << endl << pgmName << endl;
224 cout << "Usage: " << pgmName << endl << usage << endl;
226 // ATTN: KS om.printHelp(const char* pgmName, OptionManager om);
227 cout << extraHelp << endl;
232 int main(int argc, char** argv)
235 // Get options (from command line and from configuration file); this
236 // removes corresponding options and their arguments fromt he command
239 // Get options (from command line and from configuration file); this
240 // removes corresponding options and their arguments fromt he command
247 String testHome = ".";
248 GetOptions(om, argc, argv, testHome);
253 cerr << argv[0] << ": " << e.getMessage() << endl;
258 // Check to see if user asked for help (-h otpion):
259 if (om.valueEquals("verbose", "true"))
261 printHelpMsg(argv[0], usage, extra, om);
265 // Establish the namespace from the input parameters
267 if(om.lookupValue("namespace", nameSpace))
269 cout << "Namespace = " << nameSpace << endl;
273 Boolean verboseTest = (om.valueEquals("verbose", "true")) ? true :false;
275 Boolean debug = (om.valueEquals("debug", "true")) ? true :false;
277 if (om.valueEquals("help", "true"))
279 String header = "Usage ";
281 om.printOptionsHelpTxt(header, trailer);
285 String location = "localhost:5988";
286 if(om.lookupValue("location", location))
288 cout << "Location = " << location << endl;
292 String className = "IBM_CIMOMStatData";
298 client.connect(location, String::EMPTY, String::EMPTY);
303 cerr << argv[0] << " Exception connecting to : " << location << endl;
304 cerr << e.getMessage() << endl;
306 CIMClass performanceClass;
309 performanceClass = client.getClass(nameSpace,
318 cerr << argv[0] << "Exception getClass : " << className
319 << e.getMessage() << endl;
324 Boolean localOnly = false;
325 Boolean deepInheritance = false;
326 Boolean includeQualifiers = false;
327 Boolean includeClassOrigin = false;
329 Array<CIMInstance> instances;
330 instances = client.enumerateInstances(nameSpace,
337 // Output a table with the values
339 // First build the header from the values strings in the class
340 printf("%-25s%10s %10s %10s %10s %10s\n%-25s%10s %10s %10s %10s %10s\n",
341 "CIM", "Number of", "CIMOM", "Provider",
342 "Request", "Response",
343 "Operation", "Requests", "Time", "Time", "Size", "Size");
345 // Output the returned instances
347 for (Uint32 i = 0; i < instances.size(); i++)
349 CIMInstance instance = instances[i];
350 /* Took this out because not used and
351 toMof not member of CIMInstance any more
360 mofFormat(cout, x.getData(), 4);
363 // Build a line for every information entry.
365 // Get the request type property for this instance
366 // Note that for the moment it is simply an integer.
373 if ((pos = instance.findProperty("name")) != PEG_NOT_FOUND)
375 p = (instance.getProperty(pos));
377 if (v.getType() == CIMTYPE_STRING)
384 statName = "UNKNOWN";
387 // now get number of requests property "NumberofRequests"
388 Uint64 numberOfRequests = 0;
389 if ((pos = instance.findProperty("NumberofRequests")) != PEG_NOT_FOUND)
391 p = (instance.getProperty(pos));
393 if (v.getType() == CIMTYPE_UINT64)
395 v.get(numberOfRequests);
398 // Get the total CIMOM Time property "TotalCimomTime"
399 Uint64 totalCimomTime = 0;
400 Uint64 averageCimomTime = 0;
402 if ((pos = instance.findProperty("TotalCimomTime")) != PEG_NOT_FOUND)
404 p = (instance.getProperty(pos));
406 if (v.getType() == CIMTYPE_UINT64)
408 v.get(totalCimomTime);
411 cerr << "Error Property value " << "TotalCimomTime" << endl;
414 cerr << "Error Property " << "TotalCimomTime" << endl;
416 if (totalCimomTime != 0) {
417 averageCimomTime = totalCimomTime / numberOfRequests;
419 // Get the total Provider Time property "TotalProviderTime"
421 Uint64 totalProviderTime = 0;
422 Uint64 averageProviderTime = 0;
424 if ((pos = instance.findProperty("TotalProviderTime")) != PEG_NOT_FOUND)
426 p = (instance.getProperty(pos));
428 if (v.getType() == CIMTYPE_UINT64)
430 v.get(totalProviderTime);
433 cerr << "Error Property Vlaue " << "TotalProviderTime" << endl;
436 cerr << "Error Property " << "TotalCimomTime" << endl;
438 if (totalCimomTime != 0) {
439 averageProviderTime = totalProviderTime / numberOfRequests;
441 // Get the total Response size property "TotalResponseSize"
443 Uint64 totalResponseSize = 0;
444 Uint64 averageResponseSize = 0;
447 if ((pos = instance.findProperty("TotalResponseSize")) != PEG_NOT_FOUND)
449 p = (instance.getProperty(pos));
451 if (v.getType() == CIMTYPE_UINT64)
453 v.get(totalResponseSize);
456 if (totalCimomTime != 0) {
457 averageResponseSize = totalResponseSize / numberOfRequests;
459 //Get the total request size property "TotalRequestSize"
461 Uint64 totalRequestSize = 0;
462 Uint64 averageRequestSize = 0;
465 if ((pos = instance.findProperty("TotalRequestSize")) != PEG_NOT_FOUND)
467 p = (instance.getProperty(pos));
469 if (v.getType() == CIMTYPE_UINT64)
471 v.get(totalRequestSize);
474 if (totalRequestSize != 0)
476 averageRequestSize = totalRequestSize / numberOfRequests;
479 // If there are requests made, output one line with the total
480 //if (numberOfRequests > 0) {
481 printf(" %-25s%9lu %10lu %10lu %10lu %10lu\n",
482 (const char*)statName.getCString(),
483 numberOfRequests, averageCimomTime,
484 averageProviderTime, averageRequestSize,
485 averageResponseSize);
491 cerr << argv[0] << "Exception : " << className
492 << e.getMessage() << endl;