MCPcopy Create free account
hub / github.com/F-Stack/f-stack / getMemoryOverheadData

Function getMemoryOverheadData

app/redis-6.2.6/src/object.c:981–1082  ·  view source on GitHub ↗

Return a struct redisMemOverhead filled with memory overhead * information used for the MEMORY OVERHEAD and INFO command. The returned * structure pointer should be freed calling freeMemoryOverheadData(). */

Source from the content-addressed store, hash-verified

979 * information used for the MEMORY OVERHEAD and INFO command. The returned
980 * structure pointer should be freed calling freeMemoryOverheadData(). */
981struct redisMemOverhead *getMemoryOverheadData(void) {
982 int j;
983 size_t mem_total = 0;
984 size_t mem = 0;
985 size_t zmalloc_used = zmalloc_used_memory();
986 struct redisMemOverhead *mh = zcalloc(sizeof(*mh));
987
988 mh->total_allocated = zmalloc_used;
989 mh->startup_allocated = server.initial_memory_usage;
990 mh->peak_allocated = server.stat_peak_memory;
991 mh->total_frag =
992 (float)server.cron_malloc_stats.process_rss / server.cron_malloc_stats.zmalloc_used;
993 mh->total_frag_bytes =
994 server.cron_malloc_stats.process_rss - server.cron_malloc_stats.zmalloc_used;
995 mh->allocator_frag =
996 (float)server.cron_malloc_stats.allocator_active / server.cron_malloc_stats.allocator_allocated;
997 mh->allocator_frag_bytes =
998 server.cron_malloc_stats.allocator_active - server.cron_malloc_stats.allocator_allocated;
999 mh->allocator_rss =
1000 (float)server.cron_malloc_stats.allocator_resident / server.cron_malloc_stats.allocator_active;
1001 mh->allocator_rss_bytes =
1002 server.cron_malloc_stats.allocator_resident - server.cron_malloc_stats.allocator_active;
1003 mh->rss_extra =
1004 (float)server.cron_malloc_stats.process_rss / server.cron_malloc_stats.allocator_resident;
1005 mh->rss_extra_bytes =
1006 server.cron_malloc_stats.process_rss - server.cron_malloc_stats.allocator_resident;
1007
1008 mem_total += server.initial_memory_usage;
1009
1010 mem = 0;
1011 if (server.repl_backlog)
1012 mem += zmalloc_size(server.repl_backlog);
1013 mh->repl_backlog = mem;
1014 mem_total += mem;
1015
1016 /* Computing the memory used by the clients would be O(N) if done
1017 * here online. We use our values computed incrementally by
1018 * clientsCronTrackClientsMemUsage(). */
1019 mh->clients_slaves = server.stat_clients_type_memory[CLIENT_TYPE_SLAVE];
1020 mh->clients_normal = server.stat_clients_type_memory[CLIENT_TYPE_MASTER]+
1021 server.stat_clients_type_memory[CLIENT_TYPE_PUBSUB]+
1022 server.stat_clients_type_memory[CLIENT_TYPE_NORMAL];
1023 mem_total += mh->clients_slaves;
1024 mem_total += mh->clients_normal;
1025
1026 mem = 0;
1027 if (server.aof_state != AOF_OFF) {
1028 mem += sdsZmallocSize(server.aof_buf);
1029 mem += aofRewriteBufferSize();
1030 }
1031 mh->aof_buffer = mem;
1032 mem_total+=mem;
1033
1034 mem = server.lua_scripts_mem;
1035 mem += dictSize(server.lua_scripts) * sizeof(dictEntry) +
1036 dictSlots(server.lua_scripts) * sizeof(dictEntry*);
1037 mem += dictSize(server.repl_scriptcache_dict) * sizeof(dictEntry) +
1038 dictSlots(server.repl_scriptcache_dict) * sizeof(dictEntry*);

Callers 3

genRedisInfoStringFunction · 0.85
getMemoryDoctorReportFunction · 0.85
memoryCommandFunction · 0.85

Calls 6

zmalloc_used_memoryFunction · 0.85
zmalloc_sizeFunction · 0.85
sdsZmallocSizeFunction · 0.85
aofRewriteBufferSizeFunction · 0.85
zreallocFunction · 0.85
zcallocFunction · 0.70

Tested by

no test coverage detected