Skip to content
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

Add CPU percentage of processes to the measurements #13

Closed
erikhuck opened this issue Mar 26, 2024 · 11 comments
Closed

Add CPU percentage of processes to the measurements #13

erikhuck opened this issue Mar 26, 2024 · 11 comments

Comments

@erikhuck
Copy link
Collaborator

This may not be as helpful information when child processes are used without showing the information for the main and child processes individually as described in #11. But the user can decide whether they want to see just the sum of all CPU percentages or that in addition to the more granular version. This stack overflow describes how this can be accomplished. We should explain in the documentation that a cpu usage of greater than 100% can occur if a process uses multiple threads across multiple cores.

@hunter-moseley
Copy link
Member

hunter-moseley commented Mar 26, 2024 via email

@erikhuck
Copy link
Collaborator Author

erikhuck commented Apr 9, 2024

Possible data class

class MaxCPUPercentage:
   system_cpu_count: int
   system_cpu_percent: float
   system_average_cpu_percent: float # possibly
   main_cpu_percent: float
   main_normalized_cpu_percent: float
   descendent_cpu_percent: float
   descendent_average_cpu_percent: float
   combined_cpu_percent: float
   combined_average_cpu_percent: float
   main_n_threads: int
   descendent_n_threads: int
   combined_n_threads: int
  • psutil.cpu_count() returns the system-wide number of CPUs (cores).
    • Don't worry about logical versus physical. Just accept the default return value.
  • The system-wide cpu_percent can be obtained via psutil.cpu_percent().
    • We want to test this and determine what exactly this value represents
    • Compare to the sum and average of the list of values returned when percpu is True.
  • Process.cpu_percent() provides the CPU utilization of a specific process.
    • This value can exceed 100% if the process has multiple threads that are collectively using multiple cores.
    • Can get an average CPU percent via p.cpu_percent() / psutil.cpu_count() where p is a Process.
  • It may also be helpful to list the max number of threads used by the process.

@hunter-moseley
Copy link
Member

If the information is across CPU cores, then I would recommend the following key names:
class MaxCPUUtilization:
system_core_count: int
system_core_percent: float
system_cpu_percent: float # possibly
main_core_percent: float
main_cpu_percent: float
descendent_core_percent: float
descendent_cpu_percent: float
combined_core_percent: float
combined_cpu_percent: float
main_n_threads: int
descendant_n_threads: int
combined_n_threads: int

@hunter-moseley
Copy link
Member

Just realized one more important aspect of reporting CPU utilization.
Both max and average results should be reported.
Max will help indicate if the CPU is being fully utilized at any given time and average utilization will indicate how well the CPU is being utilized across time.

@erikhuck
Copy link
Collaborator Author

erikhuck commented Apr 10, 2024

@hunter-moseley

  1. What is the difference between cpu_percent and core_percent?
  2. To account for collecting the average, should we rename the class to just CPUUtilization? And should we name the fields as so: system_max_core_percent, system_mean_core_percent, main_max_core_percent, main_mean_core_percent, etc.

@hunter-moseley
Copy link
Member

hunter-moseley commented Apr 10, 2024 via email

@erikhuck
Copy link
Collaborator Author

@hunter-moseley I did an experiment and it is strongly evident that psutil.cpu_percent() is the same as numpy.mean(psutil.cpu_percent(percpu=True)). In other words, the mean percentage across all available CPUs. As I understand it, that would be the value for system_cpu_percent. So the question is, how would we like to calculate the value for system_core_percent? I'd think that would be the sum of all the core percentages as opposed to the mean? If that isn't very meaningful (perhaps because the value would possibly be more dependent on the number of cores in the system than anything else), we could alternatively exclude system_core_percent.

@hunter-moseley
Copy link
Member

hunter-moseley commented Apr 10, 2024 via email

@erikhuck
Copy link
Collaborator Author

So the final implementation should be?

@dclass.dataclass
class CPUUtilization:
    system_core_count: int
    system_max_core_percent: float = 0.
    system_max_cpu_percent: float = 0.
    main_max_core_percent: float = 0.
    main_max_cpu_percent: float = 0.
    descendent_max_core_percent: float = 0.
    descendent_max_cpu_percent: float = 0.
    combined_max_core_percent: float = 0.
    combined_max_cpu_percent: float = 0.
    system_mean_cpu_percent: float = 0.
    system_mean_core_percent: float = 0.
    main_mean_core_percent: float = 0.
    main_mean_cpu_percent: float = 0.
    descendent_mean_core_percent: float = 0.
    descendent_mean_cpu_percent: float = 0.
    combined_mean_core_percent: float = 0.
    combined_mean_cpu_percent: float = 0.
    main_n_threads: int = 0
    descendant_n_threads: int = 0
    combined_n_threads: int = 0

@hunter-moseley
Copy link
Member

hunter-moseley commented Apr 11, 2024 via email

@erikhuck
Copy link
Collaborator Author

Fixed by #30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants