--- projects/cms/source/host/c++/SysMon.cpp 2001/03/23 16:57:03 1.7 +++ projects/cms/source/host/c++/SysMon.cpp 2001/03/27 00:04:30 1.8 @@ -11,12 +11,9 @@ SysMon::SysMon( Config config, int printDebug){ // setup some standard variables sequence = 0; // no packets sent yet - // get our values from config - - // setup our arrays titlepointer = 0; - for ( int i=0; i < maxTitles; i++ ){ + for ( int i=0; i < max_titles; i++ ){ titles[i] = ""; values[i] = ""; } @@ -28,35 +25,42 @@ SysMon::SysMon( Config config, int printDebug){ int SysMon::collect(){ if ( debug == 1 ){ std::cout << "SysMon::collect()\n"; - } + } // if // say we have checked again checks++; // collect the system data and place it in an array of strings. // presume that the data is all formtted correctly. - // char input[2048]; + if ( debug == 1 ){ std::cout << "SysMon::collect::ipipestream\n"; } - // ipipestream p("statgrab.pl"); - p = new SubPipe("statgrab.pl"); + + p = new SubPipe("./statgrab.pl"); // get the output into input from statgrab string sinput; while ( p->getLine(&sinput) == 0 ){ + if ( titlepointer == max_titles ){ + std::cout << "WARNING: Max Titles reached, skipping remaining" << endl; + std::cout << "Try recompiling with a value greater than the current (" << max_titles << ")" << endl; + titlepointer--; + break; + } // if + // locate the first white space int found = sinput.find(" ",0); if ( found == string::npos ){ // error if ( debug == 1 ){ std::cout << "SysMon::collect::Parse error from statgrab.pl\n"; - } + } // if } else { int gotTitle = 0; // now use the array of titles and values - for ( int i = 0; i < maxTitles; i++ ){ + for ( int i = 0; i < max_titles; i++ ){ // check against the array value if ( titles[i] == sinput.substr(0,found) ){ // is the one we are looking for. @@ -73,10 +77,10 @@ int SysMon::collect(){ if ( gotTitle == 0 ){ // didnt if ( debug == 1 ){ - std::cout << "SysMon::collect::Adding New Value\n"; - std::cout << "'" << sinput.substr(0,found) << "' : "; - std::cout << "'" << sinput.substr(found+1, sinput.length()) << "'\n"; - } + std::cout << "SysMon::collect::Adding New Value\n"; + std::cout << "'" << sinput.substr(0,found) << "' : "; + std::cout << "'" << sinput.substr(found+1, sinput.length()) << "'\n"; + } // if titles[titlepointer] = sinput.substr(0,found); values[titlepointer] = sinput.substr(found+1, sinput.length()); titlepointer++; @@ -86,11 +90,12 @@ int SysMon::collect(){ } // while + // delete the pointer to free up memory delete p; if ( debug == 1 ){ std::cout << "SysMon::collect::Parse from StatGrab finished\n"; - } + } // if // return sucessful return 0; @@ -100,10 +105,10 @@ int SysMon::collect(){ void SysMon::clearData(){ titlepointer = 0; - for ( int i=0; i < maxTitles; i++ ){ + for ( int i=0; i < max_titles; i++ ){ titles[i] = ""; values[i] = ""; - } + } // for return; @@ -114,14 +119,14 @@ string SysMon::getData(){ if ( debug == 1 ){ std::cout << "SysMon::getData()\n"; - } + } // if // create an xml object XMLFormatter xml = XMLFormatter(); if ( debug == 1 ){ std::cout << "SysMon::getData::Sorting " << titlepointer << " elements\n"; - } + } // if // firstly sort the data. // simple bubble sort @@ -145,14 +150,12 @@ string SysMon::getData(){ } // for } // while - /* + /* used to check the array has sorted correctly for ( int i=0; i < titlepointer; i++ ){ std::cout << titles[i] << endl; - } - */ + */ - // work through each one of the titles in turn and // work out their levels. @@ -172,15 +175,13 @@ string SysMon::getData(){ if ( debug == 1 ){ std::cout << "SysMon::getData::Starting while\n"; - } + } // if while ( count <= titlepointer ){ - - - + if ( debug == 1 ){ std::cout << "Processing: " << titles[count] << endl; - } + } // if retryCount++; @@ -224,7 +225,8 @@ string SysMon::getData(){ // first one mind! if ( levels[0] == "packet" ){ level--; - } + } // if + } // while dotPosition // now grab the value title @@ -246,8 +248,8 @@ string SysMon::getData(){ xml.addElement(attributeLevel,attributes,""); if ( debug == 1 ){ std::cout << "Adding Element + attributes" << endl; - } - // count++; + } // if + } // if isAttrib = 0; attributeLevel = ""; @@ -257,7 +259,7 @@ string SysMon::getData(){ newLevelString += levels[i]; if ( i != level-1 ){ newLevelString += "."; - } + } // if } // for } // if levels[level] @@ -270,7 +272,7 @@ string SysMon::getData(){ newLevelString += levels[i]; if ( i != level-1 ){ newLevelString += "."; - } + } // if } // for isAttrib = 1; @@ -284,7 +286,7 @@ string SysMon::getData(){ xml.addElement(attributeLevel,attributes,""); if ( debug == 1 ){ std::cout << "Adding Element + attributes1" << endl; - } + } // if attributeLevel = ""; attributes = ""; count++; @@ -293,7 +295,7 @@ string SysMon::getData(){ xml.addElement(attributeLevel,attributes,""); if ( debug == 1 ){ std::cout << "Adding Element + attributes2" << endl; - } + } // if attributeLevel = ""; attributes = ""; count++; @@ -309,7 +311,7 @@ string SysMon::getData(){ xml.addElement(attributeLevel,attributes,""); if ( debug == 1 ){ std::cout << "Adding Element + attributes3" << endl; - } + } // if attributeLevel = ""; attributes = ""; count++; @@ -321,7 +323,7 @@ string SysMon::getData(){ newLevelString += levels[i]; if ( i != level-1 ){ newLevelString += "."; - } + } // if } // for } // if level == 1 @@ -333,16 +335,14 @@ string SysMon::getData(){ attributes += "=\""; attributes += values[count]; attributes += "\" "; - // now check if this is the last element - - + } else { xml.addElement(levels[level], values[count]); count++; if ( debug == 1 ){ std::cout << "Adding Element" << endl; - } - } + } // if + } // if } else { // gotta change it @@ -351,13 +351,13 @@ string SysMon::getData(){ if ( currentLevelint <= 0 ){ break; - } + } // if // back up atleast one level... xml.closeNest(); if ( debug == 1 ){ std::cout << "Closing Nest" << endl; - } + } // if // remove the last item currentLevelint--; @@ -381,7 +381,7 @@ string SysMon::getData(){ xml.addNest(levels[currentLevelint]); if ( debug == 1 ){ std::cout << "Adding nest " << levels[currentLevelint] << endl; - } + } // if // set this to be the top level of the new level currentLevelint++; @@ -415,7 +415,7 @@ string SysMon::getData(){ if ( debug == 1 ){ std::cout << "\n"; - } + } // if // return the string return xml.returnXML();