4

I would like to run a process from bash in Cygwin so that I have some short summary after execution like peak memory usage or average CPU usage, like time but with more information.

Are there any options?

Euri Pinhollow
  • 231
  • 1
  • 7
  • 1
    OS doesn't matter? I think we would have to choose a Unix- based one here. – Jeff Schaller Feb 19 '17 at 11:59
  • @JeffSchaller Unix is not represented by a single OS. Neither Linux nor Unix are OS's. My remark makes quite a bit of sense considering how many spinoffs these two have and not all programs are universal. I am really not interested in a specific OS. – Euri Pinhollow Feb 19 '17 at 13:40
  • Then this question is too broad to answer here. See [Questions with too many possible answers or that would require an extremely long answer](http://unix.stackexchange.com/tour) – Jeff Schaller Feb 19 '17 at 13:43
  • @JeffSchaller thereifixedit. – Euri Pinhollow Feb 19 '17 at 13:48
  • there are several good related questions, including http://unix.stackexchange.com/questions/331691/how-much-ram-diskspace-and-cpu-time-is-used-by-a-script?rq=1 and http://unix.stackexchange.com/questions/18841/measuring-ram-usage-of-a-program?rq=1 – Jeff Schaller Feb 19 '17 at 14:55
  • @JeffSchaller yes those are helpful. – Euri Pinhollow Feb 19 '17 at 15:07

1 Answers1

4

You can do this by running the command inside GNU time. By default, time shows you the real (wall clock), user (CPU-seconds used in user mode), and sys (CPU-seconds used in kernel mode) data items. However, you can also ask it to measure other things, such as RAM and disk usage:

/usr/bin/time -f "File system outputs: %O\nMaximum RSS size: %M\nCPU percentage used: %P" <command>

where <command> is replaced by the command you wish to run. The output will be something like:

File system outputs: 18992
Maximum RSS size: 40056
CPU percentage used: 367%

where "CPU percentage used" is a percentage and shows here that 3.6 cores were used, "Maximum RSS size" is as close as it gets to "maximum memory used" and is expressed in kilobytes, and "File system outputs" is expressed in number of operations (i.e., it does not say how much data is written). The du and df commands you gave should help there.

Note: you need to use /usr/bin/time rather than just time, as many shells have that as a builtin, which doesn't necessarily support the -f option.

For more information, see man time

https://unix.stackexchange.com/a/331707/213127

Same goes for Cygwin: there is a bash built-in which can be substituted by GNU time.

Euri Pinhollow
  • 231
  • 1
  • 7