Coverage for procpath/procfile.py: 100%
338 statements
« prev ^ index » next coverage.py v6.5.0, created at 2025-04-05 18:56 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2025-04-05 18:56 +0000
1"""
2This module represents several Procfs [1]_ sources.
4.. [1] https://www.kernel.org/doc/html/latest/filesystems/proc.html
5"""
7import os
8import stat
9from collections import Counter
10from functools import partial, wraps
11from typing import (
12 Annotated,
13 Callable,
14 Dict,
15 NamedTuple,
16 NamedTupleMeta,
17 Optional,
18 Tuple,
19 Union,
20 _AnnotatedAlias,
21)
24__all__ = 'registry', 'ProcfileType'
27class ProcfileType(NamedTuple):
28 reader: Callable[..., dict]
29 schema: Union[type, str]
30 empty: Optional[dict]
32registry: Dict[str, ProcfileType] = {}
35def read_file(fn):
36 """Wrap target function to pass it bytes read from the filename."""
38 @wraps(fn)
39 def wrapper(filename, **kwargs):
40 with open(filename, 'rb') as f: (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_ioprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_smaps_rollupprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_statusprocpath.test.unit.TestProctreeForest.test_read_process_dict_file_not_found_errorprocpath.test.unit.TestProctreeForest.test_read_process_dict_permission_error
41 return fn(f.read(), **kwargs) (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_ioprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_smaps_rollupprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
43 return wrapper
46class Stat(NamedTuple):
47 """
48 Representation of ``/proc/{pid}/stat``, see ``man proc``.
50 Fields are read up until ``rss`` plus the range from
51 ``delayacct_blkio_ticks`` to ``cguest_time``. Other fields don't
52 seem to be useful for the monitoring purposes.
54 Formats of the fields are defined in C `printf`_ syntax.
56 .. _printf: http://www.cplusplus.com/reference/cstdio/printf/
57 """
59 pid: int
60 """
61 The process ID.
63 :format: %d
64 """
66 comm: str
67 """
68 The filename of the executable. This is visible whether or not the
69 executable is swapped out.
71 :format: %s
72 """
74 state: str
75 """
76 One of the following characters, indicating process state:
78 - **R** Running
79 - **S** Sleeping in an interruptible wait
80 - **D** Waiting in uninterruptible disk sleep
81 - **Z** Zombie
82 - **T** Stopped (on a signal) or (before Linux 2.6.33) trace stopped
83 - **t** Tracing stop (Linux 2.6.33 onward)
84 - **W** Paging (only before Linux 2.6.0)
85 - **X** Dead (from Linux 2.6.0 onward)
86 - **x** Dead (Linux 2.6.33 to 3.13 only)
87 - **K** Wakekill (Linux 2.6.33 to 3.13 only)
88 - **W** Waking (Linux 2.6.33 to 3.13 only)
89 - **P** Parked (Linux 3.9 to 3.13 only)
91 :format: %c
92 """
94 ppid: int
95 """
96 The PID of the parent of this process.
98 :format: %d
99 """
101 pgrp: int
102 """
103 The process group ID of the process.
105 :format: %d
106 """
108 session: int
109 """
110 The session ID of the process.
112 :format: %d
113 """
115 tty_nr: int
116 """
117 The controlling terminal of the process. (The minor device number
118 is contained in the combination of bits 31 to 20 and 7 to 0; the
119 major device number is in bits 15 to 8.)
121 :format: %d
122 """
124 tpgid: int
125 """
126 The ID of the foreground process group of the controlling terminal
127 of the process.
129 :format: %d
130 """
132 flags: int
133 """
134 The kernel flags word of the process. For bit meanings, see the
135 PF_* defines in the Linux kernel source file include/linux/sched.h.
136 Details depend on the kernel version.
138 The format for this field was %lu before Linux 2.6.
140 :format: %u
141 """
143 minflt: int
144 """
145 The number of minor faults the process has made
146 which have not required loading a memory page from disk.
148 :format: %lu
149 """
151 cminflt: int
152 """
153 The number of minor faults that the process's
154 waited-for children have made.
156 :format: %lu
157 """
159 majflt: int
160 """
161 The number of major faults the process has made
162 which have required loading a memory page from disk.
164 :format: %lu
165 """
167 cmajflt: int
168 """
169 The number of major faults that the process's
170 waited-for children have made.
172 :format: %lu
173 """
175 utime: int
176 """
177 Amount of time that this process has been scheduled
178 in user mode, measured in clock ticks (divide by
179 sysconf(_SC_CLK_TCK)). This includes guest time,
180 guest_time (time spent running a virtual CPU, see
181 below), so that applications that are not aware of
182 the guest time field do not lose that time from
183 their calculations.
185 :format: %lu
186 """
188 stime: int
189 """
190 Amount of time that this process has been scheduled
191 in kernel mode, measured in clock ticks (divide by
192 sysconf(_SC_CLK_TCK)).
194 :format: %lu
195 """
197 cutime: int
198 """
199 Amount of time that this process's waited-for children have been
200 scheduled in user mode, measured in clock ticks (divide by
201 sysconf(_SC_CLK_TCK)). (See also times(2).) This includes guest
202 time, cguest_time (time spent running a virtual CPU, see below).
204 :format: %ld
205 """
207 cstime: int
208 """
209 Amount of time that this process's waited-for children have been
210 scheduled in kernel mode, measured in clock ticks (divide by
211 sysconf(_SC_CLK_TCK)).
213 :format: %ld
214 """
216 priority: int
217 """
218 (Explanation for Linux 2.6) For processes running a
219 real-time scheduling policy (policy below; see
220 sched_setscheduler(2)), this is the negated schedul‐
221 ing priority, minus one; that is, a number in the
222 range -2 to -100, corresponding to real-time priori‐
223 ties 1 to 99. For processes running under a non-
224 real-time scheduling policy, this is the raw nice
225 value (setpriority(2)) as represented in the kernel.
226 The kernel stores nice values as numbers in the
227 range 0 (high) to 39 (low), corresponding to the
228 user-visible nice range of -20 to 19.
230 Before Linux 2.6, this was a scaled value based on
231 the scheduler weighting given to this process.
233 :format: %ld
234 """
236 nice: int
237 """
238 The nice value (see setpriority(2)), a value in the
239 range 19 (low priority) to -20 (high priority).
241 :format: %ld
242 """
244 num_threads: int
245 """
246 Number of threads in this process (since Linux 2.6).
247 Before kernel 2.6, this field was hard coded to 0 as
248 a placeholder for an earlier removed field.
250 :format: %ld
251 """
253 itrealvalue: int
254 """
255 The time in jiffies before the next SIGALRM is sent to the process
256 due to an interval timer. Since kernel 2.6.17, this field is no
257 longer maintained, and is hard coded as 0.
259 :format: %ld
260 """
262 starttime: int
263 """
264 The time the process started after system boot. In
265 kernels before Linux 2.6, this value was expressed
266 in jiffies. Since Linux 2.6, the value is expressed
267 in clock ticks (divide by sysconf(_SC_CLK_TCK)).
269 The format for this field was %lu before Linux 2.6.
271 :format: %llu
272 """
274 vsize: int
275 """
276 Virtual memory size in bytes.
278 :format: %lu
279 """
281 rss: int
282 """
283 Resident Set Size: number of pages the process has
284 in real memory. This is just the pages which count
285 toward text, data, or stack space. This does not
286 include pages which have not been demand-loaded in,
287 or which are swapped out.
289 :format: %ld
290 """
292 delayacct_blkio_ticks: int = None
293 """
294 Aggregated block I/O delays, measured in clock
295 ticks (centiseconds). Available since Linux 2.6.18.
297 :format: %llu
298 """
300 guest_time: int = None
301 """
302 Guest time of the process (time spent running a
303 virtual CPU for a guest operating system), measured
304 in clock ticks (divide by sysconf(_SC_CLK_TCK)).
305 Available since Linux 2.6.24.
307 :format: %lu
308 """
310 cguest_time: int = None
311 """
312 Guest time of the process's children, measured in clock ticks
313 (divide by sysconf(_SC_CLK_TCK)). Available since Linux 2.6.24.
315 :format: %ld
316 """
318 @classmethod
319 def from_bytes(cls, b):
320 pid, _, rest = b.partition(b' (') (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_statprocpath.test.unit.TestProcfile.test_read_stat_kernel_2_6_8procpath.test.unit.TestProctreeForest.test_read_process_dict
321 comm, _, rest = rest.rpartition(b') ') (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_statprocpath.test.unit.TestProcfile.test_read_stat_kernel_2_6_8procpath.test.unit.TestProctreeForest.test_read_process_dict
322 state, _, rest = rest.partition(b' ') (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_statprocpath.test.unit.TestProcfile.test_read_stat_kernel_2_6_8procpath.test.unit.TestProctreeForest.test_read_process_dict
323 fields = [int(pid), comm.decode(), state.decode()] (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_statprocpath.test.unit.TestProcfile.test_read_stat_kernel_2_6_8procpath.test.unit.TestProctreeForest.test_read_process_dict
325 read_fields = 41 # cguest_time is 44th, -3 for already read fields (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_statprocpath.test.unit.TestProcfile.test_read_stat_kernel_2_6_8procpath.test.unit.TestProctreeForest.test_read_process_dict
326 raw = rest.split(b' ', maxsplit=read_fields)[:read_fields] (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_statprocpath.test.unit.TestProcfile.test_read_stat_kernel_2_6_8procpath.test.unit.TestProctreeForest.test_read_process_dict
327 del raw[21:38] # rsslim is 24th, delayacct_blkio_ticks is 41th, -3 (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_statprocpath.test.unit.TestProcfile.test_read_stat_kernel_2_6_8procpath.test.unit.TestProctreeForest.test_read_process_dict
328 fields.extend(map(int, raw)) (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_statprocpath.test.unit.TestProcfile.test_read_stat_kernel_2_6_8procpath.test.unit.TestProctreeForest.test_read_process_dict
330 return cls(*fields) (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_statprocpath.test.unit.TestProcfile.test_read_stat_kernel_2_6_8procpath.test.unit.TestProctreeForest.test_read_process_dict
332def read_stat(b, *, dictcls=dict, **kwargs):
333 return dictcls(zip(Stat._fields, Stat.from_bytes(b))) (empty)procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestPlayCommand.test_play_watchprocpath.test.cmd.TestPlayCommand.test_play_watch_overrideprocpath.test.cmd.TestQueryCommand.test_query_delimitedprocpath.test.cmd.TestQueryCommand.test_query_jsonpath_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_no_new_line_on_empty_outputprocpath.test.cmd.TestQueryCommand.test_query_no_query_root_outputprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_query_node_list_json_outputprocpath.test.cmd.TestQueryCommand.test_query_sql_syntax_errorprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.cmd.TestQueryCommand.test_query_with_envrionmentprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.cmd.TestRecordCommand.test_record_environmentprocpath.test.cmd.TestRecordCommand.test_record_environment_database_fileprocpath.test.cmd.TestRecordCommand.test_record_n_timesprocpath.test.cmd.TestRecordCommand.test_record_pid_list_onlyprocpath.test.cmd.TestRecordCommand.test_record_queryprocpath.test.cmd.TestRecordCommand.test_record_syntax_errorprocpath.test.cmd.TestWatchCommand.test_watch_empty_env_command_resultprocpath.test.cmd.TestWatchCommand.test_watch_empty_query_resultprocpath.test.cmd.TestWatchCommand.test_watch_environmentprocpath.test.cmd.TestWatchCommand.test_watch_no_restartprocpath.test.cmd.TestWatchCommand.test_watch_no_restart_no_reevalprocpath.test.cmd.TestWatchCommand.test_watch_process_pids_exposedprocpath.test.cmd.TestWatchCommand.test_watch_queryprocpath.test.cmd.TestWatchCommand.test_watch_query_errorprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_loggingprocpath.test.cmd.TestWatchCommand.test_watch_std_stream_write_after_stopprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_by_sigtermprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_errorprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_repeat_endprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigintprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_firstprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_killprocpath.test.cmd.TestWatchCommand.test_watch_tree_cleanup_on_sigint_shell_first_ptyprocpath.test.cmd.TestWatchCommand.test_watch_verbatim_commandsprocpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_statprocpath.test.unit.TestProcfile.test_read_stat_kernel_2_6_8procpath.test.unit.TestProctreeForest.test_read_process_dict
335registry['stat'] = ProcfileType(
336 reader=read_file(read_stat),
337 schema=Stat,
338 empty=Stat(*[None] * len(Stat._fields))._asdict(),
339)
342def read_cmdline(b, **kwargs):
343 return b.replace(b'\x00', b' ').strip().decode() (empty)procpath.test.cmd.TestPlayCommand.test_play_record_plotprocpath.test.cmd.TestQueryCommand.test_query_only_sqlprocpath.test.cmd.TestQueryCommand.test_query_with_sqlprocpath.test.cmd.TestRecordCommand.test_record_allprocpath.test.unit.TestProcfile.test_read_cmdlineprocpath.test.unit.TestProctreeForest.test_read_process_dict
345registry['cmdline'] = ProcfileType(
346 reader=read_file(read_cmdline),
347 schema='cmdline',
348 empty=None,
349)
352class Io(NamedTuple):
353 """Representation of ``/proc/{pid}/io``, see ``man proc``."""
355 rchar: int
356 """
357 I/O counter: chars read.
359 The number of bytes which this task has caused to be read from
360 storage. This is simply the sum of bytes which this process passed
361 to read() and pread(). It includes things like tty IO and it is
362 unaffected by whether or not actual physical disk IO was required
363 (the read might have been satisfied from pagecache).
364 """
366 wchar: int
367 """
368 I/O counter: chars written.
370 The number of bytes which this task has caused, or shall cause to
371 be written to disk. Similar caveats apply here as with rchar.
372 """
374 syscr: int
375 """
376 I/O counter: read syscalls.
378 Attempt to count the number of read I/O operations, i.e. syscalls
379 like read() and pread().
380 """
382 syscw: int
383 """
384 I/O counter: write syscalls.
386 Attempt to count the number of write I/O operations, i.e. syscalls
387 like write() and pwrite().
388 """
390 read_bytes: int
391 """
392 I/O counter: bytes read.
394 Attempt to count the number of bytes which this process really did
395 cause to be fetched from the storage layer. Done at the
396 submit_bio() level, so it is accurate for block-backed filesystems.
397 """
399 write_bytes: int
400 """
401 I/O counter: bytes written.
403 Attempt to count the number of bytes which this process caused to
404 be sent to the storage layer. This is done at page-dirtying time.
405 """
407 cancelled_write_bytes: int
408 """
409 The big inaccuracy here is truncate. If a process writes 1MB to a
410 file and then deletes the file, it will in fact perform no
411 writeout. But it will have been accounted as having caused 1MB of
412 write. In other words: The number of bytes which this process
413 caused to not happen, by truncating pagecache. A task can cause
414 "negative" IO too. If this task truncates some dirty pagecache,
415 some IO which another task has been accounted for (in its
416 write_bytes) will not be happening. We _could_ just subtract that
417 from the truncating task's write_bytes, but there is information
418 loss in doing that.
419 """
421 @classmethod
422 def from_bytes(cls, b):
423 pairs = [line.decode().split(': ', 1) for line in b.splitlines()] procpath.test.unit.TestProcfile.test_read_ioprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_io
424 d = {k: int(v) for k, v in pairs if k in cls._field_set} procpath.test.unit.TestProcfile.test_read_ioprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_io
425 return cls(**d) procpath.test.unit.TestProcfile.test_read_ioprocpath.test.unit.TestProctreeForest.test_read_process_dict
427Io._field_set = set(Io._fields)
429def read_io(b, *, dictcls=dict, **kwargs):
430 return dictcls(zip(Io._fields, Io.from_bytes(b))) procpath.test.unit.TestProcfile.test_read_ioprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_io
432registry['io'] = ProcfileType(
433 reader=read_file(read_io),
434 schema=Io,
435 empty=Io(*[None] * len(Io._fields))._asdict(),
436)
439class StatusMeta(NamedTupleMeta):
440 """Metaclass for ``(in_type, out_type)`` annotated named tuple."""
442 def __new__(cls, typename, bases, ns):
443 field_conv_map = {}
444 types = ns.get('__annotations__', {})
445 for field_name, annotation in types.items():
446 assert isinstance(annotation, _AnnotatedAlias)
447 field_conv_map[field_name] = annotation.__metadata__[0]
448 types[field_name] = annotation.__origin__
450 rescls = super().__new__(cls, typename, bases, ns)
451 rescls._field_conv_map = field_conv_map
453 field_types = rescls.__annotations__
454 rescls._optional_none = {f: None for f, t in field_types.items() if Optional[t] == t}
456 return rescls
458class Status(NamedTuple, metaclass=StatusMeta):
459 """Representation of ``/proc/{pid}/status``, see ``man proc``."""
461 def _kb(s: str) -> int: # @NoSelf
462 return int(s.split(maxsplit=1)[0]) # type: ignore[attribute-error] procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dict
464 def _slashed_pair(s) -> Tuple[int, int]: # @NoSelf
465 a, _, b = s.partition('/') # type: ignore[attribute-error] procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dict
466 return (int(a), int(b)) procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dict
468 def _whitespace_separated_list(s) -> Tuple[int, ...]: # @NoSelf
469 return tuple([int(v) for v in s.split()]) # type: ignore[attribute-error] procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dict
471 def _comma_separated_hex_list(s) -> Tuple[int, ...]: # @NoSelf
472 return tuple([int(h, 16) for h in s.split(',')]) # type: ignore[attribute-error] procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dict
474 def _state(s) -> str: # @NoSelf
475 return s.split(maxsplit=1)[0].upper() # type: ignore[attribute-error] procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
477 name: Annotated[str, str]
478 """
479 Command run by this process. Strings longer than TASK_COMM_LEN
480 (16) characters (including the terminating null byte) are silently
481 truncated.
482 """
484 umask: Annotated[Optional[int], partial(int, base=8)]
485 """Process umask; see umask(2) (since Linux 4.7)."""
487 state: Annotated[str, _state]
488 """
489 Current state of the process. One of:
491 - R (running)
492 - S (sleeping)
493 - D (disk sleep)
494 - T (stopped)
495 - t (tracing stop)
496 - Z (zombie)
497 - X (dead)
499 Only the letter code is kept.
500 """
502 tgid: Annotated[int, int]
503 """Thread group ID (i.e., Process ID)."""
505 ngid: Annotated[Optional[int], int]
506 """NUMA group ID (0 if none; since Linux 3.13)."""
508 pid: Annotated[int, int]
509 """Thread ID (see gettid(2))."""
511 ppid: Annotated[int, int]
512 """PID of parent process."""
514 tracerpid: Annotated[int, int]
515 """
516 PID of process tracing this process (0 if not being traced).
517 """
519 uid: Annotated[Tuple[int, ...], _whitespace_separated_list]
520 """Real, effective, saved set, and filesystem UIDs."""
522 gid: Annotated[Tuple[int, ...], _whitespace_separated_list]
523 """Real, effective, saved set, and filesystem GIDs."""
525 fdsize: Annotated[int, int]
526 """Number of file descriptor slots currently allocated."""
528 groups: Annotated[Tuple[int, ...], _whitespace_separated_list]
529 """Supplementary group list."""
531 nstgid: Annotated[Optional[Tuple[int, ...]], _whitespace_separated_list]
532 """
533 Thread group ID (i.e., PID) in each of the PID namespaces of which
534 [pid] is a member. The leftmost entry shows the value with respect
535 to the PID namespace of the process that mounted this procfs (or
536 the root namespace if mounted by the kernel), followed by the value
537 in successively nested inner namespaces (since Linux 4.1).
538 """
540 nspid: Annotated[Optional[Tuple[int, ...]], _whitespace_separated_list]
541 """
542 Thread ID in each of the PID namespaces of which [pid] is a member.
543 The fields are ordered as for NStgid (since Linux 4.1).
544 """
546 nspgid: Annotated[Optional[Tuple[int, ...]], _whitespace_separated_list]
547 """
548 Process group ID in each of the PID namespaces of which [pid] is a
549 member. The fields are ordered as for NStgid (since Linux 4.1).
550 """
552 nssid: Annotated[Optional[Tuple[int, ...]], _whitespace_separated_list]
553 """
554 Descendant namespace session ID hierarchy Session ID in each of the
555 PID namespaces of which [pid] is a member. The fields are ordered
556 as for NStgid (since Linux 4.1).
557 """
559 vmpeak: Annotated[Optional[int], _kb]
560 """Peak virtual memory size, in kB."""
562 vmsize: Annotated[Optional[int], _kb]
563 """Virtual memory size, in kB."""
565 vmlck: Annotated[Optional[int], _kb]
566 """Locked memory size, in kB (see mlock(2))."""
568 vmpin: Annotated[Optional[int], _kb]
569 """
570 Pinned memory size (since Linux 3.2). These are pages that can't be
571 moved because something needs to directly access physical memory,
572 in kB.
573 """
575 vmhwm: Annotated[Optional[int], _kb]
576 """Peak resident set size, in kB ("high water mark")."""
578 vmrss: Annotated[Optional[int], _kb]
579 """
580 Resident set size, in kB. Note that the value here is the sum of
581 RssAnon, RssFile, and RssShmem.
582 """
584 rssanon: Annotated[Optional[int], _kb]
585 """Size of resident anonymous memory, in kB (since Linux 4.5)."""
587 rssfile: Annotated[Optional[int], _kb]
588 """Size of resident file mappings, in kB (since Linux 4.5)."""
590 rssshmem: Annotated[Optional[int], _kb]
591 """
592 Size of resident shared memory, in kB (includes System V shared
593 memory, mappings from tmpfs(5), and shared anonymous mappings).
594 (since Linux 4.5).
595 """
597 vmdata: Annotated[Optional[int], _kb]
598 """Size of data, in kB."""
600 vmstk: Annotated[Optional[int], _kb]
601 """Size of stack, in kB."""
603 vmexe: Annotated[Optional[int], _kb]
604 """Size of text segments, in kB."""
606 vmlib: Annotated[Optional[int], _kb]
607 """Shared library code size, in kB."""
609 vmpte: Annotated[Optional[int], _kb]
610 """Page table entries size, in kB (since Linux 2.6.10)."""
612 vmpmd: Annotated[Optional[int], _kb]
613 """
614 Size of second-level page tables, in kB
615 (added in Linux 4.0; removed in Linux 4.15).
616 """
618 vmswap: Annotated[Optional[int], _kb]
619 """
620 Swapped-out virtual memory size by anonymous private pages, in kB;
621 shmem swap usage is not included (since Linux 2.6.34).
622 """
624 hugetlbpages: Annotated[Optional[int], _kb]
625 """
626 Size of hugetlb memory portions, in kB (since Linux 4.4).
627 """
629 coredumping: Annotated[Optional[int], int]
630 """
631 Contains the value 1 if the process is currently dumping core, and
632 0 if it is not (since Linux 4.15). This information can be used by
633 a monitoring process to avoid killing a process that is currently
634 dumping core, which could result in a corrupted core dump file.
635 """
637 threads: Annotated[int, int]
638 """Number of threads in process containing this thread."""
640 sigq: Annotated[Tuple[int, int], _slashed_pair]
641 """
642 This field contains two numbers that relate to queued signals for
643 the real user ID of this process. The first of these is the number
644 of currently queued signals for this real user ID, and the second
645 is the resource limit on the number of queued signals for this
646 process (see the description of RLIMIT_SIGPENDING in getrlimit(2)).
647 """
649 sigpnd: Annotated[int, partial(int, base=16)]
650 """
651 Mask of signals pending for thread (see pthreads(7) and signal(7)).
652 """
654 shdpnd: Annotated[int, partial(int, base=16)]
655 """
656 Mask of signals pending for process as a whole (see pthreads(7)
657 and signal(7)).
658 """
660 sigblk: Annotated[int, partial(int, base=16)]
661 """Masks indicating signals being blocked (see signal(7))."""
663 sigign: Annotated[int, partial(int, base=16)]
664 """Masks indicating signals being ignored (see signal(7))."""
666 sigcgt: Annotated[int, partial(int, base=16)]
667 """Masks indicating signals being caught (see signal(7))."""
669 capinh: Annotated[int, partial(int, base=16)]
670 """
671 Masks of capabilities enabled in inheritable sets
672 (see capabilities(7)).
673 """
675 capprm: Annotated[int, partial(int, base=16)]
676 """
677 Masks of capabilities enabled in permitted sets
678 (see capabilities(7)).
679 """
681 capeff: Annotated[int, partial(int, base=16)]
682 """
683 Masks of capabilities enabled in effective sets
684 (see capabilities(7)).
685 """
687 capbnd: Annotated[Optional[int], partial(int, base=16)]
688 """
689 Capability bounding set (since Linux 2.6.26, see capabilities(7)).
690 """
692 capamb: Annotated[Optional[int], partial(int, base=16)]
693 """
694 Ambient capability set (since Linux 4.3, see capabilities(7)).
695 """
697 nonewprivs: Annotated[Optional[int], int]
698 """
699 Value of the no_new_privs bit (since Linux 4.10, see prctl(2)).
700 """
702 seccomp: Annotated[Optional[int], int]
703 """
704 Seccomp mode of the process (since Linux 3.8, see seccomp(2)).
706 - 0 means SECCOMP_MODE_DISABLED
707 - 1 means SECCOMP_MODE_STRICT
708 - 2 means SECCOMP_MODE_FILTER
710 This field is provided only if the kernel was built with the
711 CONFIG_SECCOMP kernel configuration option enabled.
712 """
714 speculation_store_bypass: Annotated[Optional[str], str.strip]
715 """
716 Speculation flaw mitigation state (since Linux 4.17, see prctl(2)).
717 """
719 cpus_allowed: Annotated[Optional[int], partial(int, base=16)]
720 """
721 Mask of CPUs on which this process may run
722 (since Linux 2.6.24, see cpuset(7)).
723 """
725 cpus_allowed_list: Annotated[Optional[str], str.strip]
726 """
727 Same as previous, but in "list format"
728 (since Linux 2.6.26, see cpuset(7)).
729 """
731 mems_allowed: Annotated[Optional[Tuple[int, ...]], _comma_separated_hex_list]
732 """
733 Mask of memory nodes allowed to this process
734 (since Linux 2.6.24, see cpuset(7)).
735 """
737 mems_allowed_list: Annotated[Optional[str], str.strip]
738 """
739 Same as previous, but in "list format"
740 (since Linux 2.6.26, see cpuset(7)).
741 """
743 voluntary_ctxt_switches: Annotated[Optional[int], int]
744 """Number of voluntary context switches (since Linux 2.6.23)."""
746 nonvoluntary_ctxt_switches: Annotated[Optional[int], int]
747 """Number of involuntary context switches (since Linux 2.6.23)."""
749 @classmethod
750 def from_bytes(cls, b):
751 fields = {} procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
752 # decode order is important for PyPy performance
753 nameline, rest = b.split(b'\n', 1) procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
754 fields['name'] = nameline.decode().split(':', 1)[1].strip() procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
755 for line in rest.lower().decode().splitlines(): procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
756 k, _, v = line.partition(':') procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
757 if k in cls._field_conv_map: # type: ignore[attribute-error] procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
758 fields[k] = cls._field_conv_map[k](v) # type: ignore[attribute-error] procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
760 return cls(**{**cls._optional_none, **fields}) # type: ignore[attribute-error] procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
762def read_status(b, *, dictcls=dict, **kwargs):
763 return dictcls(zip(Status._fields, Status.from_bytes(b))) procpath.test.cmd.TestPlayCommand.test_play_queryprocpath.test.cmd.TestQueryCommand.test_query_thread_targetprocpath.test.unit.TestProcfile.test_read_status_3_2procpath.test.unit.TestProcfile.test_read_status_3_16procpath.test.unit.TestProcfile.test_read_status_4_13procpath.test.unit.TestProcfile.test_read_status_kthreadprocpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
765registry['status'] = ProcfileType(
766 reader=read_file(read_status),
767 schema=Status,
768 empty=Status(*[None] * len(Status._fields))._asdict(),
769)
772class Fd(NamedTuple):
773 """
774 Counts of file descriptor types in ``/proc/{pid}/fd/*``.
776 For more details see ``man proc`` and ``man fstat``.
777 """
779 anon: int = 0
780 """
781 For file descriptors that have no corresponding inode (e.g., file
782 descriptors produced by epoll_create(2), eventfd(2),
783 inotify_init(2), signalfd(2), and timerfd(2)), the entry will be a
784 symbolic link with contents of the form::
786 anon_inode:<file-type>
788 In some cases, the file-type is surrounded by square brackets like:
790 - ``anon_inode:[eventfd]``
791 - ``anon_inode:[eventpoll]``
792 - ``anon_inode:[timerfd]``
793 - ``anon_inode:[signalfd]``
794 - ``anon_inode:inotify``
795 - ``anon_inode:dmabuf``
796 - ``anon_inode:sync_fence``
798 """
800 dir: int = 0
801 """Directory."""
803 chr: int = 0
804 """Character device."""
806 blk: int = 0
807 """Block device."""
809 reg: int = 0
810 """Regular file."""
812 fifo: int = 0
813 """FIFO (named pipe)."""
815 lnk: int = 0
816 """Symbolic link."""
818 sock: int = 0
819 """Socket file."""
821 _lookup = {
822 0: 'anon',
823 stat.S_IFDIR: 'dir',
824 stat.S_IFCHR: 'chr',
825 stat.S_IFBLK: 'blk',
826 stat.S_IFREG: 'reg',
827 stat.S_IFIFO: 'fifo',
828 stat.S_IFLNK: 'lnk',
829 stat.S_IFSOCK: 'sock',
830 }
832 @classmethod
833 def _scan_fd(cls, dirname):
834 for entry in os.scandir(dirname): procpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_fd_unknown_descriptor_typeprocpath.test.unit.TestProctreeForest.test_read_process_dict
835 try: procpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_fd_unknown_descriptor_typeprocpath.test.unit.TestProctreeForest.test_read_process_dict
836 yield cls._lookup[stat.S_IFMT(entry.stat().st_mode)] procpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_fd_unknown_descriptor_typeprocpath.test.unit.TestProctreeForest.test_read_process_dict
837 except (KeyError, FileNotFoundError): procpath.test.unit.TestProcfile.test_read_fd_unknown_descriptor_type
838 pass procpath.test.unit.TestProcfile.test_read_fd_unknown_descriptor_type
840 @classmethod
841 def from_dir(cls, dirname):
842 return cls(**Counter(cls._scan_fd(dirname))) procpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_fd_unknown_descriptor_typeprocpath.test.unit.TestProctreeForest.test_read_process_dict
844def read_fd(dirname, *, dictcls=dict, **kwargs):
845 return dictcls(zip(Fd._fields, Fd.from_dir(dirname))) procpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_fd_unknown_descriptor_typeprocpath.test.unit.TestProctreeForest.test_read_process_dict
847registry['fd'] = ProcfileType(read_fd, Fd, Fd()._asdict())
850class SmapsRollup(NamedTuple):
851 """
852 Representation of ``/proc/{pid}/smaps_rollup``.
854 This file was added to the Kernel in version 4.14. It provides
855 pre-summed memory information for a process, and contains most of
856 the fields of ``/proc/{pid}/smaps``.
858 All fields are expressed in kB. Kernel threads have the file empty.
859 """
861 rss: Optional[int]
862 """
863 Resident Set Size. Sum of the mappings that are currently
864 resident in RAM.
865 """
867 pss: Optional[int]
868 """
869 Proportional Set Size. The process' proportional share of its
870 mappings. If a process has 100 unshared pages(``USS``), and 100
871 shared with another process, its ``PSS`` will be 150.
872 """
874 shared_clean: Optional[int]
875 """The number of clean shared pages in process' mappings."""
877 shared_dirty: Optional[int]
878 """The number of dirty shared pages in process' mappings."""
880 private_clean: Optional[int]
881 """The number of clean private pages in process' mappings."""
883 private_dirty: Optional[int]
884 """The number of dirty private pages in process' mappings."""
886 referenced: Optional[int]
887 """
888 It indicates the amount of memory currently marked as referenced
889 or accessed.
890 """
892 anonymous: Optional[int]
893 """
894 It shows the amount of memory that does not belong to any file.
895 """
897 lazyfree: Optional[int]
898 """
899 It shows the amount of memory which is marked by
900 ``madvise(MADV_FREE)``. The memory isn't freed immediately with
901 ``madvise()``. It's freed in memory pressure if the memory is
902 clean.
903 """
905 anonhugepages: Optional[int]
906 """
907 It shows the amount of memory backed by transparent huge pages.
908 """
910 shmempmdmapped: Optional[int]
911 """
912 It shows the amount of shared (shmem/tmpfs) memory backed by
913 huge pages.
914 """
916 shared_hugetlb: Optional[int]
917 """
918 It shows the amount of memory backed by hugetlbfs page which is not
919 counted in ``rss`` or ``pss`` fields for historical reasons. And
920 it is not included in ``shared_clean`` and ``shared_dirty`` fields.
921 """
923 private_hugetlb: Optional[int]
924 """
925 It shows the amount of memory backed by hugetlbfs page which is not
926 counted in ``rss`` or ``pss`` fields for historical reasons. And
927 it is not included in ``private_clean`` and ``private_dirty``
928 fields.
929 """
931 swap: Optional[int]
932 """
933 It shows how much would-be-anonymous memory is also used, but out
934 on swap.
935 """
937 swappss: Optional[int]
938 """
939 It shows proportional swap share of process' mappings. Unlike
940 ``swap``, this does not take into account swapped out page of
941 underlying shmem objects.
942 """
944 locked: Optional[int]
945 """It indicates the mappings that are locked in memory."""
947 @classmethod
948 def from_bytes(cls, b):
949 fields = {k: None for k in cls._fields} procpath.test.unit.TestProcfile.test_read_smaps_rollupprocpath.test.unit.TestProcfile.test_read_smaps_rollup_kthreadprocpath.test.unit.TestProcfile.test_read_smaps_rollup_unknownprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_smaps_rollup
950 if b: procpath.test.unit.TestProcfile.test_read_smaps_rollupprocpath.test.unit.TestProcfile.test_read_smaps_rollup_kthreadprocpath.test.unit.TestProcfile.test_read_smaps_rollup_unknownprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_smaps_rollup
951 for line in b[b.index(b'\n') + 1:].lower().decode().splitlines(): procpath.test.unit.TestProcfile.test_read_smaps_rollupprocpath.test.unit.TestProcfile.test_read_smaps_rollup_unknownprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_smaps_rollup
952 k, _, v = line.partition(':') procpath.test.unit.TestProcfile.test_read_smaps_rollupprocpath.test.unit.TestProcfile.test_read_smaps_rollup_unknownprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_smaps_rollup
953 if k in fields: procpath.test.unit.TestProcfile.test_read_smaps_rollupprocpath.test.unit.TestProcfile.test_read_smaps_rollup_unknownprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_smaps_rollup
954 v, _, _ = v.rpartition(' ') procpath.test.unit.TestProcfile.test_read_smaps_rollupprocpath.test.unit.TestProcfile.test_read_smaps_rollup_unknownprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_smaps_rollup
955 fields[k] = int(v) procpath.test.unit.TestProcfile.test_read_smaps_rollupprocpath.test.unit.TestProcfile.test_read_smaps_rollup_unknownprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_smaps_rollup
957 return cls(**fields) procpath.test.unit.TestProcfile.test_read_smaps_rollupprocpath.test.unit.TestProcfile.test_read_smaps_rollup_kthreadprocpath.test.unit.TestProcfile.test_read_smaps_rollup_unknownprocpath.test.unit.TestProctreeForest.test_read_process_dict
959def read_smaps_rollup(b, *, dictcls=dict, **kwargs):
960 return dictcls(zip(SmapsRollup._fields, SmapsRollup.from_bytes(b))) procpath.test.unit.TestProcfile.test_read_smaps_rollupprocpath.test.unit.TestProcfile.test_read_smaps_rollup_kthreadprocpath.test.unit.TestProcfile.test_read_smaps_rollup_unknownprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_smaps_rollup
962registry['smaps_rollup'] = ProcfileType(
963 reader=read_file(read_smaps_rollup),
964 schema=SmapsRollup,
965 empty=SmapsRollup(*[None] * len(SmapsRollup._fields))._asdict(),
966)