Results 11 to 16 of 16
Sorry about another post so quickly but in this new modification the script shutsdown automatically on process death.
Code:
#!/bin/sh
#GetmemUsageModified2
USAGE="Usage: $0 processName"
if [ $# -ne 1 ]; ...
- 11-26-2005 #11Just Joined!
- Join Date
- Jun 2005
- Location
- Blackburn, North West England (UK)
- Posts
- 50
Sorry about another post so quickly but in this new modification the script shutsdown automatically on process death.
I wont post again untill i recive a reply so i know you have gotten this, then after that i'll just edit this post with the new script to prevent this thread from becoming huge.Code:#!/bin/sh #GetmemUsageModified2 USAGE="Usage: $0 processName" if [ $# -ne 1 ]; then echo $USAGE exit 1 fi # In case the monitored process has not yet started # keep searching until its PID is found PROCESS_PID="" while : do PROCESS_PID=`/sbin/pidof $1` if [ "$PROCESS_PID.X" != ".X" ]; then break fi done LOG_FILE="memusage.csv" echo "ElapsedTime,VmSize,VmRSS" > $LOG_FILE ELAPSED_TIME=`date` PERIOD=2 # seconds while : do if [ -d /proc/$PROCESS_PID ] ; then VM_SIZE=`awk '/VmSize/ {print $2}' < /proc/$PROCESS_PID/status` if [ "$VM_SIZE.X" = ".X" ]; then continue fi VM_RSS=`awk '/VmRSS/ {print $2}' < /proc/$PROCESS_PID/status` if [ "$VM_RSS.X" = ".X" ]; then continue fi echo "$ELAPSED_TIME,$VM_SIZE,$VM_RSS" >> $LOG_FILE sleep $PERIOD VM_SIZE="" VM_RSS="" ELAPSED_TIME=`date +%H:%M:%S:%N` else echo "$1 is no longer a running process" exit 0 fi done
- 11-27-2005 #12Just Joined!
- Join Date
- Jun 2005
- Posts
- 23
skrye,
I'm a developer and this is my attempt at a simple memory usage profiling for an application I'm testing:
1) I was aiming for a _relative_ elapsed time, i.e. number of milliseconds since the start of the process, not absolute time. (This makes for simple graphing and comparison across multiple runs and versions.)
2) Running GetMemUsage as a daemon certainly has its advantages but requires root privileges, and that's not always possible. However, please post your solution so I can see if I can adapt it to my needs.
My original thinking is this:
a1) write a launch script and names it the same as the monitored process (of course, rename the monitored process to something else), thus achieving transparency. (This means a different launch script for each monitored process. Since I'm a developer interested in a few particular applications, this is fine.) Or,
a2) pass the name of the monitored process as an argument to the launch script
b) This launch script, running as a user process, would first launch GetMemUsage in the background, then launch the monitored process in the foreground. The launch script would end when the monitored process ends (either normally or interrupted via Ctrl-C, which in my case, happens quite frequently). When the launch script ends, it would end the GetMemUsage script, preferably cleanly (so far I can only think of kill -9), as part of its cleanup.
Looking forward to seeing your solutions.
- 11-27-2005 #13Just Joined!
- Join Date
- Jun 2005
- Location
- Blackburn, North West England (UK)
- Posts
- 50
Ok i think i we got the launch script covered, take a look at this and see what you think.
I'm trying to utilize the time command to resolve to the relative elapsed time issue. If you run this in debug mode on the modified GetMemUsage you shall see that its simple but effcient.Code:#!/bin/sh # #GetMemUsage launch script cmd=$1 if [ -n $cmd ] ; then ./GetMemUsageModified.sh $cmd & $cmd wait fi if ps x | perl -ne 'print if /\b'$cmd'\b/' > /dev/null 2>&1 ; then wait else exit 0 fi
- 01-30-2006 #14Just Joined!
- Join Date
- Jan 2006
- Posts
- 1
portable `pidof` location
w.r.t. GetMemUsg: my debian system has `/bin/pidof` and not `/sbin/pidof`
so add this line:
and perform following replacement:Code:PIDOF_CMD=`which pidof`
perhaps you can just try to call `pidof` instead of assigning the result of `which pidof`Code:# replace this: PROCESS_PID=`/sbin/pidof $1` # with this: PROCESS_PID=`$PIDOF_CMD $1`
also, if you want to monitor scripts too (e.g. ruby, perl, etc), add this line instead
Code:PIDOF_CMD="`which pidof` -x"
- 03-08-2007 #15Just Joined!
- Join Date
- Mar 2007
- Posts
- 2
Dear Guys,
I searched on the net for monitor memory usage and I got a very good solution here.
Thank you very much.
Regards,
shathy
- 09-09-2007 #16Just Joined!
- Join Date
- Sep 2007
- Posts
- 2
This is awsome andf i am sure will help u out.. chekc this guys
First of all thanks, this thread was really helpful.
Even i am a developer, and I found this link to be immensely useful. Awsome and accurate memory profiling can be done using these.
Check them out.
Per process accurate memory usage , private region , public region and shared library page mapping included. better than VMSIZE and RSS values.
Memory usage Retrieval on Linux ( process wise and general )
How much RAM / Memory does a program use.
How much RAM is used per program .
Regards,
-- Ritu




