Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions layersvt/api_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,19 @@
#pragma warning(disable : 4554)
#endif

#ifdef _WIN32
#include <processthreadsapi.h>
#elif defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNX__) || defined(__FreeBSD__) || \
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || defined(__ANDROID__)
#include <unistd.h>
#endif

#define MAX_STRING_LENGTH 1024

// Defines for utilized environment variables.
#define kSettingsKeyFile "file"
#define kSettingsKeyLogFilename "log_filename"
#define kSettingsKeyAppendPid "append_pid"
#define kSettingsKeyOutputFormat "output_format"
#define kSettingsKeyDetailedOutput "detailed"
#define kSettingsKeyNoAddr "no_addr"
Expand Down Expand Up @@ -549,18 +557,36 @@ class ApiDumpSettings {
size_t html_pos = filename_string.find(".html", filename_string.size() - 5);
size_t json_pos = filename_string.find(".json", filename_string.size() - 5);

bool append_pid = false;

// Check if pid should be appended to the filename.
if (vkuHasLayerSetting(layerSettingSet, kSettingsKeyAppendPid)) {
vkuGetLayerSettingValue(layerSettingSet, kSettingsKeyAppendPid, append_pid);
}

std::string pid_string;

if (append_pid) {
pid_string = getCurrentPidString();
}

// Filter the filename itself.
if (json_pos != std::string::npos) filename_string.erase(json_pos);
if (txt_pos != std::string::npos) filename_string.erase(txt_pos);
if (html_pos != std::string::npos) filename_string.erase(html_pos);

if (append_pid) {
// Append with pid if needed.
filename_string.append("_").append(pid_string);
}

// Restore the file extension.
if (output_format == ApiDumpFormat::Html) {
if (json_pos != std::string::npos) filename_string.erase(json_pos);
if (txt_pos != std::string::npos) filename_string.erase(txt_pos);
if (html_pos == std::string::npos) filename_string.append(".html");
filename_string.append(".html");
} else if (output_format == ApiDumpFormat::Json) {
if (html_pos != std::string::npos) filename_string.erase(html_pos);
if (txt_pos != std::string::npos) filename_string.erase(txt_pos);
if (json_pos == std::string::npos) filename_string.append(".json");
filename_string.append(".json");
} else {
if (html_pos != std::string::npos) filename_string.erase(html_pos);
if (json_pos != std::string::npos) filename_string.erase(json_pos);
if (txt_pos == std::string::npos) filename_string.append(".txt");
filename_string.append(".txt");
}
}

Expand Down Expand Up @@ -776,6 +802,22 @@ class ApiDumpSettings {
return lower_value;
}

std::string getCurrentPidString() {
std::stringstream ss;
#ifdef _WIN32
DWORD pid = GetCurrentProcessId();
ss << pid;
#elif defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNX__) || defined(__FreeBSD__) || \
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || defined(__ANDROID__)
pid_t pid = getpid();
ss << pid;
#else
// Should never reach here due to the #error above
throw std::runtime_error("Unsupported operating system");
#endif
return ss.str();
}

// The mutable is necessary because everyone who 'writes' to the stream necessarily must be able to modify it.
// Since basically every function in this struct is const, we have to work around that.
mutable std::ostream output_stream;
Expand Down
17 changes: 17 additions & 0 deletions layersvt/json/VkLayer_api_dump.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@
}
]
}
},
{
"key": "append_pid",
"env": "VK_APIDUMP_APPEND_LOG_FILENAME_WITH_PID",
"label": "Append log filename with pid.",
"description": "If set, appends the log filename with pid.",
"type": "BOOL",
"default": "false",
"dependence": {
"mode": "ALL",
"settings": [
{
"key": "file",
"value": true
}
]
}
}
]
},
Expand Down