| 567 | */ |
| 568 | #if defined(HAVE_PROC_SMAPS) |
| 569 | size_t zmalloc_get_smap_bytes_by_field(const char *field, long pid) { |
| 570 | char line[1024]; |
| 571 | size_t bytes = 0; |
| 572 | int flen = strlen(field); |
| 573 | FILE *fp; |
| 574 | |
| 575 | if (pid == -1) { |
| 576 | fp = fopen("/proc/self/smaps","r"); |
| 577 | } else { |
| 578 | char filename[128]; |
| 579 | snprintf(filename,sizeof(filename),"/proc/%ld/smaps",pid); |
| 580 | fp = fopen(filename,"r"); |
| 581 | } |
| 582 | |
| 583 | if (!fp) return 0; |
| 584 | while(fgets(line,sizeof(line),fp) != NULL) { |
| 585 | if (strncmp(line,field,flen) == 0) { |
| 586 | char *p = strchr(line,'k'); |
| 587 | if (p) { |
| 588 | *p = '\0'; |
| 589 | bytes += strtol(line+flen,NULL,10) * 1024; |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | fclose(fp); |
| 594 | return bytes; |
| 595 | } |
| 596 | #else |
| 597 | /* Get sum of the specified field from libproc api call. |
| 598 | * As there are per page value basis we need to convert |
no outgoing calls
no test coverage detected