命令具体实现在redis-3.0/src/redis.c:genRedisInfoString。
Memory
used_memory是redis通过在每次执行malloc和free等函数的时候维护定义在src/zmalloc.c中的used_memory变量实现的used_memory_rss在linux中是通过读/proc/{pid}/stat这个文件的第24个字段rss得到number of pages the process in real memory然后再乘以sysconf(_SC_PAGESIZE)实现的。sysconf(_SC_PAGESIZE)表示Size of a page in bytes。used_memory_peakRecord the max memory used since the server was started.mem_fragmentation_ratioFragmentation = RSS / allocated-bytes,allocated-bytes即为used_memory
CPU
used_cpu_user调用getrusage得到的ru_utimeused_cpu_sys调用getrusage得到的ru_stime