15 from collections
import OrderedDict
16 from TrigValTools.TrigARTUtils
import first_existing_file, newest_file
18 logging.basicConfig(stream=sys.stdout,
19 format=
'%(levelname)-8s %(message)s',
27 from pandas
import read_csv
28 mod_name =
'scipy.optimize'
29 from scipy.optimize
import curve_fit
30 mod_name =
'matplotlib'
33 import matplotlib.pyplot
as plt
34 except Exception
as e:
36 logging.warning(
'Failed to import module %s, prmon output analysis will be skipped! %s', mod_name, e)
39 'Store items in the order the keys were last added'
44 OrderedDict.__setitem__(self, key, value)
47 if not os.path.isfile(filename):
48 logging.warning(f
"Cannot open file {filename}")
50 with open(filename)
as logfile:
51 if re.search(
"No error/warning messages found in.*$", logfile.read(), re.MULTILINE)
is not None:
52 logging.debug(
"Number of errors/warnings: 0")
55 match = re.search(
r'Found (\d+) (\w+) message\(s\) in.*$', logfile.read(), re.MULTILINE)
57 logging.warning(f
"Cannot extract number of messages from {filename}")
59 logging.debug(f
"Number of {match[2]}s: {match[1]}")
63 if not os.path.isfile(filename):
64 logging.warning(f
"Cannot open file {filename}")
66 with open(filename)
as logfile:
67 match = re.search(
r"Total histograms:.* (\d+)$", logfile.read(), re.MULTILINE)
69 logging.warning(
"Cannot extract number of histograms from {}".
format(filename))
71 logging.debug(f
"Found {match[1]} histograms")
82 for unit_name, mult
in multipliers.items():
84 return float(number)*mult
85 logging.error(
"Unit conversion failed from {} to MB".
format(unit))
90 words = line[0].
split()
92 logging.debug(
"mem_end = {}".
format(mem_end))
93 mem_delta = words[8:10]
94 logging.debug(
"mem_delta = {}".
format(mem_delta))
96 logging.debug(
"mem_mb = {}".
format(mem_mb))
98 logging.debug(
"delta_mb = {}".
format(delta_mb))
99 return mem_mb, delta_mb
103 if not os.path.isfile(filename):
104 logging.warning(
"Cannot open file {}".
format(filename))
106 with open(filename)
as logfile:
109 all_lines = logfile.readlines()
110 for i, line
in enumerate(all_lines):
111 if first_line >= 0
and last_line >= 0:
113 if "=== [evt - slice] ===" in line:
115 elif "=== [fin - slice] ===" in line:
117 if first_line < 0
or last_line < 0:
118 logging.warning(
"Cannot extract memory usage information from {}".
format(filename))
120 evt_mon_lines = all_lines[first_line:last_line]
121 vmem_line = re.findall(
"^VMem.*$",
'\n'.
join(evt_mon_lines), re.MULTILINE)
122 rss_line = re.findall(
"^RSS.*$",
'\n'.
join(evt_mon_lines), re.MULTILINE)
123 logging.debug(
"vmem_line = {}".
format(vmem_line))
124 logging.debug(
"rss_line = {}".
format(rss_line))
125 if len(vmem_line) == 0:
126 logging.warning(
"Cannot extract VMem information from {}".
format(filename))
127 if len(rss_line) == 0:
128 logging.warning(
"Cannot extract RSS information from {}".
format(filename))
132 data[
'vmem'] =
"{0:.3f}".
format(vmem)
133 data[
'delta-vmem'] =
"{0:.3f}".
format(dvmem)
134 data[
'rss'] =
"{0:.3f}".
format(rss)
135 data[
'delta-rss'] =
"{0:.3f}".
format(drss)
139 def mem_func(x_arr, x_trans, init_slope, exec_slope):
143 retval.append(init_slope * x)
145 retval.append(exec_slope * x + (init_slope - exec_slope) * x_trans)
150 popt, pcov = curve_fit(mem_func, xdata, ydata, bounds=(0, [0.9*
max(xdata), np.inf, np.inf]))
151 logging.debug(
"Fit result: %s",
str(popt))
152 plot_prmon(xdata, ydata, label, filename, popt)
154 x_last = xdata.iloc[-1]
155 dmem_v =
mem_func([x_last, x_trans], popt[0], popt[1], popt[2])
156 return dmem_v[0] - dmem_v[1]
160 plt.plot(xdata, ydata,
'b-', label=name)
162 plt.plot(xdata,
mem_func(xdata, *params),
'r-', label=
'{:s} fit, exec slope={:.2f} kB/s'.
format(name, params[2]))
163 plt.xlabel(
'wtime [s]')
164 plt.ylabel(name+
' [kB]')
166 plt.title(
'{:s} from {:s}'.
format(name, filename))
167 plt.savefig(
'prmon_{:s}.pdf'.
format(name), bbox_inches=
'tight')
173 prmon_data = read_csv(filename, sep=
'\t')
175 logging.warning(
"Cannot open file {}".
format(filename))
177 time_v = prmon_data[
'wtime']
178 pss_v = prmon_data[
'pss']
179 rss_v = prmon_data[
'rss']
180 vmem_v = prmon_data[
'vmem']
186 logging.info(
'Not enough prmon data points, skipping memory slope fitting')
207 logging.debug(
"ne: {}".
format(ne))
209 logging.warning(
"Failed to read number of errors from the log")
210 data[
'num-errors'] =
'n/a'
212 data[
'num-errors'] = ne
217 logging.debug(
"nw: {}".
format(nw))
219 logging.warning(
"Failed to read number of warnings from the log")
220 data[
'num-warnings'] =
'n/a'
222 data[
'num-warnings'] = nw
227 logging.debug(
"nh: {}".
format(nh))
229 logging.warning(
"Failed to read number of histograms from the log")
230 data[
'num-histograms'] =
'n/a'
232 data[
'num-histograms'] = nh
238 prmon_log =
first_existing_file([
'prmon.full.RDOtoRDOTrigger',
'prmon.full.RAWtoESD',
'prmon.full.ESDtoAOD',
'prmon.full.RAWtoALL'])
240 logging.info(
"No prmon output found, the result will be empty")
241 data[
'prmon'] =
'n/a'
243 logging.info(
"Analysing prmon output from %s", prmon_log)
245 if prmon_data
is None:
246 logging.warning(
"Could not analyse prmon output, the result will be empty")
247 data[
'prmon'] =
'n/a'
249 data[
'prmon'] = prmon_data
252 perfmon_log =
newest_file(
r'.*perfmon\.summary\.txt')
254 logging.info(
"No PerfMon output found, the result will be empty")
255 data[
'memory-usage'] =
'n/a'
257 logging.info(
"Analysing PerfMon output from %s", perfmon_log)
259 if perfmon_data
is None:
260 logging.warning(
"Could not analyse PerfMon output, the result will be empty")
261 data[
'memory-usage'] =
'n/a'
263 data[
'memory-usage'] = perfmon_data
266 with open(
'extra-results.json',
'w')
as outfile:
267 json.dump(data, outfile, indent=4)
270 if "__main__" in __name__: