31{
   34 
   36  string        process;
   37  unsigned int  T_us;
   38  bool          interactive;
   40 
   41  try {
   42 
   43    JParser<> zap(
"Auxiliary program to monitor memory and CPU usage of process.");
 
   44 
   46    zap[
'P'] = 
make_field(process,     
"name of process");
 
   47    zap[
'T'] = 
make_field(T_us,        
"interval time [us]")    =  100000;
 
   48    zap[
'u'] = 
make_field(interactive, 
"run in interactive mode");
 
   50 
   51    zap(argc, argv);
   52  }
   53  catch(const exception &error) {
   54    FATAL(error.what() << endl);
 
   55  }
   56 
   59 
   60  const char QUIT = 'q';
   61 
   62  if (interactive) {
   63    cout << "Press '" << QUIT << "' to quit." << endl;
   64  }
   65 
   66  int pid = -1;
   67 
   68  for (int i = 0; ;++i) {
   69 
   70    try {
   71 
   72      pid = 
getPID(shell, process.c_str());
 
   73 
   74      break;
   75    }
   76    catch(const exception& error) {
   77 
   78      if (interactive || 
debug >= debug_t) {
 
   79        cout << "No process " << setw(8) << i << endl;
   80      }
   81 
   82      if (keypress.timeout(T_us)) {
   83        if (keypress.get() == QUIT && interactive) {
   84          break;
   85        }
   86      }
   87    }
   88  } 
   89 
   90  NOTICE(
"Process identifier " << pid << endl);
 
   91    
   92  if (pid == -1) {
   93    FATAL(
"Invalid process identifier " << pid << endl);
 
   94  }
   95 
   96  TH1D h0("h0", NULL,  101,-0.5,  100.5);
   97  TH1D h1("h1", NULL, 1001,-0.5, 1000.5);
   98    
  102 
  104 
  105  for (int i = 0; ;++i) {
  106      
  107    try {
  108 
  109      const double t1  = double (getLocalTime() - t0) * 1.0e-6;
  112 
  113      h0.Fill(mem);
  114      h1.Fill(cpu);
  115 
  116      X.push_back(t1);
  117      Y.push_back(mem);
  118      Z.push_back(cpu);
  119 
  120      if (interactive || 
debug >= debug_t) {
 
  121        cout << setw(8) << i << 
' ' << 
FIXED(12,3) << t1 << 
' ' << 
FIXED(7,3) << mem << 
' ' << 
FIXED(7,3) << cpu << endl;
 
  122      }
  123 
  124      if (keypress.timeout(T_us)) {
  125        if (keypress.get() == QUIT && interactive) {
  126          break;
  127        }
  128      }
  129    }
  130    catch(const exception& error) {
  131      break;
  132    }
  133  }
  134 
  135 
  136  TGraph g0(X.size(), X.data(), Y.data());
  137  TGraph 
g1(X.size(), X.data(), Z.data());
 
  138 
  141    
  143 
  144  out << h0 << h1;
  146    
  147  out.Write();
  148  out.Close();
  149}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
#define MAKE_CSTRING(A)
Make C-string.
 
Double_t g1(const Double_t x)
Function.
 
Utility class to parse command line options.
 
Enable unbuffered terminal input.
 
The JShell clas can be used to interact with the shell via I/O streams.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
float getMemoryUsage(JShell &shell, const pid_t pid)
Get memory usage in percent of given process identifier.
 
long long int localtime_t
Type definition of local time.
 
float getCpuUsage(JShell &shell, const pid_t pid)
Get cpu usage in percent of given process identifier.
 
pid_t getPID(JShell &shell, const char *process)
Get process identifier.
 
Auxiliary data structure for floating point format specification.