From 1777cf8f6968501f9202a8e2cb8f2fa0761eaaa7 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 11 Jun 2021 15:38:58 -0600 Subject: [PATCH] add some initial timing points for dsp stats --- libs/ardour/ardour/audio_backend.h | 11 +++++++++++ libs/ardour/ardour/audioengine.h | 8 ++++++++ libs/ardour/ardour/session.h | 11 +++++++++++ libs/ardour/audioengine.cc | 1 + libs/ardour/session_process.cc | 6 ++++++ libs/backends/alsa/alsa_audiobackend.cc | 7 +++++++ 6 files changed, 44 insertions(+) diff --git a/libs/ardour/ardour/audio_backend.h b/libs/ardour/ardour/audio_backend.h index c36930545d..551a70a31f 100644 --- a/libs/ardour/ardour/audio_backend.h +++ b/libs/ardour/ardour/audio_backend.h @@ -849,6 +849,17 @@ public: return false; } + enum TimingTypes { + DeviceWait = 0, + PreProcess = 1, + ProcessCallback = 2, + PostProcess = 3, + /* end */ + NTT = 4 + }; + + PBD::TimingStats dsp_stats[NTT]; + protected: AudioBackendInfo& _info; AudioEngine& engine; diff --git a/libs/ardour/ardour/audioengine.h b/libs/ardour/ardour/audioengine.h index 935c008e3f..6a7d2807da 100644 --- a/libs/ardour/ardour/audioengine.h +++ b/libs/ardour/ardour/audioengine.h @@ -250,6 +250,14 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr void add_pending_port_deletion (Port*); void queue_latency_update (bool); + enum TimingTypes { + ProcessCallback = 0, + /* end */ + NTT = 1 + }; + + PBD::TimingStats dsp_stats[NTT]; + private: AudioEngine (); diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index c6cf15c738..3a1279098c 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1322,6 +1322,17 @@ public: std::vector ptfwavpair; SourceList pt_imported_sources; + enum TimingTypes { + OverallProcess = 0, + ProcessFunction = 1, + NoRoll = 2, + Roll = 3, + /* end */ + NTT = 4 + }; + + PBD::TimingStats dsp_stats[NTT]; + protected: friend class AudioEngine; void set_block_size (pframes_t nframes); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 4b4130aac9..ae2c504e43 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -228,6 +228,7 @@ __attribute__((annotate("realtime"))) int AudioEngine::process_callback (pframes_t nframes) { + TimerRAII tr (dsp_stats[ProcessCallback]); Glib::Threads::Mutex::Lock tm (_process_lock, Glib::Threads::TRY_LOCK); Port::set_speed_ratio (1.0); diff --git a/libs/ardour/session_process.cc b/libs/ardour/session_process.cc index 5087dc7fc8..afd2fc84ff 100644 --- a/libs/ardour/session_process.cc +++ b/libs/ardour/session_process.cc @@ -74,6 +74,8 @@ using namespace std; void Session::process (pframes_t nframes) { + TimerRAII tr (dsp_stats[OverallProcess]); + samplepos_t transport_at_start = _transport_sample; _silent = false; @@ -166,6 +168,7 @@ int Session::no_roll (pframes_t nframes) { PT_TIMING_CHECK (4); + TimerRAII tr (dsp_stats[NoRoll]); samplepos_t end_sample = _transport_sample + floor (nframes * _transport_fsm->transport_speed()); int ret = 0; @@ -212,6 +215,7 @@ Session::no_roll (pframes_t nframes) int Session::process_routes (pframes_t nframes, bool& need_butler) { + TimerRAII tr (dsp_stats[Roll]); boost::shared_ptr r = routes.reader (); const samplepos_t start_sample = _transport_sample; @@ -331,6 +335,7 @@ void Session::process_with_events (pframes_t nframes) { PT_TIMING_CHECK (3); + TimerRAII tr (dsp_stats[ProcessFunction]); SessionEvent* ev; pframes_t this_nframes; @@ -631,6 +636,7 @@ Session::transport_locked () const void Session::process_without_events (pframes_t nframes) { + TimerRAII tr (dsp_stats[ProcessFunction]); bool session_needs_butler = false; samplecnt_t samples_moved; diff --git a/libs/backends/alsa/alsa_audiobackend.cc b/libs/backends/alsa/alsa_audiobackend.cc index a1b6bf0eb1..407c7f716a 100644 --- a/libs/backends/alsa/alsa_audiobackend.cc +++ b/libs/backends/alsa/alsa_audiobackend.cc @@ -1852,9 +1852,12 @@ AlsaAudioBackend::main_process_thread () } if (!_freewheel) { + dsp_stats[DeviceWait].start(); nr = _pcmi->pcm_wait (); + dsp_stats[DeviceWait].update(); /* update DLL */ + dsp_stats[PreProcess].start(); uint64_t clock0 = g_get_monotonic_time (); if (reset_dll || last_n_periods != 1) { reset_dll = false; @@ -1957,11 +1960,13 @@ AlsaAudioBackend::main_process_thread () /* call engine process callback */ _last_process_start = g_get_monotonic_time (); + dsp_stats[PreProcess].update(); if (engine.process_callback (_samples_per_period)) { _pcmi->pcm_stop (); _active = false; return 0; } + dsp_stats[PostProcess].start (); /* only used when adding/removing MIDI device/system ports */ pthread_mutex_lock (&_device_port_mutex); @@ -2012,6 +2017,8 @@ AlsaAudioBackend::main_process_thread () _dsp_load_calc.set_stop_timestamp_us (g_get_monotonic_time ()); _dsp_load = _dsp_load_calc.get_dsp_load (); ++last_n_periods; + + dsp_stats[PostProcess].update (); } if (xrun && (_pcmi->capt_xrun () > 0 || _pcmi->play_xrun () > 0)) {