2019-02-28 10:20:04 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-09-06 15:34:26 +02:00
|
|
|
#include <AK/String.h>
|
2019-02-28 10:20:04 +01:00
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/Vector.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <LibGUI/GModel.h>
|
2019-02-28 10:20:04 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2019-05-06 03:21:23 +02:00
|
|
|
class GraphWidget;
|
|
|
|
|
2019-03-23 01:42:49 +01:00
|
|
|
class ProcessModel final : public GModel {
|
2019-02-28 10:20:04 +01:00
|
|
|
public:
|
2019-06-07 17:13:23 +02:00
|
|
|
enum Column {
|
2019-03-09 13:33:52 +01:00
|
|
|
Icon = 0,
|
|
|
|
Name,
|
|
|
|
CPU,
|
|
|
|
State,
|
|
|
|
Priority,
|
|
|
|
User,
|
|
|
|
PID,
|
2019-06-07 12:44:29 +02:00
|
|
|
Virtual,
|
2019-03-09 13:33:52 +01:00
|
|
|
Physical,
|
2019-04-17 14:48:55 +02:00
|
|
|
Syscalls,
|
2019-10-02 14:13:49 +02:00
|
|
|
InodeFaults,
|
|
|
|
ZeroFaults,
|
|
|
|
CowFaults,
|
2019-03-09 13:33:52 +01:00
|
|
|
__Count
|
|
|
|
};
|
|
|
|
|
2019-10-02 20:26:19 +02:00
|
|
|
static ProcessModel& the();
|
|
|
|
|
|
|
|
static NonnullRefPtr<ProcessModel> create() { return adopt(*new ProcessModel); }
|
2019-03-23 01:42:49 +01:00
|
|
|
virtual ~ProcessModel() override;
|
2019-02-28 10:20:04 +01:00
|
|
|
|
2019-03-29 03:27:03 +01:00
|
|
|
virtual int row_count(const GModelIndex&) const override;
|
|
|
|
virtual int column_count(const GModelIndex&) const override;
|
2019-02-28 10:20:04 +01:00
|
|
|
virtual String column_name(int column) const override;
|
2019-02-28 11:27:04 +01:00
|
|
|
virtual ColumnMetadata column_metadata(int column) const override;
|
2019-03-09 14:24:34 +01:00
|
|
|
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
2019-02-28 10:20:04 +01:00
|
|
|
virtual void update() override;
|
|
|
|
|
2019-10-02 20:26:19 +02:00
|
|
|
Function<void(float)> on_new_cpu_data_point;
|
2019-05-06 03:21:23 +02:00
|
|
|
|
2019-10-02 20:26:19 +02:00
|
|
|
private:
|
|
|
|
ProcessModel();
|
2019-03-20 03:27:07 +01:00
|
|
|
|
2019-02-28 10:20:04 +01:00
|
|
|
struct ProcessState {
|
|
|
|
pid_t pid;
|
2019-07-17 22:22:22 +02:00
|
|
|
unsigned times_scheduled;
|
2019-02-28 10:20:04 +01:00
|
|
|
String name;
|
|
|
|
String state;
|
|
|
|
String user;
|
|
|
|
String priority;
|
2019-07-17 22:22:22 +02:00
|
|
|
size_t amount_virtual;
|
|
|
|
size_t amount_resident;
|
|
|
|
unsigned syscall_count;
|
2019-10-02 14:13:49 +02:00
|
|
|
unsigned inode_faults;
|
|
|
|
unsigned zero_faults;
|
|
|
|
unsigned cow_faults;
|
2019-02-28 10:20:04 +01:00
|
|
|
float cpu_percent;
|
2019-07-29 07:26:01 +02:00
|
|
|
int icon_id;
|
2019-02-28 10:20:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Process {
|
|
|
|
ProcessState current_state;
|
|
|
|
ProcessState previous_state;
|
|
|
|
};
|
|
|
|
|
2019-02-28 14:12:53 +01:00
|
|
|
HashMap<uid_t, String> m_usernames;
|
2019-07-24 08:42:55 +02:00
|
|
|
HashMap<pid_t, NonnullOwnPtr<Process>> m_processes;
|
2019-02-28 10:20:04 +01:00
|
|
|
Vector<pid_t> m_pids;
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<GraphicsBitmap> m_generic_process_icon;
|
|
|
|
RefPtr<GraphicsBitmap> m_high_priority_icon;
|
|
|
|
RefPtr<GraphicsBitmap> m_low_priority_icon;
|
|
|
|
RefPtr<GraphicsBitmap> m_normal_priority_icon;
|
2019-02-28 10:20:04 +01:00
|
|
|
};
|