ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/SysMon.cpp
(Generate patch)

Comparing projects/cms/source/host/c++/SysMon.cpp (file contents):
Revision 1.7 by ab11, Fri Mar 23 16:57:03 2001 UTC vs.
Revision 1.8 by ab11, Tue Mar 27 00:04:30 2001 UTC

# Line 11 | Line 11 | SysMon::SysMon( Config config, int printDebug){
11          // setup some standard variables
12          sequence = 0; // no packets sent yet
13          
14        // get our values from config
15        
16        
14          // setup our arrays
15          titlepointer = 0;
16 <        for ( int i=0; i < maxTitles; i++ ){
16 >        for ( int i=0; i < max_titles; i++ ){
17                  titles[i] = "";
18                  values[i] = "";
19          }
# Line 28 | Line 25 | SysMon::SysMon( Config config, int printDebug){
25   int SysMon::collect(){
26          if ( debug == 1 ){
27                  std::cout << "SysMon::collect()\n";
28 <        }
28 >        } // if
29          
30          // say we have checked again
31          checks++;
32          
33          // collect the system data and place it in an array of strings.
34          // presume that the data is all formtted correctly.
35 <        // char input[2048];
35 >
36          if ( debug == 1 ){
37                  std::cout << "SysMon::collect::ipipestream\n";
38          }
39 <        // ipipestream p("statgrab.pl");
40 <        p = new SubPipe("statgrab.pl");
39 >
40 >        p = new SubPipe("./statgrab.pl");
41          
42          // get the output into input from statgrab
43          string sinput;
44          while ( p->getLine(&sinput) == 0 ){
45                  
46 +                if ( titlepointer == max_titles ){
47 +                    std::cout << "WARNING: Max Titles reached, skipping remaining" << endl;
48 +                    std::cout << "Try recompiling with a value greater than the current (" << max_titles << ")" << endl;
49 +                    titlepointer--;
50 +                    break;
51 +                } // if
52 +                
53                  // locate the first white space
54                  int found = sinput.find(" ",0);
55                  if ( found == string::npos ){
56                          // error
57                          if ( debug == 1 ){
58                                  std::cout << "SysMon::collect::Parse error from statgrab.pl\n";
59 <                        }
59 >                        } // if
60                  } else {
61                          int gotTitle = 0;
62                          // now use the array of titles and values
63 <                        for ( int i = 0; i < maxTitles; i++ ){
63 >                        for ( int i = 0; i < max_titles; i++ ){
64                                  // check against the array value
65                                  if ( titles[i] == sinput.substr(0,found) ){
66                                          // is the one we are looking for.
# Line 73 | Line 77 | int SysMon::collect(){
77                          if ( gotTitle == 0 ){
78                                  // didnt
79                                  if ( debug == 1 ){
80 <                                                std::cout << "SysMon::collect::Adding New Value\n";
81 <                                                std::cout << "'" << sinput.substr(0,found) << "' : ";
82 <                                                std::cout << "'" <<  sinput.substr(found+1, sinput.length()) << "'\n";
83 <                                }
80 >                                        std::cout << "SysMon::collect::Adding New Value\n";
81 >                                        std::cout << "'" << sinput.substr(0,found) << "' : ";
82 >                                        std::cout << "'" <<  sinput.substr(found+1, sinput.length()) << "'\n";
83 >                                } // if
84                                  titles[titlepointer] = sinput.substr(0,found);
85                                  values[titlepointer] = sinput.substr(found+1, sinput.length());
86                                  titlepointer++;
# Line 86 | Line 90 | int SysMon::collect(){
90                  
91          } // while
92          
93 +        // delete the pointer to free up memory
94          delete p;
95          
96          if ( debug == 1 ){
97                  std::cout << "SysMon::collect::Parse from StatGrab finished\n";
98 <        }
98 >        } // if
99          
100          // return sucessful
101          return 0;
# Line 100 | Line 105 | int SysMon::collect(){
105   void SysMon::clearData(){
106      
107      titlepointer = 0;
108 <        for ( int i=0; i < maxTitles; i++ ){
108 >        for ( int i=0; i < max_titles; i++ ){
109                  titles[i] = "";
110                  values[i] = "";
111 <        }
111 >        } // for
112      
113      return;
114      
# Line 114 | Line 119 | string SysMon::getData(){
119          
120          if ( debug == 1 ){
121                  std::cout << "SysMon::getData()\n";
122 <        }
122 >        } // if
123          
124          // create an xml object
125          XMLFormatter xml = XMLFormatter();
126  
127      if ( debug == 1 ){
128                  std::cout << "SysMon::getData::Sorting " << titlepointer << " elements\n";
129 <        }
129 >        } // if
130  
131      // firstly sort the data.
132      // simple bubble sort
# Line 145 | Line 150 | string SysMon::getData(){
150          } // for
151      } // while
152          
153 <    /*
153 >    /* used to check the array has sorted correctly
154      for ( int i=0; i < titlepointer; i++ ){
155          std::cout << titles[i] << endl;    
151        
156      }
157 <     */
157 >    */
158        
155    
159          // work through each one of the titles in turn and
160          // work out their levels.
161          
# Line 172 | Line 175 | string SysMon::getData(){
175          
176          if ( debug == 1 ){
177                  std::cout << "SysMon::getData::Starting while\n";
178 <        }
178 >        } // if
179          
180          while ( count <= titlepointer ){
181 <            
179 <            
180 <            
181 >
182              if ( debug == 1 ){
183                      std::cout << "Processing: " << titles[count] << endl;
184 <            }
184 >            } // if
185              
186              retryCount++;
187                      
# Line 224 | Line 225 | string SysMon::getData(){
225                  // first one mind!      
226                  if ( levels[0] == "packet" ){
227                      level--;
228 <                }              
228 >                } // if
229 >                        
230              } // while dotPosition
231              
232              // now grab the value title
# Line 246 | Line 248 | string SysMon::getData(){
248                           xml.addElement(attributeLevel,attributes,"");
249                           if ( debug == 1 ){
250                                 std::cout << "Adding Element + attributes" << endl;
251 <                         }
252 <                         // count++;
251 >                         } // if
252 >                        
253                      } // if
254                  isAttrib = 0;
255                  attributeLevel = "";
# Line 257 | Line 259 | string SysMon::getData(){
259                      newLevelString += levels[i];                
260                      if ( i != level-1 ){
261                          newLevelString += ".";
262 <                    }
262 >                    } // if
263                  } // for
264              } // if levels[level]
265              
# Line 270 | Line 272 | string SysMon::getData(){
272                      newLevelString += levels[i];                
273                      if ( i != level-1 ){
274                          newLevelString += ".";
275 <                    }
275 >                    } // if
276                  } // for
277                  
278                  isAttrib = 1;
# Line 284 | Line 286 | string SysMon::getData(){
286                             xml.addElement(attributeLevel,attributes,"");
287                             if ( debug == 1 ){
288                                          std::cout << "Adding Element + attributes1" << endl;
289 <                                }
289 >                                } // if
290                             attributeLevel = "";
291                             attributes = "";
292                             count++;
# Line 293 | Line 295 | string SysMon::getData(){
295                                  xml.addElement(attributeLevel,attributes,"");
296                              if ( debug == 1 ){
297                                          std::cout << "Adding Element + attributes2" << endl;
298 <                                }
298 >                                } // if
299                              attributeLevel = "";
300                              attributes = "";
301                              count++;
# Line 309 | Line 311 | string SysMon::getData(){
311                      xml.addElement(attributeLevel,attributes,"");
312                      if ( debug == 1 ){
313                                  std::cout << "Adding Element + attributes3" << endl;
314 <                        }
314 >                        } // if
315                      attributeLevel = "";
316                      attributes = "";
317                      count++;
# Line 321 | Line 323 | string SysMon::getData(){
323                      newLevelString += levels[i];                
324                      if ( i != level-1 ){
325                          newLevelString += ".";
326 <                    }
326 >                    } // if
327                  } // for
328              } // if level == 1
329              
# Line 333 | Line 335 | string SysMon::getData(){
335                      attributes += "=\"";
336                      attributes += values[count];        
337                      attributes += "\" ";
338 <                    // now check if this is the last element
337 <                    
338 <        
338 >                            
339                  } else {
340                  xml.addElement(levels[level],  values[count]);
341                  count++;            
342                  if ( debug == 1 ){
343                      std::cout << "Adding Element" << endl;
344 <                }
345 <            }
344 >                } // if
345 >            } // if
346                      
347              } else {
348                  // gotta change it    
# Line 351 | Line 351 | string SysMon::getData(){
351                  
352                  if ( currentLevelint <= 0 ){
353                      break;
354 <                }
354 >                } // if
355                  
356                  // back up atleast one level...
357                  xml.closeNest();
358                  if ( debug == 1 ){
359                      std::cout << "Closing Nest" << endl;
360 <                }
360 >                } // if
361                  // remove the last item
362                  currentLevelint--;
363                  
# Line 381 | Line 381 | string SysMon::getData(){
381                  xml.addNest(levels[currentLevelint]);
382                  if ( debug == 1 ){
383                      std::cout << "Adding nest " << levels[currentLevelint] << endl;
384 <                }
384 >                } // if
385                  
386                  // set this to be the top level of the new level
387                  currentLevelint++;
# Line 415 | Line 415 | string SysMon::getData(){
415  
416      if ( debug == 1 ){
417                  std::cout << "\n";
418 <        }              
418 >        } // if
419  
420          // return the string
421          return xml.returnXML();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines