139 iterates over the file pointed at by `fname` and yields a tuple of
140 (step, idx, comp, out)
142 - `step` is in ('ini','evt','fin','cbk','usr','dso',...)
143 - `idx` is 0 or 1 (resp. start or stop)
144 - `comp` is the name of the entity being monitored (alg,library,cbk,...)
145 - `out` is the up-to-date table of data collected so far
147 the table is a dict of {'step':{'comp':numpy.array}}
149 this table is the suitable python object for further analyses
152 if fname.endswith(
'.pmon.gz'):
154 stream_file = o[
'data']
155 stream_fname = stream_file.name
156 elif fname.endswith(
'.stream'):
157 stream_file =
open(fname)
160 raise ValueError(
"expect a xyz.pmon.gz or xyz.stream file (got [%s])"%(fname,))
165 with open(stream_fname,
'r')
as f:
167 data, step, idx, comp = (
None, ) * 4
168 if z.startswith(
'#'):
174 z = z.replace(
'unsigned int',
'unsigned-int')\
179 if fields[0].startswith((
'/ini/',
'/evt/',
'/fin/',
193 fields[0] = fields[0]+fields[1]
200 step = fields[0][1:-1]
201 step = step.split(
'/')[0]
202 comp = fields[0][len(step)+2:]
210 offset = comp.split(
']+')[1]
211 bracket_idx = comp.find(
'[')
213 comp =
'%s{+%s}' % (comp[:bracket_idx],offset)
217 data = out[step][comp]
221 data = np.zeros(1, data.dtype)
222 data = out[step][comp] = np.append(out[step][comp],
228 cpu[
'user'][idx] =
float(fields[2])
229 cpu[
'sys'][idx] =
float(fields[3])
230 cpu[
'real'][idx] =
float(fields[4])
231 cpu[
'rt'][idx] =
float(fields[5])
232 cpu[
'cpu'][idx] = cpu[
'user'][idx] + cpu[
'sys'][idx]
235 mem[
'vmem'][idx] =
float(fields[6])/1024.
236 mem[
'rss'][idx] =
float(fields[7])/1024.
237 mem[
'mall'][idx] =
float(fields[8])/1024.
238 mem[
'nmall'][idx]=
float(fields[9])
239 mem[
'nfree'][idx]=
float(fields[10])
244 for n
in d.dtype.names:
246 d[n][1] = d[n][0] + d[n][1]
248 for n
in d.dtype.names:
249 d[n][2] = d[n][1] - d[n][0]
252 elif fields[0].startswith(
'/io/'):
254 comp = fields[0][len(step)+2:]
255 data = out[step][comp]
257 data = np.zeros(1, data.dtype)
259 data = out[step][comp] = np.append(out[step][comp],
264 r[
'user'] =
float(fields[1])
265 r[
'sys'] =
float(fields[2])
266 r[
'real'] =
float(fields[3])
267 r[
'cpu'] = r[
'user'] + r[
'sys']
268 r[
'rt'] =
float(fields[4])
271 rr[
'user'] =
float(fields[5])
272 rr[
'sys'] =
float(fields[6])
273 rr[
'real'] =
float(fields[7])
274 rr[
'cpu'] = rr[
'user'] + rr[
'sys']
275 rr[
'rt'] =
float(fields[8])
278 w[
'user'] =
float(fields[9])
279 w[
'sys'] =
float(fields[10])
280 w[
'real'] =
float(fields[11])
281 w[
'cpu'] = w[
'user'] + w[
'sys']
282 w[
'rt'] =
float(fields[12])
286 elif fields[0].startswith(
'/dso/'):
288 comp = fields[0][len(step)+2:]
289 data = out[step][comp]
292 data = out[step][comp]
296 data = np.zeros(1, data.dtype)
297 data = out[step][comp] = np.append(out[step][comp],
302 if len(fields) >= 10:
304 cpu[
'user'][idx] =
float(fields[2])
305 cpu[
'sys'][idx] =
float(fields[3])
306 cpu[
'real'][idx] =
float(fields[4])
307 cpu[
'rt'][idx] =
float(fields[5])
308 cpu[
'cpu'][idx] = cpu[
'user'][idx] + cpu[
'sys'][idx]
311 mem[
'vmem'][idx] =
float(fields[6])/1024.
312 mem[
'rss'][idx] =
float(fields[7])/1024.
313 mem[
'mall'][idx] =
float(fields[8])/1024.
314 mem[
'nmall'][idx]=
float(fields[9])
315 mem[
'nfree'][idx]=
float(fields[10])
319 cpu[
'user'][idx] = 0.
321 cpu[
'real'][idx] = 0.
326 mem[
'vmem'][idx] =
float(fields[2])/1024.
328 mem[
'mall'][idx] = 0.
329 mem[
'nmall'][idx]= 0.
330 mem[
'nfree'][idx]= 0.
335 for n
in d.dtype.names:
337 d[n][1] = d[n][0] + d[n][1]
339 for n
in d.dtype.names:
340 d[n][2] = d[n][1] - d[n][0]
344 print(
"warning: unhandled field [%s]" % (fields[0],))
348 yield step, idx, comp, out