Logger now works as expected
This commit is contained in:
parent
24bd0d8119
commit
c7ecaaa060
3 changed files with 51 additions and 7 deletions
|
|
@ -1,8 +1,10 @@
|
|||
#include "Logger.h"
|
||||
#include "Debug.h"
|
||||
#include "absl/algorithm/container.h"
|
||||
#include "ghc/fs_std.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
|
@ -36,14 +38,26 @@ void printStatistics(std::vector<T>& data)
|
|||
std::cout << '\n';
|
||||
}
|
||||
|
||||
sfz::Logger::Logger()
|
||||
{
|
||||
keepRunning.test_and_set();
|
||||
clearFlag.test_and_set();
|
||||
loggingThread = std::thread(&Logger::moveEvents, this);
|
||||
}
|
||||
|
||||
sfz::Logger::~Logger()
|
||||
{
|
||||
keepRunning.clear();
|
||||
loggingThread.join();
|
||||
|
||||
if (!fileTimes.empty()) {
|
||||
fs::path loadLogPath{ fs::current_path() / "file_times.csv" };
|
||||
std::ofstream loadLogFile { loadLogPath.string() };
|
||||
std::stringstream fileLogFilename;
|
||||
fileLogFilename << this << "_"
|
||||
<< prefix
|
||||
<< "_file_log.csv";
|
||||
fs::path fileLogPath{ fs::current_path() / fileLogFilename.str() };
|
||||
DBG("Logging file times to " << fileLogPath.filename());
|
||||
std::ofstream loadLogFile { fileLogPath.string() };
|
||||
loadLogFile << "WaitDuration,LoadDuration,FileSize,FileName" << '\n';
|
||||
for (auto& time: fileTimes)
|
||||
loadLogFile << time.waitDuration.count() << ','
|
||||
|
|
@ -53,7 +67,12 @@ sfz::Logger::~Logger()
|
|||
}
|
||||
|
||||
if (!callbackTimes.empty()) {
|
||||
fs::path callbackLogPath{ fs::current_path() / "callback_times.csv" };
|
||||
std::stringstream callbackLogFilename;
|
||||
callbackLogFilename << this << "_"
|
||||
<< prefix
|
||||
<< "_callback_log.csv";
|
||||
fs::path callbackLogPath{ fs::current_path() / callbackLogFilename.str() };
|
||||
DBG("Logging callback times to " << callbackLogPath.filename());
|
||||
std::ofstream callbackLogFile { callbackLogPath.string() };
|
||||
callbackLogFile << "Duration,NumVoices,NumSamples" << '\n';
|
||||
for (auto& time: callbackTimes)
|
||||
|
|
@ -74,6 +93,17 @@ void sfz::Logger::logFileTime(std::chrono::duration<double> waitDuration, std::c
|
|||
fileTimeQueue.try_push<FileTime>({ waitDuration, loadDuration, fileSize, filename });
|
||||
}
|
||||
|
||||
void sfz::Logger::setPrefix(const std::string& prefix)
|
||||
{
|
||||
this->prefix = prefix;
|
||||
}
|
||||
|
||||
void sfz::Logger::clear()
|
||||
{
|
||||
clearFlag.clear();
|
||||
prefix.clear();
|
||||
}
|
||||
|
||||
void sfz::Logger::moveEvents()
|
||||
{
|
||||
while(keepRunning.test_and_set()) {
|
||||
|
|
@ -85,6 +115,11 @@ void sfz::Logger::moveEvents()
|
|||
while (fileTimeQueue.try_pop(fileTime))
|
||||
fileTimes.push_back(fileTime);
|
||||
|
||||
if (!clearFlag.test_and_set()) {
|
||||
fileTimes.clear();
|
||||
callbackTimes.clear();
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(50ms);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include "Config.h"
|
||||
#include "atomic_queue/atomic_queue.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include "absl/strings/string_view.h"
|
||||
|
|
@ -50,20 +51,26 @@ struct CallbackTime
|
|||
class Logger
|
||||
{
|
||||
public:
|
||||
Logger() = default;
|
||||
Logger();
|
||||
~Logger();
|
||||
void setPrefix(const std::string& prefix);
|
||||
void clear();
|
||||
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();
|
||||
|
||||
std::string prefix { "" };
|
||||
|
||||
atomic_queue::AtomicQueue2<CallbackTime, config::loggerQueueSize, true, true, false, true> callbackTimeQueue;
|
||||
atomic_queue::AtomicQueue2<FileTime, config::loggerQueueSize, true, true, false, true> fileTimeQueue;
|
||||
std::vector<CallbackTime> callbackTimes;
|
||||
std::vector<FileTime> fileTimes;
|
||||
|
||||
|
||||
std::atomic_flag keepRunning;
|
||||
std::thread loggingThread { &Logger::moveEvents, this };
|
||||
std::atomic_flag clearFlag;
|
||||
std::thread loggingThread;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ void sfz::Synth::clear()
|
|||
list.clear();
|
||||
regions.clear();
|
||||
resources.filePool.clear();
|
||||
resources.logger.clear();
|
||||
numGroups = 0;
|
||||
numMasters = 0;
|
||||
numCurves = 0;
|
||||
|
|
@ -220,7 +221,7 @@ void addEndpointsToVelocityCurve(sfz::Region& region)
|
|||
}
|
||||
}
|
||||
|
||||
bool sfz::Synth::loadSfzFile(const fs::path& filename)
|
||||
bool sfz::Synth::loadSfzFile(const fs::path& file)
|
||||
{
|
||||
AtomicDisabler callbackDisabler { canEnterCallback };
|
||||
while (inCallback) {
|
||||
|
|
@ -228,7 +229,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
|
|||
}
|
||||
|
||||
clear();
|
||||
auto parserReturned = sfz::Parser::loadSfzFile(filename);
|
||||
auto parserReturned = sfz::Parser::loadSfzFile(file);
|
||||
if (!parserReturned)
|
||||
return false;
|
||||
|
||||
|
|
@ -236,6 +237,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
|
|||
return false;
|
||||
|
||||
resources.filePool.setRootDirectory(this->originalDirectory);
|
||||
resources.logger.setPrefix(file.filename());
|
||||
|
||||
auto currentRegion = regions.begin();
|
||||
auto lastRegion = regions.rbegin();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue