Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
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 ]; ...
  1. #11
    Just 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.
    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/ &#123;print $2&#125;' < /proc/$PROCESS_PID/status`
       if &#91; "$VM_SIZE.X" = ".X" &#93;; then
          continue
       fi
       VM_RSS=`awk '/VmRSS/ &#123;print $2&#125;' < /proc/$PROCESS_PID/status`
       if &#91; "$VM_RSS.X" = ".X" &#93;; then
          continue
       fi
       echo "$ELAPSED_TIME,$VM_SIZE,$VM_RSS" >> $LOG_FILE
       sleep $PERIOD
       VM_SIZE=""
       VM_RSS=""
       ELAPSED_TIME=`date +%H&#58;%M&#58;%S&#58;%N`
     else
     echo "$1 is no longer a running process"
     exit 0
     fi
    done
    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.

  2. #12
    Just 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.

  3. #13
    Just 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.
    Code:
    #!/bin/sh
    #
    #GetMemUsage launch script
    
    cmd=$1
    
    if &#91; -n $cmd &#93; ; 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
    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.

  4. #14
    Just 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:
    Code:
    PIDOF_CMD=`which pidof`
    and perform following replacement:
    Code:
    # replace this: PROCESS_PID=`/sbin/pidof $1`
    # with this:
    PROCESS_PID=`$PIDOF_CMD $1`
    perhaps you can just try to call `pidof` instead of assigning the result of `which pidof`

    also, if you want to monitor scripts too (e.g. ruby, perl, etc), add this line instead
    Code:
    PIDOF_CMD="`which pidof` -x"

  5. #15
    Just 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

  6. #16
    Just 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
    Quote Originally Posted by shathy View Post
    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

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •