2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2021-05-23 06:08:32 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-05-16 13:47:47 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-11-26 17:25:45 -03:00
|
|
|
#include <AK/String.h>
|
2021-01-03 14:08:51 -03:00
|
|
|
#include <LibCore/File.h>
|
2019-11-26 17:25:45 -03:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2020-02-02 08:34:39 -03:00
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
|
|
struct ThreadStatistics {
|
2020-08-08 20:08:24 -03:00
|
|
|
pid_t tid;
|
2019-11-26 17:25:45 -03:00
|
|
|
unsigned times_scheduled;
|
2021-07-15 00:46:32 -03:00
|
|
|
u64 time_user;
|
|
|
|
|
u64 time_kernel;
|
2019-11-26 17:35:24 -03:00
|
|
|
unsigned syscall_count;
|
|
|
|
|
unsigned inode_faults;
|
|
|
|
|
unsigned zero_faults;
|
|
|
|
|
unsigned cow_faults;
|
2019-12-01 13:36:06 -03: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-11-26 17:25:45 -03:00
|
|
|
String state;
|
2020-06-28 01:36:15 -03:00
|
|
|
u32 cpu;
|
2019-12-30 14:46:17 -03:00
|
|
|
u32 priority;
|
2019-12-07 16:50:30 -03:00
|
|
|
String name;
|
2019-11-26 17:25:45 -03:00
|
|
|
};
|
2019-05-16 13:47:47 -03:00
|
|
|
|
2020-02-02 08:34:39 -03:00
|
|
|
struct ProcessStatistics {
|
2019-07-17 17:22:22 -03:00
|
|
|
// Keep this in sync with /proc/all.
|
|
|
|
|
// From the kernel side:
|
2019-05-16 13:47:47 -03:00
|
|
|
pid_t pid;
|
2020-09-06 14:04:47 -03:00
|
|
|
pid_t pgid;
|
|
|
|
|
pid_t pgp;
|
|
|
|
|
pid_t sid;
|
2019-05-16 13:47:47 -03:00
|
|
|
uid_t uid;
|
2019-07-17 17:22:22 -03:00
|
|
|
gid_t gid;
|
|
|
|
|
pid_t ppid;
|
|
|
|
|
unsigned nfds;
|
2021-04-06 12:17:53 -03:00
|
|
|
bool kernel;
|
2019-07-17 17:22:22 -03:00
|
|
|
String name;
|
2020-12-26 20:54:13 -03:00
|
|
|
String executable;
|
2019-07-17 17:22:22 -03:00
|
|
|
String tty;
|
2020-01-11 17:17:07 -03:00
|
|
|
String pledge;
|
2020-01-21 14:56:23 -03:00
|
|
|
String veil;
|
2019-07-17 17:22:22 -03:00
|
|
|
size_t amount_virtual;
|
|
|
|
|
size_t amount_resident;
|
|
|
|
|
size_t amount_shared;
|
2019-12-29 08:28:32 -03:00
|
|
|
size_t amount_dirty_private;
|
2019-12-29 08:45:58 -03:00
|
|
|
size_t amount_clean_inode;
|
2019-12-09 15:16:58 -03:00
|
|
|
size_t amount_purgeable_volatile;
|
|
|
|
|
size_t amount_purgeable_nonvolatile;
|
2019-07-17 17:22:22 -03:00
|
|
|
|
2020-02-02 08:34:39 -03:00
|
|
|
Vector<Core::ThreadStatistics> threads;
|
2019-11-26 17:25:45 -03:00
|
|
|
|
2019-07-17 17:22:22 -03:00
|
|
|
// synthetic
|
|
|
|
|
String username;
|
2019-05-16 13:47:47 -03:00
|
|
|
};
|
|
|
|
|
|
2021-07-14 15:05:59 -03:00
|
|
|
struct AllProcessesStatistics {
|
|
|
|
|
Vector<ProcessStatistics> processes;
|
2021-07-15 00:46:32 -03:00
|
|
|
u64 total_time_scheduled;
|
|
|
|
|
u64 total_time_scheduled_kernel;
|
2021-07-14 15:05:59 -03:00
|
|
|
};
|
|
|
|
|
|
2020-02-02 08:34:39 -03:00
|
|
|
class ProcessStatisticsReader {
|
2019-05-16 13:47:47 -03:00
|
|
|
public:
|
2021-07-14 15:05:59 -03:00
|
|
|
static Optional<AllProcessesStatistics> get_all(RefPtr<Core::File>&);
|
|
|
|
|
static Optional<AllProcessesStatistics> get_all();
|
2019-05-16 13:47:47 -03:00
|
|
|
|
|
|
|
|
private:
|
2019-07-10 08:56:28 -03:00
|
|
|
static String username_from_uid(uid_t);
|
|
|
|
|
static HashMap<uid_t, String> s_usernames;
|
2019-05-16 13:47:47 -03:00
|
|
|
};
|
2020-02-02 08:34:39 -03:00
|
|
|
|
|
|
|
|
}
|