VmaReplay: Added -i parameter for repeating playback a number of times (iterations).

This commit is contained in:
Adam Sawicki 2018-08-21 13:31:04 +02:00
parent 069dc11452
commit 4b360aa9a8

View File

@ -33,6 +33,7 @@ static const int RESULT_ERROR_VULKAN = -4;
enum CMD_LINE_OPT enum CMD_LINE_OPT
{ {
CMD_LINE_OPT_VERBOSITY, CMD_LINE_OPT_VERBOSITY,
CMD_LINE_OPT_ITERATIONS,
CMD_LINE_OPT_LINES, CMD_LINE_OPT_LINES,
}; };
@ -98,6 +99,7 @@ static std::string g_FilePath;
// Most significant 16 bits are major version, least significant 16 bits are minor version. // Most significant 16 bits are major version, least significant 16 bits are minor version.
static uint32_t g_FileVersion; static uint32_t g_FileVersion;
static size_t g_IterationCount = 1;
static RangeSequence<size_t> g_LineRanges; static RangeSequence<size_t> g_LineRanges;
static bool ValidateFileVersion() static bool ValidateFileVersion()
@ -680,7 +682,7 @@ bool Player::IssueWarning()
int Player::InitVulkan() int Player::InitVulkan()
{ {
if(g_Verbosity > VERBOSITY::MINIMUM) if(g_Verbosity == VERBOSITY::MAXIMUM)
{ {
printf("Initializing Vulkan...\n"); printf("Initializing Vulkan...\n");
} }
@ -1888,20 +1890,18 @@ static void PrintCommandLineSyntax()
" 0 - Minimum verbosity. Prints only warnings and errors.\n" " 0 - Minimum verbosity. Prints only warnings and errors.\n"
" 1 - Default verbosity. Prints important messages and statistics.\n" " 1 - Default verbosity. Prints important messages and statistics.\n"
" 2 - Maximum verbosity. Prints a lot of information.\n" " 2 - Maximum verbosity. Prints a lot of information.\n"
" -i <Number> - Repeat playback given number of times (iterations)\n"
" Default is 1. Vulkan is reinitialized with every iteration.\n"
" --Lines <Ranges> - Replay only limited set of lines from file\n" " --Lines <Ranges> - Replay only limited set of lines from file\n"
" Ranges is comma-separated list of ranges, e.g. \"-10,15,18-25,31-\".\n" " Ranges is comma-separated list of ranges, e.g. \"-10,15,18-25,31-\".\n"
); );
} }
static int ProcessFile(const char* data, size_t numBytes) static int ProcessFile(size_t iterationIndex, const char* data, size_t numBytes, duration& outDuration)
{ {
const bool useLineRanges = !g_LineRanges.IsEmpty(); outDuration = duration::max();
// Begin stats. const bool useLineRanges = !g_LineRanges.IsEmpty();
if(g_Verbosity == VERBOSITY::MAXIMUM)
{
printf("File size: %zu B\n", numBytes);
}
LineSplit lineSplit(data, numBytes); LineSplit lineSplit(data, numBytes);
StrRange line; StrRange line;
@ -1933,11 +1933,11 @@ static int ProcessFile(const char* data, size_t numBytes)
{ {
if(useLineRanges) if(useLineRanges)
{ {
printf("Playing (limited range of lines)...\n"); printf("Playing #%zu (limited range of lines)...\n", iterationIndex + 1);
} }
else else
{ {
printf("Playing...\n"); printf("Playing #%zu...\n", iterationIndex + 1);
} }
} }
@ -1959,6 +1959,7 @@ static int ProcessFile(const char* data, size_t numBytes)
} }
const duration playDuration = std::chrono::high_resolution_clock::now() - timeBeg; const duration playDuration = std::chrono::high_resolution_clock::now() - timeBeg;
outDuration = playDuration;
// End stats. // End stats.
if(g_Verbosity > VERBOSITY::MINIMUM) if(g_Verbosity > VERBOSITY::MINIMUM)
@ -1967,12 +1968,12 @@ static int ProcessFile(const char* data, size_t numBytes)
SecondsToFriendlyStr(ToFloatSeconds(playDuration), playDurationStr); SecondsToFriendlyStr(ToFloatSeconds(playDuration), playDurationStr);
printf("Done.\n"); printf("Done.\n");
printf("Executed %zu file lines\n", executedLineCount);
printf("Playback took: %s\n", playDurationStr.c_str()); printf("Playback took: %s\n", playDurationStr.c_str());
} }
if(g_Verbosity == VERBOSITY::MAXIMUM) if(g_Verbosity == VERBOSITY::MAXIMUM)
{ {
printf("File lines: %zu\n", lineSplit.GetNextLineIndex()); printf("File lines: %zu\n", lineSplit.GetNextLineIndex());
printf("Executed %zu file lines\n", executedLineCount);
} }
} }
@ -1999,7 +2000,27 @@ static int ProcessFile()
{ {
std::vector<char> fileContents(fileSize); std::vector<char> fileContents(fileSize);
fread(fileContents.data(), 1, fileSize, file); fread(fileContents.data(), 1, fileSize, file);
ProcessFile(fileContents.data(), fileContents.size());
// Begin stats.
if(g_Verbosity == VERBOSITY::MAXIMUM)
{
printf("File size: %zu B\n", fileSize);
}
duration durationSum = duration::zero();
for(size_t i = 0; i < g_IterationCount; ++i)
{
duration currDuration;
ProcessFile(i, fileContents.data(), fileContents.size(), currDuration);
durationSum += currDuration;
}
if(g_IterationCount > 1)
{
std::string playDurationStr;
SecondsToFriendlyStr(ToFloatSeconds(durationSum / g_IterationCount), playDurationStr);
printf("Average playback time from %zu iterations: %s\n", g_IterationCount, playDurationStr.c_str());
}
} }
else else
{ {
@ -2023,6 +2044,7 @@ static int main2(int argc, char** argv)
CmdLineParser cmdLineParser(argc, argv); CmdLineParser cmdLineParser(argc, argv);
cmdLineParser.RegisterOpt(CMD_LINE_OPT_VERBOSITY, 'v', true); cmdLineParser.RegisterOpt(CMD_LINE_OPT_VERBOSITY, 'v', true);
cmdLineParser.RegisterOpt(CMD_LINE_OPT_ITERATIONS, 'i', true);
cmdLineParser.RegisterOpt(CMD_LINE_OPT_LINES, "Lines", true); cmdLineParser.RegisterOpt(CMD_LINE_OPT_LINES, "Lines", true);
CmdLineParser::RESULT res; CmdLineParser::RESULT res;
@ -2048,13 +2070,18 @@ static int main2(int argc, char** argv)
} }
} }
break; break;
case CMD_LINE_OPT_LINES: case CMD_LINE_OPT_ITERATIONS:
if(!StrRangeToUint(StrRange(cmdLineParser.GetParameter()), g_IterationCount))
{ {
if(!g_LineRanges.Parse(StrRange(cmdLineParser.GetParameter()))) PrintCommandLineSyntax();
{ return RESULT_ERROR_COMMAND_LINE;
PrintCommandLineSyntax(); }
return RESULT_ERROR_COMMAND_LINE; break;
} case CMD_LINE_OPT_LINES:
if(!g_LineRanges.Parse(StrRange(cmdLineParser.GetParameter())))
{
PrintCommandLineSyntax();
return RESULT_ERROR_COMMAND_LINE;
} }
break; break;
default: default: