Return the number of bytes used by the data and stack segments. * @return -1 on error */
| 21 | * @return -1 on error |
| 22 | */ |
| 23 | static inline ssize_t getMemoryUsage() |
| 24 | { |
| 25 | #if __MACH__ |
| 26 | struct task_basic_info t_info; |
| 27 | mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT; |
| 28 | int status = task_info(mach_task_self(), |
| 29 | TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count); |
| 30 | assert(status == KERN_SUCCESS); |
| 31 | return status == KERN_SUCCESS ? (ssize_t)t_info.virtual_size : -1; |
| 32 | #elif HAVE_GETPAGESIZE |
| 33 | std::ifstream in("/proc/self/statm"); |
| 34 | size_t size, resident, share, text, lib, data; |
| 35 | return in >> size >> resident >> share >> text >> lib >> data |
| 36 | ? ssize_t(data * getpagesize()) : -1; |
| 37 | #else |
| 38 | /** Start of the data segment. */ |
| 39 | static intptr_t sbrk0 = reinterpret_cast<intptr_t>(sbrk(0)); |
| 40 | return reinterpret_cast<intptr_t>(sbrk(0)) - sbrk0; |
| 41 | #endif |
| 42 | } |
| 43 | |
| 44 | #endif |
no outgoing calls
no test coverage detected