简体   繁体   中英

How to determine the maximum memory a program uses?

I am going to write a Perl program which is going to use accordingly preliminary benchmarks on small amounts of data about 100MB memory. I want to know the used amount of memory more precisely.

How can I determine the amount of memory a Perl script uses?

There should be some command like (its name printmaxmemoryuse is made up by me):

printmaxmemoryuse perl myscript.pl

We are on FreeBSD.

In FreeBSD you can use procstat to get extend details about the process. for example to obtain the memory a process is consuming:

procstat -r <PID>

Example output:

# procstat -r 847
PID COMM             RESOURCE                          VALUE
847 immortal         user time                    00:00:09.842315
847 immortal         system time                  00:00:26.680180
847 immortal         maximum RSS                             9884 KB
847 immortal         integral shared memory              11960644 KB
847 immortal         integral unshared data               1685608 KB
847 immortal         integral unshared stack               573824 KB
847 immortal         page reclaims                        1126497
847 immortal         page faults                              176
847 immortal         swaps                                      0
847 immortal         block reads                               57
847 immortal         block writes                          356464
847 immortal         messages sent                          13712
847 immortal         messages received                          2
847 immortal         signals received                       13708
847 immortal         voluntary context switches            272454
847 immortal         involuntary context switches           14765

Also, you could use top with cmdwatch for example:

cmdwatch -n1 'top -d 1 | grep 847'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM