Coverage for procpath/procfile.py: 99%
347 statements
« prev ^ index » next coverage.py v6.5.0, created at 2025-12-16 20:22 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2025-12-16 20:22 +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)
24try:
25 import annotationlib
26except ImportError:
27 def get_class_namespace_annotations(ns):
28 return ns.get('__annotations__', {})
29else: # py314+
30 def get_class_namespace_annotations(ns):
31 annotate = annotationlib.get_annotate_from_class_namespace(ns)
32 return annotationlib.call_annotate_function(annotate, format=annotationlib.Format.VALUE)
35__all__ = 'registry', 'ProcfileType'
38class ProcfileType(NamedTuple):
39 reader: Callable[..., dict]
40 schema: Union[type, str]
41 empty: Optional[dict]
43registry: Dict[str, ProcfileType] = {}
46def read_file(fn):
47 """Wrap target function to pass it bytes read from the filename."""
49 @wraps(fn)
50 def wrapper(filename, **kwargs):
51 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
52 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
54 return wrapper
57class Stat(NamedTuple):
58 """
59 Representation of ``/proc/{pid}/stat``, see ``man proc``.
61 Fields are read up until ``rss`` plus the range from
62 ``delayacct_blkio_ticks`` to ``cguest_time``. Other fields don't
63 seem to be useful for the monitoring purposes.
65 Formats of the fields are defined in C `printf`_ syntax.
67 .. _printf: http://www.cplusplus.com/reference/cstdio/printf/
68 """
70 pid: int
71 """
72 The process ID.
74 :format: %d
75 """
77 comm: str
78 """
79 The filename of the executable. This is visible whether or not the
80 executable is swapped out.
82 :format: %s
83 """
85 state: str
86 """
87 One of the following characters, indicating process state:
89 - **R** Running
90 - **S** Sleeping in an interruptible wait
91 - **D** Waiting in uninterruptible disk sleep
92 - **Z** Zombie
93 - **T** Stopped (on a signal) or (before Linux 2.6.33) trace stopped
94 - **t** Tracing stop (Linux 2.6.33 onward)
95 - **W** Paging (only before Linux 2.6.0)
96 - **X** Dead (from Linux 2.6.0 onward)
97 - **x** Dead (Linux 2.6.33 to 3.13 only)
98 - **K** Wakekill (Linux 2.6.33 to 3.13 only)
99 - **W** Waking (Linux 2.6.33 to 3.13 only)
100 - **P** Parked (Linux 3.9 to 3.13 only)
102 :format: %c
103 """
105 ppid: int
106 """
107 The PID of the parent of this process.
109 :format: %d
110 """
112 pgrp: int
113 """
114 The process group ID of the process.
116 :format: %d
117 """
119 session: int
120 """
121 The session ID of the process.
123 :format: %d
124 """
126 tty_nr: int
127 """
128 The controlling terminal of the process. (The minor device number
129 is contained in the combination of bits 31 to 20 and 7 to 0; the
130 major device number is in bits 15 to 8.)
132 :format: %d
133 """
135 tpgid: int
136 """
137 The ID of the foreground process group of the controlling terminal
138 of the process.
140 :format: %d
141 """
143 flags: int
144 """
145 The kernel flags word of the process. For bit meanings, see the
146 PF_* defines in the Linux kernel source file include/linux/sched.h.
147 Details depend on the kernel version.
149 The format for this field was %lu before Linux 2.6.
151 :format: %u
152 """
154 minflt: int
155 """
156 The number of minor faults the process has made
157 which have not required loading a memory page from disk.
159 :format: %lu
160 """
162 cminflt: int
163 """
164 The number of minor faults that the process's
165 waited-for children have made.
167 :format: %lu
168 """
170 majflt: int
171 """
172 The number of major faults the process has made
173 which have required loading a memory page from disk.
175 :format: %lu
176 """
178 cmajflt: int
179 """
180 The number of major faults that the process's
181 waited-for children have made.
183 :format: %lu
184 """
186 utime: int
187 """
188 Amount of time that this process has been scheduled
189 in user mode, measured in clock ticks (divide by
190 sysconf(_SC_CLK_TCK)). This includes guest time,
191 guest_time (time spent running a virtual CPU, see
192 below), so that applications that are not aware of
193 the guest time field do not lose that time from
194 their calculations.
196 :format: %lu
197 """
199 stime: int
200 """
201 Amount of time that this process has been scheduled
202 in kernel mode, measured in clock ticks (divide by
203 sysconf(_SC_CLK_TCK)).
205 :format: %lu
206 """
208 cutime: int
209 """
210 Amount of time that this process's waited-for children have been
211 scheduled in user mode, measured in clock ticks (divide by
212 sysconf(_SC_CLK_TCK)). (See also times(2).) This includes guest
213 time, cguest_time (time spent running a virtual CPU, see below).
215 :format: %ld
216 """
218 cstime: int
219 """
220 Amount of time that this process's waited-for children have been
221 scheduled in kernel mode, measured in clock ticks (divide by
222 sysconf(_SC_CLK_TCK)).
224 :format: %ld
225 """
227 priority: int
228 """
229 (Explanation for Linux 2.6) For processes running a
230 real-time scheduling policy (policy below; see
231 sched_setscheduler(2)), this is the negated schedul‐
232 ing priority, minus one; that is, a number in the
233 range -2 to -100, corresponding to real-time priori‐
234 ties 1 to 99. For processes running under a non-
235 real-time scheduling policy, this is the raw nice
236 value (setpriority(2)) as represented in the kernel.
237 The kernel stores nice values as numbers in the
238 range 0 (high) to 39 (low), corresponding to the
239 user-visible nice range of -20 to 19.
241 Before Linux 2.6, this was a scaled value based on
242 the scheduler weighting given to this process.
244 :format: %ld
245 """
247 nice: int
248 """
249 The nice value (see setpriority(2)), a value in the
250 range 19 (low priority) to -20 (high priority).
252 :format: %ld
253 """
255 num_threads: int
256 """
257 Number of threads in this process (since Linux 2.6).
258 Before kernel 2.6, this field was hard coded to 0 as
259 a placeholder for an earlier removed field.
261 :format: %ld
262 """
264 itrealvalue: int
265 """
266 The time in jiffies before the next SIGALRM is sent to the process
267 due to an interval timer. Since kernel 2.6.17, this field is no
268 longer maintained, and is hard coded as 0.
270 :format: %ld
271 """
273 starttime: int
274 """
275 The time the process started after system boot. In
276 kernels before Linux 2.6, this value was expressed
277 in jiffies. Since Linux 2.6, the value is expressed
278 in clock ticks (divide by sysconf(_SC_CLK_TCK)).
280 The format for this field was %lu before Linux 2.6.
282 :format: %llu
283 """
285 vsize: int
286 """
287 Virtual memory size in bytes.
289 :format: %lu
290 """
292 rss: int
293 """
294 Resident Set Size: number of pages the process has
295 in real memory. This is just the pages which count
296 toward text, data, or stack space. This does not
297 include pages which have not been demand-loaded in,
298 or which are swapped out.
300 :format: %ld
301 """
303 delayacct_blkio_ticks: int = None
304 """
305 Aggregated block I/O delays, measured in clock
306 ticks (centiseconds). Available since Linux 2.6.18.
308 :format: %llu
309 """
311 guest_time: int = None
312 """
313 Guest time of the process (time spent running a
314 virtual CPU for a guest operating system), measured
315 in clock ticks (divide by sysconf(_SC_CLK_TCK)).
316 Available since Linux 2.6.24.
318 :format: %lu
319 """
321 cguest_time: int = None
322 """
323 Guest time of the process's children, measured in clock ticks
324 (divide by sysconf(_SC_CLK_TCK)). Available since Linux 2.6.24.
326 :format: %ld
327 """
329 @classmethod
330 def from_bytes(cls, b):
331 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
332 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
333 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
334 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
336 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
337 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
338 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
339 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
341 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
343def read_stat(b, *, dictcls=dict, **kwargs):
344 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
346registry['stat'] = ProcfileType(
347 reader=read_file(read_stat),
348 schema=Stat,
349 empty=Stat(*[None] * len(Stat._fields))._asdict(),
350)
353def read_cmdline(b, **kwargs):
354 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
356registry['cmdline'] = ProcfileType(
357 reader=read_file(read_cmdline),
358 schema='cmdline',
359 empty=None,
360)
363class Io(NamedTuple):
364 """Representation of ``/proc/{pid}/io``, see ``man proc``."""
366 rchar: int
367 """
368 I/O counter: chars read.
370 The number of bytes which this task has caused to be read from
371 storage. This is simply the sum of bytes which this process passed
372 to read() and pread(). It includes things like tty IO and it is
373 unaffected by whether or not actual physical disk IO was required
374 (the read might have been satisfied from pagecache).
375 """
377 wchar: int
378 """
379 I/O counter: chars written.
381 The number of bytes which this task has caused, or shall cause to
382 be written to disk. Similar caveats apply here as with rchar.
383 """
385 syscr: int
386 """
387 I/O counter: read syscalls.
389 Attempt to count the number of read I/O operations, i.e. syscalls
390 like read() and pread().
391 """
393 syscw: int
394 """
395 I/O counter: write syscalls.
397 Attempt to count the number of write I/O operations, i.e. syscalls
398 like write() and pwrite().
399 """
401 read_bytes: int
402 """
403 I/O counter: bytes read.
405 Attempt to count the number of bytes which this process really did
406 cause to be fetched from the storage layer. Done at the
407 submit_bio() level, so it is accurate for block-backed filesystems.
408 """
410 write_bytes: int
411 """
412 I/O counter: bytes written.
414 Attempt to count the number of bytes which this process caused to
415 be sent to the storage layer. This is done at page-dirtying time.
416 """
418 cancelled_write_bytes: int
419 """
420 The big inaccuracy here is truncate. If a process writes 1MB to a
421 file and then deletes the file, it will in fact perform no
422 writeout. But it will have been accounted as having caused 1MB of
423 write. In other words: The number of bytes which this process
424 caused to not happen, by truncating pagecache. A task can cause
425 "negative" IO too. If this task truncates some dirty pagecache,
426 some IO which another task has been accounted for (in its
427 write_bytes) will not be happening. We _could_ just subtract that
428 from the truncating task's write_bytes, but there is information
429 loss in doing that.
430 """
432 @classmethod
433 def from_bytes(cls, b):
434 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
435 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
436 return cls(**d) procpath.test.unit.TestProcfile.test_read_ioprocpath.test.unit.TestProctreeForest.test_read_process_dict
438Io._field_set = set(Io._fields)
440def read_io(b, *, dictcls=dict, **kwargs):
441 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
443registry['io'] = ProcfileType(
444 reader=read_file(read_io),
445 schema=Io,
446 empty=Io(*[None] * len(Io._fields))._asdict(),
447)
450class StatusMeta(NamedTupleMeta):
451 """Metaclass for ``(in_type, out_type)`` annotated named tuple."""
453 def __new__(cls, typename, bases, ns):
454 field_conv_map = {}
455 unwrapped = {}
456 types = get_class_namespace_annotations(ns)
457 for field_name, annotation in types.items():
458 assert isinstance(annotation, _AnnotatedAlias)
459 field_conv_map[field_name] = annotation.__metadata__[0]
460 unwrapped[field_name] = annotation.__origin__
462 rescls = super().__new__(cls, typename, bases, ns)
464 # Keep unwrapped Annotated as on other procfile schemata
465 rescls.__annotations__ = unwrapped
466 rescls._field_conv_map = field_conv_map
467 rescls._optional_none = {f: None for f, t in unwrapped.items() if Optional[t] == t}
469 return rescls
471class Status(NamedTuple, metaclass=StatusMeta):
472 """Representation of ``/proc/{pid}/status``, see ``man proc``."""
474 def _kb(s: str) -> int: # @NoSelf
475 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dict
477 def _slashed_pair(s) -> Tuple[int, int]: # @NoSelf
478 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dict
479 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dict
481 def _whitespace_separated_list(s) -> Tuple[int, ...]: # @NoSelf
482 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dict
484 def _comma_separated_hex_list(s) -> Tuple[int, ...]: # @NoSelf
485 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dict
487 def _state(s) -> str: # @NoSelf
488 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
490 name: Annotated[str, str]
491 """
492 Command run by this process. Strings longer than TASK_COMM_LEN
493 (16) characters (including the terminating null byte) are silently
494 truncated.
495 """
497 umask: Annotated[Optional[int], partial(int, base=8)]
498 """Process umask; see umask(2) (since Linux 4.7)."""
500 state: Annotated[str, _state]
501 """
502 Current state of the process. One of:
504 - R (running)
505 - S (sleeping)
506 - D (disk sleep)
507 - T (stopped)
508 - t (tracing stop)
509 - Z (zombie)
510 - X (dead)
512 Only the letter code is kept.
513 """
515 tgid: Annotated[int, int]
516 """Thread group ID (i.e., Process ID)."""
518 ngid: Annotated[Optional[int], int]
519 """NUMA group ID (0 if none; since Linux 3.13)."""
521 pid: Annotated[int, int]
522 """Thread ID (see gettid(2))."""
524 ppid: Annotated[int, int]
525 """PID of parent process."""
527 tracerpid: Annotated[int, int]
528 """
529 PID of process tracing this process (0 if not being traced).
530 """
532 uid: Annotated[Tuple[int, ...], _whitespace_separated_list]
533 """Real, effective, saved set, and filesystem UIDs."""
535 gid: Annotated[Tuple[int, ...], _whitespace_separated_list]
536 """Real, effective, saved set, and filesystem GIDs."""
538 fdsize: Annotated[int, int]
539 """Number of file descriptor slots currently allocated."""
541 groups: Annotated[Tuple[int, ...], _whitespace_separated_list]
542 """Supplementary group list."""
544 nstgid: Annotated[Optional[Tuple[int, ...]], _whitespace_separated_list]
545 """
546 Thread group ID (i.e., PID) in each of the PID namespaces of which
547 [pid] is a member. The leftmost entry shows the value with respect
548 to the PID namespace of the process that mounted this procfs (or
549 the root namespace if mounted by the kernel), followed by the value
550 in successively nested inner namespaces (since Linux 4.1).
551 """
553 nspid: Annotated[Optional[Tuple[int, ...]], _whitespace_separated_list]
554 """
555 Thread ID in each of the PID namespaces of which [pid] is a member.
556 The fields are ordered as for NStgid (since Linux 4.1).
557 """
559 nspgid: Annotated[Optional[Tuple[int, ...]], _whitespace_separated_list]
560 """
561 Process group ID in each of the PID namespaces of which [pid] is a
562 member. The fields are ordered as for NStgid (since Linux 4.1).
563 """
565 nssid: Annotated[Optional[Tuple[int, ...]], _whitespace_separated_list]
566 """
567 Descendant namespace session ID hierarchy Session ID in each of the
568 PID namespaces of which [pid] is a member. The fields are ordered
569 as for NStgid (since Linux 4.1).
570 """
572 vmpeak: Annotated[Optional[int], _kb]
573 """Peak virtual memory size, in kB."""
575 vmsize: Annotated[Optional[int], _kb]
576 """Virtual memory size, in kB."""
578 vmlck: Annotated[Optional[int], _kb]
579 """Locked memory size, in kB (see mlock(2))."""
581 vmpin: Annotated[Optional[int], _kb]
582 """
583 Pinned memory size (since Linux 3.2). These are pages that can't be
584 moved because something needs to directly access physical memory,
585 in kB.
586 """
588 vmhwm: Annotated[Optional[int], _kb]
589 """Peak resident set size, in kB ("high water mark")."""
591 vmrss: Annotated[Optional[int], _kb]
592 """
593 Resident set size, in kB. Note that the value here is the sum of
594 RssAnon, RssFile, and RssShmem.
595 """
597 rssanon: Annotated[Optional[int], _kb]
598 """Size of resident anonymous memory, in kB (since Linux 4.5)."""
600 rssfile: Annotated[Optional[int], _kb]
601 """Size of resident file mappings, in kB (since Linux 4.5)."""
603 rssshmem: Annotated[Optional[int], _kb]
604 """
605 Size of resident shared memory, in kB (includes System V shared
606 memory, mappings from tmpfs(5), and shared anonymous mappings).
607 (since Linux 4.5).
608 """
610 vmdata: Annotated[Optional[int], _kb]
611 """Size of data, in kB."""
613 vmstk: Annotated[Optional[int], _kb]
614 """Size of stack, in kB."""
616 vmexe: Annotated[Optional[int], _kb]
617 """Size of text segments, in kB."""
619 vmlib: Annotated[Optional[int], _kb]
620 """Shared library code size, in kB."""
622 vmpte: Annotated[Optional[int], _kb]
623 """Page table entries size, in kB (since Linux 2.6.10)."""
625 vmpmd: Annotated[Optional[int], _kb]
626 """
627 Size of second-level page tables, in kB
628 (added in Linux 4.0; removed in Linux 4.15).
629 """
631 vmswap: Annotated[Optional[int], _kb]
632 """
633 Swapped-out virtual memory size by anonymous private pages, in kB;
634 shmem swap usage is not included (since Linux 2.6.34).
635 """
637 hugetlbpages: Annotated[Optional[int], _kb]
638 """
639 Size of hugetlb memory portions, in kB (since Linux 4.4).
640 """
642 coredumping: Annotated[Optional[int], int]
643 """
644 Contains the value 1 if the process is currently dumping core, and
645 0 if it is not (since Linux 4.15). This information can be used by
646 a monitoring process to avoid killing a process that is currently
647 dumping core, which could result in a corrupted core dump file.
648 """
650 threads: Annotated[int, int]
651 """Number of threads in process containing this thread."""
653 sigq: Annotated[Tuple[int, int], _slashed_pair]
654 """
655 This field contains two numbers that relate to queued signals for
656 the real user ID of this process. The first of these is the number
657 of currently queued signals for this real user ID, and the second
658 is the resource limit on the number of queued signals for this
659 process (see the description of RLIMIT_SIGPENDING in getrlimit(2)).
660 """
662 sigpnd: Annotated[int, partial(int, base=16)]
663 """
664 Mask of signals pending for thread (see pthreads(7) and signal(7)).
665 """
667 shdpnd: Annotated[int, partial(int, base=16)]
668 """
669 Mask of signals pending for process as a whole (see pthreads(7)
670 and signal(7)).
671 """
673 sigblk: Annotated[int, partial(int, base=16)]
674 """Masks indicating signals being blocked (see signal(7))."""
676 sigign: Annotated[int, partial(int, base=16)]
677 """Masks indicating signals being ignored (see signal(7))."""
679 sigcgt: Annotated[int, partial(int, base=16)]
680 """Masks indicating signals being caught (see signal(7))."""
682 capinh: Annotated[int, partial(int, base=16)]
683 """
684 Masks of capabilities enabled in inheritable sets
685 (see capabilities(7)).
686 """
688 capprm: Annotated[int, partial(int, base=16)]
689 """
690 Masks of capabilities enabled in permitted sets
691 (see capabilities(7)).
692 """
694 capeff: Annotated[int, partial(int, base=16)]
695 """
696 Masks of capabilities enabled in effective sets
697 (see capabilities(7)).
698 """
700 capbnd: Annotated[Optional[int], partial(int, base=16)]
701 """
702 Capability bounding set (since Linux 2.6.26, see capabilities(7)).
703 """
705 capamb: Annotated[Optional[int], partial(int, base=16)]
706 """
707 Ambient capability set (since Linux 4.3, see capabilities(7)).
708 """
710 nonewprivs: Annotated[Optional[int], int]
711 """
712 Value of the no_new_privs bit (since Linux 4.10, see prctl(2)).
713 """
715 seccomp: Annotated[Optional[int], int]
716 """
717 Seccomp mode of the process (since Linux 3.8, see seccomp(2)).
719 - 0 means SECCOMP_MODE_DISABLED
720 - 1 means SECCOMP_MODE_STRICT
721 - 2 means SECCOMP_MODE_FILTER
723 This field is provided only if the kernel was built with the
724 CONFIG_SECCOMP kernel configuration option enabled.
725 """
727 speculation_store_bypass: Annotated[Optional[str], str.strip]
728 """
729 Speculation flaw mitigation state (since Linux 4.17, see prctl(2)).
730 """
732 cpus_allowed: Annotated[Optional[Tuple[int, ...]], _comma_separated_hex_list]
733 """
734 Mask of CPUs on which this process may run
735 (since Linux 2.6.24, see cpuset(7)).
736 """
738 cpus_allowed_list: Annotated[Optional[str], str.strip]
739 """
740 Same as previous, but in "list format"
741 (since Linux 2.6.26, see cpuset(7)).
742 """
744 mems_allowed: Annotated[Optional[Tuple[int, ...]], _comma_separated_hex_list]
745 """
746 Mask of memory nodes allowed to this process
747 (since Linux 2.6.24, see cpuset(7)).
748 """
750 mems_allowed_list: Annotated[Optional[str], str.strip]
751 """
752 Same as previous, but in "list format"
753 (since Linux 2.6.26, see cpuset(7)).
754 """
756 voluntary_ctxt_switches: Annotated[Optional[int], int]
757 """Number of voluntary context switches (since Linux 2.6.23)."""
759 nonvoluntary_ctxt_switches: Annotated[Optional[int], int]
760 """Number of involuntary context switches (since Linux 2.6.23)."""
762 @classmethod
763 def from_bytes(cls, b):
764 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
765 # decode order is important for PyPy performance
766 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
767 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
768 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
769 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
770 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
771 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
773 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
775def read_status(b, *, dictcls=dict, **kwargs):
776 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_lt_32_cpus_6_8procpath.test.unit.TestProcfile.test_read_status_multiple_nsprocpath.test.unit.TestProctreeForest.test_read_process_dictprocpath.test.unit.TestProctreeForest.test_read_process_dict_corrupted_status
778registry['status'] = ProcfileType(
779 reader=read_file(read_status),
780 schema=Status,
781 empty=Status(*[None] * len(Status._fields))._asdict(),
782)
785class Fd(NamedTuple):
786 """
787 Counts of file descriptor types in ``/proc/{pid}/fd/*``.
789 For more details see ``man proc`` and ``man fstat``.
790 """
792 anon: int = 0
793 """
794 For file descriptors that have no corresponding inode (e.g., file
795 descriptors produced by epoll_create(2), eventfd(2),
796 inotify_init(2), signalfd(2), and timerfd(2)), the entry will be a
797 symbolic link with contents of the form::
799 anon_inode:<file-type>
801 In some cases, the file-type is surrounded by square brackets like:
803 - ``anon_inode:[eventfd]``
804 - ``anon_inode:[eventpoll]``
805 - ``anon_inode:[timerfd]``
806 - ``anon_inode:[signalfd]``
807 - ``anon_inode:inotify``
808 - ``anon_inode:dmabuf``
809 - ``anon_inode:sync_fence``
811 """
813 dir: int = 0
814 """Directory."""
816 chr: int = 0
817 """Character device."""
819 blk: int = 0
820 """Block device."""
822 reg: int = 0
823 """Regular file."""
825 fifo: int = 0
826 """FIFO (named pipe)."""
828 lnk: int = 0
829 """Symbolic link."""
831 sock: int = 0
832 """Socket file."""
834 _lookup = {
835 0: 'anon',
836 stat.S_IFDIR: 'dir',
837 stat.S_IFCHR: 'chr',
838 stat.S_IFBLK: 'blk',
839 stat.S_IFREG: 'reg',
840 stat.S_IFIFO: 'fifo',
841 stat.S_IFLNK: 'lnk',
842 stat.S_IFSOCK: 'sock',
843 }
845 @classmethod
846 def _scan_fd(cls, dirname):
847 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
848 try: procpath.test.unit.TestProcfile.test_read_fdprocpath.test.unit.TestProcfile.test_read_fd_unknown_descriptor_typeprocpath.test.unit.TestProctreeForest.test_read_process_dict
849 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
850 except (KeyError, FileNotFoundError): procpath.test.unit.TestProcfile.test_read_fd_unknown_descriptor_type
851 pass procpath.test.unit.TestProcfile.test_read_fd_unknown_descriptor_type
853 @classmethod
854 def from_dir(cls, dirname):
855 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
857def read_fd(dirname, *, dictcls=dict, **kwargs):
858 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
860registry['fd'] = ProcfileType(read_fd, Fd, Fd()._asdict())
863class SmapsRollup(NamedTuple):
864 """
865 Representation of ``/proc/{pid}/smaps_rollup``.
867 This file was added to the Kernel in version 4.14. It provides
868 pre-summed memory information for a process, and contains most of
869 the fields of ``/proc/{pid}/smaps``.
871 All fields are expressed in kB. Kernel threads have the file empty.
872 """
874 rss: Optional[int]
875 """
876 Resident Set Size. Sum of the mappings that are currently
877 resident in RAM.
878 """
880 pss: Optional[int]
881 """
882 Proportional Set Size. The process' proportional share of its
883 mappings. If a process has 100 unshared pages(``USS``), and 100
884 shared with another process, its ``PSS`` will be 150.
885 """
887 shared_clean: Optional[int]
888 """The number of clean shared pages in process' mappings."""
890 shared_dirty: Optional[int]
891 """The number of dirty shared pages in process' mappings."""
893 private_clean: Optional[int]
894 """The number of clean private pages in process' mappings."""
896 private_dirty: Optional[int]
897 """The number of dirty private pages in process' mappings."""
899 referenced: Optional[int]
900 """
901 It indicates the amount of memory currently marked as referenced
902 or accessed.
903 """
905 anonymous: Optional[int]
906 """
907 It shows the amount of memory that does not belong to any file.
908 """
910 lazyfree: Optional[int]
911 """
912 It shows the amount of memory which is marked by
913 ``madvise(MADV_FREE)``. The memory isn't freed immediately with
914 ``madvise()``. It's freed in memory pressure if the memory is
915 clean.
916 """
918 anonhugepages: Optional[int]
919 """
920 It shows the amount of memory backed by transparent huge pages.
921 """
923 shmempmdmapped: Optional[int]
924 """
925 It shows the amount of shared (shmem/tmpfs) memory backed by
926 huge pages.
927 """
929 shared_hugetlb: Optional[int]
930 """
931 It shows the amount of memory backed by hugetlbfs page which is not
932 counted in ``rss`` or ``pss`` fields for historical reasons. And
933 it is not included in ``shared_clean`` and ``shared_dirty`` fields.
934 """
936 private_hugetlb: Optional[int]
937 """
938 It shows the amount of memory backed by hugetlbfs page which is not
939 counted in ``rss`` or ``pss`` fields for historical reasons. And
940 it is not included in ``private_clean`` and ``private_dirty``
941 fields.
942 """
944 swap: Optional[int]
945 """
946 It shows how much would-be-anonymous memory is also used, but out
947 on swap.
948 """
950 swappss: Optional[int]
951 """
952 It shows proportional swap share of process' mappings. Unlike
953 ``swap``, this does not take into account swapped out page of
954 underlying shmem objects.
955 """
957 locked: Optional[int]
958 """It indicates the mappings that are locked in memory."""
960 @classmethod
961 def from_bytes(cls, b):
962 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
963 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
964 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
965 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
966 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
967 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
968 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
970 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
972def read_smaps_rollup(b, *, dictcls=dict, **kwargs):
973 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
975registry['smaps_rollup'] = ProcfileType(
976 reader=read_file(read_smaps_rollup),
977 schema=SmapsRollup,
978 empty=SmapsRollup(*[None] * len(SmapsRollup._fields))._asdict(),
979)