Get real-time machine usage data while running com

2019-09-19 06:40发布

问题:

Suppose as an example that I want to run some script in a terminal (or some command/snippet that I just hardcoded into it). I wonder if it exists a tool for analyzing live statistics of machine usage (% CPU, execution speed, dedicated memory, etc.) which I can pipe my script into or something like that, so I can obtain this data in the output just after the script's output.

I've had no luck searching in Google, neither in SO questions. I'm using Ubuntu 14.04

EDIT: Using the manual indications, I tried up this way:

:~$ time -f "CPU %P%%\nMax RAM %M\n" ./myscript.sh
-f: command not found
/*
  normal output
*/
:~$

also tried:

:~$ time --format="CPU %P%%\nMax RAM %M\n" ./myscript.sh
--format: command not found
/*
  normal output
*/
:~$

also, as a desperate measure:

:~$ time --verbose ./myscript.sh
--verbose: command not found
/*
  normal output
*/
:~$

Nothing works. I don't understand why args are rejected.

回答1:

Try /usr/bin/time or simpler version built-in bash time



回答2:

time -p sh script_name

O/p

real 13.37 user 0.00 sys 0.82



回答3:

Here I leave the results obtained thanks to the help offered by @mefju and @Poo, long ago:

Using the external app /usr/bin/time instead (which is not the same than the bash builtin time, as JID explained above) solved the args rejection. This way it works well for me:

:~$ /usr/bin/time -f "CPU: %P\nMax RAM: %M kB\nTime: %e s\nSwap cnt: %W" ./myscript.sh

The resulting output:

CPU: 63%
Max RAM: 1432 kB
Time: 0.45 s
Swap cnt: 0


标签: bash shell