KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVGELogReader.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Fri Nov 25 09:53:18 2011
2 //Author: John Frankland
3 
4 #include "KVGELogReader.h"
5 #include "TObjString.h"
6 #include "Riostream.h"
7 #include <TObjArray.h>
8 
10 
11 
12 
13 
16 void KVGELogReader::ReadLine(const KVString& line, Bool_t& ok)
17 {
18  //analyse contents of line read from log file
19 
21 
22  if (!ok) return;
23 
24  if (line.Contains("Cputime limit exceeded")) {
25  ok = kFALSE;
26  fStatus = line;
27  fOK = kFALSE;
28  return;
29  }
30  else if (line.Contains("Filesize limit exceeded")) {
31  ok = kFALSE;
32  fStatus = line;
33  fOK = kFALSE;
34  return;
35  }
36  else if (line.Contains("File size limit exceeded")) {
37  ok = kFALSE;
38  fStatus = line;
39  fOK = kFALSE;
40  return;
41  }
42  else if (line.Contains("Job received KILL signal")) {
43  fStatus = "KILLED";
44  fOK = kFALSE;
45  }
46  else if (line.BeginsWith("* Requested")) {
47  fInRequested = kTRUE;
48  fInConsumed = kFALSE;
49  }
50  else if (line.BeginsWith("* Consumed")) {
51  fInRequested = kFALSE;
52  fInConsumed = kTRUE;
53  }
54  else if (line.BeginsWith("* CPU time:")) {
55  ReadCPU(line);
56  }
57  else if (line.Contains("CpuUser ="))
58  ReadKVCPU(line);
59  else if (fInConsumed && line.BeginsWith("* vmem:"))
60  ReadMemUsed(line);
61  else if (fStatus != "KILLED" && line.BeginsWith("* Exit status:"))
62  ReadStatus(line);
63  else if (line.Contains("Jobname:"))
64  ReadJobname(line);
65  else if (line.Contains("DISK_REQ") || line.Contains("MEM_REQ"))
66  ReadStorageReq(line);
67 }
68 
69 
70 
74 
76 {
77  // update infos on CPU time, memoire & disk from lines such as
78  // "CpuSys = 7.044505 s. CpuUser = 846.259888 s. ResMem = 338.109375 MB VirtMem = 1039.921875 MB DiskUsed = 5678742 KB"
79 
80  line.Begin("= ");
81  while (!line.End()) {
82  KVString token = line.Next();
83  if (token == "CpuUser") {
84  fCPUused = line.Next().Atof();
85  }
86  else if (token == "VirtMem") {
87  fMemKB = line.Next().Atof();
88  fMemKB *= GetByteMultiplier(line.Next());
89  }
90  else if (token == "DiskUsed") {
91  fScratchKB = ReadStorage(line.Next());
92  }
93  }
94 }
95 
96 
97 
102 
104 {
105  //read line of type "* CPU time: 00:32:14 (1934 seconds) *"
106  //which is either the requested CPU time or the consumed CPU time, depending on
107  //where we are in the file
108 
109  line.Begin("()");
110  line.Next();
111  // at this point, myline.Next() will give "1934 seconds"
112  // we can directly call TString::Atoi() as it ignores any non-numeric stuff
113  if (fInRequested) fCPUreq = line.Next().Atoi();
114  else if (fInConsumed) fCPUused = line.Next().Atoi();
115 }
116 
117 
118 
122 
124 {
125  // this just sets fScratcKB=0 because there is no information on
126  // scratch disk usage in the GE logfiles
127  fScratchKB = 0;
128 }
129 
130 
131 
135 
137 {
138  //read line of type "* vmem: 1.284 GB (2) *"
139  //corresponding to memory used by job
140 
141  if (line.GetNValues(":(") < 3) {
142  //in case Grid Engine goes west & doesn't write vmem in log
143  return;
144  }
145  line.Begin(":(");
146  line.Next();
147  // at this point line.Next(kTRUE) will give "1.284 GB"
148  KVString vmem = line.Next(kTRUE);
149  if (vmem.GetNValues(" ") < 2) {
150  //something wrong here
151  return;
152  }
153  vmem.Begin(" ");
154  Double_t mem_use = vmem.Next().Atof();
155  //value read is converted to KB, depending on units
156  fMemKB = mem_use * GetByteMultiplier(vmem.Next());
157 }
158 
159 
160 
164 
166 {
167  //unit = "K", "M" or "G"
168  //value returned is 1, 2**10 or 2**20, respectively
169  static Int_t KB = 1;
170  static Int_t MB = 2 << 9;
171  static Int_t GB = 2 << 19;
172  return (unit.BeginsWith("K") ? KB : (unit.BeginsWith("M") ? MB : GB));
173 }
174 
175 
176 
186 
188 {
189  //read line of type
190  //
191  // "* Exit status: 0 *"
192  //
193  //with final status of job.
194  //
195  //if status = "0" then JobOK() will return kTRUE
196  //otherwise, JobOK() will be kFALSE.
197 
198  fGotStatus = kTRUE;
199  line.Begin("*:");
200  line.Next();
201  fStatus = line.Next(kTRUE);
202  fOK = (fStatus == "0");
203 }
204 
205 
206 
211 
213 {
214  //'stor' is a string such as "200MB", "3GB" etc.
215  //value returned is corresponding storage space in KB
216  //if no units symbol found, we assume MB
217 
218  static KVString units[] = { "K", "M", "G" };
219  Int_t i = 0, index = -1;
220  while ((index = stor.Index(units[i])) < 0 && i < 2)
221  i++;
222  KVString u, STOR(stor);
223  if (index >= 0) {
224  STOR.Remove(index);
225  u = units[i];
226  }
227  else {
228  u = "M";
229  }
230  return (STOR.Atof() * GetByteMultiplier(u));
231 }
232 
233 
234 
int Int_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
const Bool_t kFALSE
bool Bool_t
double Double_t
const Bool_t kTRUE
Read GE (Grid Engine) log files to extract status of batch jobs.
Definition: KVGELogReader.h:39
virtual Double_t ReadStorage(const KVString &stor)
virtual Int_t GetByteMultiplier(const KVString &unit)
virtual void ReadCPU(const KVString &line)
virtual void ReadKVCPU(const KVString &line)
virtual void ReadStatus(const KVString &line)
Bool_t fInRequested
Definition: KVGELogReader.h:49
virtual void ReadScratchUsed(const KVString &line)
virtual void ReadMemUsed(const KVString &line)
Bool_t fInConsumed
Definition: KVGELogReader.h:50
KVString fStatus
status string
Definition: KVLogReader.h:26
virtual void ReadLine(const KVString &line, Bool_t &)
Definition: KVLogReader.cpp:74
Bool_t fOK
job OK or not ?
Definition: KVLogReader.h:27
Double_t fCPUused
normalized used CPU time in seconds
Definition: KVLogReader.h:20
Bool_t fGotStatus
set true when end of job infos have been read
Definition: KVLogReader.h:29
Double_t fMemKB
used memory in KB
Definition: KVLogReader.h:25
Double_t fCPUreq
requested CPU time in seconds
Definition: KVLogReader.h:21
Double_t fScratchKB
used disk space in KB
Definition: KVLogReader.h:24
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
void Begin(TString delim) const
Definition: KVString.cpp:565
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
Int_t GetNValues(TString delim) const
Definition: KVString.cpp:886
Double_t Atof() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Remove(EStripType s, char c)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
TLine * line