View topic - Get memory usage for a process programmatically

Get memory usage for a process programmatically

Discussion about the general applications that run on QNX6

Get memory usage for a process programmatically

Postby mankoula » Tue Feb 04, 2020 6:41 pm

I am trying to write a little program that check the memory used by a process at runtime.
My attempt is to use DCMD_PROC_PAGEDATA and sum up the memory segment size. But when I compare the result of this compution with the result of command Showmem -P pid, they are not equal: The output of Showmem is less that the ouput of the program (by ~500K).
I don't want to use showmem because that utility is not deployed on the target system.
How do I get the same result as Showmem with a standalone program?
Thanks
mankoula
New Member
 
Posts: 4
Joined: Mon Feb 03, 2020 3:55 pm

Re: Get memory usage for a process programmatically

Postby Tim » Tue Feb 04, 2020 11:37 pm

What is showmem reporting to you for your process in terms of the counts for total, heap, stack, data other?

http://www.qnx.com/developers/docs/6.5. ... owmem.html

I wonder if your program is counting memory allocated to your process but not currently in use (stack or freed heap) while showmem is not doing that. It could account for the difference especially if your program is consistently off the by the same amount when testing against different processes.

Tim
Tim
Senior Member
 
Posts: 1503
Joined: Wed Mar 10, 2004 12:28 am

Re: Get memory usage for a process programmatically

Postby mankoula » Thu Feb 06, 2020 5:28 pm

Thanks for the interest.

I tried to follow the example described here: http://www.qnx.com/developers/docs/6.5. ... OC_MAPINFO

Here is the result:

Output of showmem for pipe process:
-----------------
# showmem -P 4100
Process listing (Total, Code, Data, Heap, Stack, Other)
942080 753664 24576 106496 57344 0 4100 pipe
-------------------

Output of devctl( fd, DCMD_PROC_MAPINFO, ...) for pip process - the sum of segments size is 1478656.

index vaddr size dev offset ino flags
0 133902336 4096 0 0 0 1000
1 133906432 12288 2 0 1 1085702
2 133918720 4096 0 0 0 1000
3 133922816 12288 2 0 1 1085702
4 133935104 4096 0 0 0 1000
5 133939200 12288 2 0 1 1085702
6 133951488 4096 0 0 0 1000
7 133955584 12288 2 0 1 1085702
8 133984256 4096 0 0 0 1000
9 133988352 516096 2 0 0 1081782
10 134504448 8192 2 0 1 1081782
11 134512640 20480 4 2752512 134512640 571
12 134533120 8192 4 2772992 134512640 1080332
13 134541312 32768 2 0 1 1084302
14 134574080 4096 2 0 1 1080302
15 134578176 65536 2 0 1 1084302
16 2955935744 733184 4 806912 2955935744 561
17 2956673024 16384 4 2956673024 2956673024 1080332
18 2956689408 4096 2 0 1 1080312
mankoula
New Member
 
Posts: 4
Joined: Mon Feb 03, 2020 3:55 pm

Re: Get memory usage for a process programmatically

Postby Tim » Thu Feb 06, 2020 6:06 pm

If you group the 19 segments based on the example you linked to, do any of the sizes for the various regions (code, data, heap, stack, other) match showmems numbers? Knowing whether any/some of them match might give a clue to why the total isn't matching.

Tim
Tim
Senior Member
 
Posts: 1503
Joined: Wed Mar 10, 2004 12:28 am


Return to QNX6 - Applications

Who is online

Users browsing this forum: No registered users and 1 guest

cron