game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
MangoHudLogReader Class Reference

Reads frame metrics from MangoHud CSV log files. More...

#include <frame_metrics.h>

Inheritance diagram for MangoHudLogReader:
Collaboration diagram for MangoHudLogReader:

Public Member Functions

 MangoHudLogReader ()
 ~MangoHudLogReader () override
FrameMetrics getMetrics () const override
 Get the latest metrics.
std::string getSourceName () const override
 Get the source name for this reader.
bool isActive () const override
 Check if reader is actively collecting.
bool isAvailable () const override
 Check if this reader is available on the system.
void setLogDirectory (const std::string &path)
 Set the log directory to monitor.
bool start (int pid) override
 Start collecting metrics for a process.
void stop () override
 Stop collecting metrics.
Public Member Functions inherited from IFrameMetricsReader
virtual ~IFrameMetricsReader ()=default

Static Public Member Functions

static std::string buildLaunchConfigFile (const std::string &gameId, const std::string &userConfigFile={})
 Materialise a complete MangoHud config file for a launch.
static std::string getDefaultLogDirectory ()
 Get the default log directory.
static std::string getLoggingConfig ()
 Get the MangoHud config string for logging.

Detailed Description

Reads frame metrics from MangoHud CSV log files.

MangoHud can log metrics to CSV files. This reader tails the log file and parses the latest entries for frame timing data.

Requires MangoHud to be launched with logging enabled: MANGOHUD_CONFIG="output_folder=/tmp/gamelauncher,autostart_log=1"

This is a fallback when gamescope is not being used.

Definition at line 316 of file frame_metrics.h.

Constructor & Destructor Documentation

◆ MangoHudLogReader()

MangoHudLogReader::MangoHudLogReader ( )

Definition at line 282 of file frame_metrics.cpp.

References getDefaultLogDirectory().

◆ ~MangoHudLogReader()

MangoHudLogReader::~MangoHudLogReader ( )
override

Definition at line 288 of file frame_metrics.cpp.

References stop().

Member Function Documentation

◆ buildLaunchConfigFile()

std::string MangoHudLogReader::buildLaunchConfigFile ( const std::string & gameId,
const std::string & userConfigFile = {} )
static

Materialise a complete MangoHud config file for a launch.

Writes our logging keys (output_folder/autostart_log/log_duration/ log_interval) to a file under the log directory. If userConfigFile is non-empty and exists, its contents are copied first so the user's overlay layout / display options are preserved; our logging keys are appended last and therefore win because parseConfigLine in MangoHud's src/config.cpp simply overwrites earlier values in the options map.

The returned path is intended to be passed via MANGOHUD_CONFIGFILE, which causes MangoHud's parseConfigFile (src/config.cpp) to skip enumerate_config_files and load only this file — fully isolating us from the user's ~/.config/MangoHud/MangoHud.conf (which goverlay 1.7.5 may populate with a competing log_duration).

Parameters
gameIdIdentifier used to scope the file per-game
userConfigFileOptional path to a user-provided MangoHud config
Returns
Absolute path to the generated config file, or empty on failure

Definition at line 392 of file frame_metrics.cpp.

References getDefaultLogDirectory(), and Logger::warn().

Referenced by FrameMetricsService::buildMangoHudLaunchConfigFile().

◆ getDefaultLogDirectory()

std::string MangoHudLogReader::getDefaultLogDirectory ( )
static

Get the default log directory.

Returns
Path to log directory

Definition at line 295 of file frame_metrics.cpp.

References core::SettingsController::readIsolateMangoHudLogsFromDisk(), and start().

Referenced by MangoHudLogReader(), buildLaunchConfigFile(), FrameMetricsService::cleanupOldLogs(), and getLoggingConfig().

◆ getLoggingConfig()

std::string MangoHudLogReader::getLoggingConfig ( )
static

Get the MangoHud config string for logging.

Returns
Config string to pass via MANGOHUD_CONFIG

Definition at line 373 of file frame_metrics.cpp.

References getDefaultLogDirectory().

Referenced by FrameMetricsService::getMangoHudLoggingConfig().

◆ getMetrics()

FrameMetrics MangoHudLogReader::getMetrics ( ) const
overridevirtual

Get the latest metrics.

Returns
Current frame metrics (check isValid())

Implements IFrameMetricsReader.

Definition at line 812 of file frame_metrics.cpp.

◆ getSourceName()

std::string MangoHudLogReader::getSourceName ( ) const
inlineoverridevirtual

Get the source name for this reader.

Returns
Source identifier (e.g., "gamescope", "mangohud")

Implements IFrameMetricsReader.

Definition at line 326 of file frame_metrics.h.

◆ isActive()

bool MangoHudLogReader::isActive ( ) const
overridevirtual

Check if reader is actively collecting.

Returns
True if collecting metrics

Implements IFrameMetricsReader.

Definition at line 807 of file frame_metrics.cpp.

◆ isAvailable()

bool MangoHudLogReader::isAvailable ( ) const
overridevirtual

Check if this reader is available on the system.

Returns
True if the underlying source is available

Implements IFrameMetricsReader.

Definition at line 511 of file frame_metrics.cpp.

Referenced by FrameMetricsService::isMangoHudLoggingAvailable().

◆ setLogDirectory()

void MangoHudLogReader::setLogDirectory ( const std::string & path)

Set the log directory to monitor.

Parameters
pathDirectory path where MangoHud writes logs

Definition at line 505 of file frame_metrics.cpp.

◆ start()

bool MangoHudLogReader::start ( int pid)
overridevirtual

Start collecting metrics for a process.

Parameters
pidProcess ID of the game
Returns
True if successfully started

Implements IFrameMetricsReader.

Definition at line 769 of file frame_metrics.cpp.

References stop().

Referenced by getDefaultLogDirectory().

◆ stop()

void MangoHudLogReader::stop ( )
overridevirtual

Stop collecting metrics.

Implements IFrameMetricsReader.

Definition at line 797 of file frame_metrics.cpp.

Referenced by ~MangoHudLogReader(), and start().


The documentation for this class was generated from the following files: