mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
Add a /bin/top program for process table monitoring.
It automagically computes %CPU usage based on the number of times a process has been scheduled between samples. The colonel task is used as idle timer. This is pretty cool. :^)
This commit is contained in:
parent
642e2447c9
commit
c0cffe1134
8 changed files with 156 additions and 4 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "i386.h"
|
||||
#include "KSyms.h"
|
||||
#include "Console.h"
|
||||
#include "Scheduler.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
|
@ -486,9 +487,10 @@ ByteBuffer procfs$all(InodeIdentifier)
|
|||
InterruptDisabler disabler;
|
||||
auto processes = Process::all_processes();
|
||||
StringBuilder builder;
|
||||
for (auto* process : processes) {
|
||||
builder.appendf("%u,%u,%u,%u,%u,%u,%s,%u,%u,%u,%s,%s,%u,%u,%u\n",
|
||||
auto build_process_line = [&builder] (Process* process) {
|
||||
builder.appendf("%u,%u,%u,%u,%u,%u,%u,%s,%u,%u,%s,%s,%u,%u,%u\n",
|
||||
process->pid(),
|
||||
process->times_scheduled(),
|
||||
process->tty() ? process->tty()->pgid() : 0,
|
||||
process->pgid(),
|
||||
process->sid(),
|
||||
|
@ -496,7 +498,6 @@ ByteBuffer procfs$all(InodeIdentifier)
|
|||
process->gid(),
|
||||
to_string(process->state()),
|
||||
process->ppid(),
|
||||
process->times_scheduled(),
|
||||
process->number_of_open_file_descriptors(),
|
||||
process->tty() ? process->tty()->tty_name().characters() : "notty",
|
||||
process->name().characters(),
|
||||
|
@ -504,7 +505,10 @@ ByteBuffer procfs$all(InodeIdentifier)
|
|||
process->amount_resident(),
|
||||
process->amount_shared()
|
||||
);
|
||||
}
|
||||
};
|
||||
build_process_line(Scheduler::colonel());
|
||||
for (auto* process : processes)
|
||||
build_process_line(process);
|
||||
return builder.to_byte_buffer();
|
||||
}
|
||||
|
||||
|
|
|
@ -303,6 +303,11 @@ void Scheduler::prepare_to_modify_tss(Process& process)
|
|||
load_task_register(s_redirection.selector);
|
||||
}
|
||||
|
||||
Process* Scheduler::colonel()
|
||||
{
|
||||
return s_colonel_process;
|
||||
}
|
||||
|
||||
void Scheduler::initialize()
|
||||
{
|
||||
memset(&s_redirection, 0, sizeof(s_redirection));
|
||||
|
|
|
@ -18,6 +18,7 @@ public:
|
|||
static bool yield();
|
||||
static bool context_switch(Process&);
|
||||
static void prepare_to_modify_tss(Process&);
|
||||
static Process* colonel();
|
||||
private:
|
||||
static void prepare_for_iret_to_new_process();
|
||||
};
|
||||
|
|
|
@ -50,6 +50,7 @@ cp -v ../FontEditor/FontEditor mnt/bin/FontEditor
|
|||
ln -s FontEditor mnt/bin/ff
|
||||
cp -v ../Userland/dmesg mnt/bin/dmesg
|
||||
cp -v ../Userland/chmod mnt/bin/chmod
|
||||
cp -v ../Userland/top mnt/bin/top
|
||||
sh sync-local.sh
|
||||
cp -v kernel.map mnt/
|
||||
ln -s dir_a mnt/dir_cur
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue