1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

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.
This commit is contained in:
Andreas Kling 2019-11-26 21:25:45 +01:00
parent 86a9a52355
commit 712ae73581
9 changed files with 243 additions and 123 deletions

View file

@ -1,13 +1,22 @@
#pragma once
#include <AK/String.h>
#include <AK/HashMap.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibGUI/GModel.h>
#include <unistd.h>
class GraphWidget;
struct PidAndTid {
bool operator==(const PidAndTid& other) const
{
return pid == other.pid && tid == other.tid;
}
pid_t pid;
int tid;
};
class ProcessModel final : public GModel {
public:
enum Column {
@ -18,6 +27,7 @@ public:
Priority,
User,
PID,
TID,
Virtual,
Physical,
Syscalls,
@ -44,7 +54,8 @@ public:
private:
ProcessModel();
struct ProcessState {
struct ThreadState {
int tid;
pid_t pid;
unsigned times_scheduled;
String name;
@ -61,16 +72,23 @@ private:
int icon_id;
};
struct Process {
ProcessState current_state;
ProcessState previous_state;
struct Thread {
ThreadState current_state;
ThreadState previous_state;
};
HashMap<uid_t, String> m_usernames;
HashMap<pid_t, NonnullOwnPtr<Process>> m_processes;
Vector<pid_t> m_pids;
HashMap<PidAndTid, NonnullOwnPtr<Thread>> m_threads;
Vector<PidAndTid> m_pids;
RefPtr<GraphicsBitmap> m_generic_process_icon;
RefPtr<GraphicsBitmap> m_high_priority_icon;
RefPtr<GraphicsBitmap> m_low_priority_icon;
RefPtr<GraphicsBitmap> m_normal_priority_icon;
};
namespace AK {
template<>
struct Traits<PidAndTid> : public GenericTraits<PidAndTid> {
static unsigned hash(const PidAndTid& value) { return pair_int_hash(value.pid, value.tid); }
};
}