Reputation: 2989
I have written a shell script (myScript.sh) comprising of a set of commands of the following form:
command1 #first run
command1 #second run
command1 #third run
Now I want to find the maximum RAM consumed by each individual run of command1. I can find the maximum RAM consumed by command 1 by running in a separate terminal the command:
smem -c "command pss" | grep "command1"
In order to find the maximum RAM consumed by first, second and third run individually I have the run command1 and smem on different terminals manually in an interleaved fashion
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/
Is there any way by which I may automate this process within a single shell script or program using either linux commands or python?
Upvotes: 0
Views: 164
Reputation: 207873
Not sure about Linux, but you can do this on a Mac under OS X:
/usr/bin/time -l <command> 2>&1 | grep -i max
Sample output:
/usr/bin/time -l sleep 1 2>&1 | grep -i max
557056 maximum resident set size # <--- program used 557kB
or, full output:
/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 switches
Upvotes: 1