diff --git a/Kernel/KBuffer.h b/Kernel/KBuffer.h index 6da99d19a6..b6722d71ba 100644 --- a/Kernel/KBuffer.h +++ b/Kernel/KBuffer.h @@ -106,25 +106,25 @@ private: class KBuffer { public: - static OwnPtr try_create_with_size(size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer") + static OwnPtr try_create_with_size(size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) { - auto impl = KBufferImpl::try_create_with_size(size, access, name); + auto impl = KBufferImpl::try_create_with_size(size, access, name, strategy); if (!impl) return nullptr; return adopt_own(*new KBuffer(impl.release_nonnull())); } - static OwnPtr try_create_with_bytes(ReadonlyBytes bytes, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer") + static OwnPtr try_create_with_bytes(ReadonlyBytes bytes, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) { - auto impl = KBufferImpl::try_create_with_bytes(bytes, access, name); + auto impl = KBufferImpl::try_create_with_bytes(bytes, access, name, strategy); if (!impl) return nullptr; return adopt_own(*new KBuffer(impl.release_nonnull())); } - static KBuffer create_with_size(size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer") + static KBuffer create_with_size(size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) { - return KBuffer(KBufferImpl::create_with_size(size, access, name)); + return KBuffer(KBufferImpl::create_with_size(size, access, name, strategy)); } static KBuffer copy(const void* data, size_t size, u8 access = Region::Access::Read | Region::Access::Write, const char* name = "KBuffer") diff --git a/Kernel/Profiling.cpp b/Kernel/Profiling.cpp index de7fb545ac..08278a5c01 100644 --- a/Kernel/Profiling.cpp +++ b/Kernel/Profiling.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -36,8 +37,13 @@ namespace Kernel { namespace Profiling { -static KBufferImpl* s_profiling_buffer; static size_t s_slot_count; +static AK::Singleton KBuffer* { + auto buffer = KBuffer::try_create_with_size(8 * MiB, Region::Access::Read | Region::Access::Write, "Profiling Buffer", AllocationStrategy::AllocateNow); + s_slot_count = buffer->size() / sizeof(Sample); + return buffer.leak_ptr(); +}> + s_profiling_buffer; static size_t s_next_slot_index; static ProcessID s_pid { -1 }; @@ -62,10 +68,7 @@ void start(Process& process) executable_path() = {}; s_pid = process.pid(); - if (!s_profiling_buffer) { - s_profiling_buffer = RefPtr(KBuffer::create_with_size(8 * MiB).impl()).leak_ref(); - s_slot_count = s_profiling_buffer->size() / sizeof(Sample); - } + s_profiling_buffer.ensure_instance(); s_next_slot_index = 0; }