RSS always added to profile
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?
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.
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?
Right, I agree. Do you have a patch prepared already?
Nope, but I can come up with one if you want.
Would be cool, otherwise I'll change it when I find some time!