Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

macos - Is there any API for the command vmmap

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...