From 04ca644ccabce91e1a644aa28ff84827ca4d0f4c Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Tue, 1 Mar 2016 21:57:05 +0100 Subject: [PATCH] Added structured logging --- src/logging.cpp | 5 +++++ src/logging.h | 3 +++ src/main.cpp | 5 +---- src/mouthAnimation.cpp | 9 ++++++++- src/phoneExtraction.cpp | 13 +++++++++++-- src/tools.cpp | 9 +++++++++ src/tools.h | 3 +++ 7 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/logging.cpp b/src/logging.cpp index 3c8e327..e09c3fd 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include "tools.h" using std::string; using std::lock_guard; @@ -64,3 +66,6 @@ boost::shared_ptr initLogging() { return pausableAdapter; } +void logTimedEvent(const string& eventName, centiseconds start, centiseconds end, const string& value) { + LOG_DEBUG << "##" << eventName << "[" << formatDuration(start) << "-" << formatDuration(end) << "]: " << value; +} diff --git a/src/logging.h b/src/logging.h index c1312e9..03f2b83 100644 --- a/src/logging.h +++ b/src/logging.h @@ -8,6 +8,7 @@ #include #include #include +#include "centiseconds.h" enum class LogLevel { Trace, @@ -56,3 +57,5 @@ private: }; boost::shared_ptr initLogging(); + +void logTimedEvent(const std::string& eventName, centiseconds start, centiseconds end, const std::string& value); diff --git a/src/main.cpp b/src/main.cpp index 9230d73..40294eb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ #include "ProgressBar.h" #include "logging.h" #include +#include using std::exception; using std::string; @@ -41,10 +42,6 @@ unique_ptr createAudioStream(path filePath) { } } -string formatDuration(duration seconds) { - return fmt::format("{0:.2f}", seconds.count()); -} - ptree createXmlTree(const path& filePath, const map& phones, const map& shapes) { ptree tree; diff --git a/src/mouthAnimation.cpp b/src/mouthAnimation.cpp index 62dc823..288288a 100644 --- a/src/mouthAnimation.cpp +++ b/src/mouthAnimation.cpp @@ -1,4 +1,5 @@ #include "mouthAnimation.h" +#include "logging.h" using std::map; @@ -69,12 +70,18 @@ Shape getShape(Phone phone) { map animate(const map &phones) { map shapes; Shape lastShape = Shape::Invalid; - for (auto it = phones.cbegin(); it != phones.cend(); it++) { + for (auto it = phones.cbegin(); it != phones.cend(); ++it) { Shape shape = getShape(it->second); if (shape != lastShape || next(it) == phones.cend()) { shapes[it->first] = shape; lastShape = shape; } } + + for (auto it = shapes.cbegin(); it != shapes.cend(); ++it) { + if (next(it) == shapes.cend()) break; + logTimedEvent("shape", it->first, next(it)->first, shapeToString(it->second)); + } + return shapes; } diff --git a/src/phoneExtraction.cpp b/src/phoneExtraction.cpp index 425472b..7c99189 100644 --- a/src/phoneExtraction.cpp +++ b/src/phoneExtraction.cpp @@ -31,6 +31,7 @@ using boost::filesystem::path; using std::function; using std::regex; using std::regex_replace; +using std::chrono::duration; unique_ptr to16kHzMono(unique_ptr stream) { // Downmix, if required @@ -180,6 +181,10 @@ vector recognizeWords(unique_ptr audioStream, ps_decoder_t& for (ps_seg_t* it = ps_seg_iter(&recognizer, &score); it; it = ps_seg_next(it)) { const char* word = ps_seg_word(it); result.push_back(word); + + int firstFrame, lastFrame; + ps_seg_frames(it, &firstFrame, &lastFrame); + logTimedEvent("word", centiseconds(firstFrame), centiseconds(lastFrame + 1), word); } return result; @@ -288,8 +293,12 @@ map getPhoneAlignment(const vector& wordIds, uniqu int duration = phoneEntry->duration; // Add map entries - result[centiseconds(startFrame)] = stringToPhone(phoneName); - result[centiseconds(startFrame + duration)] = Phone::None; + centiseconds start(startFrame); + result[start] = stringToPhone(phoneName); + centiseconds end(startFrame + duration); + result[end] = Phone::None; + + logTimedEvent("phone", start, end, phoneName); } return result; } diff --git a/src/tools.cpp b/src/tools.cpp index 2fa7e97..e36f9ef 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -1 +1,10 @@ #include "tools.h" +#include +#include + +using std::string; +using std::chrono::duration; + +string formatDuration(duration seconds) { + return fmt::format("{0:.2f}", seconds.count()); +} diff --git a/src/tools.h b/src/tools.h index a19118e..fd15ff4 100644 --- a/src/tools.h +++ b/src/tools.h @@ -2,8 +2,11 @@ #include #include +#include #define UNUSED(x) ((void)(x)) template using lambda_unique_ptr = std::unique_ptr>; + +std::string formatDuration(std::chrono::duration seconds); \ No newline at end of file