Added some logging facility for callback and

file loading times
This commit is contained in:
Paul Ferrand 2020-01-12 09:55:44 +01:00
parent 81c95178d3
commit 93b07dfac9
6 changed files with 108 additions and 1 deletions

View file

@ -16,7 +16,7 @@ if (UNIX)
add_compile_options(-ffast-math)
add_compile_options(-fno-omit-frame-pointer) # For debugging purposes
add_compile_options(-fPIC)
endif()
endif()
if (WIN32)
find_package(LibSndFile REQUIRED)

View file

@ -8,6 +8,7 @@ set (SFIZZ_SOURCES
sfizz/SfzHelpers.cpp
sfizz/Oversampler.cpp
sfizz/FloatEnvelopes.cpp
sfizz/Logger.cpp
)
include (SfizzSIMDSourceFilesCheck)

View file

@ -42,6 +42,7 @@ namespace config {
constexpr int defaultSamplesPerBlock { 1024 };
constexpr int maxBlockSize { 8192 };
constexpr int preloadSize { 8192 };
constexpr int loggerQueueSize { 16 };
constexpr size_t numChannels { 2 };
constexpr int numBackgroundThreads { 4 };
constexpr int numVoices { 64 };

41
src/sfizz/Logger.cpp Normal file
View file

@ -0,0 +1,41 @@
#include "Logger.h"
using namespace std::chrono_literals;
sfz::Logger::~Logger()
{
keepRunning.clear();
loggingThread.join();
}
void sfz::Logger::logCallbackTime(std::chrono::duration<double> value)
{
callbackTimeQueue.try_push(value);
}
void sfz::Logger::logFileWaitTime(std::chrono::duration<double> value)
{
fileWaitTimeQueue.try_push(value);
}
void sfz::Logger::logFileLoadTime(std::chrono::duration<double> value, uint32_t fileSize, absl::string_view filename)
{
FileLoadTime toPush { value, fileSize, filename };
fileLoadTimeQueue.try_push(toPush);
}
void sfz::Logger::moveEvents()
{
while(keepRunning.test_and_set()) {
std::chrono::duration<double> callbackTime;
while (callbackTimeQueue.try_pop(callbackTime))
callbackTimes.push_back(callbackTime);
std::chrono::duration<double> waitTime;
while (fileWaitTimeQueue.try_pop(waitTime))
waitTimes.push_back(waitTime);
sfz::FileLoadTime loadTime;
while (fileLoadTimeQueue.try_pop(loadTime))
loadTimes.push_back(loadTime);
std::this_thread::sleep_for(50ms);
}
}

62
src/sfizz/Logger.h Normal file
View file

@ -0,0 +1,62 @@
// Copyright (c) 2019-2020, Paul Ferrand
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "Config.h"
#include "atomic_queue/atomic_queue.h"
#include <vector>
#include <chrono>
#include <thread>
#include "absl/strings/string_view.h"
namespace sfz
{
struct FileLoadTime
{
std::chrono::duration<double> value;
uint32_t fileSize;
absl::string_view filename;
};
class Logger
{
public:
Logger() = default;
~Logger();
void logCallbackTime(std::chrono::duration<double> value);
void logFileWaitTime(std::chrono::duration<double> value);
void logFileLoadTime(std::chrono::duration<double> value, uint32_t fileSize, absl::string_view filename);
private:
void moveEvents();
atomic_queue::AtomicQueue2<std::chrono::duration<double>, config::loggerQueueSize, true, true, false, true> callbackTimeQueue;
atomic_queue::AtomicQueue2<FileLoadTime, config::loggerQueueSize, true, true, false, true> fileLoadTimeQueue;
atomic_queue::AtomicQueue2<std::chrono::duration<double>, config::loggerQueueSize, true, true, false, true> fileWaitTimeQueue;
std::vector<std::chrono::duration<double>> callbackTimes;
std::vector<FileLoadTime> loadTimes;
std::vector<std::chrono::duration<double>> waitTimes;
std::atomic_flag keepRunning;
std::thread loggingThread { &Logger::moveEvents, this };
};
}

View file

@ -1,10 +1,12 @@
#pragma once
#include "FilePool.h"
#include "Logger.h"
namespace sfz
{
struct Resources
{
FilePool filePool;
Logger logger;
};
}