blob: fafd7d00440eb843b2f0424510398ff66828b90d [file] [log] [blame]
Hisham Muhammad430c7c92014-11-27 21:02:52 -02001#ifndef HEADER_LinuxProcess
2#define HEADER_LinuxProcess
3/*
4htop - LinuxProcess.h
5(C) 2014 Hisham H. Muhammad
Nathan Scott500fb282020-08-20 09:35:24 +10006(C) 2020 Red Hat, Inc. All Rights Reserved.
Daniel Lange94ad1112021-09-22 11:33:00 +02007Released under the GNU GPLv2+, see the COPYING file
Hisham Muhammad430c7c92014-11-27 21:02:52 -02008in the source distribution for its full text.
9*/
10
Benny Baumann0f526292020-09-19 13:55:23 +020011#include <stdbool.h>
Benny Baumann0f526292020-09-19 13:55:23 +020012
Nathan Scott0bdade12023-05-02 09:02:22 +100013#include "Machine.h"
Benny Baumann0f526292020-09-19 13:55:23 +020014#include "Object.h"
15#include "Process.h"
Benny Baumanne56089e2023-11-28 15:15:03 +010016#include "Row.h"
17
Benny Baumann32f8d4c2023-05-24 10:08:28 +020018#include "linux/IOPriority.h"
Benny Baumann0f526292020-09-19 13:55:23 +020019
Christian Göttsche7cf52772020-11-18 14:26:30 +010020
Christian Göttsche293c16e2020-12-28 20:51:02 +010021#define PROCESS_FLAG_LINUX_IOPRIO 0x00000100
22#define PROCESS_FLAG_LINUX_OPENVZ 0x00000200
23#define PROCESS_FLAG_LINUX_VSERVER 0x00000400
24#define PROCESS_FLAG_LINUX_CGROUP 0x00000800
25#define PROCESS_FLAG_LINUX_OOM 0x00001000
26#define PROCESS_FLAG_LINUX_SMAPS 0x00002000
27#define PROCESS_FLAG_LINUX_CTXT 0x00004000
28#define PROCESS_FLAG_LINUX_SECATTR 0x00008000
29#define PROCESS_FLAG_LINUX_LRS_FIX 0x00010000
Christian Göttsche293c16e2020-12-28 20:51:02 +010030#define PROCESS_FLAG_LINUX_DELAYACCT 0x00040000
Nathan Scott1bd95982021-08-06 16:45:30 +100031#define PROCESS_FLAG_LINUX_AUTOGROUP 0x00080000
Christian Göttschef8c5bdd2023-08-29 13:03:31 +020032#define PROCESS_FLAG_LINUX_GPU 0x00100000
Christian Göttsche85c3c3a2024-01-09 23:10:03 +010033#define PROCESS_FLAG_LINUX_CONTAINER 0x00200000
Hisham Muhammade3fe3962015-03-15 20:29:13 -030034
Hisham Muhammad430c7c92014-11-27 21:02:52 -020035typedef struct LinuxProcess_ {
36 Process super;
37 IOPriority ioPriority;
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030038 unsigned long int cminflt;
39 unsigned long int cmajflt;
40 unsigned long long int utime;
41 unsigned long long int stime;
42 unsigned long long int cutime;
43 unsigned long long int cstime;
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030044 long m_share;
BowDown097986dbfc2023-11-24 13:12:34 -080045 long m_priv;
Alexander Schlarbfc0bf542018-10-09 21:49:29 +020046 long m_pss;
47 long m_swap;
48 long m_psswp;
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030049 long m_trs;
50 long m_drs;
51 long m_lrs;
Christian Göttschefdaa15b2021-01-27 15:11:48 +010052
Rin Cat (鈴猫)07496ea2021-11-08 09:42:12 -050053 /* Process flags */
54 unsigned long int flags;
55
Christian Göttsche323d7e72021-04-26 17:57:47 +020056 /* Data read (in bytes) */
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030057 unsigned long long io_rchar;
Christian Göttschefdaa15b2021-01-27 15:11:48 +010058
Christian Göttsche323d7e72021-04-26 17:57:47 +020059 /* Data written (in bytes) */
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030060 unsigned long long io_wchar;
Christian Göttschefdaa15b2021-01-27 15:11:48 +010061
62 /* Number of read(2) syscalls */
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030063 unsigned long long io_syscr;
Christian Göttschefdaa15b2021-01-27 15:11:48 +010064
65 /* Number of write(2) syscalls */
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030066 unsigned long long io_syscw;
Christian Göttschefdaa15b2021-01-27 15:11:48 +010067
Christian Göttsche323d7e72021-04-26 17:57:47 +020068 /* Storage data read (in bytes) */
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030069 unsigned long long io_read_bytes;
Christian Göttschefdaa15b2021-01-27 15:11:48 +010070
Christian Göttsche323d7e72021-04-26 17:57:47 +020071 /* Storage data written (in bytes) */
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030072 unsigned long long io_write_bytes;
Christian Göttschefdaa15b2021-01-27 15:11:48 +010073
Christian Göttsche323d7e72021-04-26 17:57:47 +020074 /* Storage data cancelled (in bytes) */
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030075 unsigned long long io_cancelled_write_bytes;
Christian Göttschefdaa15b2021-01-27 15:11:48 +010076
Christian Göttsche323d7e72021-04-26 17:57:47 +020077 /* Point in time of last io scan (in milliseconds elapsed since the Epoch) */
78 unsigned long long io_last_scan_time_ms;
Christian Göttschefdaa15b2021-01-27 15:11:48 +010079
Christian Göttsche323d7e72021-04-26 17:57:47 +020080 /* Storage data read (in bytes per second) */
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030081 double io_rate_read_bps;
Christian Göttsche323d7e72021-04-26 17:57:47 +020082
83 /* Storage data written (in bytes per second) */
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030084 double io_rate_write_bps;
Christian Göttsche323d7e72021-04-26 17:57:47 +020085
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030086 #ifdef HAVE_OPENVZ
Benny Baumann2970cae2020-09-30 23:46:52 +020087 char* ctid;
88 pid_t vpid;
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030089 #endif
90 #ifdef HAVE_VSERVER
91 unsigned int vxid;
92 #endif
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030093 char* cgroup;
Benny Baumann9dc964b2021-10-19 23:36:31 +020094 char* cgroup_short;
Benny Baumannd5b15562023-11-20 22:58:23 +010095 char* container_short;
Hisham Muhammadbe1700c2015-03-16 01:43:04 -030096 unsigned int oom;
André Carvalhob7b66b72017-12-04 00:15:29 -020097 #ifdef HAVE_DELAYACCT
98 unsigned long long int delay_read_time;
99 unsigned long long cpu_delay_total;
100 unsigned long long blkio_delay_total;
101 unsigned long long swapin_delay_total;
102 float cpu_delay_percent;
103 float blkio_delay_percent;
104 float swapin_delay_percent;
105 #endif
Christian Göttsche98ee8332020-09-11 15:02:00 +0200106 unsigned long ctxt_total;
107 unsigned long ctxt_diff;
Benny Baumann61e14d42020-10-31 23:28:02 +0100108 char* secattr;
Benny Baumann721d9112020-11-16 19:12:41 +0100109 unsigned long long int last_mlrs_calctime;
Nathan Scott1bd95982021-08-06 16:45:30 +1000110
Christian Göttschef8c5bdd2023-08-29 13:03:31 +0200111 /* Total GPU time used in nano seconds */
112 unsigned long long int gpu_time;
113 /* GPU utilization in percent */
114 float gpu_percent;
Christian Göttsche03185892023-11-05 17:31:16 +0100115 /* Activity of GPU: 0 if active, otherwise time of last scan in milliseconds */
116 uint64_t gpu_activityMs;
Christian Göttschef8c5bdd2023-08-29 13:03:31 +0200117
Nathan Scott1bd95982021-08-06 16:45:30 +1000118 /* Autogroup scheduling (CFS) information */
119 long int autogroup_id;
120 int autogroup_nice;
Hisham Muhammad430c7c92014-11-27 21:02:52 -0200121} LinuxProcess;
122
Nathan Scott75e9f9a2020-12-10 11:57:48 +1100123extern int pageSize;
124
125extern int pageSizeKB;
126
Christian Göttsche9f68c8d2020-12-15 19:44:52 +0100127extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD];
Hisham Muhammade3fe3962015-03-15 20:29:13 -0300128
Christian Göttsche7af06652020-10-13 14:35:30 +0200129extern const ProcessClass LinuxProcess_class;
Hisham Muhammad4c24a9b2015-03-31 23:23:10 -0300130
Nathan Scott0bdade12023-05-02 09:02:22 +1000131Process* LinuxProcess_new(const Machine* host);
Hisham Muhammad6f868b02015-02-20 14:52:10 -0200132
Zev Weiss7b7822b2020-09-02 02:38:44 -0500133void Process_delete(Object* cast);
Hisham Muhammad430c7c92014-11-27 21:02:52 -0200134
Nathan Scott0f751e92023-08-22 16:11:05 +1000135IOPriority LinuxProcess_updateIOPriority(Process* proc);
Hisham Muhammad430c7c92014-11-27 21:02:52 -0200136
Nathan Scott0f751e92023-08-22 16:11:05 +1000137bool LinuxProcess_rowSetIOPriority(Row* super, Arg ioprio);
Hisham Muhammad430c7c92014-11-27 21:02:52 -0200138
Nathan Scott1bd95982021-08-06 16:45:30 +1000139bool LinuxProcess_isAutogroupEnabled(void);
140
Nathan Scott0f751e92023-08-22 16:11:05 +1000141bool LinuxProcess_rowChangeAutogroupPriorityBy(Row* super, Arg delta);
Nathan Scott1bd95982021-08-06 16:45:30 +1000142
Christian Göttsche41eea8a2020-10-07 19:02:15 +0200143bool Process_isThread(const Process* this);
Hisham Muhammadbe1700c2015-03-16 01:43:04 -0300144
Hisham Muhammad430c7c92014-11-27 21:02:52 -0200145#endif