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

Function zmalloc_get_rss

app/redis-6.2.6/src/zmalloc.c:353–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

cronUpdateMemoryStatsFunction · 0.85

Calls 7

snprintfFunction · 0.85
strchrFunction · 0.85
sysctlFunction · 0.85
zmalloc_used_memoryFunction · 0.85
readFunction · 0.70
closeFunction · 0.70
ioctlFunction · 0.70

Tested by

no test coverage detected