【发布时间】:2017-09-14 08:24:54
【问题描述】:
假设有两个脚本:(a) 一个调用 JAVA jar 的 bash shell 脚本(以下称为 my_shell_script),以及 (b) 一个从其他 Python 包导入函数但确实如此的 Python 脚本不要调用任何非 Python 包或软件(以下称为my_Python_script)。这两个脚本的目的相同:它们采用相同的输入(以下称为testinput)并生成大致相同的输出。
我想测量和比较两个脚本的内存使用情况,作为它们执行时的时间函数。
为此,我使用massif(将time_unit 设置为毫秒)通过valgrind 执行每个脚本,然后是通过ms_print 输出的massif 的摘要。
INF=testinput
# Testing Shell script
valgrind --tool=massif --pages-as-heap=yes --time-unit=ms --massif-out-file=${INF}_shell.out bash my_shell_script -f $INF -j my_java_jar
ms_print --threshold=50.0 ${INF}_shell.out > ${INF}_shell.summary
# Testing Python script
valgrind --tool=massif --pages-as-heap=yes --time-unit=ms --massif-out-file=${INF}_Python.out python2 my_python_script $INF
ms_print --threshold=50.0 ${INF}_Python.out > ${INF}_Python.summary
虽然 valgrind/massif 记录了 my_python_script 的内存使用情况,这与我通过 htop 看到的大致一致,但 my_shell_script 的情况并非如此。 htop 的统计数据表明在执行 my_shell_script 期间使用了 GB 的内存,而 valgrind/massif 记录仅使用了几十 MB 的内存。
因此,我怀疑 valgrind/massif 记录了执行 bash 代码的内存使用情况,但没有记录 bash 代码正在调用的 JAVA jar。
如何正确测量my_shell_script 的内存使用量随时间的变化?
【问题讨论】:
标签: python shell memory valgrind performance-testing