Operating System - HP-UX
1830245 Members
1823 Online
110000 Solutions
New Discussion

Process Accounting (Memory Usage)

 
Chris_164
Contributor

Process Accounting (Memory Usage)

Does anyone know how to get application level memory usage? Specifically, I'm trying to figure out how much memory is used by a C++ application. I need a way of setting a start and end point in my code that will measure the memory consumption.

Thanks in advance!!
Chris Thompson
4 REPLIES 4
Ricardo Bassoi
Regular Advisor

Re: Process Accounting (Memory Usage)


Hi Chris,

You can use the top command in the HP-UX machines !
Do a man top for more details.
To change the priority and the memory consumption you can run a program using the nice option.
Do a man nice for more details.

Regards,
Ricardo
If you never try, never will work
Chris_164
Contributor

Re: Process Accounting (Memory Usage)

Ricardo,

I'm trying to get the memory at the application/code level inside a C++ program. Top is not going to work in this case.
Ricardo Bassoi
Regular Advisor

Re: Process Accounting (Memory Usage)


Hi Chris,

You can try to use the system to cal top and so send the output to a file !

Regards,
Ricardo
If you never try, never will work
Mike Stroyan
Honored Contributor

Re: Process Accounting (Memory Usage)

You can get most of the story from mallinfo(). It will report the amount of memory malloc has allocated and how much of that memory is now free and ready to reuse. The free() call just puts memory into a cache instead of reducing the size of a processes data area. The malloc/realloc/free calls are used by new/delete. Mallinfo is not a complete accounting because a new[] array operation actually uses a second cache of allocated memory managed by the c++ runtime library. That means memory may look like it is in use when it is actually available for another new [] operation. A program may also be using memory allocated by mmap or shmget calls.

#include
{
struct mallinfo mi;

mi = mallinfo();
malloc_free_buffer = mi.fordblks;
printf("malloc arena memory is %d bytes\n", mi.arena);
printf("free malloc ordinary buffer memory is %d bytes\n", mi.fordblks);
printf("free malloc small block memory is %d bytes\n", mi.fsmblks);
}