我已经编写了一个外壳脚本(myScript.sh),它由一组以下形式的命令组成:
command1 #first run
command1 #second run
command1 #third run现在,我想要找出每次运行command1所消耗的最大内存。我可以通过在单独的终端上运行以下命令来找到命令1消耗的最大RAM:
smem -c "command pss" | grep "command1"为了分别找到第一次、第二次和第三次运行所消耗的最大内存,我以交错的方式在不同的终端上手动运行command1和smem
command1 #terminal 1
smem -c "command pss" | grep "command1" #terminal 2 in a loop to get maximum memory
command1 #terminal 1
smem -c "command pss" | grep "command1" #terminal 2 in a loop to get maximum memory
command1 #terminal 1
smem -c "command pss" | grep "command1" #terminal 2 in a loop to get maximum memory/有没有什么方法可以让我使用linux命令或python在单个shell脚本或程序中自动执行此过程?
发布于 2015-09-06 05:52:43
对Linux不太确定,但你可以在OS X的Mac上做到这一点:
/usr/bin/time -l <command> 2>&1 | grep -i max示例输出:
/usr/bin/time -l sleep 1 2>&1 | grep -i max
557056 maximum resident set size # <--- program used 557kB或者,完整输出:
/usr/bin/time -l sleep 1
1.00 real 0.00 user 0.00 sys
557056 maximum resident set size
0 average shared memory size
0 average unshared data size
0 average unshared stack size
145 page reclaims
0 page faults
0 swaps
0 block input operations
0 block output operations
0 messages sent
0 messages received
0 signals received
0 voluntary context switches
2 involuntary context switcheshttps://stackoverflow.com/questions/32417175
复制相似问题