Script to record max memory usage of program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to record max memory usage of program
# 1  
Old 08-09-2018
Script to record max memory usage of program

Hello,

I am working on an application that uses allot of memory depending on the input. I am also working on more than one processing algorithm.

The program has a long processing time (hours) so it would be nice to be able to monitor the maximum memory footprint of the application during runs of various data.

It seems like there may be a linux tool that could do that from a script but I don't know of such a thing.

I am running under windows with cygwin so I have most of the linux toolbox, but could do this in open suse as well.

Are there any suggestions?

------ Post updated 08-09-18 at 01:19 PM ------

It looks like

/usr/bin/time -v

gives me the output I need.
Code:
User time (seconds): 354.48
System time (seconds): 0.00
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 5:54.98
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 350976
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 1366
Minor (reclaiming a frame) page faults: 0
Voluntary context switches: 0
Involuntary context switches: 0
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 65536
Exit status: 0

Now I need to figure out where all those page faults are coming from. I would appreciate other suggestions if they are out there.

Thanks,

LMHmedchem
# 2  
Old 08-09-2018
When a page fault occurs then something is paged in or out, usually from or to the swap space.
If you run
Code:
vmstat 2

you see it listed as si (swap in) or so (swap out).
Here is a suggestion for a bash script that monitors a given PID, and displays the maximum RSS memory (kilobyte of RAM used).
Code:
#!/bin/bash
[[ $1 =~ ^[0-9]+$ ]] || {
  echo "usage:
  ${0}: <pid>"
  exit 1
}
pid=$1
ps -fp $pid
max=0
while :
do
  rss=$(ps -o rss= -p $pid)
  if [[ $rss -gt $max ]]
  then
    max=$rss
    echo "maxRSS (kb): $max"
  fi
  sleep 10
done

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Memory usage per user,percent usage,sytem time in ksh

Let's say i have 20 users logged on Server. How can I know how much memory percent used each of them is using with system time in each user? (2 Replies)
Discussion started by: roy1912
2 Replies

2. Shell Programming and Scripting

Shell script to calculate the max cpu usage from the main script

Hi All, I have a script which does report the cpu usuage, there are few output parameter/fields displayed from the script. My problem is I have monitor the output and decide which cpu number (column 2) has maximum value (column 6). Since the output is displayed/updated every seconds, it's very... (1 Reply)
Discussion started by: Optimus81
1 Replies

3. AIX

Script to check the memory usage in AIX

Hello Everyone, I'm looking for a efficient script that monitors the memory usage on AIX and send email alerts when it reaches certain point. Q) need to get alerts, when the memory usage exceed 90% on AIX? or Q) Need to get alerts when available free Memory is 1G or 10% etc Any idea... (3 Replies)
Discussion started by: System Admin 77
3 Replies

4. Shell Programming and Scripting

Help creating a timestamp script to record mem usage

Hi, I'm looking into doing a few performance tweaks by adjusting my max memory on a few lpars. I would to create a time stamp script so i could review it for a week and determine how much space i can lower my max memory to so i could reclaim and allocate that memory to where it is needed the... (2 Replies)
Discussion started by: vpundit
2 Replies

5. Shell Programming and Scripting

help in high memory usage alert script

can any one please help me to shell script high memory usage alert (6 Replies)
Discussion started by: robo
6 Replies

6. Solaris

restrcit physical memory with zone.max-locked-memory

Is it possible to restrict physical memory in solaris zone with zone.max-locked-memory just like we can do with rcapd ? I do not want to used rcapd (1 Reply)
Discussion started by: fugitive
1 Replies

7. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

8. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

10. AIX

ulimits max locked memory virtual memory

Hi, Would any one be so kind to explain me : are ulimits defined for each user seperately ? When ? Specialy what is the impact of : max locked memory and virtual memory on performance of applications for a user. Many thanks. PS : this is what I can see in MAN : ulimit ] ... (5 Replies)
Discussion started by: big123456
5 Replies
Login or Register to Ask a Question