Coverage for procpath/procfile.py: 100%

338 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2025-04-05 18:56 +0000

1""" 

2This module represents several Procfs [1]_ sources. 

3 

4.. [1] https://www.kernel.org/doc/html/latest/filesystems/proc.html 

5""" 

6 

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) 

22 

23 

24__all__ = 'registry', 'ProcfileType' 

25 

26 

27class ProcfileType(NamedTuple): 

28 reader: Callable[..., dict] 

29 schema: Union[type, str] 

30 empty: Optional[dict] 

31 

32registry: Dict[str, ProcfileType] = {} 

33 

34 

35def read_file(fn): 

36 """Wrap target function to pass it bytes read from the filename.""" 

37 

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

42 

43 return wrapper 

44 

45 

46class Stat(NamedTuple): 

47 """ 

48 Representation of ``/proc/{pid}/stat``, see ``man proc``. 

49 

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. 

53 

54 Formats of the fields are defined in C `printf`_ syntax. 

55 

56 .. _printf: http://www.cplusplus.com/reference/cstdio/printf/ 

57 """ 

58 

59 pid: int 

60 """ 

61 The process ID. 

62 

63 :format: %d 

64 """ 

65 

66 comm: str 

67 """ 

68 The filename of the executable. This is visible whether or not the 

69 executable is swapped out. 

70 

71 :format: %s 

72 """ 

73 

74 state: str 

75 """ 

76 One of the following characters, indicating process state: 

77 

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) 

90 

91 :format: %c 

92 """ 

93 

94 ppid: int 

95 """ 

96 The PID of the parent of this process. 

97 

98 :format: %d 

99 """ 

100 

101 pgrp: int 

102 """ 

103 The process group ID of the process. 

104 

105 :format: %d 

106 """ 

107 

108 session: int 

109 """ 

110 The session ID of the process. 

111 

112 :format: %d 

113 """ 

114 

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.) 

120 

121 :format: %d 

122 """ 

123 

124 tpgid: int 

125 """ 

126 The ID of the foreground process group of the controlling terminal 

127 of the process. 

128 

129 :format: %d 

130 """ 

131 

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. 

137 

138 The format for this field was %lu before Linux 2.6. 

139 

140 :format: %u 

141 """ 

142 

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. 

147 

148 :format: %lu 

149 """ 

150 

151 cminflt: int 

152 """ 

153 The number of minor faults that the process's 

154 waited-for children have made. 

155 

156 :format: %lu 

157 """ 

158 

159 majflt: int 

160 """ 

161 The number of major faults the process has made 

162 which have required loading a memory page from disk. 

163 

164 :format: %lu 

165 """ 

166 

167 cmajflt: int 

168 """ 

169 The number of major faults that the process's 

170 waited-for children have made. 

171 

172 :format: %lu 

173 """ 

174 

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. 

184 

185 :format: %lu 

186 """ 

187 

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)). 

193 

194 :format: %lu 

195 """ 

196 

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). 

203 

204 :format: %ld 

205 """ 

206 

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)). 

212 

213 :format: %ld 

214 """ 

215 

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. 

229 

230 Before Linux 2.6, this was a scaled value based on 

231 the scheduler weighting given to this process. 

232 

233 :format: %ld 

234 """ 

235 

236 nice: int 

237 """ 

238 The nice value (see setpriority(2)), a value in the 

239 range 19 (low priority) to -20 (high priority). 

240 

241 :format: %ld 

242 """ 

243 

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. 

249 

250 :format: %ld 

251 """ 

252 

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. 

258 

259 :format: %ld 

260 """ 

261 

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)). 

268 

269 The format for this field was %lu before Linux 2.6. 

270 

271 :format: %llu 

272 """ 

273 

274 vsize: int 

275 """ 

276 Virtual memory size in bytes. 

277 

278 :format: %lu 

279 """ 

280 

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. 

288 

289 :format: %ld 

290 """ 

291 

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. 

296 

297 :format: %llu 

298 """ 

299 

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. 

306 

307 :format: %lu 

308 """ 

309 

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. 

314 

315 :format: %ld 

316 """ 

317 

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

324 

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

329 

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

331 

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

334 

335registry['stat'] = ProcfileType( 

336 reader=read_file(read_stat), 

337 schema=Stat, 

338 empty=Stat(*[None] * len(Stat._fields))._asdict(), 

339) 

340 

341 

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

344 

345registry['cmdline'] = ProcfileType( 

346 reader=read_file(read_cmdline), 

347 schema='cmdline', 

348 empty=None, 

349) 

350 

351 

352class Io(NamedTuple): 

353 """Representation of ``/proc/{pid}/io``, see ``man proc``.""" 

354 

355 rchar: int 

356 """ 

357 I/O counter: chars read. 

358 

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 """ 

365 

366 wchar: int 

367 """ 

368 I/O counter: chars written. 

369 

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 """ 

373 

374 syscr: int 

375 """ 

376 I/O counter: read syscalls. 

377 

378 Attempt to count the number of read I/O operations, i.e. syscalls 

379 like read() and pread(). 

380 """ 

381 

382 syscw: int 

383 """ 

384 I/O counter: write syscalls. 

385 

386 Attempt to count the number of write I/O operations, i.e. syscalls 

387 like write() and pwrite(). 

388 """ 

389 

390 read_bytes: int 

391 """ 

392 I/O counter: bytes read. 

393 

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 """ 

398 

399 write_bytes: int 

400 """ 

401 I/O counter: bytes written. 

402 

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 """ 

406 

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 """ 

420 

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

426 

427Io._field_set = set(Io._fields) 

428 

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

431 

432registry['io'] = ProcfileType( 

433 reader=read_file(read_io), 

434 schema=Io, 

435 empty=Io(*[None] * len(Io._fields))._asdict(), 

436) 

437 

438 

439class StatusMeta(NamedTupleMeta): 

440 """Metaclass for ``(in_type, out_type)`` annotated named tuple.""" 

441 

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__ 

449 

450 rescls = super().__new__(cls, typename, bases, ns) 

451 rescls._field_conv_map = field_conv_map 

452 

453 field_types = rescls.__annotations__ 

454 rescls._optional_none = {f: None for f, t in field_types.items() if Optional[t] == t} 

455 

456 return rescls 

457 

458class Status(NamedTuple, metaclass=StatusMeta): 

459 """Representation of ``/proc/{pid}/status``, see ``man proc``.""" 

460 

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

463 

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

467 

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

470 

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

473 

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

476 

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 """ 

483 

484 umask: Annotated[Optional[int], partial(int, base=8)] 

485 """Process umask; see umask(2) (since Linux 4.7).""" 

486 

487 state: Annotated[str, _state] 

488 """ 

489 Current state of the process. One of: 

490 

491 - R (running) 

492 - S (sleeping) 

493 - D (disk sleep) 

494 - T (stopped) 

495 - t (tracing stop) 

496 - Z (zombie) 

497 - X (dead) 

498 

499 Only the letter code is kept. 

500 """ 

501 

502 tgid: Annotated[int, int] 

503 """Thread group ID (i.e., Process ID).""" 

504 

505 ngid: Annotated[Optional[int], int] 

506 """NUMA group ID (0 if none; since Linux 3.13).""" 

507 

508 pid: Annotated[int, int] 

509 """Thread ID (see gettid(2)).""" 

510 

511 ppid: Annotated[int, int] 

512 """PID of parent process.""" 

513 

514 tracerpid: Annotated[int, int] 

515 """ 

516 PID of process tracing this process (0 if not being traced). 

517 """ 

518 

519 uid: Annotated[Tuple[int, ...], _whitespace_separated_list] 

520 """Real, effective, saved set, and filesystem UIDs.""" 

521 

522 gid: Annotated[Tuple[int, ...], _whitespace_separated_list] 

523 """Real, effective, saved set, and filesystem GIDs.""" 

524 

525 fdsize: Annotated[int, int] 

526 """Number of file descriptor slots currently allocated.""" 

527 

528 groups: Annotated[Tuple[int, ...], _whitespace_separated_list] 

529 """Supplementary group list.""" 

530 

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 """ 

539 

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 """ 

545 

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 """ 

551 

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 """ 

558 

559 vmpeak: Annotated[Optional[int], _kb] 

560 """Peak virtual memory size, in kB.""" 

561 

562 vmsize: Annotated[Optional[int], _kb] 

563 """Virtual memory size, in kB.""" 

564 

565 vmlck: Annotated[Optional[int], _kb] 

566 """Locked memory size, in kB (see mlock(2)).""" 

567 

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 """ 

574 

575 vmhwm: Annotated[Optional[int], _kb] 

576 """Peak resident set size, in kB ("high water mark").""" 

577 

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 """ 

583 

584 rssanon: Annotated[Optional[int], _kb] 

585 """Size of resident anonymous memory, in kB (since Linux 4.5).""" 

586 

587 rssfile: Annotated[Optional[int], _kb] 

588 """Size of resident file mappings, in kB (since Linux 4.5).""" 

589 

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 """ 

596 

597 vmdata: Annotated[Optional[int], _kb] 

598 """Size of data, in kB.""" 

599 

600 vmstk: Annotated[Optional[int], _kb] 

601 """Size of stack, in kB.""" 

602 

603 vmexe: Annotated[Optional[int], _kb] 

604 """Size of text segments, in kB.""" 

605 

606 vmlib: Annotated[Optional[int], _kb] 

607 """Shared library code size, in kB.""" 

608 

609 vmpte: Annotated[Optional[int], _kb] 

610 """Page table entries size, in kB (since Linux 2.6.10).""" 

611 

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 """ 

617 

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 """ 

623 

624 hugetlbpages: Annotated[Optional[int], _kb] 

625 """ 

626 Size of hugetlb memory portions, in kB (since Linux 4.4). 

627 """ 

628 

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 """ 

636 

637 threads: Annotated[int, int] 

638 """Number of threads in process containing this thread.""" 

639 

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 """ 

648 

649 sigpnd: Annotated[int, partial(int, base=16)] 

650 """ 

651 Mask of signals pending for thread (see pthreads(7) and signal(7)). 

652 """ 

653 

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 """ 

659 

660 sigblk: Annotated[int, partial(int, base=16)] 

661 """Masks indicating signals being blocked (see signal(7)).""" 

662 

663 sigign: Annotated[int, partial(int, base=16)] 

664 """Masks indicating signals being ignored (see signal(7)).""" 

665 

666 sigcgt: Annotated[int, partial(int, base=16)] 

667 """Masks indicating signals being caught (see signal(7)).""" 

668 

669 capinh: Annotated[int, partial(int, base=16)] 

670 """ 

671 Masks of capabilities enabled in inheritable sets 

672 (see capabilities(7)). 

673 """ 

674 

675 capprm: Annotated[int, partial(int, base=16)] 

676 """ 

677 Masks of capabilities enabled in permitted sets 

678 (see capabilities(7)). 

679 """ 

680 

681 capeff: Annotated[int, partial(int, base=16)] 

682 """ 

683 Masks of capabilities enabled in effective sets 

684 (see capabilities(7)). 

685 """ 

686 

687 capbnd: Annotated[Optional[int], partial(int, base=16)] 

688 """ 

689 Capability bounding set (since Linux 2.6.26, see capabilities(7)). 

690 """ 

691 

692 capamb: Annotated[Optional[int], partial(int, base=16)] 

693 """ 

694 Ambient capability set (since Linux 4.3, see capabilities(7)). 

695 """ 

696 

697 nonewprivs: Annotated[Optional[int], int] 

698 """ 

699 Value of the no_new_privs bit (since Linux 4.10, see prctl(2)). 

700 """ 

701 

702 seccomp: Annotated[Optional[int], int] 

703 """ 

704 Seccomp mode of the process (since Linux 3.8, see seccomp(2)). 

705 

706 - 0 means SECCOMP_MODE_DISABLED 

707 - 1 means SECCOMP_MODE_STRICT 

708 - 2 means SECCOMP_MODE_FILTER 

709 

710 This field is provided only if the kernel was built with the 

711 CONFIG_SECCOMP kernel configuration option enabled. 

712 """ 

713 

714 speculation_store_bypass: Annotated[Optional[str], str.strip] 

715 """ 

716 Speculation flaw mitigation state (since Linux 4.17, see prctl(2)). 

717 """ 

718 

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 """ 

724 

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 """ 

730 

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 """ 

736 

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 """ 

742 

743 voluntary_ctxt_switches: Annotated[Optional[int], int] 

744 """Number of voluntary context switches (since Linux 2.6.23).""" 

745 

746 nonvoluntary_ctxt_switches: Annotated[Optional[int], int] 

747 """Number of involuntary context switches (since Linux 2.6.23).""" 

748 

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

759 

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

761 

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

764 

765registry['status'] = ProcfileType( 

766 reader=read_file(read_status), 

767 schema=Status, 

768 empty=Status(*[None] * len(Status._fields))._asdict(), 

769) 

770 

771 

772class Fd(NamedTuple): 

773 """ 

774 Counts of file descriptor types in ``/proc/{pid}/fd/*``. 

775 

776 For more details see ``man proc`` and ``man fstat``. 

777 """ 

778 

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:: 

785 

786 anon_inode:<file-type> 

787 

788 In some cases, the file-type is surrounded by square brackets like: 

789 

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`` 

797 

798 """ 

799 

800 dir: int = 0 

801 """Directory.""" 

802 

803 chr: int = 0 

804 """Character device.""" 

805 

806 blk: int = 0 

807 """Block device.""" 

808 

809 reg: int = 0 

810 """Regular file.""" 

811 

812 fifo: int = 0 

813 """FIFO (named pipe).""" 

814 

815 lnk: int = 0 

816 """Symbolic link.""" 

817 

818 sock: int = 0 

819 """Socket file.""" 

820 

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 } 

831 

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

839 

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

843 

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

846 

847registry['fd'] = ProcfileType(read_fd, Fd, Fd()._asdict()) 

848 

849 

850class SmapsRollup(NamedTuple): 

851 """ 

852 Representation of ``/proc/{pid}/smaps_rollup``. 

853 

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``. 

857 

858 All fields are expressed in kB. Kernel threads have the file empty. 

859 """ 

860 

861 rss: Optional[int] 

862 """ 

863 Resident Set Size. Sum of the mappings that are currently 

864 resident in RAM. 

865 """ 

866 

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 """ 

873 

874 shared_clean: Optional[int] 

875 """The number of clean shared pages in process' mappings.""" 

876 

877 shared_dirty: Optional[int] 

878 """The number of dirty shared pages in process' mappings.""" 

879 

880 private_clean: Optional[int] 

881 """The number of clean private pages in process' mappings.""" 

882 

883 private_dirty: Optional[int] 

884 """The number of dirty private pages in process' mappings.""" 

885 

886 referenced: Optional[int] 

887 """ 

888 It indicates the amount of memory currently marked as referenced 

889 or accessed. 

890 """ 

891 

892 anonymous: Optional[int] 

893 """ 

894 It shows the amount of memory that does not belong to any file. 

895 """ 

896 

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 """ 

904 

905 anonhugepages: Optional[int] 

906 """ 

907 It shows the amount of memory backed by transparent huge pages. 

908 """ 

909 

910 shmempmdmapped: Optional[int] 

911 """ 

912 It shows the amount of shared (shmem/tmpfs) memory backed by 

913 huge pages. 

914 """ 

915 

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 """ 

922 

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 """ 

930 

931 swap: Optional[int] 

932 """ 

933 It shows how much would-be-anonymous memory is also used, but out 

934 on swap. 

935 """ 

936 

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 """ 

943 

944 locked: Optional[int] 

945 """It indicates the mappings that are locked in memory.""" 

946 

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

956 

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

958 

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

961 

962registry['smaps_rollup'] = ProcfileType( 

963 reader=read_file(read_smaps_rollup), 

964 schema=SmapsRollup, 

965 empty=SmapsRollup(*[None] * len(SmapsRollup._fields))._asdict(), 

966)