# Looking for simple utility that shows the peak maximum memory consumption of a program



## Snurg (Jan 25, 2021)

I know there are complex utilities (profilers, debuggers,...) that one can use to determine the peak maximum memory consumption of a program.

But what I am looking for is something super simple, just like something `showmemoryusage <someprogram>`.
Ideally it would just tell me the peak memory usage after <someprogram> exited.


----------



## olli@ (Jan 25, 2021)

Snurg said:


> I know there are complex utilities (profilers, debuggers,...) that one can use to determine the peak maximum memory consumption of a program.
> 
> But what I am looking for is something super simple, just like something `showmemoryusage <someprogram>`.
> Ideally it would just tell me the peak memory usage after <someprogram> exited.


 
You can use time(1) with the `-l` option. The memory consumption of the process is in the line labeled “maximum resident set size”. See the manual page for details.
 
Beware, many shells have a built-in command with the same name, which might work differently. So be sure to type `/usr/bin/time` in order to be sure that FreeBSD’s time(1) command is executed, not the shell’s one.
 
Here’s a simple example. It’s an AWK one-liner that just fills a memory array with some junk data. It doesn’t produce any output itself. The output that you see here comes from the time(1) command after the AWK command has exited.

```
/usr/bin/time -l awk 'BEGIN { for (i=1; i<10000; i++) a[i]=a[i-1] "foo" }'

        0.21 real         0.13 user         0.07 sys
    170632  maximum resident set size
        84  average shared memory size
         7  average unshared data size
       123  average unshared stack size
     43251  page reclaims
         0  page faults
         0  swaps
         0  block input operations
         0  block output operations
         0  messages sent
         0  messages received
         0  signals received
         2  voluntary context switches
         3  involuntary context switches
```


----------

