Skip to content

Commit

Permalink
Merge pull request #600 from daschuer/stat_memory
Browse files Browse the repository at this point in the history
Avoid strdup in Stat::track
  • Loading branch information
daschuer authored Nov 20, 2019
2 parents f51d575 + 1ac2b3d commit 7b1f4d1
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 100 deletions.
6 changes: 3 additions & 3 deletions scripts/generate_sample_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ def write(data, depth=0):
if not inplace:
write('SampleUtil::clear(pOutput, iBufferSize);', depth=1)
write('if (totalActive == 0) {', depth=1)
write('ScopedTimer t("EngineMaster::applyEffects%(inplace)sAndMixChannels_0active");' %
write('//ScopedTimer t("EngineMaster::applyEffects%(inplace)sAndMixChannels_0active");' %
{'inplace': 'InPlace' if inplace else ''}, depth=2)
if inplace:
write('SampleUtil::clear(pOutput, iBufferSize);', depth=2)
for i in xrange(1, num_channels+1):
write('} else if (totalActive == %d) {' % i, depth=1)
write('ScopedTimer t("EngineMaster::applyEffects%(inplace)sAndMixChannels_%(i)dactive");' %
write('//ScopedTimer t("EngineMaster::applyEffects%(inplace)sAndMixChannels_%(i)dactive");' %
{'inplace': 'InPlace' if inplace else '', 'i': i}, depth=2)
write('CSAMPLE_GAIN oldGain[%(i)d];' % {'i': i}, depth=2)
write('CSAMPLE_GAIN newGain[%(i)d];' % {'i': i}, depth=2)
Expand Down Expand Up @@ -116,7 +116,7 @@ def write(data, depth=0):
write('}', depth=2)

write('} else {', depth=1)
write('ScopedTimer t("EngineMaster::applyEffects%(inplace)sAndMixChannels_Over32active");' %
write('//ScopedTimer t("EngineMaster::applyEffects%(inplace)sAndMixChannels_Over32active");' %
{'inplace': 'InPlace' if inplace else ''}, depth=2)
if inplace:
write('SampleUtil::clear(pOutput, iBufferSize);', depth=2)
Expand Down
136 changes: 68 additions & 68 deletions src/engine/channelmixer_autogen.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void BpmControl::slotTapFilter(double averageLength, int numSamples) {

double rateRatio = m_pRateRatio->get();
if (rateRatio == 0.0) {
return;
return;
}

// (60 seconds per minute) * (1000 milliseconds per second) / (X millis per
Expand Down
4 changes: 2 additions & 2 deletions src/engine/enginemaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void EngineMaster::processChannels(int iBufferSize) {
m_activeTalkoverChannels.clear();
m_activeChannels.clear();

ScopedTimer timer("EngineMaster::processChannels");
//ScopedTimer timer("EngineMaster::processChannels");
EngineChannel* pMasterChannel = m_pMasterSync->getMaster();
// Reserve the first place for the master channel which
// should be processed first
Expand Down Expand Up @@ -377,7 +377,7 @@ void EngineMaster::process(const int iBufferSize) {
QThread::currentThread()->setObjectName("Engine");
haveSetName = true;
}
Trace t("EngineMaster::process");
//Trace t("EngineMaster::process");

bool masterEnabled = m_pMasterEnabled->get();
bool boothEnabled = m_pBoothEnabled->get();
Expand Down
5 changes: 3 additions & 2 deletions src/engine/engineworkerscheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ void EngineWorkerScheduler::runWorkers() {
}

void EngineWorkerScheduler::run() {
static const QString tag("EngineWorkerScheduler");
while (!m_bQuit) {
Event::start("EngineWorkerScheduler");
Event::start(tag);
{
QMutexLocker lock(&m_mutex);
for(const auto& pWorker: m_workers) {
pWorker->wakeIfReady();
}
}
Event::end("EngineWorkerScheduler");
Event::end(tag);
{
QMutexLocker lock(&m_mutex);
if (!m_bQuit) {
Expand Down
7 changes: 4 additions & 3 deletions src/engine/sidechain/enginerecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ bool EngineRecord::metaDataHasChanged()
void EngineRecord::process(const CSAMPLE* pBuffer, const int iBufferSize) {

float recordingStatus = m_pRecReady->get();
static const QString tag("EngineRecord recording");

if (recordingStatus == RECORD_OFF) {
//qDebug("Setting record flag to: OFF");
if (fileOpen()) {
Event::end("EngineRecord recording");
Event::end(tag);
closeFile(); // Close file and free encoder.
if (m_bCueIsEnabled) {
closeCueFile();
Expand All @@ -125,7 +126,7 @@ void EngineRecord::process(const CSAMPLE* pBuffer, const int iBufferSize) {
// open a new file.
updateFromPreferences(); // Update file location from preferences.
if (openFile()) {
Event::start("EngineRecord recording");
Event::start(tag);
qDebug("Setting record flag to: ON");
m_pRecReady->set(RECORD_ON);
emit(isRecording(true, false)); // will notify the RecordingManager
Expand Down Expand Up @@ -177,7 +178,7 @@ void EngineRecord::process(const CSAMPLE* pBuffer, const int iBufferSize) {
}
} else { // Maybe the encoder could not be initialized
qDebug() << "Could not open" << m_fileName << "for writing.";
Event::end("EngineRecord recording");
Event::end(tag);
qDebug("Setting record flag to: OFF");
m_pRecReady->slotSet(RECORD_OFF);
// An error occurred.
Expand Down
8 changes: 4 additions & 4 deletions src/engine/sidechain/enginesidechain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ void EngineSideChain::run() {
// factor this out somehow), -kousu 2/2009
unsigned static id = 0;
QThread::currentThread()->setObjectName(QString("EngineSideChain %1").arg(++id));

Event::start("EngineSideChain");
static const QString tag("EngineSideChain");
Event::start(tag);
while (!m_bStopThread) {
// Sleep until samples are available.
m_waitLock.lock();

Event::end("EngineSideChain");
Event::end(tag);
m_waitForSamples.wait(&m_waitLock);
m_waitLock.unlock();
Event::start("EngineSideChain");
Event::start(tag);

int samples_read;
while ((samples_read = m_sampleFifo.read(m_pWorkBuffer,
Expand Down
9 changes: 9 additions & 0 deletions src/util/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@ class Event {
static bool start(const QString& tag) {
return event(tag, Stat::EVENT_START);
}

static bool end(const QString& tag) {
return event(tag, Stat::EVENT_END);
}

// Disallow to use this class with implicit converted char strings.
// This should not be uses to avoid unicode encoding and memory
// allocation at every call. Use a static tag like this:
// static const QString tag("TAG TEXT");
static bool event(const char*, Event::EventType) = delete;
static bool start(const char*) = delete;
static bool end(const char*) = delete;
};

#endif /* EVENT_H */
9 changes: 9 additions & 0 deletions src/util/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ class Stat {
Stat::StatType type,
Stat::ComputeFlags compute,
double value);

// Disallow to use this class with implicit converted char strings.
// This should not be uses to avoid unicode encoding and memory
// allocation at every call. Use a static tag like this:
// static const QString tag("TAG TEXT");
static bool track(const char *,
Stat::StatType,
Stat::ComputeFlags,
double) = delete;
};

QDebug operator<<(QDebug dbg, const Stat &stat);
Expand Down
2 changes: 0 additions & 2 deletions src/vinylcontrol/vinylcontrolprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ void VinylControlProcessor::run() {
QThread::currentThread()->setObjectName(QString("VinylControlProcessor %1").arg(++id));

while (!m_bQuit) {
Event::start("VinylControlProcessor");
if (m_bReloadConfig) {
reloadConfig();
m_bReloadConfig = false;
Expand Down Expand Up @@ -130,7 +129,6 @@ void VinylControlProcessor::run() {

// Wait for a signal from the main thread or engine thread that we
// should wake up and process input.
Event::end("VinylControlProcessor");
m_waitForSampleMutex.lock();
m_samplesAvailableSignal.wait(&m_waitForSampleMutex);
m_waitForSampleMutex.unlock();
Expand Down
15 changes: 0 additions & 15 deletions src/waveform/vsyncthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#include "vsyncthread.h"
#include "util/performancetimer.h"
#include "util/event.h"
#include "util/counter.h"
#include "util/math.h"
#include "waveform/guitick.h"

Expand All @@ -33,7 +31,6 @@ VSyncThread::~VSyncThread() {
}

void VSyncThread::run() {
Counter droppedFrames("VsyncThread real time error");
QThread::currentThread()->setObjectName("VSyncThread");

m_waitToSwapMicros = m_syncIntervalTimeMicros;
Expand All @@ -44,56 +41,44 @@ void VSyncThread::run() {
if (m_vSyncMode == ST_FREE) {
// for benchmark only!

Event::start("VsyncThread vsync render");
// renders the waveform, Possible delayed due to anti tearing
emit(vsyncRender());
m_semaVsyncSlot.acquire();
Event::end("VsyncThread vsync render");

Event::start("VsyncThread vsync swap");
emit(vsyncSwap()); // swaps the new waveform to front
m_semaVsyncSlot.acquire();
Event::end("VsyncThread vsync swap");

m_timer.restart();
m_waitToSwapMicros = 1000;
usleep(1000);
} else { // if (m_vSyncMode == ST_TIMER) {

Event::start("VsyncThread vsync render");
emit(vsyncRender()); // renders the new waveform.

// wait until rendering was scheduled. It might be delayed due a
// pending swap (depends one driver vSync settings)
m_semaVsyncSlot.acquire();
Event::end("VsyncThread vsync render");

// qDebug() << "ST_TIMER " << lastMicros << restMicros;
int remainingForSwap = m_waitToSwapMicros - static_cast<int>(
m_timer.elapsed().toIntegerMicros());
// waiting for interval by sleep
if (remainingForSwap > 100) {
Event::start("VsyncThread usleep for VSync");
usleep(remainingForSwap);
Event::end("VsyncThread usleep for VSync");
}

Event::start("VsyncThread vsync swap");
// swaps the new waveform to front in case of gl-wf
emit(vsyncSwap());

// wait until swap occurred. It might be delayed due to driver vSync
// settings.
m_semaVsyncSlot.acquire();
Event::end("VsyncThread vsync swap");

// <- Assume we are VSynced here ->
int lastSwapTime = static_cast<int>(m_timer.restart().toIntegerMicros());
if (remainingForSwap < 0) {
// Our swapping call was already delayed
// The real swap might happens on the following VSync, depending on driver settings
m_droppedFrames++; // Count as Real Time Error
droppedFrames.increment();
}
// try to stay in right intervals
m_waitToSwapMicros = m_syncIntervalTimeMicros +
Expand Down

0 comments on commit 7b1f4d1

Please sign in to comment.