vmprof-python icon indicating copy to clipboard operation
vmprof-python copied to clipboard

RSS always added to profile

Open jonashaag opened this issue 9 years ago • 5 comments

I believe there's something wrong with this condition:

            long rss = get_current_proc_rss();
            if (rss >= 0)
                st->stack[depth++] = (void*)rss;

Problem: We always get the current RSS, even if the RSS getting code has never been initialised. I guess it's an implementation detail of the Unix RSS getter that it still works, and it's sheer luck that the Darwin RSS getter does not crash as it uses the mach_task variable uninitialised.

It should be something along the lines of

if (memory enabled) {
    long rss = get_current_proc_rss();
    st->stack[depth++] = (void*)rss;
}

Am I seeing things correctly?

jonashaag avatar Nov 18 '16 12:11 jonashaag

As far as I can tell the function get_current_proc_rss is built in a way to return -1 if it has not been initialized. By quickly looking over the darwin implementation, it could be that the function call to task_info returns with success even though the global variable mach_task has not been initialized to mach_task_self(). I don't know enough details about this API to be sure.

This should be fixed, by checking in get_current_proc_rss if it has been initialized, if not just bail with -1.

For linux we should check the same instead of providing the proc_file to lseek and assuming it will fail.

planrich avatar Nov 18 '16 13:11 planrich

But isn't this awkward from an abstraction point of view: You have an initialisation and teardown routine, and a main routine, and you may always use the main routine despite the fact that you haven't initialised the module?

jonashaag avatar Nov 18 '16 17:11 jonashaag

Right, I agree. Do you have a patch prepared already?

planrich avatar Nov 19 '16 10:11 planrich

Nope, but I can come up with one if you want.

jonashaag avatar Nov 19 '16 12:11 jonashaag

Would be cool, otherwise I'll change it when I find some time!

planrich avatar Nov 19 '16 12:11 planrich