summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-04 10:28:12 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-04 10:28:12 +0100
commitc0cffe1134bc286d24199813726e7b929f414b67 (patch)
tree3fc42e0e95abed37324a1e13362679015f539868 /Kernel
parent642e2447c99db6e10b625d9899336c7fea8d59ec (diff)
downloadserenity-c0cffe1134bc286d24199813726e7b929f414b67.zip
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. :^)
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/ProcFS.cpp12
-rw-r--r--Kernel/Scheduler.cpp5
-rw-r--r--Kernel/Scheduler.h1
-rwxr-xr-xKernel/sync.sh1
4 files changed, 15 insertions, 4 deletions
diff --git a/Kernel/ProcFS.cpp b/Kernel/ProcFS.cpp
index 86d1eb501b..f80a2be543 100644
--- a/Kernel/ProcFS.cpp
+++ b/Kernel/ProcFS.cpp
@@ -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();
}
diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp
index 8cc88c2492..62c0178619 100644
--- a/Kernel/Scheduler.cpp
+++ b/Kernel/Scheduler.cpp
@@ -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));
diff --git a/Kernel/Scheduler.h b/Kernel/Scheduler.h
index 813939f5bb..bd6f3f4ddc 100644
--- a/Kernel/Scheduler.h
+++ b/Kernel/Scheduler.h
@@ -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();
};
diff --git a/Kernel/sync.sh b/Kernel/sync.sh
index bb5a353045..c71ea67092 100755
--- a/Kernel/sync.sh
+++ b/Kernel/sync.sh
@@ -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