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

Singleton service managing frame metrics collection. More...

#include <frame_metrics.h>

Public Member Functions

std::string buildMangoHudLaunchConfigFile (const std::string &gameId, const std::string &userConfigFile={}) const
 Materialise a complete MangoHud config file for a launch.
int cleanupOldLogs (int maxAgeHours=24)
 Clean up old MangoHud log files.
std::string getMangoHudLoggingConfig () const
 Get MangoHud config for enabling logging.
FrameMetrics getMetrics (const std::string &gameId) const
 Get current metrics for a game.
bool isCollecting (const std::string &gameId) const
 Check if collection is active for a game.
bool isGamescopeAvailable () const
 Check if gamescope is available.
bool isMangoHudLoggingAvailable () const
 Check if MangoHud logging is available.
bool startCollection (const std::string &gameId, int pid, bool useGamescope=false, bool enableMangoHudLogging=true)
 Start collecting metrics for a game.
void stopAll ()
 Stop all active collections.
void stopCollection (const std::string &gameId)
 Stop collecting metrics for a game.

Static Public Member Functions

static FrameMetricsService & instance ()
 Get the singleton instance.

Detailed Description

Singleton service managing frame metrics collection.

Provides a unified interface for collecting frame metrics from running games. Automatically selects the best available source (gamescope > mangohud).

Usage:

// Start collecting for a game
FrameMetricsService::instance().startCollection(gameId, pid, useGamescope);
// Get current metrics
auto metrics = FrameMetricsService::instance().getMetrics(gameId);
if (metrics.isValid()) {
std::cout << "FPS: " << metrics.fps << std::endl;
}
// Stop when game exits
bool startCollection(const std::string &gameId, int pid, bool useGamescope=false, bool enableMangoHudLogging=true)
Start collecting metrics for a game.
FrameMetrics getMetrics(const std::string &gameId) const
Get current metrics for a game.
static FrameMetricsService & instance()
Get the singleton instance.
void stopCollection(const std::string &gameId)
Stop collecting metrics for a game.

Definition at line 432 of file frame_metrics.h.

Member Function Documentation

◆ buildMangoHudLaunchConfigFile()

std::string FrameMetricsService::buildMangoHudLaunchConfigFile ( const std::string & gameId,
const std::string & userConfigFile = {} ) const

Materialise a complete MangoHud config file for a launch.

Thin wrapper over MangoHudLogReader::buildLaunchConfigFile. Returns a path suitable for passing via MANGOHUD_CONFIGFILE, which fully replaces the user's ~/.config/MangoHud/MangoHud.conf during the launch.

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 1059 of file frame_metrics.cpp.

References MangoHudLogReader::buildLaunchConfigFile().

Referenced by anonymous_namespace{game_process.cpp}::buildWrapperChain().

◆ cleanupOldLogs()

int FrameMetricsService::cleanupOldLogs ( int maxAgeHours = 24)

Clean up old MangoHud log files.

Parameters
maxAgeHoursDelete completed logs older than this (default 24 hours)
Returns
Number of files deleted

Deletes completed MangoHud log files (those with _summary.csv siblings) that are older than the specified age. Active logs are never deleted.

Definition at line 1065 of file frame_metrics.cpp.

References Logger::debug(), MangoHudLogReader::getDefaultLogDirectory(), Logger::info(), and Logger::warn().

Referenced by MainWindow::MainWindow().

◆ getMangoHudLoggingConfig()

std::string FrameMetricsService::getMangoHudLoggingConfig ( ) const

Get MangoHud config for enabling logging.

Returns
Config string to append to MANGOHUD_CONFIG

Definition at line 1053 of file frame_metrics.cpp.

References MangoHudLogReader::getLoggingConfig().

◆ getMetrics()

FrameMetrics FrameMetricsService::getMetrics ( const std::string & gameId) const

Get current metrics for a game.

Parameters
gameIdGame identifier
Returns
Frame metrics (check isValid() before use)

Definition at line 1016 of file frame_metrics.cpp.

Referenced by DetailsPanelManager::Impl::update(), and DetailsPanelManager::Impl::updateRunningInfo().

◆ instance()

◆ isCollecting()

bool FrameMetricsService::isCollecting ( const std::string & gameId) const

Check if collection is active for a game.

Parameters
gameIdGame identifier
Returns
True if actively collecting

Definition at line 1029 of file frame_metrics.cpp.

Referenced by DetailsPanelManager::Impl::update(), and DetailsPanelManager::Impl::updateRunningInfo().

◆ isGamescopeAvailable()

bool FrameMetricsService::isGamescopeAvailable ( ) const

Check if gamescope is available.

Returns
True if gamescope metrics can be collected

Definition at line 1037 of file frame_metrics.cpp.

◆ isMangoHudLoggingAvailable()

bool FrameMetricsService::isMangoHudLoggingAvailable ( ) const

Check if MangoHud logging is available.

Returns
True if MangoHud log reading is available

Definition at line 1047 of file frame_metrics.cpp.

References MangoHudLogReader::isAvailable().

◆ startCollection()

bool FrameMetricsService::startCollection ( const std::string & gameId,
int pid,
bool useGamescope = false,
bool enableMangoHudLogging = true )

Start collecting metrics for a game.

Parameters
gameIdUnique game identifier
pidProcess ID of the game
useGamescopeTrue if game is running through gamescope
enableMangoHudLoggingTrue to enable MangoHud logging config
Returns
True if collection started successfully

Definition at line 944 of file frame_metrics.cpp.

References Logger::debug(), and Logger::info().

Referenced by GameProcess::launch(), and GameProcessManager::launchGame().

◆ stopAll()

void FrameMetricsService::stopAll ( )

Stop all active collections.

Definition at line 1005 of file frame_metrics.cpp.

◆ stopCollection()

void FrameMetricsService::stopCollection ( const std::string & gameId)

Stop collecting metrics for a game.

Parameters
gameIdGame identifier to stop

Definition at line 992 of file frame_metrics.cpp.

References Logger::debug().

Referenced by GameProcess::stop(), and GameProcess::update().


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