nvitop.utils module
Utilities of nvitop APIs.
- nvitop.utils.UINT_MAX: int = 4294967295
The maximum value of
ctypes.c_uint
.
- nvitop.utils.ULONGLONG_MAX: int = 18446744073709551615
The maximum value of
ctypes.c_ulonglong
.
- nvitop.utils.SIZE_UNITS: dict[str | None, int] = {None: 1, '': 1, 'B': 1, 'KiB': 1024, 'MiB': 1048576, 'GiB': 1073741824, 'TiB': 1099511627776, 'PiB': 1125899906842624, 'KB': 1000, 'MB': 1000000, 'GB': 1000000000, 'TB': 1000000000000, 'PB': 1000000000000000}
Units of storage and memory measurements.
- nvitop.utils.bytes2human(b: int | float | NaType, *, min_unit: int = 1) str [source]
Convert bytes to a human readable string.
- nvitop.utils.human2bytes(s: int | str) int [source]
Convert a human readable size string (case insensitive) to bytes.
- Raises:
ValueError – If cannot convert the given size string.
Examples
>>> human2bytes('500B') 500 >>> human2bytes('10k') 10000 >>> human2bytes('10ki') 10240 >>> human2bytes('1M') 1000000 >>> human2bytes('1MiB') 1048576 >>> human2bytes('1.5GiB') 1610612736
- nvitop.utils.timedelta2human(dt: int | float | datetime.timedelta | NaType, *, round: bool = False) str [source]
Convert a number in seconds or a
datetime.timedelta
instance to a human readable string.
- nvitop.utils.utilization2string(utilization: int | float | NaType) str [source]
Convert a utilization rate to string.
- nvitop.utils.colored(text: str, color: str | None = None, on_color: str | None = None, attrs: Iterable[str] | None = None) str [source]
Colorize text with ANSI color escape codes.
- Available text colors:
red, green, yellow, blue, magenta, cyan, white.
- Available text highlights:
on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white.
- Available attributes:
bold, dark, underline, blink, reverse, concealed.
Examples
>>> colored('Hello, World!', 'red', 'on_grey', ['blue', 'blink']) >>> colored('Hello, World!', 'green')
- nvitop.utils.boolify(string: str, default: Any | None = None) bool [source]
Convert the given value, usually a string, to boolean.
- class nvitop.utils.Snapshot(real: Any, **items: Any)[source]
Bases:
object
A dict-like object holds the snapshot values.
The value can be accessed by
snapshot.name
orsnapshot['name']
syntax. The Snapshot can also be converted to a dictionary bydict(snapshot)
or{**snapshot}
.Missing attributes will be automatically fetched from the original object.
- __init__(real: Any, **items: Any) None [source]
Initialize a new
Snapshot
object with the given attributes.
- __getattr__(name: str) Any [source]
Get a member from the instance.
If the attribute is not defined, fetches from the original object and makes a function call.