Fallback current-RSS reader for Linux, used if cbm_mem_rss() returns 0 (MI_OVERRIDE=0 with no OS fallback compiled in). Returns 0 if unavailable.
| 118 | // Fallback current-RSS reader for Linux, used if cbm_mem_rss() returns 0 |
| 119 | // (MI_OVERRIDE=0 with no OS fallback compiled in). Returns 0 if unavailable. |
| 120 | static size_t rss_bytes(void) { |
| 121 | size_t v = cbm_mem_rss(); |
| 122 | if (v > 0) { |
| 123 | return v; |
| 124 | } |
| 125 | #if defined(__linux__) |
| 126 | // /proc/self/statm: fields are "VmSize VmRSS ..." in pages |
| 127 | FILE *f = fopen("/proc/self/statm", "r"); |
| 128 | if (!f) { |
| 129 | return 0; |
| 130 | } |
| 131 | unsigned long vm_pages = 0; |
| 132 | unsigned long rss_pages = 0; |
| 133 | if (fscanf(f, "%lu %lu", &vm_pages, &rss_pages) != 2) { |
| 134 | rss_pages = 0; |
| 135 | } |
| 136 | fclose(f); |
| 137 | long ps = sysconf(_SC_PAGESIZE); |
| 138 | return rss_pages * (size_t)(ps > 0 ? (unsigned long)ps : 4096UL); |
| 139 | #else |
| 140 | return 0; |
| 141 | #endif |
| 142 | } |
| 143 | |
| 144 | // Small fixture: a tiny Python module with a few functions. |
| 145 | // Chosen to produce a small but real graph (~5 nodes/edges) so that |
no test coverage detected