Checking mem usage at specific times in a program


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Checking mem usage at specific times in a program
# 1  
Old 04-05-2009
Checking mem usage at specific times in a program

Hi all,

I'm running a simulator and I'm noticing an slow increase in memory for long simulations such that the simulation has to end because of a lack of memory. A colleague of mine ran Valgrind memcheck and reported that nothing of interest was reported other than known mem leaks. My advisor suggested that I try adding getrusage() at suspicious places in the code to try and pinpoint where the leak is occurring in the simulator. I recently tried this only to discover that Unix doesn't fully support getrusage() anymore and it doesn't seem like it will be useful for obtaining memory usage. I know I can use system() to issue a cat and grep to get the mem usage from /proc/pid/status (and I'm not sure if this would be accurate since I guess the system would fork a thread and make that call while the main thread continues?), but I was wondering if there was a better way of determining the memory usage at a particular point in the code. Most of the other solutions I've seen are scripts and would not be able to tell you the difference in memory usage between two different points in the code.


Thanks for any help,

Paul
# 2  
Old 04-05-2009
UNIX does usually fully support getrusage -- you may have to enable XOPEN support. What version of unix do you have?
Code:
uname -a

will show you.

If the system is from the last 15 years there will be macro defined that "turns on" XOPEN support. It looks like one of these
Code:
#define _XOPEN_SOURCE_EXTENDED
#define _XOPEN_SOURCE nnn <some number goes here, man page tells you>

#define _XOPEN_SOURCE causes restrictions on Darwin - OSX (Apple) rather than extensions.

You have to read your system/compiler documentation (man pages) - specifcally the one for getrusage.

If valgrid reports memory leaks, fix them regardless of what one of your buddies says. Otherwise you are programming by coincidence, not design.
# 3  
Old 04-05-2009
Hey thanks for the reply Jim,

The compute node that I'm running the simulator on is running a recent Ubuntu 64 bit version. Running uname -a yields:

Linux power1 2.6.24-19-generic #1 SMP Wed Aug 20 17:53:40 UTC 2008 x86_64 GNU/Linux


I was not aware of the XOPEN thing. When I did man getrusage, the information didn't say anything about XOPEN. Is this specific to UNIX?
I only did a man getrusage, is there someplace else I should be looking?


Thanks again,

Paul
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

shell program- how many times a function is called

We have a program source C and is required to indicate how many times each function is called from the C program. also print the line number where there is a call. I've tried something like this: #!/bin/sh for i in $*;do if ! then echo $i is not a C file. else echo $i... (0 Replies)
Discussion started by: oana06
0 Replies

3. Programming

Compare times to run a program - Serial vs MPI

Hi, I have a fortran program with serial and MPI version. I want to compare the time taken by these programs to run. I use ifort/gfortran compiler. How to compare the time taken by each program to run? Is there any sample code for comparison? Thanks, rpd (1 Reply)
Discussion started by: rpd25
1 Replies

4. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

5. Shell Programming and Scripting

Checking for higher usage and mark it

Hi Gurus, I'm using HPUX B.11.23 U ia64 with sh shell. Is it possible to insert a word "Warning" in the end of this line if there is high percentage? For example: if the percentage is higher than 80%? Sample data: /dev/vgsap/TEST1 /oracle/TST/TEST1 9.89 GB 8.37 GB ... (11 Replies)
Discussion started by: superHonda123
11 Replies

6. Shell Programming and Scripting

[bash] Run a program many times

Hi I'm running a program many times with differents input. I mean that i run my_prog with some parameters and i wait till the end, then i start again another simulations with some others differents parameters. Is possible to make it automatic with a script bash. Maybe i need some... (2 Replies)
Discussion started by: Dedalus
2 Replies

7. Gentoo

cpu%/mem% usage, scripting, dzen2: howto learn bash the hard way

I am trying to write a small (and rather simple) script to gather some info about the system and piping it to dzen2 first, i want to explain some things. I know i could have used conky, but my intention was to expand my knowledge of bash, pipes and redirections inside a script, and to have fun... (14 Replies)
Discussion started by: broli
14 Replies

8. Linux

Linux Mem Usage

What is amount of free RAM i have now? total used free shared buffers cached Mem: 1010 963 46 0 215 256 -/+ buffers/cache: 491 518 Swap: 1983 0 1983 Above is the output of... (1 Reply)
Discussion started by: new2ss
1 Replies

9. Shell Programming and Scripting

Can I use $1 several times in shell program?

Hi, I am new to Unix and shell programming. I am trying to write a shell program to read 4 variables from command line. For example, Please enter your name: somebody Please enter your address: address plase enter your phone: phone I'd like to save all threee variables in my program for... (3 Replies)
Discussion started by: whatisthis
3 Replies

10. UNIX for Dummies Questions & Answers

Difference in Mem usage ?

Hi All, I have a pair of sun ultra 5_10 with SunOS 5.5.1. Both are almost equally patched and set up with simillar applications. host# uname -a SunOS host 5.5.1 Generic_103640-24 sun4u sparc SUNW,Ultra-5_10 Even though both have same amount of RAM ( 512 Mb ) , ... (1 Reply)
Discussion started by: shibz
1 Replies
Login or Register to Ask a Question