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

CPU Stats per CPU #125

Closed
giampaolo opened this issue May 23, 2014 · 14 comments
Closed

CPU Stats per CPU #125

giampaolo opened this issue May 23, 2014 · 14 comments

Comments

@giampaolo
Copy link
Owner

From kenneths...@gmail.com on October 28, 2010 21:06:58

This is a feature. 

It would be nice to see the cpu stats broken down on a per cpu basis (and 
important to know sometimes - as one process may be maxing out a single cpu and 
you only see 25% on a 4cpu system).

Original issue: http://code.google.com/p/psutil/issues/detail?id=125

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 28, 2010 12:12:58

Labels: -Type-Defect Type-Enhancement OpSys-All Milestone-0.3.0 Progress-0in4

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 28, 2010 12:13:44

Status: Accepted

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 29, 2010 07:19:07

I checked out the sigar library since Kenny mentioned it has per-CPU stats and 
it's open source. It looks like on OS X we can pull stats per CPU using 
host_processor_info() 

The same code file also has BSD per-processor information, using sysctl() with 
kern.cp_times - according to the comments in the file, this is available on 
FreeBSD sometime after version 7.0 

Looking at the Windows code seems to indicate this is available on Windows as 
well, using perfmon counters in C code (not at all looking forward to 
implementing that one). As a side note, there are some pretty funny comments in 
the Windows code from frustrated developers ;)  Not sure what versions of 
Windows will work with this method.

Lastly, for Linux they're using /proc/stat to read per-CPU statistics, so that 
shouldn't be a problem. 

It looks like we can implement this on all our platforms, so next question is 
how to (re)design the API for it. We can either re-arrange the existing calls, 
or it might make sense to create new methods that specifically return per-CPU 
statistics. In my experience with systems administration and monitoring 
software, some folks really prefer individual CPU stats and others only care 
about total overall numbers. I would recommend we provide both, regardless of 
how we work out the design. 

FWIW, sigar is using almost the exact methods we are for providing total CPU 
util on all platforms... it might be worth having separate code paths, since it 
gives us fallback capabilities if on some systems the per-CPU stats fail for 
any reason (or vice versa).

@giampaolo
Copy link
Owner Author

From wj32...@gmail.com on October 30, 2010 16:10:08

In Windows, NtQuerySystemInformation with SystemProcessorPerformanceInformation 
will give you the stats you need.

@giampaolo
Copy link
Owner Author

From g.rodola on June 04, 2011 10:06:37

Attached is a patch which implements system per-CPU times/percent on Linux.
As for the original OP request:

> It would be nice to see the cpu stats broken down on a per 
> cpu basis (and important to know sometimes - as one process
> may be maxing out a single cpu and you only see 25% on a 
> 4cpu system).  

This is incorrect as we are currently returning the utilization of a *single* CPU.
Hence, on a 4 core system if one process is consuming all the resources of one 
CPU, 100 is returned (and not 25).
In summary, what we need is system's per-cpu percent stats only.

Status: Started

Attachment: sys-cpus.patch

@giampaolo
Copy link
Owner Author

From g.rodola on June 04, 2011 10:43:20

Linux implementation added as r988 (tests as r989 ).

Labels: -Milestone-0.3.0 -Progress-0in4 Milestone-0.2.2 Progress-1in4

@giampaolo
Copy link
Owner Author

From g.rodola on June 04, 2011 12:04:07

Implemented on Windows in r992 .

Labels: -Progress-1in4 Progress-2in4

@giampaolo
Copy link
Owner Author

From g.rodola on June 04, 2011 12:52:33

Implemented for FreeBSD in r993 .

Labels: -Progress-2in4 Progress-3in4

@giampaolo
Copy link
Owner Author

From g.rodola on June 09, 2011 15:33:51

Labels: -OpSys-All

@giampaolo
Copy link
Owner Author

From jcscoob...@gmail.com on June 22, 2011 15:48:32

Attached is a patch to implement this on OS X.  My patch also includes the 
resurrection of get_system_cpu_times for OS X since it was either removed 
accidentally or not refactored properly as the test suite, on trunk, would 
complain about the OS X module not having the get_system_cpu_times attribute.  
If my addressing that was unnecessary, or wrong, feel free to remove it from 
the patch but the work for get_system_per_cpu_times should not have an impact 
on this.  I have prepended my commit log message to the beginning of the patch 
so you know what I did, and why.

Take care,

Jeremy

Attachment: get_system_per_cpu_times_osx.patch

@giampaolo
Copy link
Owner Author

From g.rodola on June 27, 2011 01:05:46

Thanks.
Committed in r1042 .

Status: FixedInSVN
Labels: -Progress-3in4 Progress-4in4

@giampaolo
Copy link
Owner Author

From g.rodola on June 27, 2011 10:52:41

Labels: Milestone-0.3.0

@giampaolo
Copy link
Owner Author

From g.rodola on July 08, 2011 12:07:34

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 03:55:59

Updated csets after the SVN -> Mercurial migration: r988 == revision 
31dbaea0a938 r992 == revision 07454606f43f r993 == revision 8fc87c05dc2f r1042 
== revision eecd5b15fe00

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

No branches or pull requests

1 participant