Coder Social home page Coder Social logo

Memory Measurement on macOS about celero HOT 3 OPEN

jdumas avatar jdumas commented on August 17, 2024
Memory Measurement on macOS

from celero.

Comments (3)

DigitalInBlue avatar DigitalInBlue commented on August 17, 2024

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;
}

from celero.

jdumas avatar jdumas commented on August 17, 2024

Thanks! Do you have a similar code for GetRAMVirtualUsedByCurrentProcess()? It seems that's what Celero is currently measuring during testing.

from celero.

DigitalInBlue avatar DigitalInBlue commented on August 17, 2024

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;
}

from celero.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.