Results 1 to 4 of 4

Thread: Record memory usage of program?

  1. #1

    Record memory usage of program?

    Is there a way I can start a program and then record a log of how much memory it's using at a specific interval until the program ends?

    I've tried writing a shell script but get the error:
    ./apps/mem-test.sh: line 4: [: too many arguments

    Here's the non-working script:
    Code:
    $HOME/apps/ImageMagick/bin/convert -limit memory 64 -limit map 128 $HOME/SSI/davidkennardphotography/Img-Orig/95-Pole-Bank.jpg -set option:filter:filter Lanczos -set option:filter:blur 0.8 -resize 1024x720 $HOME/resizedImage.jpg &
    GOODY="ps -p $! -o pid,%cpu,rss,cmd | grep convert >>test.txt"
    
     while [ $GOODY -ne '' ]
     do
       sleep 0.5
     done
    Thanks

    Dave

  2. #2
    Join Date
    Sep 2006
    Location
    Dublin IE
    Beans
    3,275
    Distro
    Ubuntu

    Re: Record memory usage of program?

    Hi there,

    Something like this ought to do the trick ...

    Code:
    #!/bin/bash
    $HOME/apps/ImageMagick/bin/convert -limit memory 64 -limit map 128 $HOME/SSI/davidkennardphotography/Img-Orig/95-Pole-Bank.jpg -set option:filter:filter Lanczos -set option:filter:blur 0.8 -resize 1024x720 $HOME/resizedImage.jpg &
    CMD_PID=$!
    
    if [ $? -eq 0 ]; then
    	while [ $? -eq 0 ]; do
    		sleep 2
    		ps --no-headers -p $CMD_PID -o pid,%cpu,rss,cmd >> test.txt
    	done
    fi
    In your version, the error on line 4 would be solved by quoting $GOODY, but you'd only get one log entry out of it.

    I hope that helps.

  3. #3

    Re: Record memory usage of program?

    Yep, that does the trick. Thanks for the help!

    Dave

  4. #4
    Join Date
    Mar 2006
    Location
    Canada
    Beans
    1,313
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Record memory usage of program?

    This is very useful, thank you!

Tags for this Thread

Bookmarks

Posting Permissions

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