From afe099388e02f6e5a63e20d4bb6d51c62d2ad039 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Wed, 3 Mar 2021 01:00:41 -0800 Subject: [PATCH] Kernel: Add 'boot_prof' option to enable full system profiling on boot The full system profiling functionality is useful for profiling the boot performance of the system. Add a new kernel boot option to start the system with profiling enabled. This lets you disable and view a profile once the system is booted. You can use it by running: ``` $ run.sh qcmd boot_prof ``` --- Kernel/CommandLine.cpp | 5 +++++ Kernel/CommandLine.h | 1 + Kernel/init.cpp | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Kernel/CommandLine.cpp b/Kernel/CommandLine.cpp index 005cd6080fe..fdb09c4d413 100644 --- a/Kernel/CommandLine.cpp +++ b/Kernel/CommandLine.cpp @@ -88,6 +88,11 @@ bool CommandLine::contains(const String& key) const return m_params.contains(key); } +UNMAP_AFTER_INIT bool CommandLine::is_boot_profiling_enabled() const +{ + return contains("boot_prof"); +} + UNMAP_AFTER_INIT bool CommandLine::is_ide_enabled() const { return !contains("disable_ide"); diff --git a/Kernel/CommandLine.h b/Kernel/CommandLine.h index 0e15bb70a88..75a236bbcd1 100644 --- a/Kernel/CommandLine.h +++ b/Kernel/CommandLine.h @@ -61,6 +61,7 @@ public: Optional lookup(const String& key) const; [[nodiscard]] bool contains(const String& key) const; + [[nodiscard]] bool is_boot_profiling_enabled() const; [[nodiscard]] bool is_ide_enabled() const; [[nodiscard]] bool is_smp_enabled() const; [[nodiscard]] bool is_vmmouse_enabled() const; diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 5c13864361d..5e21279d2e7 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -246,7 +246,7 @@ void init_stage2(void*) FinalizerTask::spawn(); PCI::initialize(); - + auto boot_profiling = kernel_command_line().is_boot_profiling_enabled(); auto is_text_mode = kernel_command_line().is_text_mode(); if (is_text_mode) { dbgln("Text mode enabled"); @@ -319,6 +319,12 @@ void init_stage2(void*) } thread->set_priority(THREAD_PRIORITY_HIGH); + if (boot_profiling) { + dbgln("Starting full system boot profiling"); + auto result = Process::current()->sys$profiling_enable(-1); + VERIFY(!result.is_error()); + } + NetworkTask::spawn(); Process::current()->sys$exit(0);