From 03764c6ea016abd585da7d289364b3149ff281dd Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Mon, 13 Aug 2018 13:38:46 +0200 Subject: [PATCH] Statistics: added printing of original recording time. --- src/VmaReplay/Common.cpp | 15 ++++++++------- src/VmaReplay/VmaReplay.cpp | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/VmaReplay/Common.cpp b/src/VmaReplay/Common.cpp index dffd2af..cfb44dc 100644 --- a/src/VmaReplay/Common.cpp +++ b/src/VmaReplay/Common.cpp @@ -579,27 +579,28 @@ void SecondsToFriendlyStr(float seconds, std::string& out) char s[32]; - // #.# ns + // #.### ns if(seconds < 1e-6) { - sprintf_s(s, "%.4f ns", seconds * 1e-9); + sprintf_s(s, "%.3f ns", seconds * 1e-9); out += s; } - // #.# us + // #.### us else if(seconds < 1e-3) { - sprintf_s(s, "%.4f us", seconds * 1e-6); + sprintf_s(s, "%.3f us", seconds * 1e-6); out += s; } - // #.# ms + // #.### ms else if(seconds < 1.f) { - sprintf_s(s, "%.4f ms", seconds * 1e-3); + sprintf_s(s, "%.3f ms", seconds * 1e-3); out += s; } + // #.### s else if(seconds < 60.f) { - sprintf_s(s, "%.4f s", seconds); + sprintf_s(s, "%.3f s", seconds); out += s; } else diff --git a/src/VmaReplay/VmaReplay.cpp b/src/VmaReplay/VmaReplay.cpp index 7470e48..e74ba53 100644 --- a/src/VmaReplay/VmaReplay.cpp +++ b/src/VmaReplay/VmaReplay.cpp @@ -56,6 +56,7 @@ struct StrRange explicit StrRange(const std::string& s) : beg(s.data()), end(s.data() + s.length()) { } size_t length() const { return end - beg; } + void to_str(std::string& out) { out.assign(beg, end); } }; static inline bool StrRangeEq(const StrRange& lhs, const char* rhsSz) @@ -83,6 +84,12 @@ static inline bool StrRangeToPtr(const StrRange& s, uint64_t& out) out = (uint64_t)strtoull(s.beg, &end, 16); return end == s.end; } +static inline bool StrRangeToFloat(const StrRange& s, float& out) +{ + char* end = (char*)s.end; + out = strtof(s.beg, &end); + return end == s.end; +} //////////////////////////////////////////////////////////////////////////////// // LineSplit class @@ -301,6 +308,8 @@ private: std::unordered_map m_Pools; std::unordered_map m_Allocations; + // Copy of column [1] from previously parsed line. + std::string m_LastLineTimeStr; Statistics m_Stats; void Destroy(const Allocation& alloc); @@ -356,6 +365,8 @@ void Player::ExecuteLine(size_t lineNumber, const StrRange& line) if(csvSplit.GetCount() >= FIRST_PARAM_INDEX) { + csvSplit.GetRange(1).to_str(m_LastLineTimeStr); + // Update VMA current frame index. StrRange frameIndexStr = csvSplit.GetRange(2); uint32_t frameIndex; @@ -729,6 +740,14 @@ void Player::PrintStats() printf(" Total allocations created: %zu\n", m_Stats.GetAllocationCreationCount()); printf(" Total buffers created: %zu\n", m_Stats.GetBufferCreationCount()); printf(" Total images created: %zu\n", m_Stats.GetImageCreationCount()); + + float lastTime; + if(!m_LastLineTimeStr.empty() && StrRangeToFloat(StrRange(m_LastLineTimeStr), lastTime)) + { + std::string origTimeStr; + SecondsToFriendlyStr(lastTime, origTimeStr); + printf(" Original recording time: %s\n", origTimeStr.c_str()); + } } bool Player::ValidateFunctionParameterCount(size_t lineNumber, const CsvSplit& csvSplit, size_t expectedParamCount, bool lastUnbound)