2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2021-02-16 20:24:22 +01:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-02-28 10:20:04 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
2020-06-27 22:52:13 -06:00
|
|
|
#include <AK/NonnullOwnPtrVector.h>
|
2019-11-26 21:25:45 +01:00
|
|
|
#include <AK/String.h>
|
2019-02-28 10:20:04 +01:00
|
|
|
#include <AK/Vector.h>
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/Model.h>
|
2019-02-28 10:20:04 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2019-05-06 03:21:23 +02:00
|
|
|
class GraphWidget;
|
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
class ProcessModel final : public GUI::Model {
|
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,
|
2020-06-27 22:52:13 -06:00
|
|
|
Processor,
|
2019-03-09 13:33:52 +01:00
|
|
|
State,
|
|
|
|
Priority,
|
|
|
|
User,
|
|
|
|
PID,
|
2019-11-26 21:25:45 +01:00
|
|
|
TID,
|
2020-08-09 21:44:40 +02:00
|
|
|
PPID,
|
|
|
|
PGID,
|
|
|
|
SID,
|
2019-06-07 12:44:29 +02:00
|
|
|
Virtual,
|
2019-03-09 13:33:52 +01:00
|
|
|
Physical,
|
2019-12-29 12:28:32 +01:00
|
|
|
DirtyPrivate,
|
2019-12-29 12:45:58 +01:00
|
|
|
CleanInode,
|
2019-12-09 19:16:58 +01:00
|
|
|
PurgeableVolatile,
|
|
|
|
PurgeableNonvolatile,
|
2020-01-21 18:56:23 +01:00
|
|
|
Veil,
|
2020-01-11 21:17:07 +01:00
|
|
|
Pledge,
|
2019-04-17 14:48:55 +02:00
|
|
|
Syscalls,
|
2019-10-02 14:13:49 +02:00
|
|
|
InodeFaults,
|
|
|
|
ZeroFaults,
|
|
|
|
CowFaults,
|
2019-12-01 17:36:06 +01:00
|
|
|
FileReadBytes,
|
|
|
|
FileWriteBytes,
|
|
|
|
UnixSocketReadBytes,
|
|
|
|
UnixSocketWriteBytes,
|
|
|
|
IPv4SocketReadBytes,
|
|
|
|
IPv4SocketWriteBytes,
|
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
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
virtual int row_count(const GUI::ModelIndex&) const override;
|
|
|
|
virtual int column_count(const GUI::ModelIndex&) const override;
|
2019-02-28 10:20:04 +01:00
|
|
|
virtual String column_name(int column) const override;
|
2020-08-16 16:00:07 +02:00
|
|
|
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
2019-02-28 10:20:04 +01:00
|
|
|
virtual void update() override;
|
|
|
|
|
2020-07-11 21:08:40 +01:00
|
|
|
struct CpuInfo {
|
2020-06-27 22:52:13 -06:00
|
|
|
u32 id;
|
2020-07-11 21:08:40 +01:00
|
|
|
float total_cpu_percent { 0.0 };
|
2021-01-04 20:14:52 -07:00
|
|
|
float total_cpu_percent_kernel { 0.0 };
|
2020-07-11 21:08:40 +01:00
|
|
|
|
2021-02-16 20:24:22 +01:00
|
|
|
explicit CpuInfo(u32 id)
|
2020-07-11 21:08:40 +01:00
|
|
|
: id(id)
|
2020-06-27 22:52:13 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Function<void(const NonnullOwnPtrVector<CpuInfo>&)> on_cpu_info_change;
|
2021-04-04 20:46:46 +02:00
|
|
|
Function<void(int process_count, int thread_count)> on_state_update;
|
2020-06-27 22:52:13 -06:00
|
|
|
|
|
|
|
const NonnullOwnPtrVector<CpuInfo>& cpus() const { return m_cpus; }
|
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-11-26 21:25:45 +01:00
|
|
|
struct ThreadState {
|
2020-08-09 21:44:40 +02:00
|
|
|
pid_t tid;
|
2019-02-28 10:20:04 +01:00
|
|
|
pid_t pid;
|
2020-08-09 21:44:40 +02:00
|
|
|
pid_t ppid;
|
|
|
|
pid_t pgid;
|
|
|
|
pid_t sid;
|
2020-12-03 22:12:50 -07:00
|
|
|
unsigned ticks_user;
|
|
|
|
unsigned ticks_kernel;
|
2020-12-27 00:55:13 +01:00
|
|
|
String executable;
|
2019-02-28 10:20:04 +01:00
|
|
|
String name;
|
|
|
|
String state;
|
|
|
|
String user;
|
2020-01-11 21:17:07 +01:00
|
|
|
String pledge;
|
2020-01-21 18:56:23 +01:00
|
|
|
String veil;
|
2020-06-27 22:52:13 -06:00
|
|
|
u32 cpu;
|
2019-12-30 18:46:17 +01:00
|
|
|
u32 priority;
|
2019-07-17 22:22:22 +02:00
|
|
|
size_t amount_virtual;
|
|
|
|
size_t amount_resident;
|
2019-12-29 12:28:32 +01:00
|
|
|
size_t amount_dirty_private;
|
2019-12-29 12:45:58 +01:00
|
|
|
size_t amount_clean_inode;
|
2019-12-09 19:16:58 +01:00
|
|
|
size_t amount_purgeable_volatile;
|
|
|
|
size_t amount_purgeable_nonvolatile;
|
2019-07-17 22:22:22 +02:00
|
|
|
unsigned syscall_count;
|
2019-10-02 14:13:49 +02:00
|
|
|
unsigned inode_faults;
|
|
|
|
unsigned zero_faults;
|
|
|
|
unsigned cow_faults;
|
2019-12-01 17:36:06 +01:00
|
|
|
unsigned unix_socket_read_bytes;
|
|
|
|
unsigned unix_socket_write_bytes;
|
|
|
|
unsigned ipv4_socket_read_bytes;
|
|
|
|
unsigned ipv4_socket_write_bytes;
|
|
|
|
unsigned file_read_bytes;
|
|
|
|
unsigned file_write_bytes;
|
2019-02-28 10:20:04 +01:00
|
|
|
float cpu_percent;
|
2021-01-04 20:14:52 -07:00
|
|
|
float cpu_percent_kernel;
|
2019-02-28 10:20:04 +01:00
|
|
|
};
|
|
|
|
|
2019-11-26 21:25:45 +01:00
|
|
|
struct Thread {
|
|
|
|
ThreadState current_state;
|
|
|
|
ThreadState previous_state;
|
2019-02-28 10:20:04 +01:00
|
|
|
};
|
|
|
|
|
2021-02-16 20:35:21 +01:00
|
|
|
HashMap<int, NonnullOwnPtr<Thread>> m_threads;
|
2020-06-27 22:52:13 -06:00
|
|
|
NonnullOwnPtrVector<CpuInfo> m_cpus;
|
2021-02-16 20:35:21 +01:00
|
|
|
Vector<int> m_tids;
|
2021-01-03 10:13:33 -07:00
|
|
|
RefPtr<Core::File> m_proc_all;
|
2019-02-28 10:20:04 +01:00
|
|
|
};
|