Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/shrink modernize scopedtimer (Alternative to #13236) #13258

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,7 @@ set(MIXXX_LIB_PRECOMPILED_HEADER
src/track/tracknumbers.h
src/track/trackrecord.h
src/track/trackref.h
src/util/always_false_v.h
src/util/alphabetafilter.h
src/util/battery/battery.h
src/util/cache.h
Expand Down Expand Up @@ -1473,6 +1474,7 @@ set(MIXXX_LIB_PRECOMPILED_HEADER
src/util/statmodel.h
src/util/statsmanager.h
src/util/string.h
src/util/stringformat.h
src/util/tapfilter.h
src/util/task.h
src/util/taskmonitor.h
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/analyzerebur128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool AnalyzerEbur128::processSamples(const CSAMPLE* pIn, SINT count) {
VERIFY_OR_DEBUG_ASSERT(m_pState) {
return false;
}
ScopedTimer t(u"AnalyzerEbur128::processSamples()");
ScopedTimer t(QStringLiteral("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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void AnalyzerGain::cleanup() {
}

bool AnalyzerGain::processSamples(const CSAMPLE* pIn, SINT count) {
ScopedTimer t(u"AnalyzerGain::process()");
ScopedTimer t(QStringLiteral("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
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ CoreServices::CoreServices(const CmdlineArgs& args, QApplication* pApp)
m_isInitialized(false) {
m_runtime_timer.start();
mixxx::Time::start();
ScopedTimer t(u"CoreServices::CoreServices");
ScopedTimer t(QStringLiteral("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 @@ -213,7 +213,7 @@ void CoreServices::initialize(QApplication* pApp) {
return;
}

ScopedTimer t(u"CoreServices::initialize");
ScopedTimer t(QStringLiteral("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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void ChannelMixer::applyEffectsAndMixChannels(const EngineMixer::GainCalculator&
// D) Mixes the temporary buffer into pOutput
// The original channel input buffers are not modified.
SampleUtil::clear(pOutput, iBufferSize);
ScopedTimer t(u"EngineMixer::applyEffectsAndMixChannels");
ScopedTimer t(QStringLiteral("EngineMixer::applyEffectsAndMixChannels"));
for (auto* pChannelInfo : activeChannels) {
EngineMixer::GainCache& gainCache = (*channelGainCache)[pChannelInfo->m_index];
CSAMPLE_GAIN oldGain = gainCache.m_gain;
Expand Down Expand Up @@ -68,7 +68,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(u"EngineMixer::applyEffectsInPlaceAndMixChannels");
ScopedTimer t(QStringLiteral("EngineMixer::applyEffectsInPlaceAndMixChannels"));
SampleUtil::clear(pOutput, iBufferSize);
for (auto* pChannelInfo : activeChannels) {
EngineMixer::GainCache& gainCache = (*channelGainCache)[pChannelInfo->m_index];
Expand Down
2 changes: 1 addition & 1 deletion src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ void EngineBuffer::slotKeylockEngineChanged(double dIndex) {

void EngineBuffer::processTrackLocked(
CSAMPLE* pOutput, const int iBufferSize, mixxx::audio::SampleRate sampleRate) {
ScopedTimer t(u"EngineBuffer::process_pauselock");
ScopedTimer t(QStringLiteral("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/enginemixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void EngineMixer::processChannels(int iBufferSize) {
m_activeTalkoverChannels.clear();
m_activeChannels.clear();

// ScopedTimer timer(u"EngineMixer::processChannels");
// ScopedTimer timer(QStringLiteral("EngineMixer::processChannels"));
EngineChannel* pLeaderChannel = m_pEngineSync->getLeaderChannel();
// Reserve the first place for the main channel which
// should be processed first
Expand Down
2 changes: 1 addition & 1 deletion src/library/dao/trackdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,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(u"TrackDAO::getTrackById");
ScopedTimer t(QStringLiteral("TrackDAO::getTrackById"));

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

void ImportFilesTask::run() {
ScopedTimer timer(u"ImportFilesTask::run");
ScopedTimer timer(QStringLiteral("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
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ void LibraryScanner::cancel() {

void LibraryScanner::queueTask(ScannerTask* pTask) {
//kLogger.debug() << "queueTask" << pTask;
ScopedTimer timer(u"LibraryScanner::queueTask");
ScopedTimer timer(QStringLiteral("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(u"LibraryScanner::slotDirectoryHashedAndScanned");
ScopedTimer timer(QStringLiteral("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(u"LibraryScanner::slotDirectoryUnchanged");
ScopedTimer timer(QStringLiteral("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(u"LibraryScanner::slotTrackExists");
ScopedTimer timer(QStringLiteral("LibraryScanner::slotTrackExists"));
if (m_scannerGlobal) {
m_scannerGlobal->addVerifiedTrack(trackPath);
}
}

void LibraryScanner::slotAddNewTrack(const QString& trackPath) {
//kLogger.debug() << "slotAddNewTrack" << trackPath;
ScopedTimer timer(u"LibraryScanner::addNewTrack");
ScopedTimer timer(QStringLiteral("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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RecursiveScanDirectoryTask::RecursiveScanDirectoryTask(
}

void RecursiveScanDirectoryTask::run() {
ScopedTimer timer(u"RecursiveScanDirectoryTask::run");
ScopedTimer timer(QStringLiteral("RecursiveScanDirectoryTask::run"));
if (m_scannerGlobal->shouldCancel()) {
setSuccess(false);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ void MixxxMainWindow::slotUpdateWindowTitle(TrackPointer pTrack) {

void MixxxMainWindow::createMenuBar() {
qWarning() << " $ createMenuBar";
ScopedTimer t(u"MixxxMainWindow::createMenuBar");
ScopedTimer t(QStringLiteral("MixxxMainWindow::createMenuBar"));
DEBUG_ASSERT(m_pCoreServices->getKeyboardConfig());
m_pMenuBar = make_parented<WMainMenuBar>(
this, m_pCoreServices->getSettings(), m_pCoreServices->getKeyboardConfig().get());
Expand All @@ -789,7 +789,7 @@ void MixxxMainWindow::connectMenuBar() {
// so all connections must be unique!
qWarning() << " $ connectMenuBar";

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

QWidget* LegacySkinParser::parseSkin(const QString& skinPath, QWidget* pParent) {
ScopedTimer timer(u"SkinLoader::parseSkin");
ScopedTimer timer(QStringLiteral("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
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ QString SkinLoader::getDefaultSkinName() const {
QWidget* SkinLoader::loadConfiguredSkin(QWidget* pParent,
QSet<ControlObject*>* pSkinCreatedControls,
mixxx::CoreServices* pCoreServices) {
ScopedTimer timer(u"SkinLoader::loadConfiguredSkin");
ScopedTimer timer(QStringLiteral("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
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ void SoundDeviceNetwork::callbackProcessClkRef() {
m_pSoundManager->readProcess(framesPerBuffer);

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

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

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

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

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

// read module file to byte array
const QString fileName(getLocalFileName());
Expand Down
54 changes: 32 additions & 22 deletions src/util/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "util/duration.h"
#include "util/performancetimer.h"
#include "util/stat.h"
#include "util/stringformat.h"

static constexpr Stat::ComputeFlags kDefaultComputeFlags = Stat::COUNT | Stat::SUM | Stat::AVERAGE |
Stat::MAX | Stat::MIN | Stat::SAMPLE_VARIANCE;
Expand Down Expand Up @@ -39,40 +40,49 @@ class Timer {
// TODO: replace with std::experimental::scope_exit<Timer> once stabilized
class ScopedTimer {
public:
ScopedTimer(QStringView key,
Stat::ComputeFlags compute = kDefaultComputeFlags)
: ScopedTimer(key, QStringView(), compute) {
}
ScopedTimer(QStringView key,
int i,
Stat::ComputeFlags compute = kDefaultComputeFlags)
: ScopedTimer(key,
CmdlineArgs::Instance().getDeveloper()
? QString::number(i)
: QStringView(),
compute) {
}

ScopedTimer(QStringView key, QStringView arg, Stat::ComputeFlags compute = kDefaultComputeFlags)
// Allows the timer to contain a format string which is only assembled
// when we're not in `--developer` mode.
/// @param compute Flags to use for the Stat::ComputeFlags (can be omitted)
/// @param key The format string as QStringLiteral to identify the timer
/// @param args The arguments to pass to the format string
template<typename T, typename... Ts>
ScopedTimer(Stat::ComputeFlags compute, T&& key, Ts&&... args)
: m_maybeTimer(std::nullopt) {
// we take a T here so we can detect the type and warn the user accordingly
// instead of paying for an implicit runtime conversion at the call site
static_assert(std::is_same_v<T, QString>,
"only QString is supported as key type. Wrap it in u\"\""
"_s or QStringLiteral() "
"to avoid runtime UTF-16 conversion.");
// we can now assume that T is a QString.
if (!CmdlineArgs::Instance().getDeveloper()) {
return;
return; // leave timer in cancelled state
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QString strKey = arg.isEmpty() ? key.toString() : key.arg(arg);
#else
QString strKey = arg.isEmpty() ? key.toString() : key.toString().arg(arg);
#endif
m_maybeTimer = std::make_optional<Timer>(std::move(strKey), compute);
DEBUG_ASSERT(key.capacity() == 0);
m_maybeTimer = std::make_optional<Timer>(([&]() {
// only try to call QString::arg when we've been given parameters
if constexpr (sizeof...(args) > 0) {
return key.arg(convertToQStringConvertible(std::forward<Ts>(args))...);
} else {
return key;
}
})(),
compute);
m_maybeTimer->start();
}

template<typename T, typename... Ts>
ScopedTimer(T&& key, Ts&&... args)
: ScopedTimer(kDefaultComputeFlags, std::forward<T>(key), std::forward<Ts>(args)...) {
}

~ScopedTimer() noexcept {
if (m_maybeTimer) {
m_maybeTimer->elapsed(true);
}
}

// copying would technically be possible, but likely not intended
ScopedTimer(const ScopedTimer&) = delete;
ScopedTimer& operator=(const ScopedTimer&) = delete;

Expand Down
2 changes: 1 addition & 1 deletion src/vinylcontrol/vinylcontrolprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ bool VinylControlProcessor::deckConfigured(int index) const {
void VinylControlProcessor::receiveBuffer(const AudioInput& input,
const CSAMPLE* pBuffer,
unsigned int nFrames) {
ScopedTimer t(u"VinylControlProcessor::receiveBuffer");
ScopedTimer t(QStringLiteral("VinylControlProcessor::receiveBuffer"));
if (input.getType() != AudioPathType::VinylControl) {
qDebug() << "WARNING: AudioInput type is not VINYLCONTROL. Ignoring incoming buffer.";
return;
Expand Down
2 changes: 1 addition & 1 deletion src/vinylcontrol/vinylcontrolxwax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ bool VinylControlXwax::writeQualityReport(VinylSignalQualityReport* pReport) {


void VinylControlXwax::analyzeSamples(CSAMPLE* pSamples, size_t nFrames) {
ScopedTimer t(u"VinylControlXwax::analyzeSamples");
ScopedTimer t(QStringLiteral("VinylControlXwax::analyzeSamples"));
auto gain = static_cast<CSAMPLE_GAIN>(m_pVinylControlInputGain->get());

// We only support amplifying with the VC pre-amp.
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/waveformrendererendoftrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void WaveformRendererEndOfTrack::draw(QPainter* painter,
return;
}

// ScopedTimer t(u"WaveformRendererEndOfTrack::draw");
// ScopedTimer t(QStringLiteral("WaveformRendererEndOfTrack::draw"));

const int elapsed = m_timer.elapsed().toIntegerMillis() % kBlinkingPeriodMillis;

Expand Down
4 changes: 2 additions & 2 deletions src/waveform/waveformwidgetfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ void WaveformWidgetFactory::notifyZoomChange(WWaveformViewer* viewer) {
}

void WaveformWidgetFactory::renderSelf() {
ScopedTimer t(u"WaveformWidgetFactory::render() %1waveforms",
ScopedTimer t(QStringLiteral("WaveformWidgetFactory::render() %1waveforms"),
static_cast<int>(m_waveformWidgetHolders.size()));

if (!m_skipRender) {
Expand Down Expand Up @@ -831,7 +831,7 @@ void WaveformWidgetFactory::render() {
}

void WaveformWidgetFactory::swapSelf() {
ScopedTimer t(u"WaveformWidgetFactory::swap() %1waveforms",
ScopedTimer t(QStringLiteral("WaveformWidgetFactory::swap() %1waveforms"),
static_cast<int>(m_waveformWidgetHolders.size()));

// Do this in an extra slot to be sure to hit the desired interval
Expand Down
2 changes: 1 addition & 1 deletion src/widget/woverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ void WOverview::leaveEvent(QEvent* pEvent) {

void WOverview::paintEvent(QPaintEvent* pEvent) {
Q_UNUSED(pEvent);
ScopedTimer t(u"WOverview::paintEvent");
ScopedTimer t(QStringLiteral("WOverview::paintEvent"));

QPainter painter(this);
painter.fillRect(rect(), m_backgroundColor);
Expand Down
2 changes: 1 addition & 1 deletion src/widget/woverviewhsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WOverviewHSV::WOverviewHSV(
}

bool WOverviewHSV::drawNextPixmapPart() {
ScopedTimer t(u"WOverviewHSV::drawNextPixmapPart");
ScopedTimer t(QStringLiteral("WOverviewHSV::drawNextPixmapPart"));

//qDebug() << "WOverview::drawNextPixmapPart()";

Expand Down
2 changes: 1 addition & 1 deletion src/widget/woverviewlmh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WOverviewLMH::WOverviewLMH(
}

bool WOverviewLMH::drawNextPixmapPart() {
ScopedTimer t(u"WOverviewLMH::drawNextPixmapPart");
ScopedTimer t(QStringLiteral("WOverviewLMH::drawNextPixmapPart"));

//qDebug() << "WOverview::drawNextPixmapPart()";

Expand Down
2 changes: 1 addition & 1 deletion src/widget/woverviewrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ WOverviewRGB::WOverviewRGB(
}

bool WOverviewRGB::drawNextPixmapPart() {
ScopedTimer t(u"WOverviewRGB::drawNextPixmapPart");
ScopedTimer t(QStringLiteral("WOverviewRGB::drawNextPixmapPart"));

//qDebug() << "WOverview::drawNextPixmapPart()";

Expand Down
Loading