Skip to content

Commit

Permalink
Merge pull request #11807 from Swiftb0y/refactor/timers
Browse files Browse the repository at this point in the history
Refactor timers
  • Loading branch information
daschuer committed Aug 20, 2023
2 parents b9df1ff + e39df37 commit 1c4096e
Show file tree
Hide file tree
Showing 38 changed files with 142 additions and 557 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Expand Up @@ -1103,7 +1103,6 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/util/mac.cpp
src/util/moc_included_test.cpp
src/util/movinginterquartilemean.cpp
src/util/performancetimer.cpp
src/util/rangelist.cpp
src/util/readaheadsamplebuffer.cpp
src/util/ringdelaybuffer.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/analyzerebur128.cpp
Expand Up @@ -50,7 +50,7 @@ bool AnalyzerEbur128::processSamples(const CSAMPLE* pIn, SINT count) {
VERIFY_OR_DEBUG_ASSERT(m_pState) {
return false;
}
ScopedTimer t("AnalyzerEbur128::processSamples()");
ScopedTimer t(u"AnalyzerEbur128::processSamples()");
size_t frames = count / mixxx::kAnalysisChannels;
int e = ebur128_add_frames_float(m_pState, pIn, frames);
VERIFY_OR_DEBUG_ASSERT(e == EBUR128_SUCCESS) {
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/analyzergain.cpp
Expand Up @@ -37,7 +37,7 @@ void AnalyzerGain::cleanup() {
}

bool AnalyzerGain::processSamples(const CSAMPLE* pIn, SINT count) {
ScopedTimer t("AnalyzerGain::process()");
ScopedTimer t(u"AnalyzerGain::process()");

SINT numFrames = count / mixxx::kAnalysisChannels;
if (numFrames > static_cast<SINT>(m_pLeftTempBuffer.size())) {
Expand Down
4 changes: 2 additions & 2 deletions src/coreservices.cpp
Expand Up @@ -110,7 +110,7 @@ CoreServices::CoreServices(const CmdlineArgs& args, QApplication* pApp)
m_isInitialized(false) {
m_runtime_timer.start();
mixxx::Time::start();
ScopedTimer t("CoreServices::CoreServices");
ScopedTimer t(u"CoreServices::CoreServices");
// All this here is running without without start up screen
// Defer long initializations to CoreServices::initialize() which is
// called after the GUI is initialized
Expand Down Expand Up @@ -210,7 +210,7 @@ void CoreServices::initialize(QApplication* pApp) {
return;
}

ScopedTimer t("CoreServices::initialize");
ScopedTimer t(u"CoreServices::initialize");

VERIFY_OR_DEBUG_ASSERT(SoundSourceProxy::registerProviders()) {
qCritical() << "Failed to register any SoundSource providers";
Expand Down
4 changes: 2 additions & 2 deletions src/engine/channelmixer.cpp
Expand Up @@ -22,7 +22,7 @@ void ChannelMixer::applyEffectsAndMixChannels(const EngineMaster::GainCalculator
// D) Mixes the temporary buffer into pOutput
// The original channel input buffers are not modified.
SampleUtil::clear(pOutput, iBufferSize);
ScopedTimer t("EngineMaster::applyEffectsAndMixChannels");
ScopedTimer t(u"EngineMaster::applyEffectsAndMixChannels");
for (auto* pChannelInfo : activeChannels) {
EngineMaster::GainCache& gainCache = (*channelGainCache)[pChannelInfo->m_index];
CSAMPLE_GAIN oldGain = gainCache.m_gain;
Expand Down Expand Up @@ -67,7 +67,7 @@ void ChannelMixer::applyEffectsInPlaceAndMixChannels(
// A) Applies the calculated gain to the channel buffer, modifying the original input buffer
// B) Applies effects to the buffer, modifying the original input buffer
// 4. Mix the channel buffers together to make pOutput, overwriting the pOutput buffer from the last engine callback
ScopedTimer t("EngineMaster::applyEffectsInPlaceAndMixChannels");
ScopedTimer t(u"EngineMaster::applyEffectsInPlaceAndMixChannels");
SampleUtil::clear(pOutput, iBufferSize);
for (auto* pChannelInfo : activeChannels) {
EngineMaster::GainCache& gainCache = (*channelGainCache)[pChannelInfo->m_index];
Expand Down
2 changes: 1 addition & 1 deletion src/engine/enginebuffer.cpp
Expand Up @@ -815,7 +815,7 @@ void EngineBuffer::slotKeylockEngineChanged(double dIndex) {

void EngineBuffer::processTrackLocked(
CSAMPLE* pOutput, const int iBufferSize, mixxx::audio::SampleRate sampleRate) {
ScopedTimer t("EngineBuffer::process_pauselock");
ScopedTimer t(u"EngineBuffer::process_pauselock");

m_trackSampleRateOld = mixxx::audio::SampleRate::fromDouble(m_pTrackSampleRate->get());
m_trackEndPositionOld = getTrackEndPosition();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/enginemaster.cpp
Expand Up @@ -279,7 +279,7 @@ void EngineMaster::processChannels(int iBufferSize) {
m_activeTalkoverChannels.clear();
m_activeChannels.clear();

//ScopedTimer timer("EngineMaster::processChannels");
// ScopedTimer timer(u"EngineMaster::processChannels");
EngineChannel* pLeaderChannel = m_pEngineSync->getLeaderChannel();
// Reserve the first place for the master channel which
// should be processed first
Expand Down
2 changes: 1 addition & 1 deletion src/library/dao/trackdao.cpp
Expand Up @@ -1374,7 +1374,7 @@ TrackPointer TrackDAO::getTrackById(TrackId trackId) const {
// be executed with a lock on the GlobalTrackCache. The GlobalTrackCache
// will be locked again after the query has been executed (see below)
// and potential race conditions will be resolved.
ScopedTimer t("TrackDAO::getTrackById");
ScopedTimer t(u"TrackDAO::getTrackById");

QSqlRecord queryRecord;
{
Expand Down
2 changes: 1 addition & 1 deletion src/library/scanner/importfilestask.cpp
Expand Up @@ -22,7 +22,7 @@ ImportFilesTask::ImportFilesTask(LibraryScanner* pScanner,
}

void ImportFilesTask::run() {
ScopedTimer timer("ImportFilesTask::run");
ScopedTimer timer(u"ImportFilesTask::run");
for (const QFileInfo& fileInfo: m_filesToImport) {
// If a flag was raised telling us to cancel the library scan then stop.
if (m_scannerGlobal->shouldCancel()) {
Expand Down
10 changes: 5 additions & 5 deletions src/library/scanner/libraryscanner.cpp
Expand Up @@ -489,7 +489,7 @@ void LibraryScanner::cancel() {

void LibraryScanner::queueTask(ScannerTask* pTask) {
//kLogger.debug() << "queueTask" << pTask;
ScopedTimer timer("LibraryScanner::queueTask");
ScopedTimer timer(u"LibraryScanner::queueTask");
if (m_scannerGlobal.isNull() || m_scannerGlobal->shouldCancel()) {
return;
}
Expand Down Expand Up @@ -531,7 +531,7 @@ void LibraryScanner::queueTask(ScannerTask* pTask) {

void LibraryScanner::slotDirectoryHashedAndScanned(const QString& directoryPath,
bool newDirectory, mixxx::cache_key_t hash) {
ScopedTimer timer("LibraryScanner::slotDirectoryHashedAndScanned");
ScopedTimer timer(u"LibraryScanner::slotDirectoryHashedAndScanned");
//kLogger.debug() << "sloDirectoryHashedAndScanned" << directoryPath
// << newDirectory << hash;

Expand All @@ -550,7 +550,7 @@ void LibraryScanner::slotDirectoryHashedAndScanned(const QString& directoryPath,
}

void LibraryScanner::slotDirectoryUnchanged(const QString& directoryPath) {
ScopedTimer timer("LibraryScanner::slotDirectoryUnchanged");
ScopedTimer timer(u"LibraryScanner::slotDirectoryUnchanged");
//kLogger.debug() << "slotDirectoryUnchanged" << directoryPath;
if (m_scannerGlobal) {
m_scannerGlobal->addVerifiedDirectory(directoryPath);
Expand All @@ -560,15 +560,15 @@ void LibraryScanner::slotDirectoryUnchanged(const QString& directoryPath) {

void LibraryScanner::slotTrackExists(const QString& trackPath) {
//kLogger.debug() << "slotTrackExists" << trackPath;
ScopedTimer timer("LibraryScanner::slotTrackExists");
ScopedTimer timer(u"LibraryScanner::slotTrackExists");
if (m_scannerGlobal) {
m_scannerGlobal->addVerifiedTrack(trackPath);
}
}

void LibraryScanner::slotAddNewTrack(const QString& trackPath) {
//kLogger.debug() << "slotAddNewTrack" << trackPath;
ScopedTimer timer("LibraryScanner::addNewTrack");
ScopedTimer timer(u"LibraryScanner::addNewTrack");
// For statistics tracking and to detect moved tracks
TrackPointer pTrack = m_trackDao.addTracksAddFile(
trackPath,
Expand Down
2 changes: 1 addition & 1 deletion src/library/scanner/recursivescandirectorytask.cpp
Expand Up @@ -20,7 +20,7 @@ RecursiveScanDirectoryTask::RecursiveScanDirectoryTask(
}

void RecursiveScanDirectoryTask::run() {
ScopedTimer timer("RecursiveScanDirectoryTask::run");
ScopedTimer timer(u"RecursiveScanDirectoryTask::run");
if (m_scannerGlobal->shouldCancel()) {
setSuccess(false);
return;
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Expand Up @@ -170,6 +170,8 @@ int main(int argc, char * argv[]) {
// the main thread. Issue #9130.
ErrorDialogHandler::instance();

PerformanceTimer::debugEnsureClockIsMonotonic();

#ifdef __APPLE__
Sandbox::checkSandboxed();
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/mixxxmainwindow.cpp
Expand Up @@ -682,7 +682,7 @@ void MixxxMainWindow::slotUpdateWindowTitle(TrackPointer pTrack) {
}

void MixxxMainWindow::createMenuBar() {
ScopedTimer t("MixxxMainWindow::createMenuBar");
ScopedTimer t(u"MixxxMainWindow::createMenuBar");
DEBUG_ASSERT(m_pCoreServices->getKeyboardConfig());
m_pMenuBar = make_parented<WMainMenuBar>(
this, m_pCoreServices->getSettings(), m_pCoreServices->getKeyboardConfig().get());
Expand All @@ -696,7 +696,7 @@ void MixxxMainWindow::connectMenuBar() {
// This function might be invoked multiple times on startup
// so all connections must be unique!

ScopedTimer t("MixxxMainWindow::connectMenuBar");
ScopedTimer t(u"MixxxMainWindow::connectMenuBar");
connect(this,
&MixxxMainWindow::skinLoaded,
m_pMenuBar,
Expand Down
2 changes: 1 addition & 1 deletion src/skin/legacy/legacyskinparser.cpp
Expand Up @@ -328,7 +328,7 @@ Qt::MouseButton LegacySkinParser::parseButtonState(const QDomNode& node,
}

QWidget* LegacySkinParser::parseSkin(const QString& skinPath, QWidget* pParent) {
ScopedTimer timer("SkinLoader::parseSkin");
ScopedTimer timer(u"SkinLoader::parseSkin");
qDebug() << "LegacySkinParser loading skin:" << skinPath;

m_pContext = std::make_unique<SkinContext>(m_pConfig, skinPath + "/skin.xml");
Expand Down
2 changes: 1 addition & 1 deletion src/skin/skinloader.cpp
Expand Up @@ -138,7 +138,7 @@ QString SkinLoader::getDefaultSkinName() const {
QWidget* SkinLoader::loadConfiguredSkin(QWidget* pParent,
QSet<ControlObject*>* pSkinCreatedControls,
mixxx::CoreServices* pCoreServices) {
ScopedTimer timer("SkinLoader::loadConfiguredSkin");
ScopedTimer timer(u"SkinLoader::loadConfiguredSkin");
SkinPointer pSkin = getConfiguredSkin();

// If we don't have a skin then fail. This makes sense here, because the
Expand Down
2 changes: 1 addition & 1 deletion src/soundio/sounddevicenetwork.cpp
Expand Up @@ -485,7 +485,7 @@ void SoundDeviceNetwork::callbackProcessClkRef() {
m_pSoundManager->readProcess(framesPerBuffer);

{
ScopedTimer t("SoundDevicePortAudio::callbackProcess prepare %1",
ScopedTimer t(u"SoundDevicePortAudio::callbackProcess prepare %1",
m_deviceId.name);
m_pSoundManager->onDeviceOutputCallback(framesPerBuffer);
}
Expand Down
6 changes: 3 additions & 3 deletions src/soundio/sounddeviceportaudio.cpp
Expand Up @@ -975,7 +975,7 @@ int SoundDevicePortAudio::callbackProcessClkRef(

// Send audio from the soundcard's input off to the SoundManager...
if (in) {
ScopedTimer t("SoundDevicePortAudio::callbackProcess input %1",
ScopedTimer t(u"SoundDevicePortAudio::callbackProcess input %1",
m_deviceId.debugName());
composeInputBuffer(in, framesPerBuffer, 0, m_inputParams.channelCount);
m_pSoundManager->pushInputBuffers(m_audioInputs, framesPerBuffer);
Expand All @@ -984,13 +984,13 @@ int SoundDevicePortAudio::callbackProcessClkRef(
m_pSoundManager->readProcess(framesPerBuffer);

{
ScopedTimer t("SoundDevicePortAudio::callbackProcess prepare %1",
ScopedTimer t(u"SoundDevicePortAudio::callbackProcess prepare %1",
m_deviceId.debugName());
m_pSoundManager->onDeviceOutputCallback(framesPerBuffer);
}

if (out) {
ScopedTimer t("SoundDevicePortAudio::callbackProcess output %1",
ScopedTimer t(u"SoundDevicePortAudio::callbackProcess output %1",
m_deviceId.debugName());

if (m_outputParams.channelCount <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourcemodplug.cpp
Expand Up @@ -119,7 +119,7 @@ SoundSourceModPlug::importTrackMetadataAndCoverImage(
SoundSource::OpenResult SoundSourceModPlug::tryOpen(
OpenMode /*mode*/,
const OpenParams& /*config*/) {
ScopedTimer t("SoundSourceModPlug::open()");
ScopedTimer t(u"SoundSourceModPlug::open()");

// read module file to byte array
const QString fileName(getLocalFileName());
Expand Down
4 changes: 4 additions & 0 deletions src/test/performancetimer_test.cpp
Expand Up @@ -3,6 +3,10 @@

#include "util/performancetimer.h"

TEST(PerformanceTimerTest, ElapsedIsMonotonic) {
ASSERT_TRUE(PerformanceTimer::debugEnsureClockIsMonotonic());
}

// This test was added because of an signed/unsigned underflow bug that
// affected Windows and (presumably) Symbian.
// See https://github.com/mixxxdj/mixxx/issues/7397
Expand Down
11 changes: 7 additions & 4 deletions src/util/battery/battery.cpp
@@ -1,5 +1,7 @@
#include "util/battery/battery.h"

#include <chrono>

#include "moc_battery.cpp"

// Do not include platform-specific battery implementation unless we are built
Expand All @@ -15,17 +17,18 @@
#endif
#include "util/math.h"

// interval (in ms) of the timer which calls update()
constexpr int kiUpdateInterval = 5000;
using namespace std::chrono_literals;
// interval of the timer which calls update()
static constexpr std::chrono::milliseconds kBatteryUpdateInterval = 5000ms;

Battery::Battery(QObject* parent)
: QObject(parent),
m_chargingState(UNKNOWN),
m_dPercentage(0.0),
m_iMinutesLeft(0),
m_timer(this) {
connect(&m_timer, &GuiTickTimer::timeout, this, &Battery::update);
m_timer.start(mixxx::Duration::fromMillis(kiUpdateInterval));
connect(&m_timer, &QTimer::timeout, this, &Battery::update);
m_timer.start(kBatteryUpdateInterval);
}

Battery* Battery::getBattery(QObject* parent) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/battery/battery.h
Expand Up @@ -43,5 +43,5 @@ class Battery : public QObject {
int m_iMinutesLeft;

private:
GuiTickTimer m_timer;
QTimer m_timer;
};
9 changes: 9 additions & 0 deletions src/util/duration.h
Expand Up @@ -154,6 +154,15 @@ class Duration : public DurationBase {
return Duration(nanos);
}

static constexpr Duration fromStdDuration(
std::chrono::duration<std::int64_t, std::nano> duration) {
return Duration::fromNanos(duration.count());
}

constexpr std::chrono::duration<std::int64_t, std::nano> toStdDuration() {
return std::chrono::duration<std::int64_t, std::nano>(m_durationNanos);
}

static constexpr Duration empty() {
return Duration();
}
Expand Down

0 comments on commit 1c4096e

Please sign in to comment.