Skip to content

Commit

Permalink
RAII-style profiler probes
Browse files Browse the repository at this point in the history
  • Loading branch information
he29-net committed Sep 1, 2023
1 parent aaf1c34 commit 4dc1f85
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 11 deletions.
46 changes: 46 additions & 0 deletions include/AudioEngineProfilerProbe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* AudioEngineProfilerProbe.h - RAII-style probe for AudioEngineProfiler
*
* Copyright (c) 2023 Martin Pavelek <[email protected]>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef LMMS_AUDIO_ENGINE_PROFILER_PROBE_H
#define LMMS_AUDIO_ENGINE_PROFILER_PROBE_H

#include "AudioEngineProfiler.h"

namespace lmms
{

class AudioEngineProfilerProbe
{
public:
AudioEngineProfilerProbe(AudioEngineProfiler& profiler, AudioEngineProfiler::DetailType type);
~AudioEngineProfilerProbe();

private:
AudioEngineProfiler &m_profiler;
const AudioEngineProfiler::DetailType m_type;
};

}

#endif // LMMS_AUDIO_ENGINE_PROFILER_PROBE_H
16 changes: 5 additions & 11 deletions src/core/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "lmmsconfig.h"

#include "AudioEngineProfilerProbe.h"
#include "AudioEngineWorkerThread.h"
#include "AudioPort.h"
#include "Mixer.h"
Expand Down Expand Up @@ -335,7 +336,7 @@ void AudioEngine::pushInputFrames( sampleFrame * _ab, const f_cnt_t _frames )

void AudioEngine::renderStageNoteSetup()
{
m_profiler.startDetail(AudioEngineProfiler::DetailType::NoteSetup);
AudioEngineProfilerProbe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::NoteSetup);

if( m_clearSignal )
{
Expand Down Expand Up @@ -384,15 +385,13 @@ void AudioEngine::renderStageNoteSetup()
m_newPlayHandles.free( e );
e = next;
}

m_profiler.finishDetail(AudioEngineProfiler::DetailType::NoteSetup);
}



void AudioEngine::renderStageInstruments()
{
m_profiler.startDetail(AudioEngineProfiler::DetailType::Instruments);
AudioEngineProfilerProbe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::Instruments);

AudioEngineWorkerThread::fillJobQueue(m_playHandles);
AudioEngineWorkerThread::startAndWaitForJobs();
Expand Down Expand Up @@ -422,27 +421,24 @@ void AudioEngine::renderStageInstruments()
++it;
}
}
m_profiler.finishDetail(AudioEngineProfiler::DetailType::Instruments);
}



void AudioEngine::renderStageEffects()
{
m_profiler.startDetail(AudioEngineProfiler::DetailType::Effects);
AudioEngineProfilerProbe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::Effects);

// STAGE 2: process effects of all instrument- and sampletracks
AudioEngineWorkerThread::fillJobQueue(m_audioPorts);
AudioEngineWorkerThread::startAndWaitForJobs();

m_profiler.finishDetail(AudioEngineProfiler::DetailType::Effects);
}



void AudioEngine::renderStageMix()
{
m_profiler.startDetail(AudioEngineProfiler::DetailType::Mixing);
AudioEngineProfilerProbe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::Mixing);

Mixer *mixer = Engine::mixer();
mixer->masterMix(m_outputBufferWrite);
Expand All @@ -455,8 +451,6 @@ void AudioEngine::renderStageMix()
EnvelopeAndLfoParameters::instances()->trigger();
Controller::triggerFrameCounter();
AutomatableModel::incrementPeriodCounter();

m_profiler.finishDetail(AudioEngineProfiler::DetailType::Mixing);
}


Expand Down
44 changes: 44 additions & 0 deletions src/core/AudioEngineProfilerProbe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* AudioEngineProfilerProbe.cpp - RAII-style probe for AudioEngineProfiler
*
* Copyright (c) 2023 Martin Pavelek <[email protected]>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#include "AudioEngineProfilerProbe.h"


namespace lmms
{

AudioEngineProfilerProbe::AudioEngineProfilerProbe(AudioEngineProfiler& profiler, AudioEngineProfiler::DetailType type)
: m_profiler(profiler)
, m_type(type)
{
profiler.startDetail(type);
}


AudioEngineProfilerProbe::~AudioEngineProfilerProbe()
{
m_profiler.finishDetail(m_type);
}

}
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(LMMS_SRCS

core/AudioEngine.cpp
core/AudioEngineProfiler.cpp
core/AudioEngineProfilerProbe.cpp
core/AudioEngineWorkerThread.cpp
core/AutomatableModel.cpp
core/AutomationClip.cpp
Expand Down

0 comments on commit 4dc1f85

Please sign in to comment.