Added a way to activate/deactivate logging

This commit is contained in:
Paul Ferrand 2020-01-17 14:10:28 +01:00
parent c7ecaaa060
commit ed402c92a0
3 changed files with 24 additions and 2 deletions

View file

@ -43,6 +43,7 @@ namespace config {
constexpr int maxBlockSize { 8192 };
constexpr int preloadSize { 8192 };
constexpr int loggerQueueSize { 16 };
constexpr bool loggingEnabled { true };
constexpr size_t numChannels { 2 };
constexpr int numBackgroundThreads { 4 };
constexpr int numVoices { 64 };

View file

@ -50,6 +50,9 @@ sfz::Logger::~Logger()
keepRunning.clear();
loggingThread.join();
if (!loggingEnabled)
return;
if (!fileTimes.empty()) {
std::stringstream fileLogFilename;
fileLogFilename << this << "_"
@ -85,11 +88,17 @@ sfz::Logger::~Logger()
void sfz::Logger::logCallbackTime(std::chrono::duration<double> duration, int numVoices, int numSamples)
{
if (!loggingEnabled)
return;
callbackTimeQueue.try_push<CallbackTime>({ duration, numVoices, numSamples });
}
void sfz::Logger::logFileTime(std::chrono::duration<double> waitDuration, std::chrono::duration<double> loadDuration, uint32_t fileSize, absl::string_view filename)
{
if (!loggingEnabled)
return;
fileTimeQueue.try_push<FileTime>({ waitDuration, loadDuration, fileSize, filename });
}
@ -123,3 +132,14 @@ void sfz::Logger::moveEvents()
std::this_thread::sleep_for(50ms);
}
}
void sfz::Logger::enableLogging()
{
loggingEnabled = false;
}
void sfz::Logger::disableLogging()
{
loggingEnabled = false;
clearFlag.clear();
}

View file

@ -55,11 +55,13 @@ public:
~Logger();
void setPrefix(const std::string& prefix);
void clear();
void enableLogging();
void disableLogging();
void logCallbackTime(std::chrono::duration<double> duration, int numVoices, int numSamples);
void logFileTime(std::chrono::duration<double> waitDuration, std::chrono::duration<double> loadDuration, uint32_t fileSize, absl::string_view filename);
private:
void moveEvents();
bool loggingEnabled { config::loggingEnabled };
std::string prefix { "" };
atomic_queue::AtomicQueue2<CallbackTime, config::loggerQueueSize, true, true, false, true> callbackTimeQueue;
@ -67,7 +69,6 @@ private:
std::vector<CallbackTime> callbackTimes;
std::vector<FileTime> fileTimes;
std::atomic_flag keepRunning;
std::atomic_flag clearFlag;
std::thread loggingThread;