| 351 | #include <fcntl.h> |
| 352 | |
| 353 | size_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> |
no test coverage detected