-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Measurement on macOS #168
Comments
This is a perfectly doable thing. Something like: uint64_t GetRAMPhysicalUsedByCurrentProcess() {
task_vm_info_data_t vmInfo;
mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
if (task_info(mach_task_self(), TASK_VM_INFO, (task_info_t)&vmInfo, &count) == KERN_SUCCESS) {
return vmInfo.phys_footprint;
}
return 0;
} |
Thanks! Do you have a similar code for |
Perhaps something like this. You should look at the API to be sure. #include <iostream>
#include <mach/mach.h>
#include <mach/task_info.h>
uint64_t GetVirtualMemoryUsed() {
mach_task_basic_info_data_t taskInfo;
mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
kern_return_t kr = task_info(mach_task_self(), MACH_TASK_BASIC_INFO, reinterpret_cast<task_info_t>(&taskInfo), &infoCount);
if (kr != KERN_SUCCESS) {
std::cerr << "Error: Unable to get task_info. Error code: " << kr << std::endl;
return 0;
}
return taskInfo.virtual_size;
}
int main() {
uint64_t virtualRAMUsed = GetVirtualMemoryUsed();
std::cout << "Virtual RAM used by current process: " << virtualRAMUsed << " bytes." << std::endl;
return 0;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature Request
Hi,
It seems that the functions
GetRAMPhysicalUsedByCurrentProcess()
,GetRAMVirtualUsedByCurrentProcess()
andGetRAMVirtualTotal()
are not implemented for macOS platforms. Is this a limitation of macOS, or just a missing feature? If the latter I'd be interested in implementing it, but do you have a unit test/way to measure that the implementation is correct?The text was updated successfully, but these errors were encountered: