kernel: Add keyboard combinations for debug information dumps

Ctrl+Alt+E: Dump threads
Ctrl+Alt+M: Dump memory usage
Ctrl+Alt+H: Dump heap state
This commit is contained in:
apio 2023-05-04 23:32:48 +02:00
parent 3ed9e578c7
commit 3a1c22bb93
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 48 additions and 0 deletions

View File

@ -1,10 +1,13 @@
#include "fs/devices/ConsoleDevice.h"
#include "Log.h"
#include "arch/Keyboard.h"
#include "memory/MemoryManager.h"
#include "thread/Scheduler.h"
#include "video/TextConsole.h"
#include <bits/termios.h>
#include <luna/Buffer.h>
#include <luna/CString.h>
#include <luna/Units.h>
#include <luna/Vector.h>
static Buffer g_console_input;
@ -63,6 +66,27 @@ void ConsoleDevice::did_press_key(char key)
return;
}
if (key == 'e' && (Keyboard::modifiers() & (Keyboard::LeftAlt | Keyboard::LeftControl)))
{
Scheduler::dump_state();
return;
}
if (key == 'm' && (Keyboard::modifiers() & (Keyboard::LeftAlt | Keyboard::LeftControl)))
{
kinfoln("Total memory: %s", to_dynamic_unit(MemoryManager::total()).release_value().chars());
kinfoln("Free memory: %s", to_dynamic_unit(MemoryManager::free()).release_value().chars());
kinfoln("Used memory: %s", to_dynamic_unit(MemoryManager::used()).release_value().chars());
kinfoln("Reserved memory: %s", to_dynamic_unit(MemoryManager::reserved()).release_value().chars());
return;
}
if (key == 'h' && (Keyboard::modifiers() & (Keyboard::LeftAlt | Keyboard::LeftControl)))
{
dump_heap_usage();
return;
}
g_temp_input.try_append((u8)key).value();
if (key == '\n')

View File

@ -327,6 +327,28 @@ namespace Scheduler
return result;
}
void dump_state()
{
CPU::disable_interrupts();
kdbgln("--- BEGIN SCHEDULER DUMP ---");
kdbgln("current at %p, id = %zu", g_current, g_current->id);
for (const auto* thread : g_threads)
{
kdbgln("%p %c [%-20s] %4zu, parent = (%-18p,%zu), state = %d, ticks: (t:%04zu,k:%04zu,u:%04zu), status = "
"%d, cwd = %s",
thread, thread->is_kernel ? 'k' : 'u', thread->name.chars(), thread->id, thread->parent,
thread->parent ? thread->parent->id : 0, (int)thread->state, thread->ticks, thread->ticks_in_kernel,
thread->ticks_in_user, thread->status,
thread->current_directory_path.is_empty() ? "/" : thread->current_directory_path.chars());
}
kdbgln("--- END SCHEDULER DUMP ---");
CPU::enable_interrupts();
}
}
void kernel_sleep(u64 ms)

View File

@ -45,6 +45,8 @@ namespace Scheduler
}
}
void dump_state();
bool has_children(Thread* thread);
Option<Thread*> find_exited_child(Thread* thread);