In-app profiling of AudioProcessorGraph


#1

How would one implement a system which reports (to the user, not the developer) how much time each node in an AudioProcessorGraph is taking?

I can think of a few ways:

  1. Instrument each node with some code that records how long processing takes. Store that in an atomic variable for use in the message thread. 
  2. Instrument the call to process each node, and send that data centrally to the message thread over a FIFO. This could ensure a profile is complete. Need to have a big enough FIFO to hold the profile data.
  3. Sampling. Use a separate thread to read an atomic variable indicating the current node being processed. Potentially this would have very little performance impact on the audio thread.

Any thoughts?


#2

I was thinking about this before. If you look at the audio graph class, line ~1440, the processing function.

You could modify it easily enough to record the timing for each graph operation, including the audio processing parts. If you to get the start and end times, you should see how closely each audio callback (the total graph callback) is running into the next. I think you could generate a nice real-time visual graph from this data. You'd just need to offload the collected data to some UI component then. 

 
template <typename FloatType>
void AudioProcessorGraph::processAudio (AudioBuffer<FloatType>& buffer, MidiBuffer& midiMessages)
{
    // Timings - Take starting tick count
    /*
     Parts removed
    */
    for (int i = 0; i < renderingOps.size(); ++i)
    {
        GraphRenderingOps::AudioGraphRenderingOpBase* const op
            = (GraphRenderingOps::AudioGraphRenderingOpBase*) renderingOps.getUnchecked(i);
        // Timings - Take OP name and start tick
        op->perform (renderingBuffers, midiBuffers, numSamples);
        // Timings - record end tick
    }
    /*
     Parts removed
     */
     // Timings - Callback finished end tick
}