diff --git a/src/VmaReplay/Common.cpp b/src/VmaReplay/Common.cpp index 4c1a6b7..dffd2af 100644 --- a/src/VmaReplay/Common.cpp +++ b/src/VmaReplay/Common.cpp @@ -558,3 +558,70 @@ void PrintErrorF(const wchar_t* format, ...) va_end(argList); } */ + +void SecondsToFriendlyStr(float seconds, std::string& out) +{ + if(seconds == 0.f) + { + out = "0"; + return; + } + + if (seconds < 0.f) + { + out = "-"; + seconds = -seconds; + } + else + { + out.clear(); + } + + char s[32]; + + // #.# ns + if(seconds < 1e-6) + { + sprintf_s(s, "%.4f ns", seconds * 1e-9); + out += s; + } + // #.# us + else if(seconds < 1e-3) + { + sprintf_s(s, "%.4f us", seconds * 1e-6); + out += s; + } + // #.# ms + else if(seconds < 1.f) + { + sprintf_s(s, "%.4f ms", seconds * 1e-3); + out += s; + } + else if(seconds < 60.f) + { + sprintf_s(s, "%.4f s", seconds); + out += s; + } + else + { + uint64_t seconds_u = (uint64_t)seconds; + // "#:## min" + if (seconds_u < 3600) + { + uint64_t minutes = seconds_u / 60; + seconds_u -= minutes * 60; + sprintf_s(s, "%llu:%02llu min", minutes, seconds_u); + out += s; + } + // "#:##:## h" + else + { + uint64_t minutes = seconds_u / 60; + seconds_u -= minutes * 60; + uint64_t hours = minutes / 60; + minutes -= hours * 60; + sprintf_s(s, "%llu:%02llu:%02llu h", hours, minutes, seconds_u); + out += s; + } + } +} diff --git a/src/VmaReplay/Common.h b/src/VmaReplay/Common.h index afd52c1..f5f4c44 100644 --- a/src/VmaReplay/Common.h +++ b/src/VmaReplay/Common.h @@ -27,6 +27,8 @@ inline float ToFloatSeconds(duration d) return std::chrono::duration_cast>(d).count(); } +void SecondsToFriendlyStr(float seconds, std::string& out); + template inline T ceil_div(T x, T y) { diff --git a/src/VmaReplay/VmaReplay.cpp b/src/VmaReplay/VmaReplay.cpp index dd88f42..7470e48 100644 --- a/src/VmaReplay/VmaReplay.cpp +++ b/src/VmaReplay/VmaReplay.cpp @@ -1067,15 +1067,24 @@ static int ProcessFile(const char* data, size_t numBytes) { printf("Playing...\n"); } + + const time_point timeBeg = std::chrono::high_resolution_clock::now(); + while(lineSplit.GetNextLine(line)) { player.ExecuteLine(lineSplit.GetNextLineIndex(), line); } + const duration playDuration = std::chrono::high_resolution_clock::now() - timeBeg; + // End stats. if(g_Verbosity > VERBOSITY::MINIMUM) { + std::string playDurationStr; + SecondsToFriendlyStr(ToFloatSeconds(playDuration), playDurationStr); + printf("Done.\n"); + printf("Playback took: %s\n", playDurationStr.c_str()); printf("File lines: %zu\n", lineSplit.GetNextLineIndex()); } }