你如何阅读:mnesia.info
?
例如,我只有一个表,some_table,:mnesia.info
返回给我这个。
---> Processes holding locks <---
---> Processes waiting for locks <---
---> Participant transactions <---
---> Coordinator transactions <---
---> Uncertain transactions <---
---> Active tables <---
some_table: with 16020 records occupying 433455 words of mem
schema : with 2 records occupying 536 words of mem
===> System info in version "4.15.5", debug level = none <===
opt_disc. Directory "/home/ubuntu/project/Mnesia.nonode@nohost" is NOT used.
use fallback at restart = false
running db nodes = [nonode@nohost]
stopped db nodes = []
master node tables = []
remote = []
ram_copies = ['some_table',schema]
disc_copies = []
disc_only_copies = []
[{nonode@nohost,ram_copies}] = [schema,'some_table']
488017 transactions committed, 0 aborted, 0 restarted, 0 logged to disc
0 held locks, 0 in queue; 0 local transactions, 0 remote
0 transactions waits for other nodes: []
还调用:
:mnesia.table_info("some_table", :size)
它返回我 16020,我认为这是键的数量,但我如何获取内存使用情况?
首先,您需要mnesia:table_info(Table, memory)
来获取表中占用的单词数,在您的示例中,您获得的是表中的项目数,而不是内存。要将该值转换为 MB,您可以首先使用erlang:system_info(wordsize)
获取机器体系结构的字大小(在 32 位系统上,字是 4 字节,64 位是 8 字节(,将其乘以 Mnesia 表内存以获得以字节为单位的大小,最后将值转换为兆字节,如下所示:
MnesiaMemoryMB = (mnesia:table_info("some_table", memory) * erlang:system_info(wordsize)) / (1024*1024).
您可以使用erlang:system_info(wordsize)
来获取以字节为单位的字大小,在 32 位系统上,一个字是 32 位或 4 个字节,在 64 位系统上是 8 个字节。所以你的表正在使用433455 x 字大小。