From 712ae73581a1b44b36654824229f9cc475381c34 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 26 Nov 2019 21:25:45 +0100 Subject: Kernel: Expose per-thread information in /proc/all Previously it was not possible to see what each thread in a process was up to, or how much CPU it was consuming. This patch fixes that. SystemMonitor and "top" now show threads instead of just processes. "ps" is gonna need some more fixing, but it at least builds for now. Fixes #66. --- Kernel/FileSystem/ProcFS.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'Kernel') diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index bb7a86d7bc..928719b4fe 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -677,13 +677,11 @@ Optional procfs$all(InodeIdentifier) auto build_process = [&](const Process& process) { auto process_object = array.add_object(); process_object.add("pid", process.pid()); - process_object.add("times_scheduled", process.main_thread().times_scheduled()); process_object.add("pgid", process.tty() ? process.tty()->pgid() : 0); process_object.add("pgp", process.pgid()); process_object.add("sid", process.sid()); process_object.add("uid", process.uid()); process_object.add("gid", process.gid()); - process_object.add("state", process.main_thread().state_string()); process_object.add("ppid", process.ppid()); process_object.add("nfds", process.number_of_open_file_descriptors()); process_object.add("name", process.name()); @@ -691,13 +689,21 @@ Optional procfs$all(InodeIdentifier) process_object.add("amount_virtual", (u32)process.amount_virtual()); process_object.add("amount_resident", (u32)process.amount_resident()); process_object.add("amount_shared", (u32)process.amount_shared()); - process_object.add("ticks", process.main_thread().ticks()); - process_object.add("priority", to_string(process.main_thread().priority())); process_object.add("syscall_count", process.syscall_count()); process_object.add("inode_faults", process.inode_faults()); process_object.add("zero_faults", process.zero_faults()); process_object.add("cow_faults", process.cow_faults()); process_object.add("icon_id", process.icon_id()); + auto thread_array = process_object.add_array("threads"); + process.for_each_thread([&](const Thread& thread) { + auto thread_object = thread_array.add_object(); + thread_object.add("tid", thread.tid()); + thread_object.add("times_scheduled", thread.times_scheduled()); + thread_object.add("ticks", thread.ticks()); + thread_object.add("state", thread.state_string()); + thread_object.add("priority", to_string(thread.priority())); + return IterationDecision::Continue; + }); }; build_process(*Scheduler::colonel()); for (auto* process : processes) -- cgit v1.2.3