SystemStats::getStackBacktrace suggestion


#1

Hi Jules,

I’m currently debugging/profiling a plugin where I’d like to have a feedback from where some functions are called. To keep the debug output tidy, I added the following static function which allows to reduce the backtrace size and can also return it in one line.

String SystemStats::getStackBacktrace(int numEntries, bool oneLine)
{
    StringArray backtrace(StringArray::fromLines(SystemStats::getStackBacktrace()));

    if (backtrace[0].contains("getStackBacktrace"))
        backtrace.remove(0);

    if (backtrace[0].contains("getStackBacktrace"))
        backtrace.remove(0);
	
    while (bt.size() > numEntries)
        backtrace.remove(bt.size()-1);

    return backtrace.joinIntoString(oneLine ? " <= " : "\n");
}

It should also remove the entries for getStackBacktrace if debug symbols are available. I’m not sure, if this is the best approach to do this but it suffices for my application. (An alternative might be to always remove the first two entries but I’m not familiar enough with compilers to be sure whether one of these calls might be inlined)

What do you think about adding this to JUCE?

Chris


#2

Nice helper function (although not very D.R.Y!), but I'm not sure it's something that would belong in the library itself - people can easily do what you've done to add a function that formats it in whatever way they need for their app.


#3

I added it to one of our modules at first but then did some tracking in JUCE code (trying to find out where change/action/asyn messages were posted) where I needed it to be inside the juce_core module.
I removed it afterwards together with the DBG calls, so in the end you’re right, it’s probably easier to have it separately and only temporarily add it to JUCE if needed.


#4

it's probably easier to have it separately and only temporarily add it to JUCE if needed.

Well actually I'd say it doesn't belong anywhere near the juce library code, even temporarily. It doesn't need to be a SystemStats method, the same thing could be done as a free function in your own debugging code.