From 017caabebb62c23924462890c9b115ee23e1bb57 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sat, 3 Feb 2024 15:26:01 +0100 Subject: [PATCH] feat(launcher): Integrate procmon as optional dependency Integrate this as an optional dependency into launcher and load it dynamically. Thus, these can be easily loaded/enabled by developers and end-users. --- src/main/launcher/Module.mk | 1 + src/main/launcher/launcher-config.c | 11 ++++++- src/main/launcher/launcher-config.h | 3 ++ src/main/launcher/launcher.c | 46 ++++++++++++++++++++++++++--- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/main/launcher/Module.mk b/src/main/launcher/Module.mk index df84eba..cdf2dc7 100644 --- a/src/main/launcher/Module.mk +++ b/src/main/launcher/Module.mk @@ -14,6 +14,7 @@ libs_launcher := \ hook \ util \ dwarfstack \ + procmon-lib \ src_launcher := \ avs-config.c \ diff --git a/src/main/launcher/launcher-config.c b/src/main/launcher/launcher-config.c index aaecd3e..e2f7bb2 100644 --- a/src/main/launcher/launcher-config.c +++ b/src/main/launcher/launcher-config.c @@ -15,8 +15,14 @@ PSMAP_BEGIN(launcher_debug_psmap) PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, remote_debugger, "debug/remote_debugger", false) - PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, log_property_configs, +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, log_property_configs, "debug/log_property_configs", false) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, procmon_file, + "debug/procmon/file", false) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, procmon_module, + "debug/procmon/module", false) +PSMAP_OPTIONAL(PSMAP_TYPE_BOOL, struct launcher_debug_config, procmon_thread, + "debug/procmon/thread", false) PSMAP_END // clang-format on @@ -192,6 +198,9 @@ void launcher_config_init(struct launcher_config *config) config->debug.remote_debugger = false; config->debug.log_property_configs = false; + config->debug.procmon_file = false; + config->debug.procmon_module = false; + config->debug.procmon_thread = false; } void launcher_config_load( diff --git a/src/main/launcher/launcher-config.h b/src/main/launcher/launcher-config.h index 7d6b8a6..2747a70 100644 --- a/src/main/launcher/launcher-config.h +++ b/src/main/launcher/launcher-config.h @@ -36,6 +36,9 @@ struct launcher_config { struct launcher_debug_config { bool remote_debugger; bool log_property_configs; + bool procmon_file; + bool procmon_module; + bool procmon_thread; } debug; }; diff --git a/src/main/launcher/launcher.c b/src/main/launcher/launcher.c index f77c28f..494514f 100644 --- a/src/main/launcher/launcher.c +++ b/src/main/launcher/launcher.c @@ -26,6 +26,8 @@ #include "launcher/property-util.h" #include "launcher/stubs.h" +#include "procmon-lib/procmon.h" + #include "util/debug.h" #include "util/defs.h" #include "util/fs.h" @@ -232,6 +234,32 @@ _launcher_remote_debugger_trap(const struct launcher_debug_config *config) } } +static void _launcher_procmon_init( + const struct launcher_debug_config *config, + struct procmon *procmon) +{ + procmon_init(procmon); + + if (procmon_available()) { + procmon_load(procmon); + + procmon->set_loggers(log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); + procmon->init(); + + if (config->procmon_file) { + procmon->file_mon_enable(); + } + + if (config->procmon_module) { + procmon->module_mon_enable(); + } + + if (config->procmon_thread) { + procmon->thread_mon_enable(); + } + } +} + static void _launcher_bootstrap_config_load( const struct launcher_bootstrap_config *launcher_bootstrap_config, struct bootstrap_config *config) @@ -397,7 +425,8 @@ void _launcher_init( const struct options *options, struct launcher_config *launcher_config, struct bootstrap_config *bootstrap_config, - struct ea3_ident_config *ea3_ident_config) + struct ea3_ident_config *ea3_ident_config, + struct procmon *procmon) { struct property *launcher_property; @@ -448,6 +477,8 @@ void _launcher_init( _launcher_remote_debugger_trap(&launcher_config->debug); + _launcher_procmon_init(&launcher_config->debug, procmon); + _launcher_bootstrap_config_load( &launcher_config->bootstrap, bootstrap_config); _launcher_bootstrap_log_config_options_override( @@ -508,10 +539,12 @@ void _launcher_run( void _launcher_fini( struct launcher_config *launcher_config, - const struct bootstrap_config *bootstrap_config) + const struct bootstrap_config *bootstrap_config, + struct procmon *procmon) { log_assert(launcher_config); log_assert(bootstrap_config); + log_assert(procmon); bootstrap_eamuse_fini(&bootstrap_config->startup.eamuse); @@ -519,6 +552,10 @@ void _launcher_fini( bootstrap_module_game_fini(); + if (procmon->module != NULL) { + procmon_free(procmon); + } + launcher_config_fini(launcher_config); log_info("Shutdown complete"); @@ -531,13 +568,14 @@ void launcher_main(const struct options *options) struct launcher_config launcher_config; struct bootstrap_config bootstrap_config; struct ea3_ident_config ea3_ident_config; + struct procmon procmon; log_assert(options); _launcher_init( - options, &launcher_config, &bootstrap_config, &ea3_ident_config); + options, &launcher_config, &bootstrap_config, &ea3_ident_config, &procmon); _launcher_run(&launcher_config, &bootstrap_config, &ea3_ident_config); - _launcher_fini(&launcher_config, &bootstrap_config); + _launcher_fini(&launcher_config, &bootstrap_config, &procmon); } \ No newline at end of file