MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / zmalloc_get_rss

Function zmalloc_get_rss

src/zmalloc.cpp:365–395  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363#include <fcntl.h>
364
365size_t zmalloc_get_rss(void) {
366 int page = sysconf(_SC_PAGESIZE);
367 size_t rss;
368 char buf[4096];
369 char filename[256];
370 int fd, count;
371 char *p, *x;
372
373 snprintf(filename,sizeof(filename),"/proc/%ld/stat",(long) getpid());
374 if ((fd = open(filename,O_RDONLY)) == -1) return 0;
375 if (read(fd,buf,4096) <= 0) {
376 close(fd);
377 return 0;
378 }
379 close(fd);
380
381 p = buf;
382 count = 23; /* RSS is the 24th field in /proc/<pid>/stat */
383 while(p && count--) {
384 p = strchr(p,' ');
385 if (p) p++;
386 }
387 if (!p) return 0;
388 x = strchr(p,' ');
389 if (!x) return 0;
390 *x = '\0';
391
392 rss = strtoll(p,NULL,10);
393 rss *= page;
394 return rss;
395}
396#elif defined(HAVE_TASKINFO)
397#include <sys/types.h>
398#include <sys/sysctl.h>

Callers 1

cronUpdateMemoryStatsFunction · 0.85

Calls 1

zmalloc_used_memoryFunction · 0.85

Tested by

no test coverage detected