• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Checking memory usage per script/application

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Ve'R

Registered
Joined
Jan 16, 2006
Hello , linux enthusiasts

Your help is required with the following problem:
I have written a perl script to parse some text files and i would like to measure the amount of memory it uses in a fashion like the "time" bash command does.

the usage of time is to put it in front of the command you which to execute and after completion it reports the time it took.
For the memory app i would like it to return the max memory used preferably in MB/KB

i have looked at mpatrol but this was for memory debugging and not memory usage reporting (if i recall correctly)

Thanks in advance Ve'R
 

splat

ASCII Moderator
Joined
Apr 6, 2002
all i can think of is use "top" in another terminal to monitor it
 
OP
V

Ve'R

Registered
Joined
Jan 16, 2006
hmm , thanks for the input .
but sadly this does not work in a time like fashion
i want to see at the end the max memory usage or some graph.
 

curtis1552

Member
Joined
Aug 26, 2007
Location
Dayton, Ohio
You could try using this command
ps -Ao pcpu,pmem,pid,cmd | grep *** (edit of command below)
where *** is the pid or name of the program
add this command as a recurring loop in a script and have the output piped to a file.
The goal would be to use grep to reduce the amount of data in the file.
Then you could take the file and scan it for the largest percent mem usage.
I noticed a better argument.
ps -Ao vsz,cmd | grep ***
this will show the memory usage of the program in Kb.
I'll see if i can get a script up later, gotta go to work now
 
OP
V

Ve'R

Registered
Joined
Jan 16, 2006
thanks very much i shall focus my efforts on this and learning a little bash/perl scripting.