Skip to content

Commit

Permalink
Add logging options to gfxrecon-replay
Browse files Browse the repository at this point in the history
Adds the following command line options to gfxrecon-replay:

--log-level <level> Specify highest level message to log. Options are:
                    debug, info, warning, error, and fatal. Default is
                    info.
--log-file <file>   Write log messages to a file at the specified path.
                    Default is: Empty string (file logging disabled).
--log-debugview     Log messages with OutputDebugStringA (Windows only)

Change-Id: If73a5be5ab1161bf96b7c312313eb6a09381d6f8
  • Loading branch information
davidd-lunarg committed Jan 4, 2021
1 parent 1e5caf6 commit 3738dec
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 40 deletions.
10 changes: 8 additions & 2 deletions USAGE_desktop.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ optional arguments:
capture file
--log-level {debug,info,warn,error,fatal}
Specify highest level message to log, default is info
--log-file logFile Name of the log file (disable logging with empty
string), default is stdout/stderr
--log-file <logFile> Write log messages to a file at the specified path.
Default is: Empty string (file logging disabled)
--memory-tracking-mode {page_guard,assisted,unassisted}
Method to use to track changes to memory mapped objects:
page_guard: use guard pages to track changes (default)
Expand Down Expand Up @@ -336,6 +336,7 @@ gfxrecon-replay [-h | --help] [--version] [--gpu <index>]
[--opcd | --omit-pipeline-cache-data] [--wsi <platform>]
[--surface-index <N>] [--remove-unsupported]
[-m <mode> | --memory-translation <mode>]
[--log-level <level>] [--log-file <file>] [--log-debugview]
<file>
Required arguments:
Expand All @@ -344,6 +345,11 @@ Required arguments:
Optional arguments:
-h Print usage information and exit (same as --help).
--version Print version information and exit.
--log-level <level> Specify highest level message to log. Options are:
debug, info, warning, error, and fatal. Default is info.
--log-file <file> Write log messages to a file at the specified path.
Default is: Empty string (file logging disabled).
--log-debugview Log messages with OutputDebugStringA. Windows only.
--gpu <index> Use the specified device for replay, where index
is the zero-based index to the array of physical devices
returned by vkEnumeratePhysicalDevices. Replay may fail
Expand Down
3 changes: 3 additions & 0 deletions framework/decode/vulkan_replay_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ GFXRECON_BEGIN_NAMESPACE(decode)

typedef std::function<VulkanResourceAllocator*()> CreateResourceAllocator;

// Default log level to use prior to loading settings.
const util::Log::Severity kDefaultLogLevel = util::Log::Severity::kInfoSeverity;

const char kDefaultScreenshotFilePrefix[] = "screenshot";

enum class ScreenshotFormat : uint32_t
Expand Down
25 changes: 3 additions & 22 deletions framework/encode/capture_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,30 +480,11 @@ format::CompressionType CaptureSettings::ParseCompressionTypeString(const std::s
util::Log::Severity CaptureSettings::ParseLogLevelString(const std::string& value_string,
util::Log::Severity default_value)
{
util::Log::Severity result = default_value;
util::Log::Severity result;

if (util::platform::StringCompareNoCase("debug", value_string.c_str()) == 0)
{
result = util::Log::Severity::kDebugSeverity;
}
else if (util::platform::StringCompareNoCase("info", value_string.c_str()) == 0)
{
result = util::Log::Severity::kInfoSeverity;
}
else if (util::platform::StringCompareNoCase("warning", value_string.c_str()) == 0)
{
result = util::Log::Severity::kWarningSeverity;
}
else if (util::platform::StringCompareNoCase("error", value_string.c_str()) == 0)
{
result = util::Log::Severity::kErrorSeverity;
}
else if (util::platform::StringCompareNoCase("fatal", value_string.c_str()) == 0)
{
result = util::Log::Severity::kFatalSeverity;
}
else
if (!util::Log::StringToSeverity(value_string, result))
{
result = default_value;
if (!value_string.empty())
{
GFXRECON_LOG_WARNING("Settings Loader: Ignoring unrecognized log level option value \"%s\"",
Expand Down
15 changes: 9 additions & 6 deletions framework/util/argument_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,16 @@ void ArgumentParser::Init(std::vector<std::string> command_line_args,
{
// Get the next value and strip off any quotes surrounding the whole string
std::string argument_value = command_line_args[++cur_arg];
if (argument_value.front() == '\"')
if (!argument_value.empty())
{
argument_value.erase(argument_value.begin());
}
if (argument_value.back() == '\"')
{
argument_value.pop_back();
if (argument_value.front() == '\"')
{
argument_value.erase(argument_value.begin());
}
if (argument_value.back() == '\"')
{
argument_value.pop_back();
}
}
argument_values_[cur_argument.second] = argument_value;
}
Expand Down
34 changes: 34 additions & 0 deletions framework/util/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,40 @@ class Log
}
}

// Returns true if Severity was successfully parsed into parsed_severity. Returns false if the string could not be
// parsed as a Severity and parsed_severity is not modified.
static bool StringToSeverity(const std::string& value_string, Severity& parsed_severity)
{
bool parse_success = true;

if (platform::StringCompareNoCase("debug", value_string.c_str()) == 0)
{
parsed_severity = Severity::kDebugSeverity;
}
else if (platform::StringCompareNoCase("info", value_string.c_str()) == 0)
{
parsed_severity = Severity::kInfoSeverity;
}
else if (platform::StringCompareNoCase("warning", value_string.c_str()) == 0)
{
parsed_severity = Severity::kWarningSeverity;
}
else if (platform::StringCompareNoCase("error", value_string.c_str()) == 0)
{
parsed_severity = Severity::kErrorSeverity;
}
else if (util::platform::StringCompareNoCase("fatal", value_string.c_str()) == 0)
{
parsed_severity = Severity::kFatalSeverity;
}
else
{
parse_success = false;
}

return parse_success;
}

private:
static std::string ConvertFormatVaListToString(const std::string& format_string, va_list& var_args);

Expand Down
2 changes: 1 addition & 1 deletion tools/capture/gfxrecon-capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def ParseArgs():
parser.add_argument('--compression-type', dest='compressionType', choices=compressionTypeChoices, help='Specify the type of compression to use in the capture file, default is LZ4')
parser.add_argument('--file-flush', dest='fileFlush', action='store_const', const='true', help='Flush output stream after each packet is written to capture file')
parser.add_argument('--log-level', dest='logLevel', choices=logLevelChoices, help='Specify highest level message to log, default is info')
parser.add_argument('--log-file', dest='logFile', metavar='logFile', help='Name of the log file (disable logging with empty string), default is stdout/stderr')
parser.add_argument('--log-file', dest='logFile', metavar='<logFile>', help='Write log messages to a file at the specified path. Default is: Empty string (file logging disabled)')
parser.add_argument('--log-debugview', dest='logDebugView', action='store_const', const='true', help='Log messages with OutputDebugStringA' if sys.platform=='win32' else argparse.SUPPRESS)
parser.add_argument('--memory-tracking-mode', dest='memoryTrackingMode', choices=memoryTrackingModeChoices , help=
'R|Method to use to track changes to memory mapped objects:' + os.linesep +
Expand Down
9 changes: 8 additions & 1 deletion tools/replay/desktop_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ int main(int argc, const char** argv)
{
int return_code = 0;

gfxrecon::util::Log::Init();
// Default initialize logging to report issues while loading settings.
gfxrecon::util::Log::Init(gfxrecon::decode::kDefaultLogLevel);

gfxrecon::util::ArgumentParser arg_parser(argc, argv, kOptions, kArguments);

Expand All @@ -108,6 +109,12 @@ int main(int argc, const char** argv)
ProcessDisableDebugPopup(arg_parser);
}

// Reinitialize logging with values retrieved from command line arguments
gfxrecon::util::Log::Settings log_settings;
GetLogSettings(arg_parser, log_settings);
gfxrecon::util::Log::Release();
gfxrecon::util::Log::Init(log_settings);

try
{
const std::vector<std::string>& positional_arguments = arg_parser.GetPositionalArguments();
Expand Down
52 changes: 44 additions & 8 deletions tools/replay/replay_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const char kCaptureLayer[] = "VK_LAYER_LUNARG_gfxreconstruct";
const char kHelpShortOption[] = "-h";
const char kHelpLongOption[] = "--help";
const char kVersionOption[] = "--version";
const char kLogLevelArgument[] = "--log-level";
const char kLogFileArgument[] = "--log-file";
const char kLogDebugView[] = "--log-debugview";
const char kNoDebugPopup[] = "--no-debug-popup";
const char kOverrideGpuArgument[] = "--gpu";
const char kPausedOption[] = "--paused";
Expand All @@ -73,11 +76,10 @@ const char kScreenshotFormatArgument[] = "--screenshot-format";
const char kScreenshotDirArgument[] = "--screenshot-dir";
const char kScreenshotFilePrefixArgument[] = "--screenshot-prefix";

const char kOptions[] = "-h|--help,--version,--no-debug-popup,--paused,--sync,--sfa|--skip-failed-allocations,--"
"opcd|--omit-pipeline-cache-data,--remove-unsupported,--screenshot-all";
const char kArguments[] =
"--gpu,--pause-frame,--wsi,--surface-index,-m|--memory-translation,--replace-shaders,--screenshots,--"
"screenshot-format,--screenshot-dir,--screenshot-prefix";
const char kOptions[] = "-h|--help,--version,--log-debugview,--no-debug-popup,--paused,--sync,--sfa|--skip-failed-"
"allocations,--opcd|--omit-pipeline-cache-data,--remove-unsupported,--screenshot-all";
const char kArguments[] = "--log-level,--log-file,--gpu,--pause-frame,--wsi,--surface-index,-m|--memory-translation,--"
"replace-shaders,--screenshots,--screenshot-format,--screenshot-dir,--screenshot-prefix";

enum class WsiPlatform
{
Expand Down Expand Up @@ -298,6 +300,28 @@ static std::string GetWsiArgString()
return wsi_args;
}

// Modifies settings parameter with values set via command line
static void GetLogSettings(const gfxrecon::util::ArgumentParser& arg_parser,
gfxrecon::util::Log::Settings& log_settings)
{
// Parse log level
gfxrecon::util::Log::Severity log_level;
const std::string& value_string = arg_parser.GetArgumentValue(kLogLevelArgument);
if (value_string.empty() || !gfxrecon::util::Log::StringToSeverity(value_string, log_level))
{
log_level = gfxrecon::decode::kDefaultLogLevel;
if (!value_string.empty())
{
GFXRECON_LOG_WARNING("Ignoring unrecognized log level option value \"%s\"", value_string.c_str());
}
}

// Update settings
log_settings.min_severity = log_level;
log_settings.file_name = arg_parser.GetArgumentValue(kLogFileArgument);
log_settings.output_to_os_debug_string = arg_parser.IsOptionSet(kLogDebugView);
}

static gfxrecon::decode::ScreenshotFormat GetScreenshotFormat(const gfxrecon::util::ArgumentParser& arg_parser)
{
gfxrecon::decode::ScreenshotFormat format = gfxrecon::decode::ScreenshotFormat::kBmp;
Expand Down Expand Up @@ -594,16 +618,28 @@ static void PrintUsage(const char* exe_name)
GFXRECON_WRITE_CONSOLE("\t\t\t[--opcd | --omit-pipeline-cache-data] [--wsi <platform>]");
GFXRECON_WRITE_CONSOLE("\t\t\t[--surface-index <N>] [--remove-unsupported]");
GFXRECON_WRITE_CONSOLE("\t\t\t[-m <mode> | --memory-translation <mode>]");
#if defined(WIN32) && defined(_DEBUG)
GFXRECON_WRITE_CONSOLE("\t\t\t[--no-debug-popup] <file>\n");
#if defined(WIN32)
GFXRECON_WRITE_CONSOLE("\t\t\t[--log-level <level>] [--log-file <file>] [--log-debugview]");
#if defined(_DEBUG)
GFXRECON_WRITE_CONSOLE("\t\t\t[--no-debug-popup]");
#endif
#else
GFXRECON_WRITE_CONSOLE("\t\t\t<file>\n");
GFXRECON_WRITE_CONSOLE("\t\t\t[--log-level <level>] [--log-file <file>]");
#endif
GFXRECON_WRITE_CONSOLE("\t\t\t<file>\n");

GFXRECON_WRITE_CONSOLE("Required arguments:");
GFXRECON_WRITE_CONSOLE(" <file>\t\tPath to the capture file to replay.");
GFXRECON_WRITE_CONSOLE("\nOptional arguments:");
GFXRECON_WRITE_CONSOLE(" -h\t\t\tPrint usage information and exit (same as --help).");
GFXRECON_WRITE_CONSOLE(" --version\t\tPrint version information and exit.");
GFXRECON_WRITE_CONSOLE(" --log-level <level>\tSpecify highest level message to log. Options are:");
GFXRECON_WRITE_CONSOLE(" \t\tdebug, info, warning, error, and fatal. Default is info.");
GFXRECON_WRITE_CONSOLE(" --log-file <file>\tWrite log messages to a file at the specified path.")
GFXRECON_WRITE_CONSOLE(" \t\tDefault is: Empty string (file logging disabled).");
#if defined(WIN32)
GFXRECON_WRITE_CONSOLE(" --log-debugview\tLog messages with OutputDebugStringA.");
#endif
GFXRECON_WRITE_CONSOLE(" --gpu <index>\t\tUse the specified device for replay, where index");
GFXRECON_WRITE_CONSOLE(" \t\tis the zero-based index to the array of physical devices");
GFXRECON_WRITE_CONSOLE(" \t\treturned by vkEnumeratePhysicalDevices. Replay may fail");
Expand Down

0 comments on commit 3738dec

Please sign in to comment.