17 from pathlib
import Path
19 import matplotlib.pyplot
as plt
23 from .exceptions
import ScriptError
25 DEFAULT_FILE_NAME =
"timem-output.json"
29 file = dir_path / DEFAULT_FILE_NAME
31 with open(file, mode=
'r')
as f:
33 except (FileExistsError, FileNotFoundError)
as ex:
34 raise ScriptError(f
"Failed to open file '{file.absolute()}': {ex}")
35 except json.decoder.JSONDecodeError:
37 return output[
'timemory'][
'timem'][0]
41 return f
"{data['value']:.2f}{data['unit_repr']}"
45 return output[
'peak_rss'], output[
'cpu_util']
57 data = output[
'wall_clock']
58 elapsed_time = data[
'value']
59 time = np.arange(0.0, elapsed_time, 0.2)
60 wall_clock_to_time_offset = output[
'history'][0][
'wall_clock'][
'value']
61 wall_clock_to_time_scale = elapsed_time / (
62 output[
'history'][-1][
'wall_clock'][
'value'] - wall_clock_to_time_offset
67 for sample
in output[
'history']:
69 (sample[
'wall_clock'][
'value'] - wall_clock_to_time_offset)
70 * wall_clock_to_time_scale
72 rss.append(sample[
'page_rss'][
'value'])
73 virtual_memory.append(sample[
'virtual_memory'][
'value'])
75 series = pd.DataFrame(
76 {
'time': time,
'rss': rss,
'virtual_memory': virtual_memory}
82 arg_parser = argparse.ArgumentParser(
83 description=
'Script to postprocess timem results.'
85 arg_parser.add_argument(
86 'dir', help=
'Directory with timem-output.json file', type=Path
88 args = arg_parser.parse_args()
89 dir_path = Path(args.dir)
95 print(f
"timem metrics for run '{name}':")
96 print(f
"\telapsed_time: {elapsed_time_str}")
97 print(f
"\tcpu_usage: {cpu_usage_str}")
98 print(f
"\tpeak_rss: {peak_rss_str}")
99 series.plot(subplots=
True)