allow process picking via comm

This commit is contained in:
PancakeTAS 2025-07-18 14:36:45 +02:00 committed by Pancake
parent 34da212a74
commit df37e9356a
7 changed files with 28 additions and 14 deletions

View file

@ -2,7 +2,6 @@
#include <vulkan/vulkan_core.h>
#include <string_view>
#include <cstddef>
#include <vector>
#include <atomic>
@ -68,6 +67,6 @@ namespace Config {
///
/// @throws std::runtime_error if the configuration is invalid.
///
Configuration getConfig(std::string_view name);
Configuration getConfig(const std::pair<std::string, std::string>& name);
}

View file

@ -90,7 +90,7 @@ namespace Utils {
///
/// @return The name of the process.
///
std::string getProcessName();
std::pair<std::string, std::string> getProcessName();
///
/// Get the configuration file path.

View file

@ -32,7 +32,7 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain,
// reread configuration
const std::string file = Utils::getConfigFile();
const std::string name = Utils::getProcessName();
const auto name = Utils::getProcessName();
try {
Config::updateConfig(file);
conf = Config::getConfig(name);
@ -45,7 +45,7 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain,
LSFG_3_1::finalize();
// print config
std::cerr << "lsfg-vk: Reloaded configuration for " << name << ":\n";
std::cerr << "lsfg-vk: Reloaded configuration for " << name.second << ":\n";
if (!conf.dll.empty()) std::cerr << " Using DLL from: " << conf.dll << '\n';
std::cerr << " Multiplier: " << conf.multiplier << '\n';
std::cerr << " Flow Scale: " << conf.flowScale << '\n';

View file

@ -129,7 +129,7 @@ void Extract::extractShaders() {
// ensure all shaders are present
for (const auto& [name, idx] : nameIdxTable)
if (shaders().find(idx) == shaders().end())
throw std::runtime_error("Shader not found: " + name + ".\nIs Lossless Scaling up to date?");
throw std::runtime_error("Shader not found: " + name + ".\n- Is Lossless Scaling up to date?");
}
std::vector<uint8_t> Extract::getShader(const std::string& name) {

View file

@ -24,22 +24,22 @@ namespace {
Utils::showErrorGui(e.what());
}
const std::string name = Utils::getProcessName();
const auto name = Utils::getProcessName();
try {
Config::activeConf = Config::getConfig(name);
} catch (const std::exception& e) {
std::cerr << "lsfg-vk: The configuration for " << name << " is invalid, exiting:\n";
std::cerr << "lsfg-vk: The configuration for " << name.second << " is invalid, exiting:\n";
std::cerr << e.what() << '\n';
Utils::showErrorGui(e.what());
}
// exit silently if not enabled
auto& conf = Config::activeConf;
if (!conf.enable && name != "benchmark")
if (!conf.enable && name.second != "benchmark")
return;
// print config
std::cerr << "lsfg-vk: Loaded configuration for " << name << ":\n";
std::cerr << "lsfg-vk: Loaded configuration for " << name.second << ":\n";
if (!conf.dll.empty()) std::cerr << " Using DLL from: " << conf.dll << '\n';
for (const auto& [key, value] : conf.env)
std::cerr << " Environment: " << key << "=" << value << '\n';

View file

@ -49,6 +49,8 @@ namespace {
}
void Utils::showErrorGui(const std::string& message) {
SetTraceLogLevel(LOG_WARNING);
const int height = DrawTextBox(message, 10, 60, 780, false);
InitWindow(800, height + 80, "lsfg-vk - Error");

View file

@ -15,6 +15,7 @@
#include <cstdint>
#include <cstring>
#include <utility>
#include <fstream>
#include <string>
#include <vector>
#include <array>
@ -208,16 +209,28 @@ void Utils::resetLimitN(const std::string& id) noexcept {
}
/// Get the process name
std::string Utils::getProcessName() {
std::pair<std::string, std::string> Utils::getProcessName() {
const char* benchmark_flag = std::getenv("LSFG_BENCHMARK");
if (benchmark_flag)
return "benchmark";
return { "benchmark", "benchmark" };
std::array<char, 4096> exe{};
const ssize_t exe_len = readlink("/proc/self/exe", exe.data(), exe.size() - 1);
if (exe_len <= 0)
return "Unknown Process";
return { "Unknown Process", "unknown" };
exe.at(static_cast<size_t>(exe_len)) = '\0';
return{exe.data()};
std::ifstream comm_file("/proc/self/comm");
if (!comm_file.is_open())
return { std::string(exe.data()), "unknown" };
std::array<char, 257> comm{};
comm_file.read(comm.data(), 256);
comm.at(static_cast<size_t>(comm_file.gcount())) = '\0';
std::string comm_str(comm.data());
if (comm_str.back() == '\n')
comm_str.pop_back();
return{ std::string(exe.data()), comm_str };
}
/// Get the config file