tracker_procfs
resource_tracker.tracker_procfs
#
Helpers to track resource usage via procfs
.
Note that procfs
is specific to Linux, and these helpers rely on modern (2017+)
kernel features, such as smaps_rollup
, which is much faster than iterating
over all smaps
files.
Functions:
Name | Description |
---|---|
get_sector_sizes |
Get the sector size of all disks. |
get_pid_children |
Get all descendant processes recursively. |
get_pid_rss |
Get the current resident set size of a process. |
get_pid_pss_rollup |
Reads the total PSS from |
get_pid_proc_times |
Get the current user and system times of a process from |
get_pid_proc_io |
Get the total bytes read and written by a process from |
get_pid_stats |
Collect current/cumulative stats of a process from procfs. |
get_system_stats |
Collect current system-wide stats from procfs. |
get_sector_sizes
cached
#
Get the sector size of all disks.
Returns:
Type | Description |
---|---|
Dict[str, int]
|
A dictionary mapping disk names to their sector sizes. |
Source code in resource_tracker/tracker_procfs.py
get_pid_children
#
Get all descendant processes recursively.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pid
|
int
|
The process ID to get descendant processes for. |
required |
Returns:
Type | Description |
---|---|
Set[int]
|
All descendant process ids. |
Source code in resource_tracker/tracker_procfs.py
get_pid_rss
#
Get the current resident set size of a process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pid
|
int
|
The process ID to get the resident set size for. |
required |
Returns:
Type | Description |
---|---|
int
|
The current resident set size of the process in kB. |
Source code in resource_tracker/tracker_procfs.py
get_pid_pss_rollup
#
Reads the total PSS from /proc/{pid}/smaps_rollup
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pid
|
int
|
The process ID to get the total PSS for. |
required |
Returns:
Type | Description |
---|---|
int
|
The total PSS in kB. |
Source code in resource_tracker/tracker_procfs.py
get_pid_proc_times
#
Get the current user and system times of a process from /proc/{pid}/stat
.
Note that cannot use cutime
/cstime
for real-time monitoring,
as they need to wait for the children to exit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pid
|
int
|
Process ID to track |
required |
children
|
bool
|
Whether to include stats from exited child processes |
True
|
Returns:
Type | Description |
---|---|
Dict[str, int]
|
A dictionary containing process time information:
- |
Source code in resource_tracker/tracker_procfs.py
get_pid_proc_io
#
Get the total bytes read and written by a process from /proc/{pid}/io
.
Note that it is not tracking reading from memory-mapped objects,
and is fairly limited in what it can track. E.g. the process might
not even have permissions to read its own /proc/self/io
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pid
|
int
|
The process ID to get the total bytes read and written for. |
required |
Returns:
Type | Description |
---|---|
Dict[str, int]
|
A dictionary containing the total bytes read and written by the process. |
Source code in resource_tracker/tracker_procfs.py
get_pid_stats
#
Collect current/cumulative stats of a process from procfs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pid
|
int
|
The process ID to track. |
required |
children
|
bool
|
Whether to include child processes. |
True
|
Returns:
Type | Description |
---|---|
Dict[str, Union[int, float, None, Set[int]]]
|
A dictionary containing process stats:
|
Source code in resource_tracker/tracker_procfs.py
get_system_stats
#
Collect current system-wide stats from procfs.
Returns:
Type | Description |
---|---|
Dict[str, Union[int, float, Dict]]
|
A dictionary containing system stats:
|
Source code in resource_tracker/tracker_procfs.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|