helpers
resource_tracker.helpers
#
General helpers.
Functions:
Name | Description |
---|---|
is_partition |
Determine if a disk name represents a partition rather than a whole disk. |
is_psutil_available |
Check if psutil is installed and available for import. |
is_procfs_available |
Check if procfs is available on the system. |
get_tracker_implementation |
Determine which tracker implementation to use based on available system resources. |
get_zfs_pools_space |
Get the space of ZFS pools. |
cleanup_files |
Cleanup files. |
cleanup_processes |
Gracefully, then if needed forcefully terminate and close processes. |
aggregate_stats |
Aggregate statistics from multiple sources. |
render_csv_row |
Format a single CSV row as a string in memory. |
is_partition
cached
#
Determine if a disk name represents a partition rather than a whole disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
disk_name
|
str
|
Name of the disk device (e.g., 'sda1', 'nvme0n1p1') |
required |
Returns:s True if the device is likely a partition, False otherwise
Source code in resource_tracker/helpers.py
is_psutil_available
cached
#
Check if psutil is installed and available for import.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if psutil is available, False otherwise |
Source code in resource_tracker/helpers.py
is_procfs_available
cached
#
Check if procfs is available on the system.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if procfs is available, False otherwise |
get_tracker_implementation
cached
#
Determine which tracker implementation to use based on available system resources.
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple[Callable, Callable]
|
A tuple containing (get_process_stats, get_system_stats) functions from the appropriate implementation module. |
Raises:
Type | Description |
---|---|
ImportError
|
If no suitable implementation is available. |
Source code in resource_tracker/helpers.py
get_zfs_pools_space
#
Get the space of ZFS pools.
Source code in resource_tracker/helpers.py
cleanup_files
#
cleanup_processes
#
Gracefully, then if needed forcefully terminate and close processes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
processes
|
List[Process]
|
List of |
required |
Source code in resource_tracker/helpers.py
aggregate_stats
#
Aggregate statistics from multiple sources.
This function combines statistics from multiple runs or sources generated by resource_tracker.ResourceTracker.stats, handling different aggregation types appropriately:
- For
mean
andduration
values: computes the average value across all sources. - For
max
andsum
values: takes the maximum value across all sources.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stats
|
List[Dict[str, Dict[str, Any]]]
|
A list of dictionaries containing statistics. Each dictionary should have column names as keys and dictionaries of aggregation types as values. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Dict[str, Any]]
|
A dictionary with the same structure as the input dictionaries, but with |
Dict[str, Dict[str, Any]]
|
aggregated values. |
Example:
>>> stats1 = {'cpu_usage': {'mean': 1.5, 'max': 2.0}, 'memory': {'mean': 100, 'max': 150}}
>>> stats2 = {'cpu_usage': {'mean': 2.5, 'max': 3.0}, 'memory': {'mean': 200, 'max': 250}}
>>> aggregate_stats([stats1, stats2])
{'cpu_usage': {'max': 3.0, 'mean': 2.0}, 'memory': {'max': 250, 'mean': 150.0}}
Source code in resource_tracker/helpers.py
render_csv_row
#
render_csv_row(row, quoting=QUOTE_NONNUMERIC)
Format a single CSV row as a string in memory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row
|
Iterable[Union[str, float, int, None]]
|
A list or iterable of values to write (strings, numbers, or None) with csv.writer. |
required |
quoting
|
int
|
Quoting strategy for the CSV writer. Defaults to QUOTE_NONNUMERIC. |
QUOTE_NONNUMERIC
|
Returns:
Type | Description |
---|---|
bytes
|
A bytes object representing the full CSV-formatted row (including newline). |