-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Osx temps #1284
Osx temps #1284
Changes from 11 commits
2310e46
9952285
b083462
0dd82f9
10b9a26
1483757
ea8a5da
8ec6063
9d8cef0
f19feab
75af526
44493d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
import contextlib | ||
import errno | ||
import collections | ||
import functools | ||
import os | ||
from socket import AF_INET | ||
|
@@ -212,6 +213,137 @@ def disk_partitions(all=False): | |
# ===================================================================== | ||
|
||
|
||
def sensors_temperatures(): | ||
"""Return CPU temperatures including key name and temperature. | ||
|
||
References: | ||
|
||
https://stackoverflow.com/questions/28568775/ | ||
description-for-apples-smc-keys/31033665#31033665 | ||
|
||
https://github.com/Chris911/iStats/blob/ | ||
09b159f85a9481b59f347a37259f6d272f65cc05/lib/iStats/smc.rb | ||
|
||
http://web.archive.org/web/20140714090133/http://www.parhelia.ch:80/ | ||
blog/statics/k3_keys.html | ||
""" | ||
ret = collections.defaultdict(list) | ||
temperatures = ( | ||
# group, key, label | ||
|
||
# --- CPU | ||
("CPU", "TCXC", "PECI CPU"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please define this globally as |
||
("CPU", "TCXc", "PECI CPU"), | ||
("CPU", "TC0P", "CPU 1 Proximity"), | ||
("CPU", "TC0H", "CPU 1 Heatsink"), | ||
("CPU", "TC0D", "CPU 1 Package"), | ||
("CPU", "TC0E", "CPU 1"), | ||
("CPU", "TC0F", "CPU 1"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Judging from the script output you paster earlier it seems we get a duplicate for TC0E and TC0F so I suggest to remove TC0F |
||
("CPU", "TC1C", "CPU Core 1"), | ||
("CPU", "TC2C", "CPU Core 2"), | ||
("CPU", "TC3C", "CPU Core 3"), | ||
("CPU", "TC4C", "CPU Core 4"), | ||
("CPU", "TC5C", "CPU Core 5"), | ||
("CPU", "TC6C", "CPU Core 6"), | ||
("CPU", "TC7C", "CPU Core 7"), | ||
("CPU", "TC8C", "CPU Core 8"), | ||
("CPU", "TCAH", "CPU 1 Heatsink Alt."), | ||
("CPU", "TCAD", "CPU 1 Package Alt."), | ||
("CPU", "TC1P", "CPU 2 Proximity"), | ||
("CPU", "TC1H", "CPU 2 Heatsink"), | ||
("CPU", "TC1D", "CPU 2 Package"), | ||
("CPU", "TC1E", "CPU 2"), | ||
("CPU", "TC1F", "CPU 2"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Just keep TC1E |
||
("CPU", "TCBH", "CPU 2 Heatsink Alt."), | ||
("CPU", "TCBD", "CPU 2 Package Alt."), | ||
|
||
("CPU", "TCSC", "PECI SA"), | ||
("CPU", "TCSc", "PECI SA"), | ||
("CPU", "TCSA", "PECI SA"), | ||
|
||
# --- GPU | ||
("GPU", "TCGC", "PECI GPU"), | ||
("GPU", "TCGc", "PECI GPU"), | ||
("GPU", "TG0P", "GPU Proximity"), | ||
("GPU", "TG0D", "GPU Die"), | ||
("GPU", "TG1D", "GPU Die"), | ||
("GPU", "TG0H", "GPU Heatsink"), | ||
("GPU", "TG1H", "GPU Heatsink"), | ||
|
||
# --- Memory | ||
("Memory", "Ts0S", "Memory Proximity"), | ||
("Memory", "TM0P", "Mem Bank A1"), | ||
("Memory", "TM1P", "Mem Bank A2"), | ||
("Memory", "TM8P", "Mem Bank B1"), | ||
("Memory", "TM9P", "Mem Bank B2"), | ||
("Memory", "TM0S", "Mem Module A1"), | ||
("Memory", "TM1S", "Mem Module A2"), | ||
("Memory", "TM8S", "Mem Module B1"), | ||
("Memory", "TM9S", "Mem Module B2"), | ||
|
||
# --- HDD | ||
("HDD", "TH0P", "HDD Bay 1"), | ||
("HDD", "TH1P", "HDD Bay 2"), | ||
("HDD", "TH2P", "HDD Bay 3"), | ||
("HDD", "TH3P", "HDD Bay 4"), | ||
|
||
# --- Battery | ||
("Battery", "TB0T", "Battery TS_MAX"), | ||
("Battery", "TB1T", "Battery 1"), | ||
("Battery", "TB2T", "Battery 2"), | ||
("Battery", "TB3T", "Battery"), | ||
|
||
# --- Others | ||
("Others", "TN0D", "Northbridge Die"), | ||
("Others", "TN0P", "Northbridge Proximity 1"), | ||
("Others", "TN1P", "Northbridge Proximity 2"), | ||
("Others", "TN0C", "MCH Die"), | ||
("Others", "TN0H", "MCH Heatsink"), | ||
("Others", "TP0D", "PCH Die"), | ||
("Others", "TPCD", "PCH Die"), | ||
("Others", "TP0P", "PCH Proximity"), | ||
|
||
("Others", "TA0P", "Airflow 1"), | ||
("Others", "TA1P", "Airflow 2"), | ||
("Others", "Th0H", "Heatpipe 1"), | ||
("Others", "Th1H", "Heatpipe 2"), | ||
("Others", "Th2H", "Heatpipe 3"), | ||
|
||
("Others", "Tm0P", "Mainboard Proximity"), | ||
("Others", "Tp0P", "Powerboard Proximity"), | ||
("Others", "Ts0P", "Palm Rest"), | ||
("Others", "Tb0P", "BLC Proximity"), | ||
|
||
("Others", "TL0P", "LCD Proximity"), | ||
("Others", "TW0P", "Airport Proximity"), | ||
("Others", "TO0P", "Optical Drive"), | ||
|
||
("Others", "Tp0P", "Power Supply 1"), | ||
("Others", "Tp0C", "Power Supply 1 Alt."), | ||
("Others", "Tp1P", "Power Supply 2"), | ||
("Others", "Tp1C", "Power Supply 2 Alt."), | ||
("Others", "Tp2P", "Power Supply 3"), | ||
("Others", "Tp3P", "Power Supply 4"), | ||
("Others", "Tp4P", "Power Supply 5"), | ||
("Others", "Tp5P", "Power Supply 6"), | ||
|
||
("Others", "TS0C", "Expansion Slots"), | ||
("Others", "TA0S", "PCI Slot 1 Pos 1"), | ||
("Others", "TA1S", "PCI Slot 1 Pos 2"), | ||
("Others", "TA2S", "PCI Slot 2 Pos 1"), | ||
("Others", "TA3S", "PCI Slot 2 Pos 2"), | ||
) | ||
|
||
for group, key, label in temperatures: | ||
result = cext.smc_get_temperature(key) | ||
result = round(result, 1) | ||
if result <= 0: | ||
continue | ||
ret[group].append((label, result, None, None)) | ||
|
||
return dict(ret) | ||
|
||
|
||
def sensors_battery(): | ||
"""Return battery information. | ||
""" | ||
|
@@ -230,6 +362,20 @@ def sensors_battery(): | |
return _common.sbattery(percent, secsleft, power_plugged) | ||
|
||
|
||
def sensors_fans(): | ||
"""Return fans speed information. | ||
""" | ||
ret = collections.defaultdict(list) | ||
fan_num = cext.fans_count() | ||
for fan in range(fan_num): | ||
result = cext.get_fan_speed(fan) | ||
if result < 0: | ||
continue | ||
ret["Fans"].append(_common.sfan("Fan %i" % fan, int(result))) | ||
|
||
return dict(ret) | ||
|
||
|
||
# ===================================================================== | ||
# --- network | ||
# ===================================================================== | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
#include "_psutil_common.h" | ||
#include "_psutil_posix.h" | ||
#include "arch/osx/process_info.h" | ||
#include "arch/osx/smc.h" | ||
|
||
|
||
#define PSUTIL_TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0) | ||
|
@@ -521,6 +522,19 @@ psutil_cpu_count_phys(PyObject *self, PyObject *args) { | |
return Py_BuildValue("i", num); | ||
} | ||
|
||
/* | ||
* Return the number of CPU packages | ||
*/ | ||
static PyObject * | ||
psutil_cpu_count_packages(PyObject *self, PyObject *args) { | ||
int num; | ||
size_t size = sizeof(int); | ||
|
||
if (sysctlbyname("hw.packages", &num, &size, NULL, 0)) | ||
Py_RETURN_NONE; | ||
else | ||
return Py_BuildValue("i", num); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this is no longer necessary |
||
|
||
/* | ||
* Indicates if the given virtual address on the given architecture is in the | ||
|
@@ -860,6 +874,50 @@ psutil_boot_time(PyObject *self, PyObject *args) { | |
return Py_BuildValue("f", (float)boot_time); | ||
} | ||
|
||
/* | ||
* Return a Python float indicating the value of the temperature | ||
* measured by an SMC key | ||
*/ | ||
static PyObject * | ||
psutil_smc_get_temperature(PyObject *self, PyObject *args) { | ||
char* key; | ||
float temp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add new line |
||
|
||
if (! PyArg_ParseTuple(args, "s", &key)) { | ||
return NULL; | ||
} | ||
temp = SMCGetTemperature(key); | ||
return Py_BuildValue("d", temp); | ||
} | ||
|
||
/* | ||
* Return a Python float indicating the number of fans in the system | ||
*/ | ||
static PyObject * | ||
psutil_fans_count(PyObject *self, PyObject *args) { | ||
int fan_count; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add new line |
||
|
||
fan_count = SMCGetFanNumber(SMC_KEY_FAN_NUM); | ||
if (fan_count < 0) { | ||
fan_count = 0; | ||
} | ||
return Py_BuildValue("i", fan_count); | ||
} | ||
|
||
/* | ||
* Return a Python float indicating the fan speed of the number of fan passed | ||
*/ | ||
static PyObject * | ||
psutil_get_fan_speed(PyObject *self, PyObject *args) { | ||
int key; | ||
float speed; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add new line |
||
|
||
if (! PyArg_ParseTuple(args, "i", &key)) { | ||
return NULL; | ||
} | ||
speed = SMCGetFanSpeed(key); | ||
return Py_BuildValue("f", speed); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to use a single C |
||
|
||
/* | ||
* Return a list of tuples including device, mount point and fs type | ||
|
@@ -1798,6 +1856,7 @@ psutil_cpu_stats(PyObject *self, PyObject *args) { | |
} | ||
|
||
|
||
|
||
/* | ||
* Return battery information. | ||
*/ | ||
|
@@ -1927,6 +1986,8 @@ PsutilMethods[] = { | |
"Return number of logical CPUs on the system"}, | ||
{"cpu_count_phys", psutil_cpu_count_phys, METH_VARARGS, | ||
"Return number of physical CPUs on the system"}, | ||
{"cpu_count_packages", psutil_cpu_count_packages, METH_VARARGS, | ||
"Return number of cpu packages"}, | ||
{"virtual_mem", psutil_virtual_mem, METH_VARARGS, | ||
"Return system virtual memory stats"}, | ||
{"swap_mem", psutil_swap_mem, METH_VARARGS, | ||
|
@@ -1950,6 +2011,12 @@ PsutilMethods[] = { | |
"Return currently connected users as a list of tuples"}, | ||
{"cpu_stats", psutil_cpu_stats, METH_VARARGS, | ||
"Return CPU statistics"}, | ||
{"smc_get_temperature", psutil_smc_get_temperature, METH_VARARGS, | ||
"Temperature of SMC key as float"}, | ||
{"fans_count", psutil_fans_count, METH_VARARGS, | ||
"Return the number of fans"}, | ||
{"get_fan_speed", psutil_get_fan_speed, METH_VARARGS, | ||
"Return the RPM of the fan with SMC key"}, | ||
{"sensors_battery", psutil_sensors_battery, METH_VARARGS, | ||
"Return battery information."}, | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update docstring