Skip to content

Corrects the spelling of "descendant" #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions docs/notebook/tutorial.ipynb

Large diffs are not rendered by default.

94 changes: 47 additions & 47 deletions docs/tutorial.rst

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions src/gpu_tracker/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
time_unit, _TrackingProcess._time_unit2coefficient, unit_type='time')
self._disable_logs = disable_logs
self._main_process_id = main_process_id
percent_keys = ['cpu_system', 'cpu_main', 'cpu_descendents', 'cpu_combined', 'gpu']
percent_keys = ['cpu_system', 'cpu_main', 'cpu_descendants', 'cpu_combined', 'gpu']
self._sum_percent_sums = {key: 0. for key in percent_keys}
self._hardware_percent_sums = {key: 0. for key in percent_keys}
self._tracking_iteration = 1
Expand Down Expand Up @@ -125,20 +125,20 @@ def run(self):
# Tracking has completed.
break
try:
descendent_processes = [
descendant_processes = [
process for process in main_process.children(recursive=True) if process.pid not in self._extraneous_process_ids]
# The first call to cpu_percent returns a meaningless value of 0.0 and should be ignored.
# And it's recommended to wait a specified amount of time after the first call to cpu_percent.
# See https://psutil.readthedocs.io/en/latest/#psutil.Process.cpu_percent
self._map_processes(processes=[main_process] + descendent_processes, map_func=get_cpu_percent)
self._map_processes(processes=[main_process] + descendant_processes, map_func=get_cpu_percent)
# Get the maximum RAM usage.
ram_map_func = get_memory_maps if self._is_linux else get_rss
main_ram = self._map_processes([main_process], map_func=ram_map_func)
descendents_ram = self._map_processes(descendent_processes, map_func=ram_map_func)
combined_ram = main_ram + descendents_ram
descendants_ram = self._map_processes(descendant_processes, map_func=ram_map_func)
combined_ram = main_ram + descendants_ram
kwarg = 'memory_maps_list' if self._is_linux else 'rss_list'
self._update_ram(rss_values=self._resource_usage.max_ram.main, **{kwarg: main_ram})
self._update_ram(rss_values=self._resource_usage.max_ram.descendents, **{kwarg: descendents_ram})
self._update_ram(rss_values=self._resource_usage.max_ram.descendants, **{kwarg: descendants_ram})
self._update_ram(rss_values=self._resource_usage.max_ram.combined, **{kwarg: combined_ram})
self._resource_usage.max_ram.system = max(
self._resource_usage.max_ram.system, psutil.virtual_memory().used * self._ram_coefficient)
Expand All @@ -148,8 +148,8 @@ def run(self):
if len(gpu_info):
process_ids = {self._main_process_id}
self._update_gpu_ram(attr='main', process_ids=process_ids, gpu_info=gpu_info)
process_ids = set(self._map_processes(processes=descendent_processes, map_func=lambda process: process.pid))
self._update_gpu_ram(attr='descendents', process_ids=process_ids, gpu_info=gpu_info)
process_ids = set(self._map_processes(processes=descendant_processes, map_func=lambda process: process.pid))
self._update_gpu_ram(attr='descendants', process_ids=process_ids, gpu_info=gpu_info)
process_ids.add(self._main_process_id)
self._update_gpu_ram(attr='combined', process_ids=process_ids, gpu_info=gpu_info)
gpu_info = _TrackingProcess._query_gpu(nvidia_command='--query-gpu=uuid,memory.used,utilization.gpu')
Expand All @@ -164,10 +164,10 @@ def run(self):

# Get the mean and maximum CPU usages.
main_n_threads = self._map_processes([main_process], map_func=get_n_threads)
descendent_n_threads = self._map_processes(descendent_processes, map_func=get_n_threads)
descendant_n_threads = self._map_processes(descendant_processes, map_func=get_n_threads)
self._update_n_threads(n_threads_list=main_n_threads, attr='main')
self._update_n_threads(n_threads_list=descendent_n_threads, attr='descendents')
self._update_n_threads(n_threads_list=main_n_threads + descendent_n_threads, attr='combined')
self._update_n_threads(n_threads_list=descendant_n_threads, attr='descendants')
self._update_n_threads(n_threads_list=main_n_threads + descendant_n_threads, attr='combined')
# noinspection PyTypeChecker
system_core_percentages: list[float] = psutil.cpu_percent(percpu=True)
cpu_utilization = self._resource_usage.cpu_utilization
Expand All @@ -176,15 +176,15 @@ def run(self):
percent_key='cpu_system', n_hardware_units=cpu_utilization.system_core_count)
time.sleep(_TrackingProcess._CPU_PERCENT_INTERVAL)
main_percentage = self._map_processes([main_process], map_func=get_cpu_percent)
descendent_percentages = self._map_processes(processes=descendent_processes, map_func=get_cpu_percent)
descendant_percentages = self._map_processes(processes=descendant_processes, map_func=get_cpu_percent)
self._update_processing_unit_utilization(
current_percentages=main_percentage, processing_unit_percentages=cpu_utilization.main, percent_key='cpu_main',
n_hardware_units=cpu_utilization.n_expected_cores)
self._update_processing_unit_utilization(
current_percentages=descendent_percentages, processing_unit_percentages=cpu_utilization.descendents,
percent_key='cpu_descendents', n_hardware_units=cpu_utilization.n_expected_cores)
current_percentages=descendant_percentages, processing_unit_percentages=cpu_utilization.descendants,
percent_key='cpu_descendants', n_hardware_units=cpu_utilization.n_expected_cores)
self._update_processing_unit_utilization(
current_percentages=main_percentage + descendent_percentages, processing_unit_percentages=cpu_utilization.combined,
current_percentages=main_percentage + descendant_percentages, processing_unit_percentages=cpu_utilization.combined,
percent_key='cpu_combined', n_hardware_units=cpu_utilization.n_expected_cores)
# Update compute time.
self._resource_usage.compute_time.time = (time.time() - start_time) * self._time_coefficient
Expand Down Expand Up @@ -398,7 +398,7 @@ def __str__(self) -> str:
text = text.replace(': {', ':').replace('{', '').replace('}', '').replace('_', ' ').replace('"', '').replace(',', '')
return text.replace('max', 'Max').replace('ram', 'RAM').replace('unit', 'Unit').replace('system', 'System').replace(
'compute', 'Compute').replace('time: ', 'Time: ').replace('rss', 'RSS').replace('total', 'Total').replace(
'private', 'Private').replace('shared', 'Shared').replace('main', 'Main').replace('descendents', 'Descendents').replace(
'private', 'Private').replace('shared', 'Shared').replace('main', 'Main').replace('descendants', 'Descendants').replace(
'combined', 'Combined').replace('gpu', 'GPU').replace('mean', 'Mean').replace('cpu', 'CPU').replace(
'n threads', 'number of threads').replace('n expected', 'Number of expected')

Expand Down Expand Up @@ -444,14 +444,14 @@ class MaxRAM:
:param system_capacity: A constant value for the RAM capacity of the entire operating system.
:param system: The RAM usage across the entire operating system.
:param main: The RAM usage of the main process.
:param descendents: The summed RAM usage of the descendent processes (i.e. child processes, grandchild processes, etc.).
:param combined: The summed RAM usage of both the main process and any descendent processes it may have.
:param descendants: The summed RAM usage of the descendant processes (i.e. child processes, grandchild processes, etc.).
:param combined: The summed RAM usage of both the main process and any descendant processes it may have.
"""
unit: str
system_capacity: float
system: float = 0.
main: RSSValues = dclass.field(default_factory=RSSValues)
descendents: RSSValues = dclass.field(default_factory=RSSValues)
descendants: RSSValues = dclass.field(default_factory=RSSValues)
combined: RSSValues = dclass.field(default_factory=RSSValues)


Expand All @@ -464,14 +464,14 @@ class MaxGPURAM:
:param system_capacity: A constant value for the GPU RAM capacity of all the GPUs in the system.
:param system: The GPU RAM usage of all the GPUs in the system.
:param main: The GPU RAM usage of the main process.
:param descendents: The summed GPU RAM usage of the descendent processes (i.e. child processes, grandchild processes, etc.).
:param combined: The summed GPU RAM usage of both the main process and any descendent processes it may have.
:param descendants: The summed GPU RAM usage of the descendant processes (i.e. child processes, grandchild processes, etc.).
:param combined: The summed GPU RAM usage of both the main process and any descendant processes it may have.
"""
unit: str
system_capacity: float
system: float = 0.
main: float = 0.
descendents: float = 0.
descendants: float = 0.
combined: float = 0.


Expand All @@ -498,27 +498,27 @@ class ProcessingUnitPercentages:
@dclass.dataclass
class CPUUtilization:
"""
Information related to CPU usage, including core utilization percentages of the main process and any descendent processes it may have as well as system-wide utilization.
The system hardware utilization percentages are strictly divided by the total number of cores in the system while that of the main, descendent, and combined processes can be divided by the expected number of cores used in a task.
Information related to CPU usage, including core utilization percentages of the main process and any descendant processes it may have as well as system-wide utilization.
The system hardware utilization percentages are strictly divided by the total number of cores in the system while that of the main, descendant, and combined processes can be divided by the expected number of cores used in a task.

:param system_core_count: The number of cores available to the entire operating system.
:param n_expected_cores: The number of cores expected to be used by the main process and/or any descendent processes it may have.
:param n_expected_cores: The number of cores expected to be used by the main process and/or any descendant processes it may have.
:param system: The utilization percentages of all the cores in the entire operating system.
:param main: The utilization percentages of the cores used by the main process.
:param descendents: The utilization percentages summed across descendent processes (i.e. child processes, grandchild processes, etc.).
:param combined: The utilization percentages summed across both the descendent processes and the main process.
:param descendants: The utilization percentages summed across descendant processes (i.e. child processes, grandchild processes, etc.).
:param combined: The utilization percentages summed across both the descendant processes and the main process.
:param main_n_threads: The maximum detected number of threads used by the main process at any time.
:param descendents_n_threads: The maximum sum of threads used across the descendent processes at any time.
:param combined_n_threads: The maximum sum of threads used by both the main and descendent processes.
:param descendants_n_threads: The maximum sum of threads used across the descendant processes at any time.
:param combined_n_threads: The maximum sum of threads used by both the main and descendant processes.
"""
system_core_count: int
n_expected_cores: int
system: ProcessingUnitPercentages = dclass.field(default_factory=ProcessingUnitPercentages)
main: ProcessingUnitPercentages = dclass.field(default_factory=ProcessingUnitPercentages)
descendents: ProcessingUnitPercentages = dclass.field(default_factory=ProcessingUnitPercentages)
descendants: ProcessingUnitPercentages = dclass.field(default_factory=ProcessingUnitPercentages)
combined: ProcessingUnitPercentages = dclass.field(default_factory=ProcessingUnitPercentages)
main_n_threads: int = 0
descendents_n_threads: int = 0
descendants_n_threads: int = 0
combined_n_threads: int = 0


Expand Down
8 changes: 4 additions & 4 deletions tests/data/False-Linux-bytes-megabytes-seconds.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"private_rss": 6718.0,
"shared_rss": 10036.0
},
"descendents": {
"descendants": {
"total_rss": 30208.0,
"private_rss": 13818.0,
"shared_rss": 16390.0
Expand All @@ -24,7 +24,7 @@
"system_capacity": 36594.0,
"system": 6500.0,
"main": 1600.0,
"descendents": 4300.0,
"descendants": 4300.0,
"combined": 5800.0
},
"cpu_utilization": {
Expand All @@ -42,7 +42,7 @@
"mean_sum_percent": 119.7,
"mean_hardware_percent": 39.9
},
"descendents": {
"descendants": {
"max_sum_percent": 142.2,
"max_hardware_percent": 47.4,
"mean_sum_percent": 129.73333333333332,
Expand All @@ -55,7 +55,7 @@
"mean_hardware_percent": 83.14444444444445
},
"main_n_threads": 2,
"descendents_n_threads": 6,
"descendants_n_threads": 6,
"combined_n_threads": 8
},
"gpu_utilization": {
Expand Down
8 changes: 4 additions & 4 deletions tests/data/False-Linux-bytes-megabytes-seconds.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Max RAM:
Total RSS: 16754.0
Private RSS: 6718.0
Shared RSS: 10036.0
Descendents:
Descendants:
Total RSS: 30208.0
Private RSS: 13818.0
Shared RSS: 16390.0
Expand All @@ -19,7 +19,7 @@ Max GPU RAM:
System capacity: 36594.0
System: 6500.0
Main: 1600.0
Descendents: 4300.0
Descendants: 4300.0
Combined: 5800.0
CPU utilization:
System core count: 4
Expand All @@ -34,7 +34,7 @@ CPU utilization:
Max hardware percent: 66.3
Mean sum percent: 119.7
Mean hardware percent: 39.9
Descendents:
Descendants:
Max sum percent: 142.2
Max hardware percent: 47.4
Mean sum percent: 129.733
Expand All @@ -45,7 +45,7 @@ CPU utilization:
Mean sum percent: 249.433
Mean hardware percent: 83.144
Main number of threads: 2
Descendents number of threads: 6
Descendants number of threads: 6
Combined number of threads: 8
GPU utilization:
System GPU count: 3
Expand Down
8 changes: 4 additions & 4 deletions tests/data/False-Linux-kilobytes-bytes-days.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"private_rss": 6.718,
"shared_rss": 10.036
},
"descendents": {
"descendants": {
"total_rss": 30.208,
"private_rss": 13.818,
"shared_rss": 16.39
Expand All @@ -24,7 +24,7 @@
"system_capacity": 36594000000.0,
"system": 6500000000.0,
"main": 1600000000.0,
"descendents": 4300000000.0,
"descendants": 4300000000.0,
"combined": 5800000000.0
},
"cpu_utilization": {
Expand All @@ -42,7 +42,7 @@
"mean_sum_percent": 119.7,
"mean_hardware_percent": 29.925
},
"descendents": {
"descendants": {
"max_sum_percent": 142.2,
"max_hardware_percent": 35.55,
"mean_sum_percent": 129.73333333333332,
Expand All @@ -55,7 +55,7 @@
"mean_hardware_percent": 62.35833333333333
},
"main_n_threads": 2,
"descendents_n_threads": 6,
"descendants_n_threads": 6,
"combined_n_threads": 8
},
"gpu_utilization": {
Expand Down
8 changes: 4 additions & 4 deletions tests/data/False-Linux-kilobytes-bytes-days.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Max RAM:
Total RSS: 16.754
Private RSS: 6.718
Shared RSS: 10.036
Descendents:
Descendants:
Total RSS: 30.208
Private RSS: 13.818
Shared RSS: 16.39
Expand All @@ -19,7 +19,7 @@ Max GPU RAM:
System capacity: 36594000000.0
System: 6500000000.0
Main: 1600000000.0
Descendents: 4300000000.0
Descendants: 4300000000.0
Combined: 5800000000.0
CPU utilization:
System core count: 4
Expand All @@ -34,7 +34,7 @@ CPU utilization:
Max hardware percent: 49.725
Mean sum percent: 119.7
Mean hardware percent: 29.925
Descendents:
Descendants:
Max sum percent: 142.2
Max hardware percent: 35.55
Mean sum percent: 129.733
Expand All @@ -45,7 +45,7 @@ CPU utilization:
Mean sum percent: 249.433
Mean hardware percent: 62.358
Main number of threads: 2
Descendents number of threads: 6
Descendants number of threads: 6
Combined number of threads: 8
GPU utilization:
System GPU count: 3
Expand Down
8 changes: 4 additions & 4 deletions tests/data/False-Linux-kilobytes-gigabytes-minutes.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"private_rss": 6.718,
"shared_rss": 10.036
},
"descendents": {
"descendants": {
"total_rss": 30.208,
"private_rss": 13.818,
"shared_rss": 16.39
Expand All @@ -24,7 +24,7 @@
"system_capacity": 36.594,
"system": 6.5,
"main": 1.6,
"descendents": 4.3,
"descendants": 4.3,
"combined": 5.8
},
"cpu_utilization": {
Expand All @@ -42,7 +42,7 @@
"mean_sum_percent": 119.7,
"mean_hardware_percent": 59.85
},
"descendents": {
"descendants": {
"max_sum_percent": 142.2,
"max_hardware_percent": 71.1,
"mean_sum_percent": 129.73333333333332,
Expand All @@ -55,7 +55,7 @@
"mean_hardware_percent": 124.71666666666665
},
"main_n_threads": 2,
"descendents_n_threads": 6,
"descendants_n_threads": 6,
"combined_n_threads": 8
},
"gpu_utilization": {
Expand Down
8 changes: 4 additions & 4 deletions tests/data/False-Linux-kilobytes-gigabytes-minutes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Max RAM:
Total RSS: 16.754
Private RSS: 6.718
Shared RSS: 10.036
Descendents:
Descendants:
Total RSS: 30.208
Private RSS: 13.818
Shared RSS: 16.39
Expand All @@ -19,7 +19,7 @@ Max GPU RAM:
System capacity: 36.594
System: 6.5
Main: 1.6
Descendents: 4.3
Descendants: 4.3
Combined: 5.8
CPU utilization:
System core count: 4
Expand All @@ -34,7 +34,7 @@ CPU utilization:
Max hardware percent: 99.45
Mean sum percent: 119.7
Mean hardware percent: 59.85
Descendents:
Descendants:
Max sum percent: 142.2
Max hardware percent: 71.1
Mean sum percent: 129.733
Expand All @@ -45,7 +45,7 @@ CPU utilization:
Mean sum percent: 249.433
Mean hardware percent: 124.717
Main number of threads: 2
Descendents number of threads: 6
Descendants number of threads: 6
Combined number of threads: 8
GPU utilization:
System GPU count: 3
Expand Down
Loading
Loading