Added load time checks

This commit is contained in:
Paul Ferrand 2020-01-03 17:32:40 +01:00
parent 7e8baaf411
commit ef0685963b
2 changed files with 11 additions and 2 deletions

View file

@ -29,7 +29,6 @@
#include "Oversampler.h"
#include "AtomicGuard.h"
#include "absl/types/span.h"
#include <chrono>
#include <memory>
#include <sndfile.hh>
#include <thread>
@ -181,6 +180,7 @@ sfz::FilePromisePtr sfz::FilePool::getFilePromise(const std::string& filename) n
promise->preloadedData = preloaded->second.preloadedData;
promise->sampleRate = preloaded->second.sampleRate;
promise->oversamplingFactor = oversamplingFactor;
promise->creationTime = std::chrono::high_resolution_clock::now();
if (!promiseQueue.try_push(promise)) {
DBG("[sfizz] Could not enqueue the promise for " << filename << " (queue size " << promiseQueue.size() << ")");
@ -229,7 +229,7 @@ void sfz::FilePool::loadingThread() noexcept
{
FilePromisePtr promise;
while (!quitThread) {
if (emptyQueue) {
while(promiseQueue.try_pop(promise)) {
// We're just dequeuing
@ -244,6 +244,9 @@ void sfz::FilePool::loadingThread() noexcept
}
threadsLoading++;
const auto waitDuration = std::chrono::high_resolution_clock::now() - promise->creationTime;
[[maybe_unused]] const auto waitDurationMillis = std::chrono::duration<double,std::milli>(waitDuration).count();
fs::path file { rootDirectory / std::string(promise->filename) };
SndfileHandle sndFile(file.c_str());
if (sndFile.error() != 0) {
@ -255,6 +258,10 @@ void sfz::FilePool::loadingThread() noexcept
promise->dataReady = true;
threadsLoading--;
const auto duration = std::chrono::high_resolution_clock::now() - promise->creationTime;
[[maybe_unused]] const auto durationMillis = std::chrono::duration<double,std::milli>(duration).count();
DBG("Promise filled in " << durationMillis << " ms (waiting for " << waitDurationMillis << " ms)");
while (!filledPromiseQueue.try_push(promise)) {
DBG("[sfizz] Error enqueuing the promise for " << promise->filename << " in the filledPromiseQueue");
std::this_thread::sleep_for(1ms);

View file

@ -34,6 +34,7 @@
#include "absl/strings/string_view.h"
// #include "moodycamel/concurrentqueue.h"
#include "atomic_queue/atomic_queue.h"
#include <chrono>
#include <thread>
#include <sndfile.hh>
@ -77,6 +78,7 @@ struct FilePromise
Oversampling oversamplingFactor { config::defaultOversamplingFactor };
std::atomic_size_t availableFrames { 0 };
std::atomic<bool> dataReady { false };
std::chrono::time_point<std::chrono::high_resolution_clock> creationTime;
LEAK_DETECTOR(FilePromise);
};