Convert to_dynamic_unit to OwnedStringView and rename the old variant to to_dynamic_unit_cstr
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
be22cf6267
commit
41b3c8adb2
@ -4,6 +4,7 @@
|
|||||||
#include "arch/Timer.h"
|
#include "arch/Timer.h"
|
||||||
#include "boot/Init.h"
|
#include "boot/Init.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "memory/Heap.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
#include "thread/Scheduler.h"
|
#include "thread/Scheduler.h"
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
@ -23,6 +24,13 @@ void async_thread()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void heap_thread()
|
||||||
|
{
|
||||||
|
CPU::disable_interrupts();
|
||||||
|
dump_heap_usage();
|
||||||
|
while (true) kernel_sleep(UINT64_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
Result<void> init()
|
Result<void> init()
|
||||||
{
|
{
|
||||||
kinfoln("Starting Moon %s", MOON_VERSION);
|
kinfoln("Starting Moon %s", MOON_VERSION);
|
||||||
@ -33,19 +41,15 @@ Result<void> init()
|
|||||||
|
|
||||||
Timer::init();
|
Timer::init();
|
||||||
|
|
||||||
char buffer[64];
|
kinfoln("Total memory: %s", to_dynamic_unit(MemoryManager::total()).release_value().chars());
|
||||||
to_dynamic_unit(MemoryManager::total(), buffer, sizeof(buffer));
|
kinfoln("Free memory: %s", to_dynamic_unit(MemoryManager::free()).release_value().chars());
|
||||||
kinfoln("Total memory: %s", buffer);
|
kinfoln("Used memory: %s", to_dynamic_unit(MemoryManager::used()).release_value().chars());
|
||||||
to_dynamic_unit(MemoryManager::free(), buffer, sizeof(buffer));
|
kinfoln("Reserved memory: %s", to_dynamic_unit(MemoryManager::reserved()).release_value().chars());
|
||||||
kinfoln("Free memory: %s", buffer);
|
|
||||||
to_dynamic_unit(MemoryManager::used(), buffer, sizeof(buffer));
|
|
||||||
kinfoln("Used memory: %s", buffer);
|
|
||||||
to_dynamic_unit(MemoryManager::reserved(), buffer, sizeof(buffer));
|
|
||||||
kinfoln("Reserved memory: %s", buffer);
|
|
||||||
|
|
||||||
Scheduler::init();
|
Scheduler::init();
|
||||||
|
|
||||||
TRY(Scheduler::new_kernel_thread(async_thread));
|
TRY(Scheduler::new_kernel_thread(async_thread));
|
||||||
|
TRY(Scheduler::new_kernel_thread(heap_thread));
|
||||||
|
|
||||||
CPU::platform_finish_init();
|
CPU::platform_finish_init();
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <luna/OwnedStringView.h>
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
|
|
||||||
Result<usize> to_dynamic_unit(usize value, char* buffer, usize max);
|
Result<usize> to_dynamic_unit_cstr(usize value, char* buffer, usize max);
|
||||||
|
Result<OwnedStringView> to_dynamic_unit(usize value);
|
@ -1,8 +1,10 @@
|
|||||||
|
#include <luna/Alloc.h>
|
||||||
#include <luna/Format.h>
|
#include <luna/Format.h>
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
|
#include <luna/ScopeGuard.h>
|
||||||
#include <luna/Units.h>
|
#include <luna/Units.h>
|
||||||
|
|
||||||
Result<usize> to_dynamic_unit(usize value, char* buffer, usize max)
|
Result<usize> to_dynamic_unit_cstr(usize value, char* buffer, usize max)
|
||||||
{
|
{
|
||||||
if (value < 1024) { return string_format(buffer, max, "%u bytes", value); }
|
if (value < 1024) { return string_format(buffer, max, "%u bytes", value); }
|
||||||
|
|
||||||
@ -14,4 +16,17 @@ Result<usize> to_dynamic_unit(usize value, char* buffer, usize max)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return string_format(buffer, max, "%u.%u %ciB", value / 1024, (value % 1024) / 103, *unit_prefixes);
|
return string_format(buffer, max, "%u.%u %ciB", value / 1024, (value % 1024) / 103, *unit_prefixes);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<OwnedStringView> to_dynamic_unit(usize value)
|
||||||
|
{
|
||||||
|
char* buf = TRY(make_array<char>(64));
|
||||||
|
|
||||||
|
auto guard = make_scope_guard([&] { destroy_array(buf); });
|
||||||
|
|
||||||
|
TRY(to_dynamic_unit_cstr(value, buf, 64));
|
||||||
|
|
||||||
|
guard.deactivate();
|
||||||
|
|
||||||
|
return OwnedStringView{buf};
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user