summaryrefslogtreecommitdiff
path: root/Libraries/LibCore
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-26 21:25:45 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-26 21:37:30 +0100
commit712ae73581a1b44b36654824229f9cc475381c34 (patch)
treebab8587303236eabeef92afce5fe2cad35c9c635 /Libraries/LibCore
parent86a9a52355905e4ac71730dba5c325498fd05177 (diff)
downloadserenity-712ae73581a1b44b36654824229f9cc475381c34.zip
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.
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r--Libraries/LibCore/CProcessStatisticsReader.cpp16
-rw-r--r--Libraries/LibCore/CProcessStatisticsReader.h17
2 files changed, 24 insertions, 9 deletions
diff --git a/Libraries/LibCore/CProcessStatisticsReader.cpp b/Libraries/LibCore/CProcessStatisticsReader.cpp
index 1ccb72a9e3..c9e2becbe2 100644
--- a/Libraries/LibCore/CProcessStatisticsReader.cpp
+++ b/Libraries/LibCore/CProcessStatisticsReader.cpp
@@ -26,13 +26,11 @@ HashMap<pid_t, CProcessStatistics> CProcessStatisticsReader::get_all()
// kernel data first
process.pid = process_object.get("pid").to_u32();
- process.times_scheduled = process_object.get("times_scheduled").to_u32();
process.pgid = process_object.get("pgid").to_u32();
process.pgp = process_object.get("pgp").to_u32();
process.sid = process_object.get("sid").to_u32();
process.uid = process_object.get("uid").to_u32();
process.gid = process_object.get("gid").to_u32();
- process.state = process_object.get("state").to_string();
process.ppid = process_object.get("ppid").to_u32();
process.nfds = process_object.get("nfds").to_u32();
process.name = process_object.get("name").to_string();
@@ -40,14 +38,24 @@ HashMap<pid_t, CProcessStatistics> CProcessStatisticsReader::get_all()
process.amount_virtual = process_object.get("amount_virtual").to_u32();
process.amount_resident = process_object.get("amount_resident").to_u32();
process.amount_shared = process_object.get("amount_shared").to_u32();
- process.ticks = process_object.get("ticks").to_u32();
- process.priority = process_object.get("priority").to_string();
process.syscall_count = process_object.get("syscall_count").to_u32();
process.inode_faults = process_object.get("inode_faults").to_u32();
process.zero_faults = process_object.get("zero_faults").to_u32();
process.cow_faults = process_object.get("cow_faults").to_u32();
process.icon_id = process_object.get("icon_id").to_int();
+ auto thread_array = process_object.get("threads").as_array();
+ thread_array.for_each([&](auto& value) {
+ auto& thread_object = value.as_object();
+ CThreadStatistics thread;
+ thread.tid = thread_object.get("tid").to_u32();
+ thread.times_scheduled = thread_object.get("times_scheduled").to_u32();
+ thread.state = thread_object.get("state").to_string();
+ thread.ticks = thread_object.get("ticks").to_u32();
+ thread.priority = thread_object.get("priority").to_string();
+ process.threads.append(move(thread));
+ });
+
// and synthetic data last
process.username = username_from_uid(process.uid);
map.set(process.pid, process);
diff --git a/Libraries/LibCore/CProcessStatisticsReader.h b/Libraries/LibCore/CProcessStatisticsReader.h
index c793d1f8f4..848821cb26 100644
--- a/Libraries/LibCore/CProcessStatisticsReader.h
+++ b/Libraries/LibCore/CProcessStatisticsReader.h
@@ -1,19 +1,26 @@
#pragma once
-#include <AK/String.h>
#include <AK/HashMap.h>
+#include <AK/String.h>
+#include <unistd.h>
+
+struct CThreadStatistics {
+ int tid;
+ unsigned times_scheduled;
+ unsigned ticks;
+ String state;
+ String priority;
+};
struct CProcessStatistics {
// Keep this in sync with /proc/all.
// From the kernel side:
pid_t pid;
- unsigned times_scheduled;
unsigned pgid;
unsigned pgp;
unsigned sid;
uid_t uid;
gid_t gid;
- String state;
pid_t ppid;
unsigned nfds;
String name;
@@ -21,14 +28,14 @@ struct CProcessStatistics {
size_t amount_virtual;
size_t amount_resident;
size_t amount_shared;
- unsigned ticks;
- String priority;
unsigned syscall_count;
unsigned inode_faults;
unsigned zero_faults;
unsigned cow_faults;
int icon_id;
+ Vector<CThreadStatistics> threads;
+
// synthetic
String username;
};