amsatop.utils package

Module contents

This module provides utility logic to simplify the implementation of amsatop. While it’s possible to build your solution without it, these components are designed to make your life easier.

class amsatop.utils.StatFile(pid: int, command: str, state: str, ppid: int, pgrp: int, session: int, tty_nr: int, tpgid: int, flags: int, minflt: int, cminflt: int, majflt: int, cmajflt: int, utime: int, stime: int, cutime: int, cstime: int, priority: int, nice: int, num_threads: int, starttime: int)[source]

Bases: object

Represents key fields from a process’s or thread /proc/[pid or tgid]/stat file.

cmajflt: int
cminflt: int
command: str
cstime: int
cutime: int
flags: int
classmethod from_stat_line(line: str) StatFile[source]

Get a StatFile from the lines of the file :meta private:

majflt: int
minflt: int
nice: int
num_threads: int
pgrp: int
pid: int
ppid: int
priority: int
session: int
starttime: int
state: str
stime: int
tpgid: int
tty_nr: int
utime: int
class amsatop.utils.StatusFile(Name: str, State: str, Tgid: int, Ngid: int, Pid: int, PPid: int, TracerPid: int, Uid: ~typing.List[int], Gid: ~typing.List[int], FDSize: int, Groups: ~typing.List[int] = <factory>, NStgid: int = 0, NSpid: int = 0, NSpgid: int = 0, NSsid: int = 0, Kthread: int = 0, VmPeak: int = 0, VmSize: int = 0, VmLck: int = 0, VmPin: int = 0, VmHWM: int = 0, VmRSS: int = 0, RssAnon: int = 0, RssFile: int = 0, RssShmem: int = 0, VmData: int = 0, VmStk: int = 0, VmExe: int = 0, VmLib: int = 0, VmPTE: int = 0, VmSwap: int = 0, HugetlbPages: int = 0, CoreDumping: int = 0, THP_enabled: int = 0, untag_mask: str = '', Threads: int = 0, SigQ: str = '', SigPnd: str = '', ShdPnd: str = '', SigBlk: str = '', SigIgn: str = '', SigCgt: str = '', CapInh: str = '', CapPrm: str = '', CapEff: str = '', CapBnd: str = '', CapAmb: str = '', NoNewPrivs: int = 0, Seccomp: int = 0, Seccomp_filters: int = 0, Speculation_Store_Bypass: str = '', SpeculationIndirectBranch: str = '', Cpus_allowed: str = '', Cpus_allowed_list: str = '', Mems_allowed: str = '', Mems_allowed_list: str = '', voluntary_ctxt_switches: int = 0, nonvoluntary_ctxt_switches: int = 0, x86_Thread_features: str | None = '', x86_Thread_features_locked: str | None = '', Umask: str | None = None)[source]

Bases: object

Represents the parsed contents of a /proc/[pid or tgid]/status file on a Linux system. All fields map to their corresponding values in the status file.

CapAmb: str = ''
CapBnd: str = ''
CapEff: str = ''
CapInh: str = ''
CapPrm: str = ''
CoreDumping: int = 0
Cpus_allowed: str = ''
Cpus_allowed_list: str = ''
FDSize: int
Gid: List[int]
Groups: List[int]
HugetlbPages: int = 0
Kthread: int = 0
Mems_allowed: str = ''
Mems_allowed_list: str = ''
NSpgid: int = 0
NSpid: int = 0
NSsid: int = 0
NStgid: int = 0
Name: str
Ngid: int
NoNewPrivs: int = 0
PPid: int
Pid: int
RssAnon: int = 0
RssFile: int = 0
RssShmem: int = 0
Seccomp: int = 0
Seccomp_filters: int = 0
ShdPnd: str = ''
SigBlk: str = ''
SigCgt: str = ''
SigIgn: str = ''
SigPnd: str = ''
SigQ: str = ''
SpeculationIndirectBranch: str = ''
Speculation_Store_Bypass: str = ''
State: str
THP_enabled: int = 0
Tgid: int
Threads: int = 0
TracerPid: int
Uid: List[int]
Umask: str | None = None
VmData: int = 0
VmExe: int = 0
VmHWM: int = 0
VmLck: int = 0
VmLib: int = 0
VmPTE: int = 0
VmPeak: int = 0
VmPin: int = 0
VmRSS: int = 0
VmSize: int = 0
VmStk: int = 0
VmSwap: int = 0
classmethod from_lines(lines: List[str]) StatusFile[source]

Get a StatusFile from the lines of the file :meta private:

nonvoluntary_ctxt_switches: int = 0
untag_mask: str = ''
voluntary_ctxt_switches: int = 0
x86_Thread_features: str | None = ''
x86_Thread_features_locked: str | None = ''
amsatop.utils.get_stat_file_from_path(path: str) StatFile | None[source]

Given a path, returns a StatFile, which can be useful for analyzing a process or thread.

Parameters:

path – path to the stat file (will be usually in the form of /proc/[pid or tgid]/stat

Returns:

StatFile or None if the path doesn’t exist.

Raises:

ValueError if the path isn’t valid.

amsatop.utils.get_status_file_from_path(path: str) StatusFile | None[source]

Given a path, returns a StatusFile, which can be useful for analyzing a process or thread.

Parameters:

path – path to the status file (will be usually in the form of /proc/[pid or tgid]/status

Returns:

StatusFile or None if the path doesn’t exist (or other unhandled exception)

Raises:

ValueError if the path isn’t valid.