From 8d3db084e8e34932d6a36f62fc08613c0e57aa06 Mon Sep 17 00:00:00 2001 From: Palana Date: Sat, 11 Jul 2015 08:04:12 +0200 Subject: [PATCH] UI: Profile initialization --- obs/obs-app.cpp | 28 +++++++++++++++++++++++++++- obs/window-basic-main.cpp | 30 +++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/obs/obs-app.cpp b/obs/obs-app.cpp index 0794bd4be..5bf0e051c 100644 --- a/obs/obs-app.cpp +++ b/obs/obs-app.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include @@ -354,6 +354,7 @@ bool OBSApp::InitGlobalConfig() bool OBSApp::InitLocale() { + ProfileScope("OBSApp::InitLocale"); const char *lang = config_get_string(globalConfig, "General", "Language"); @@ -545,6 +546,8 @@ static void move_basic_to_scene_collections(void) void OBSApp::AppInit() { + ProfileScope("OBSApp::AppInit"); + if (!InitApplicationBundle()) throw "Failed to initialize application bundle"; if (!MakeUserDirs()) @@ -583,6 +586,8 @@ const char *OBSApp::GetRenderModule() const bool OBSApp::OBSInit() { + ProfileScope("OBSApp::OBSInit"); + bool licenseAccepted = config_get_bool(globalConfig, "General", "LicenseAccepted"); OBSLicenseAgreement agreement(nullptr); @@ -904,6 +909,7 @@ static auto ProfilerFree = [](void *) profiler_free(); }; +static const char *run_program_init = "run_program_init"; static int run_program(fstream &logFile, int argc, char *argv[]) { int ret = -1; @@ -915,6 +921,23 @@ static int run_program(fstream &logFile, int argc, char *argv[]) ProfilerFree); profiler_start(); + profile_register_root(run_program_init, 0); + + auto PrintInitProfile = [&]() + { + auto snap = GetSnapshot(); + + profiler_snapshot_filter_roots(snap.get(), [](void *data, + const char *name, bool *remove) + { + *remove = (*static_cast(data)) != name; + return true; + }, static_cast(&run_program_init)); + + profiler_print(snap.get()); + }; + + ScopeProfiler prof{run_program_init}; QCoreApplication::addLibraryPath("."); @@ -931,6 +954,9 @@ static int run_program(fstream &logFile, int argc, char *argv[]) if (!program.OBSInit()) return 0; + prof.Stop(); + PrintInitProfile(); + return program.exec(); } catch (const char *error) { diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index bec8431e2..c3b40056b 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "obs-app.hpp" @@ -577,6 +578,8 @@ bool OBSBasic::LoadService() bool OBSBasic::InitService() { + ProfileScope("OBSBasic::InitService"); + if (LoadService()) return true; @@ -728,6 +731,8 @@ bool OBSBasic::InitBasicConfigDefaults() bool OBSBasic::InitBasicConfig() { + ProfileScope("OBSBasic::InitBasicConfig"); + char configPath[512]; int ret = GetProfilePath(configPath, sizeof(configPath), ""); @@ -766,6 +771,8 @@ bool OBSBasic::InitBasicConfig() void OBSBasic::InitOBSCallbacks() { + ProfileScope("OBSBasic::InitOBSCallbacks"); + signalHandlers.reserve(signalHandlers.size() + 6); signalHandlers.emplace_back(obs_get_signal_handler(), "source_add", OBSBasic::SourceAdded, this); @@ -783,6 +790,8 @@ void OBSBasic::InitOBSCallbacks() void OBSBasic::InitPrimitives() { + ProfileScope("OBSBasic::InitPrimitives"); + obs_enter_graphics(); gs_render_start(true); @@ -805,6 +814,8 @@ void OBSBasic::InitPrimitives() void OBSBasic::ResetOutputs() { + ProfileScope("OBSBasic::ResetOutputs"); + const char *mode = config_get_string(basicConfig, "Output", "Mode"); bool advOut = astrcmpi(mode, "Advanced") == 0; @@ -823,6 +834,8 @@ void OBSBasic::ResetOutputs() void OBSBasic::OBSInit() { + ProfileScope("OBSBasic::OBSInit"); + const char *sceneCollection = config_get_string(App()->GlobalConfig(), "Basic", "SceneCollectionFile"); char savePath[512]; @@ -878,9 +891,12 @@ void OBSBasic::OBSInit() InitPrimitives(); - disableSaving--; - Load(savePath); - disableSaving++; + { + ProfileScope("OBSBasic::Load"); + disableSaving--; + Load(savePath); + disableSaving++; + } TimedCheckForUpdates(); loaded = true; @@ -921,6 +937,8 @@ void OBSBasic::OBSInit() void OBSBasic::InitHotkeys() { + ProfileScope("OBSBasic::InitHotkeys"); + struct obs_hotkeys_translations t = {}; t.insert = Str("Hotkeys.Insert"); t.del = Str("Hotkeys.Delete"); @@ -986,6 +1004,8 @@ void OBSBasic::HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed) void OBSBasic::CreateHotkeys() { + ProfileScope("OBSBasic::CreateHotkeys"); + auto LoadHotkeyData = [&](const char *name) -> OBSData { const char *info = config_get_string(basicConfig, @@ -2001,6 +2021,8 @@ static inline enum video_format GetVideoFormatFromName(const char *name) int OBSBasic::ResetVideo() { + ProfileScope("OBSBasic::ResetVideo"); + struct obs_video_info ovi; int ret; @@ -2052,6 +2074,8 @@ int OBSBasic::ResetVideo() bool OBSBasic::ResetAudio() { + ProfileScope("OBSBasic::ResetAudio"); + struct obs_audio_info ai; ai.samples_per_sec = config_get_uint(basicConfig, "Audio", "SampleRate");