Try to init spdlog a bit earlier

pull/642/merge
jackun 2 years ago
parent 2f5efc320a
commit 73da29d4ad
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -75,6 +75,7 @@ void imgui_init()
if (cfg_inited)
return;
init_spdlog();
parse_overlay_config(&params, getenv("MANGOHUD_CONFIG"));
_params = &params;

@ -4,6 +4,9 @@
#include <thread>
#include <condition_variable>
#include <spdlog/spdlog.h>
#include <spdlog/cfg/env.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <filesystem.h>
#include <sys/stat.h>
#include "overlay.h"
@ -49,6 +52,31 @@ bool gpu_metrics_exists = false;
bool steam_focused = false;
vector<float> frametime_data(200,0.f);
void init_spdlog()
{
if (spdlog::get("MANGOHUD"))
return;
spdlog::set_default_logger(spdlog::stderr_color_mt("MANGOHUD")); // Just to get the name in log
if (getenv("MANGOHUD_USE_LOGFILE"))
{
try
{
// Not rotating when opening log as proton/wine create multiple (sub)processes
auto log = std::make_shared<spdlog::sinks::rotating_file_sink_mt> (get_config_dir() + "/MangoHud/MangoHud.log", 10*1024*1024, 5, false);
spdlog::get("MANGOHUD")->sinks().push_back(log);
}
catch (const spdlog::spdlog_ex &ex)
{
SPDLOG_ERROR("{}", ex.what());
}
}
#ifndef NDEBUG
spdlog::set_level(spdlog::level::level_enum::debug);
#endif
spdlog::cfg::load_env_levels();
}
void FpsLimiter(struct fps_limit& stats){
stats.sleepTime = stats.targetFrameTime - (stats.frameStart - stats.frameEnd);
if (stats.sleepTime > stats.frameOverhead) {
@ -638,13 +666,11 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para
}
}
SPDLOG_DEBUG("using amdgpu path: {}", path);
std::string gpu_metrics_path = path + "/device/gpu_metrics";
if (file_exists(gpu_metrics_path)) {
gpu_metrics_exists = true;
metrics_path = gpu_metrics_path;
SPDLOG_DEBUG("Using gpu_metrics");
SPDLOG_DEBUG("Using gpu_metrics of {}", path);
}
path += "/device";
if (!amdgpu.vram_total)
@ -661,6 +687,8 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para
if (!amdgpu.busy)
continue;
SPDLOG_DEBUG("using amdgpu path: {}", path);
path += "/hwmon/";
auto dirs = ls(path.c_str(), "hwmon", LS_DIRS);
for (auto& dir : dirs) {

@ -154,6 +154,7 @@ extern overlay_params *_params;
extern double min_frametime, max_frametime;
extern bool steam_focused;
void init_spdlog();
void position_layer(struct swapchain_stats& data, struct overlay_params& params, ImVec2 window_size);
void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan);
void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID);

@ -18,8 +18,6 @@
#include <array>
#include <functional>
#include <spdlog/spdlog.h>
#include <spdlog/cfg/env.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include "overlay_params.h"
#include "overlay.h"
@ -551,13 +549,6 @@ void
parse_overlay_config(struct overlay_params *params,
const char *env)
{
if (!spdlog::get("MANGOHUD"))
spdlog::set_default_logger(spdlog::stderr_color_mt("MANGOHUD")); // Just to get the name in log
#ifndef NDEBUG
spdlog::set_level(spdlog::level::level_enum::debug);
#endif
spdlog::cfg::load_env_levels();
*params = {};
/* Visible by default */

@ -1977,6 +1977,7 @@ static void *find_ptr(const char *name)
extern "C" VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL overlay_GetDeviceProcAddr(VkDevice dev,
const char *funcName)
{
init_spdlog();
void *ptr = find_ptr(funcName);
if (ptr) return reinterpret_cast<PFN_vkVoidFunction>(ptr);
@ -1990,6 +1991,7 @@ extern "C" VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL overlay_GetD
extern "C" VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL overlay_GetInstanceProcAddr(VkInstance instance,
const char *funcName)
{
init_spdlog();
void *ptr = find_ptr(funcName);
if (ptr) return reinterpret_cast<PFN_vkVoidFunction>(ptr);

Loading…
Cancel
Save