I'd like to measure the time and cpu usage of a command with the /usr/bin/time tool. But when I do os.popen( "/usr/bin/time -f \t%E MM:ss:mm ls -R" ).read() it also stores the output of ls -R. What can I do to only store the /usr/bin/time output?
I also tried it with subprocess but it doesn't work either.
out = subprocess.Popen(['/usr/bin/time', '-f', '"\t%E MM:ss:mm"', 'ls', '-R'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout,stderr = out.communicate()
print( stdout )
Running the command in the terminal looks like this:
Input:
/usr/bin/time -f "\t%E M:ss:mm, \t%P CPU" ls -R
Output:
.:
Dockerfile input output README.md src Test.py
./input:
links.txt raw yuv
./input/raw:
./input/yuv:
./output:
./src:
InstallEncoderArm.sh InstallEncoderx86.sh RunTests.py
0:00.00 M:ss:mm, 100% CPU