game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
performance_profile_service.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// performance_profile_service.h
4// ==============================================================================
5// Per-Game Performance Profile Management
6// ==============================================================================
7// Provides Steam Deck-style per-game performance profiles that allow users
8// to save and load different performance configurations for each game.
9//
10// ## About Performance Profiles
11// Performance profiles capture all the performance-related settings for a game:
12// - Framerate limits (FPS cap, VRR, refresh rate)
13// - Scaling settings (FSR, DLSS, resolution)
14// - Performance wrappers (MangoHud, GameMode, Gamescope)
15// - GPU settings (TDP limit, clock speeds for laptops)
16// - Wine/Proton sync settings (Fsync, Esync)
17// - CPU governor preferences
18//
19// ## Usage Example
20// @code
21// PerformanceProfileService profiles;
22//
23// // Save current game config as a profile
24// profiles.saveProfile("game-123", "High Performance", currentConfig);
25//
26// // List available profiles for a game
27// auto gameProfiles = profiles.getProfiles("game-123");
28//
29// // Load a profile
30// auto config = profiles.loadProfile("game-123", "High Performance");
31// @endcode
32//
33// ## References
34// - Steam Deck Performance Profiles
35// - CachyOS game-performance wrapper
36// ==============================================================================
37
38#pragma once
39
40#include <chrono>
41#include <functional>
42#include <map>
43#include <memory>
44#include <optional>
45#include <string>
46#include <vector>
47
48// ==============================================================================
49// Data Structures
50// ==============================================================================
51
52/**
53 * @enum PerformancePreset
54 * @brief Built-in performance presets
55 */
57{
58 Custom, ///< User-defined settings
59 BatteryLife, ///< Maximize battery life (30 FPS, low TDP)
60 Balanced, ///< Balance performance and efficiency
61 Performance, ///< Maximize performance
62 Quality, ///< Maximize visual quality
63 Compatibility, ///< Maximum compatibility (disable optimizations)
64 Silent ///< Minimize fan noise (thermal throttle acceptable)
65};
66
67/**
68 * @struct FramerateSettings
69 * @brief Framerate and refresh rate settings
70 */
72{
73 int fpsLimit = 0; ///< FPS limit (0 = unlimited)
74 int refreshRate = 0; ///< Target refresh rate (0 = native)
75 bool enableVRR = false; ///< Enable Variable Refresh Rate
76 bool halfRateShading = false; ///< Enable half-rate shading (power saving)
77
78 // Gamescope-specific
79 bool useGamescope = false; ///< Use Gamescope compositor
80 int gamescopeUnfocusedFps = 0; ///< FPS when unfocused (0 = same as focused)
81};
82
83/**
84 * @struct ScalingSettings
85 * @brief Resolution and upscaling settings
86 */
88{
89 // Resolution
90 int internalWidth = 0; ///< Internal render width (0 = native)
91 int internalHeight = 0; ///< Internal render height (0 = native)
92 int outputWidth = 0; ///< Output/display width (0 = native)
93 int outputHeight = 0; ///< Output/display height (0 = native)
94
95 // Upscaling
96 bool enableFSR = false; ///< AMD FSR upscaling
97 int fsrSharpness = 5; ///< FSR sharpness (0-20, 0 = max sharp)
98
99 bool enableDLSS = false; ///< NVIDIA DLSS (if available)
100 bool enableXeSS = false; ///< Intel XeSS (if available)
101
102 // Integer scaling
103 bool enableIntegerScale = false; ///< Force integer scaling
104 int scaleFactor = 1; ///< Integer scale factor (1, 2, 3...)
105};
106
107/**
108 * @struct WrapperSettings
109 * @brief Performance wrapper/overlay settings
110 */
112{
113 bool enableMangoHud = false; ///< MangoHud overlay
114 std::string mangoHudConfig; ///< Custom MangoHud config string
115
116 bool enableGameMode = false; ///< Feral GameMode
117 bool enableGamePerformance = false; ///< CachyOS game-performance
118
119 bool enableVkBasalt = false; ///< VkBasalt post-processing
120 std::string vkBasaltEffects; ///< VkBasalt effects to use
121};
122
123/**
124 * @struct PowerSettings
125 * @brief Power and thermal settings (for portable devices)
126 */
128{
129 int tdpLimit = 0; ///< TDP limit in watts (0 = default)
130 int gpuClockLimit = 0; ///< GPU max clock in MHz (0 = default)
131 std::string cpuGovernor; ///< CPU governor preference (empty = no change)
132
133 bool allowBoost = true; ///< Allow CPU/GPU boost clocks
134 int fanCurvePreset = 0; ///< Fan curve preset (0 = default)
135};
136
137/**
138 * @struct SyncSettings
139 * @brief Wine/Proton synchronization settings
140 */
142{
143 bool autoDetect = true; ///< Auto-detect best sync method
144 bool enableFsync = true; ///< Use Fsync if available
145 bool enableEsync = true; ///< Use Esync if Fsync unavailable
146 bool enableNTSync = false; ///< Use NTSync (experimental, kernel 6.14+)
147};
148
149/**
150 * @struct PerformanceProfile
151 * @brief Complete performance profile for a game
152 */
154{
155 // Identification
156 std::string id; ///< Unique profile ID
157 std::string name; ///< Display name (e.g., "High Performance")
158 std::string description; ///< Optional description
160
161 // Settings groups
167
168 // Custom environment variables
169 std::map<std::string, std::string> environmentVariables;
170
171 // Metadata
172 time_t createdAt = 0; ///< When profile was created
173 time_t lastUsedAt = 0; ///< When profile was last applied
174 int useCount = 0; ///< Number of times profile was used
175
176 // Linked games (for shared profiles)
177 std::vector<std::string> linkedGameIds;
178
179 /**
180 * @brief Check if this is the default profile
181 */
182 bool isDefault() const
183 {
184 return name == "Default";
185 }
186
187 /**
188 * @brief Get a summary string of the profile settings
189 */
190 std::string getSummary() const;
191};
192
193/**
194 * @struct GamePerformanceData
195 * @brief Performance data and profiles for a specific game
196 */
198{
199 std::string gameId; ///< Game this data belongs to
200 std::vector<PerformanceProfile> profiles; ///< Available profiles
201 std::string activeProfileId; ///< Currently active profile ID
202
203 // Performance history (for suggestions)
204 double avgFps = 0.0; ///< Average FPS across sessions
205 double avgFrametime = 0.0; ///< Average frametime in ms
206 int sessionCount = 0; ///< Number of sessions with metrics
207};
208
209// ==============================================================================
210// PerformanceProfileService Class
211// ==============================================================================
212
213/**
214 * @class PerformanceProfileService
215 * @brief Service for managing per-game performance profiles
216 *
217 * Provides Steam Deck-style performance profile management, allowing users
218 * to save and switch between different performance configurations per game.
219 */
221{
222 public:
224 std::function<void(const std::string& gameId, const std::string& profileId)>;
225
228
229 // Non-copyable
232
233 // ==========================================================================
234 // Initialization
235 // ==========================================================================
236
237 /**
238 * @brief Initialize the service with a data directory
239 * @param dataDir Directory to store profile data
240 * @return True if initialization succeeded
241 */
242 bool initialize(const std::string& dataDir);
243
244 /**
245 * @brief Check if service is initialized
246 */
247 bool isInitialized() const;
248
249 // ==========================================================================
250 // Profile Management
251 // ==========================================================================
252
253 /**
254 * @brief Create a new performance profile for a game
255 * @param gameId Game ID
256 * @param profile Profile to create
257 * @return True if created successfully
258 */
259 bool createProfile(const std::string& gameId, const PerformanceProfile& profile);
260
261 /**
262 * @brief Update an existing profile
263 * @param gameId Game ID
264 * @param profile Updated profile (matched by profile.id)
265 * @return True if updated successfully
266 */
267 bool updateProfile(const std::string& gameId, const PerformanceProfile& profile);
268
269 /**
270 * @brief Delete a profile
271 * @param gameId Game ID
272 * @param profileId Profile ID to delete
273 * @return True if deleted successfully
274 */
275 bool deleteProfile(const std::string& gameId, const std::string& profileId);
276
277 /**
278 * @brief Duplicate an existing profile
279 * @param gameId Game ID
280 * @param sourceProfileId Profile to duplicate
281 * @param newName Name for the duplicate
282 * @return New profile ID, or empty if failed
283 */
284 std::string duplicateProfile(const std::string& gameId, const std::string& sourceProfileId,
285 const std::string& newName);
286
287 // ==========================================================================
288 // Profile Retrieval
289 // ==========================================================================
290
291 /**
292 * @brief Get all profiles for a game
293 * @param gameId Game ID
294 * @return Vector of profiles
295 */
296 std::vector<PerformanceProfile> getProfiles(const std::string& gameId) const;
297
298 /**
299 * @brief Get a specific profile
300 * @param gameId Game ID
301 * @param profileId Profile ID
302 * @return Profile if found
303 */
304 std::optional<PerformanceProfile> getProfile(const std::string& gameId,
305 const std::string& profileId) const;
306
307 /**
308 * @brief Get the active profile for a game
309 * @param gameId Game ID
310 * @return Active profile if one is set
311 */
312 std::optional<PerformanceProfile> getActiveProfile(const std::string& gameId) const;
313
314 /**
315 * @brief Set the active profile for a game
316 * @param gameId Game ID
317 * @param profileId Profile ID to activate
318 * @return True if activated successfully
319 */
320 bool setActiveProfile(const std::string& gameId, const std::string& profileId);
321
322 // ==========================================================================
323 // Preset Profiles
324 // ==========================================================================
325
326 /**
327 * @brief Create a profile from a preset
328 * @param preset Preset type
329 * @param name Custom name for the profile
330 * @return New profile configured for the preset
331 */
333 const std::string& name = "") const;
334
335 /**
336 * @brief Get the default profile template
337 * @return Default profile with balanced settings
338 */
340
341 /**
342 * @brief Create game-specific default profile based on system info
343 * @param gameId Game ID
344 * @param protondbTier ProtonDB tier for the game
345 * @return Optimized default profile
346 */
347 PerformanceProfile createSmartDefault(const std::string& gameId,
348 const std::string& protondbTier = "") const;
349
350 // ==========================================================================
351 // Profile Application
352 // ==========================================================================
353
354 /**
355 * @brief Convert a profile to environment variables
356 * @param profile Profile to convert
357 * @return Map of environment variable name -> value
358 */
359 std::map<std::string, std::string> profileToEnvVars(const PerformanceProfile& profile) const;
360
361 /**
362 * @brief Convert a profile to Gamescope arguments
363 * @param profile Profile to convert
364 * @return Gamescope command line arguments
365 */
366 std::vector<std::string> profileToGamescopeArgs(const PerformanceProfile& profile) const;
367
368 /**
369 * @brief Record performance metrics for a profile
370 * @param gameId Game ID
371 * @param profileId Profile that was active
372 * @param avgFps Average FPS achieved
373 * @param avgFrametime Average frametime achieved
374 */
375 void recordMetrics(const std::string& gameId, const std::string& profileId, double avgFps,
376 double avgFrametime);
377
378 // ==========================================================================
379 // Global Profiles
380 // ==========================================================================
381
382 /**
383 * @brief Get global profiles (shared across games)
384 * @return Vector of global profiles
385 */
386 std::vector<PerformanceProfile> getGlobalProfiles() const;
387
388 /**
389 * @brief Create a global profile
390 * @param profile Profile to create globally
391 * @return True if created successfully
392 */
393 bool createGlobalProfile(const PerformanceProfile& profile);
394
395 /**
396 * @brief Link a game to use a global profile
397 * @param gameId Game ID
398 * @param globalProfileId Global profile ID
399 * @return True if linked successfully
400 */
401 bool linkToGlobalProfile(const std::string& gameId, const std::string& globalProfileId);
402
403 // ==========================================================================
404 // Import/Export
405 // ==========================================================================
406
407 /**
408 * @brief Export a profile to JSON
409 * @param profile Profile to export
410 * @return JSON string
411 */
412 std::string exportProfileToJson(const PerformanceProfile& profile) const;
413
414 /**
415 * @brief Import a profile from JSON
416 * @param json JSON string
417 * @return Parsed profile if valid
418 */
419 std::optional<PerformanceProfile> importProfileFromJson(const std::string& json) const;
420
421 /**
422 * @brief Export all profiles for a game
423 * @param gameId Game ID
424 * @param filePath Output file path
425 * @return True if export succeeded
426 */
427 bool exportGameProfiles(const std::string& gameId, const std::string& filePath) const;
428
429 /**
430 * @brief Import profiles for a game
431 * @param gameId Game ID
432 * @param filePath Input file path
433 * @return Number of profiles imported
434 */
435 int importGameProfiles(const std::string& gameId, const std::string& filePath);
436
437 // ==========================================================================
438 // Events
439 // ==========================================================================
440
442
443 // ==========================================================================
444 // Statistics
445 // ==========================================================================
446
447 /**
448 * @brief Get total number of profiles
449 */
450 int getTotalProfileCount() const;
451
452 /**
453 * @brief Get number of games with custom profiles
454 */
455 int getGamesWithProfilesCount() const;
456
457 /**
458 * @brief Get most used profile for a game
459 * @param gameId Game ID
460 * @return Most used profile if data available
461 */
462 std::optional<PerformanceProfile> getMostUsedProfile(const std::string& gameId) const;
463
464 private:
465 class Impl;
466 std::unique_ptr<Impl> impl_;
467};
468
469/**
470 * @brief Get human-readable preset name
471 */
472std::string performancePresetName(PerformancePreset preset);
PerformanceProfile getDefaultProfile() const
Get the default profile template.
std::vector< std::string > profileToGamescopeArgs(const PerformanceProfile &profile) const
Convert a profile to Gamescope arguments.
bool initialize(const std::string &dataDir)
Initialize the service with a data directory.
void setOnProfileChanged(OnProfileChanged callback)
PerformanceProfileService(const PerformanceProfileService &)=delete
std::optional< PerformanceProfile > getActiveProfile(const std::string &gameId) const
Get the active profile for a game.
bool setActiveProfile(const std::string &gameId, const std::string &profileId)
Set the active profile for a game.
std::function< void(const std::string &gameId, const std::string &profileId)> OnProfileChanged
int getTotalProfileCount() const
Get total number of profiles.
std::optional< PerformanceProfile > getMostUsedProfile(const std::string &gameId) const
Get most used profile for a game.
std::map< std::string, std::string > profileToEnvVars(const PerformanceProfile &profile) const
Convert a profile to environment variables.
bool createGlobalProfile(const PerformanceProfile &profile)
Create a global profile.
std::optional< PerformanceProfile > getProfile(const std::string &gameId, const std::string &profileId) const
Get a specific profile.
bool deleteProfile(const std::string &gameId, const std::string &profileId)
Delete a profile.
PerformanceProfile createFromPreset(PerformancePreset preset, const std::string &name="") const
Create a profile from a preset.
bool updateProfile(const std::string &gameId, const PerformanceProfile &profile)
Update an existing profile.
int getGamesWithProfilesCount() const
Get number of games with custom profiles.
std::vector< PerformanceProfile > getProfiles(const std::string &gameId) const
Get all profiles for a game.
bool exportGameProfiles(const std::string &gameId, const std::string &filePath) const
Export all profiles for a game.
bool isInitialized() const
Check if service is initialized.
PerformanceProfileService & operator=(const PerformanceProfileService &)=delete
bool linkToGlobalProfile(const std::string &gameId, const std::string &globalProfileId)
Link a game to use a global profile.
void recordMetrics(const std::string &gameId, const std::string &profileId, double avgFps, double avgFrametime)
Record performance metrics for a profile.
PerformanceProfile createSmartDefault(const std::string &gameId, const std::string &protondbTier="") const
Create game-specific default profile based on system info.
bool createProfile(const std::string &gameId, const PerformanceProfile &profile)
Create a new performance profile for a game.
std::string exportProfileToJson(const PerformanceProfile &profile) const
Export a profile to JSON.
std::vector< PerformanceProfile > getGlobalProfiles() const
Get global profiles (shared across games).
std::string duplicateProfile(const std::string &gameId, const std::string &sourceProfileId, const std::string &newName)
Duplicate an existing profile.
std::optional< PerformanceProfile > importProfileFromJson(const std::string &json) const
Import a profile from JSON.
int importGameProfiles(const std::string &gameId, const std::string &filePath)
Import profiles for a game.
nlohmann::json json
std::string performancePresetName(PerformancePreset preset)
Get human-readable preset name.
PerformancePreset
Built-in performance presets.
@ Silent
Minimize fan noise (thermal throttle acceptable).
@ BatteryLife
Maximize battery life (30 FPS, low TDP).
@ Quality
Maximize visual quality.
@ Custom
User-defined settings.
@ Performance
Maximize performance.
@ Balanced
Balance performance and efficiency.
@ Compatibility
Maximum compatibility (disable optimizations).
Framerate and refresh rate settings.
bool halfRateShading
Enable half-rate shading (power saving).
bool enableVRR
Enable Variable Refresh Rate.
int refreshRate
Target refresh rate (0 = native).
int fpsLimit
FPS limit (0 = unlimited).
int gamescopeUnfocusedFps
FPS when unfocused (0 = same as focused).
bool useGamescope
Use Gamescope compositor.
Performance data and profiles for a specific game.
double avgFrametime
Average frametime in ms.
double avgFps
Average FPS across sessions.
int sessionCount
Number of sessions with metrics.
std::string activeProfileId
Currently active profile ID.
std::string gameId
Game this data belongs to.
std::vector< PerformanceProfile > profiles
Available profiles.
Complete performance profile for a game.
time_t lastUsedAt
When profile was last applied.
std::vector< std::string > linkedGameIds
std::string description
Optional description.
std::string getSummary() const
Get a summary string of the profile settings.
std::string id
Unique profile ID.
std::map< std::string, std::string > environmentVariables
int useCount
Number of times profile was used.
time_t createdAt
When profile was created.
std::string name
Display name (e.g., "High Performance").
bool isDefault() const
Check if this is the default profile.
Power and thermal settings (for portable devices).
std::string cpuGovernor
CPU governor preference (empty = no change).
bool allowBoost
Allow CPU/GPU boost clocks.
int tdpLimit
TDP limit in watts (0 = default).
int gpuClockLimit
GPU max clock in MHz (0 = default).
int fanCurvePreset
Fan curve preset (0 = default).
Resolution and upscaling settings.
bool enableFSR
AMD FSR upscaling.
int outputHeight
Output/display height (0 = native).
int internalWidth
Internal render width (0 = native).
bool enableDLSS
NVIDIA DLSS (if available).
bool enableXeSS
Intel XeSS (if available).
int internalHeight
Internal render height (0 = native).
int scaleFactor
Integer scale factor (1, 2, 3...).
int outputWidth
Output/display width (0 = native).
int fsrSharpness
FSR sharpness (0-20, 0 = max sharp).
bool enableIntegerScale
Force integer scaling.
Wine/Proton synchronization settings.
bool autoDetect
Auto-detect best sync method.
bool enableNTSync
Use NTSync (experimental, kernel 6.14+).
bool enableEsync
Use Esync if Fsync unavailable.
bool enableFsync
Use Fsync if available.
Performance wrapper/overlay settings.
std::string vkBasaltEffects
VkBasalt effects to use.
std::string mangoHudConfig
Custom MangoHud config string.
bool enableGameMode
Feral GameMode.
bool enableVkBasalt
VkBasalt post-processing.
bool enableGamePerformance
CachyOS game-performance.
bool enableMangoHud
MangoHud overlay.