New Module: Profile your JUCE UI/dsp performance with Perfetto

Sorry, no trace file at Downloads, but I’ll continue to figure out :slight_smile:
The project where I want to use profiling is my drum machine Drumlabooh - https://psemiletov.github.io/drumlabooh/

1 Like

@semiletov Cool project! Let’s continue to discuss on the github issue, I can help get you up and running there.

Hi Sudara,
Thanks also for this module! I’m getting into some GUI performance issues in a plugin I’m working on and this will shortcut so much work!

I’m including the module as a submodule in the CMakeLists.txt file (after linking all other JUCE modules)

add_subdirectory (../juce_external/melatonin_perfetto subprojects/melatonin_perfetto)
target_link_libraries(${PROJECT_NAME} PRIVATE Melatonin::Perfetto)

I’m finding that I can use Perfetto fine in my code, and any custom JUCE-style modules, but I run into compilation issues when I try and add the Melatonin module and TRACE_COMPONENT() macro to JUCE code.

Specifically, juce_Component.cpp in Component::paintComponentAndChildren(), as @stephenk did.

I get an error in Perfetto code (perfetto.h line 54451) about some unexpected token ‘struct’, but I don’t think this is where the real issue is.

All I’ve added to juce_gui_basics.h and juce_Component.cpp is

//gui basics module header

//...
#include <juce_graphics/juce_graphics.h>
#include <juce_data_structures/juce_data_structures.h>

#if PERFETTO
#include<melatonin_perfetto/melatonin_perfetto.h>
#endif
//...


//in juce_Component.cpp

//...
void Component::paintComponentAndChildren (Graphics& g)
{
#if PERFETTO
    TRACE_COMPONENT();
#endif

    auto clipBounds = g.getClipBounds();
//...

Commenting these lines out removes the error and so does removing PERFETTO=ON from the cmake args.
Have you run into this? I feel like I’m being gaslit by the C++ error codes :sweat_smile:

unexpected token ‘struct’

Heh, what a troll.

Specifically, juce_Component.cpp

If it’s your first time with Perfetto, I’d definitely recommend just sprinkling the TRACE_COMPONENT around in your own paint methods to get some success with the whole workflow first.

It’s not really “supported” to hack it into the actual JUCE code and expect it to work. That’s part of why I opened this feature request, because being able to officially hook into the paint cycle would make make recording timings and debugging performance WAY easier: FR: Callback or other mechanism for exposing Component debugging/timing

But you can get essentially the same data (with better naming) by peppering the macro in each of your paint calls…

Maybe someone else has ran into the issue? Or to go further off the beaten path you could try checking out an earlier commit, perhaps something in the recent bump to perfetto 41 made this impossible — if you do investigate, let me know if you get it working!

I’ve had a go “sprinkling” the macro around, and got some very pretty performance graphs, so it does work outside of JUCE code…

Shame that there’s no way to safely inject it into JUCE code though, I was hoping I could get a very detailed waterfall covering child components etc, something like what @stephenk got in their post above

I’ll take your advice and try an earlier commit, but I think I’ll have to settle for as much coverage in our own code as possible.

Thanks!

1 Like

No luck in reverting. I went back to your v33.1 bump (41cc55b73c) and I got the same error.
I am using the VS2022 generator for the cmake builds, but I’ve tried with Ninja (CLion default) and get the same errors. Though they have less clutter…

If I find a solution, I’ll come back here but I’m not super hopeful

1 Like

Good news! I got it compiling.
Wonky news, it was by commenting out that line causing the error…

::protozero::ConstChars interface() const { return at<2>().as_string(); }
inside the class NetworkPacketEvent_Decoder declaration. I tried looking into the function, it doesn’t look like it’s called anywhere in Perfetto or in the Melatonin module so :crossed_fingers:

Nothing’s gone pop yet, and I’ve started benchmarking my UI without issues.