tag:blogger.com,1999:blog-865923359735383241.post4424599498172366170..comments2023-10-29T07:27:09.012-06:00Comments on Ccna final exam - java, php, javascript, ios, cshap all in one: Peak memory usage of a linux/unix processUnknownnoreply@blogger.comBlogger10125tag:blogger.com,1999:blog-865923359735383241.post-52322216511675498902012-06-08T19:14:59.917-06:002012-06-08T19:14:59.917-06:00Valgrind one-liner:
valgrind --tool=massif --page...Valgrind one-liner:<br /><br />valgrind --tool=massif --pages-as-heap=yes --massif-out-file=massif.out ./test.sh; cat massif.out | grep mem_heap_B | sed -e 's/mem_heap_B=\(.*\)/\1/' | sort | tail -n 1<br /><br />Note use of --pages-as-heap to measure all memory in a process. More info here: http://valgrind.org/docs/manual/ms-manual.htmlUserhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-29482815485914025952012-06-08T19:14:57.352-06:002012-06-08T19:14:57.352-06:00Here is (based on the other answers) a very simple...Here is (based on the other answers) a very simple script that watches an already running process. You just run it with the pid of the process you want to watch as the argument:<br /><br />#!/usr/bin/env bash<br /><br />pid=$1<br /><br />while ps $pid >/dev/null<br />do<br /> ps -o vsz= ${pid}<br /> sleep 1<br />done | sort -n | tail -n1<br /><br /><br />Example usage:<br /><br />max_mem_usage.sh 23423Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-82621020482166162142012-06-08T19:14:55.418-06:002012-06-08T19:14:55.418-06:00Use Massif: http://valgrind.org/docs/manual/ms-man...Use Massif: http://valgrind.org/docs/manual/ms-manual.htmlUserhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-71406165933503355912012-06-08T19:14:54.015-06:002012-06-08T19:14:54.015-06:00/usr/bin/time maybe does what you want, actually. .../usr/bin/time maybe does what you want, actually. Something like.<br /><br /><br /> /usr/bin/time --format='(%Xtext+%Ddata %Mmax)'<br /><br /><br />See time(1) for details...Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-14001078084117739642012-06-08T19:14:52.588-06:002012-06-08T19:14:52.588-06:00Perhaps time(1) already does what you want. For i...Perhaps time(1) already does what you want. For instance:<br /><br />$ /usr/bin/time -f "%P %M" command<br />43% 821248<br /><br /><br />But other profiling tools may give more accurate results depending on what you are looking for.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-24819732839344952402012-06-08T19:14:49.740-06:002012-06-08T19:14:49.740-06:00You can use a tool like Valgrind to do this.You can use a tool like Valgrind to do this.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-69731304493764501182012-06-08T19:14:47.743-06:002012-06-08T19:14:47.743-06:00If the process runs for at least a couple seconds,...If the process runs for at least a couple seconds, then you can use the following bash script, which will run the given command line then print to stderr the peak RSS (substitute for rss any other attribute you're interested in). It's somewhat lightweight, and it works for me with the ps included in Ubuntu 9.04 (which I can't say for time).<br /><br />#!/usr/bin/env bash<br />"$@" & # Run the given command line in the background.<br />pid=$! peak=0<br />while true; do<br /> sleep 1<br /> sample="$(ps -o rss= $pid 2> /dev/null)" || break<br /> let peak='sample > peak ? sample : peak'<br />done<br />echo "Peak: $peak" 1>&2Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-17098995381256024132012-06-08T19:14:44.307-06:002012-06-08T19:14:44.307-06:00Well, if you really want to show the memory peak a...Well, if you really want to show the memory peak and some more in-depth statistics i recommend using a profiler such as valgrind. A nice valgrind front-end is alleyoop.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-16121978174636871322012-06-08T19:14:43.115-06:002012-06-08T19:14:43.115-06:00[Edit: well, this looked useful at first but alway...[Edit: well, this looked useful at first but always seems to return 0]<br /><br />Looks like /usr/bin/time does give you that info, if you pass -v (this is on Ubuntu 8.10). See, e.g., Maximum resident set size below:<br /><br /><br />$ /usr/bin/time -v ls /<br />....<br /> Command being timed: "ls /"<br /> User time (seconds): 0.00<br /> System time (seconds): 0.01<br /> Percent of CPU this job got: 250%<br /> Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00<br /> Average shared text size (kbytes): 0<br /> Average unshared data size (kbytes): 0<br /> Average stack size (kbytes): 0<br /> Average total size (kbytes): 0<br /> Maximum resident set size (kbytes): 0<br /> Average resident set size (kbytes): 0<br /> Major (requiring I/O) page faults: 0<br /> Minor (reclaiming a frame) page faults: 315<br /> Voluntary context switches: 2<br /> Involuntary context switches: 0<br /> Swaps: 0<br /> File system inputs: 0<br /> File system outputs: 0<br /> Socket messages sent: 0<br /> Socket messages received: 0<br /> Signals delivered: 0<br /> Page size (bytes): 4096<br /> Exit status: 0Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-60773073768539589812012-06-08T19:14:38.908-06:002012-06-08T19:14:38.908-06:00(This is an already answered, old question.. but j...(This is an already answered, old question.. but just for the record :)<br /><br />I was inspired by Yang's script, and came up with this small tool, named memusg. I simply increased the sampling rate to 0.1 to handle much short living processes. Instead of monitoring a single process, I made it measure rss sum of the process group. (Yeah, I write lots of separate programs that work together) It currently works on Mac OS X and Linux. The usage had to be similar to that of time:<br /><br /><br />memusg ls -alR / >/dev/null<br /><br /><br />It only shows the peak for the moment, but I'm interested in slight extensions for recording other (rough) statistics.<br /><br />It's good to have such simple tool for just taking a look before we start any serious profiling.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.com