Is there any API for the command vmmap
Asked Answered
D

1

2

In the command line, i can use vmmap -v -purge 50554 to find the memory information of the process 50554, and get the output like below:

                                  VIRTUAL RESIDENT    DIRTY  SWAPPED VOLATILE   NONVOL    EMPTY   REGION 
REGION TYPE                          SIZE     SIZE     SIZE     SIZE     SIZE     SIZE     SIZE    COUNT (non-coalesced) 
===========                       ======= ========    =====  ======= ========   ======    =====  ======= 
Accelerate.framework                 256K     256K     256K       0K       0K     256K       0K        3 
Activity Tracing                    2048K      40K      40K       0K       0K       0K       0K        2 

......
                                          VIRTUAL   RESIDENT      DIRTY    SWAPPED ALLOCATION      BYTES          REGION
MALLOC ZONE                                  SIZE       SIZE       SIZE       SIZE      COUNT  ALLOCATED  % FULL   COUNT
===========                               =======  =========  =========  =========  =========  =========  ======  ======
DefaultMallocZone_0x10453d000              532.5M     524.4M     476.8M         0K    3203739     424.3M     79%     829
DefaultPurgeableMallocZone_0x117c92000      14.2M      13.7M      13.7M         0K          3      14.2M     99%       4
WebKit Malloc_0x7fff7c65ecb8                12.0M      8928K      8756K         0K          3      12.0M    100%       3
QuartzCore_0x7fc9519bc000                   1516K      1516K      1516K         0K      27313      1390K     91%     207
unnamed_zone_0x120a0a000                    1024K        12K        12K         0K          4        224      0%       2
x-alloc_0x7fc95189ec00                        12K        12K        12K         0K         48       1696     13%       1
x-alloc_0x7fc951047800                         8K         8K         8K         0K          4        448      5%       1
GFXMallocZone_0x10598d000                      0K         0K         0K         0K          0         0K               0
===========                               =======  =========  =========  =========  =========  =========  ======  ======
TOTAL                                      561.1M     548.3M     500.5M         0K    3231114     451.8M     80%    1047

But is there any API that i can call the implement the same function?

Doodle answered 26/10, 2015 at 2:49 Comment(3)
Certainly vmmap uses some interface to access this information. Figure out what it is.Fated
@JonathonReinhart do you know what is it? i search it in google for so many days and still has no ideaDoodle
On Linux, you would use the tool strace to watch the behavior of the program in question. I don't know what the OSX counterpart is called.Fated
E
2

The answer to your question is somewhat complex, but can be found in the kernel source code for mach_vm_region_info(): https://opensource.apple.com/source/xnu/xnu-201/osfmk/vm/vm_debug.c

This code (among other things) runs through the VM map table and builds a linked list of structures which contain all of the info displayed by the vmmap(1) command.

Enneahedron answered 15/8, 2017 at 18:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.