diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2022-01-16 21:39:05 +0000 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2022-01-16 21:39:05 +0000 |
commit | 63dcaede3fab788f9ae44d348b66c63e5f4cdb61 (patch) | |
tree | 34bd9cdda9cdacd6f27f1423f9168c8913959c59 | |
parent | 2bf98f7a70a5f1360c9444691e0ffb62b748e8eb (diff) | |
download | psutil-63dcaede3fab788f9ae44d348b66c63e5f4cdb61.tar.gz |
FreeBSD: get CPU vendor string
-rw-r--r-- | psutil/__init__.py | 2 | ||||
-rw-r--r-- | psutil/_psbsd.py | 2 | ||||
-rw-r--r-- | psutil/_psutil_bsd.c | 11 | ||||
-rw-r--r-- | psutil/arch/freebsd/cpu.c | 22 | ||||
-rw-r--r-- | psutil/arch/freebsd/cpu.h | 1 |
5 files changed, 27 insertions, 11 deletions
diff --git a/psutil/__init__.py b/psutil/__init__.py index 9b781d2b..eef32c97 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -1907,7 +1907,7 @@ if hasattr(_psplatform, "cpu_info"): Dictionary keys availability: * "model": Linux, macOS, Windows, FreeBSD, NetBSD, OpenBSD - * "vendor": Linux, macOS, Windows, OpenBSD + * "vendor": Linux, macOS, Windows, FreeBSD, OpenBSD * "arch": Linux, macOS, Windows * "byteorder": all * "l1d_cache": Linux, macOS diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index ead05381..18f2566f 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -282,7 +282,7 @@ else: def cpu_info(): d = dict(model=cext.cpu_model()) - if OPENBSD: + if OPENBSD or FREEBSD: d["vendor"] = cext.cpu_vendor() return d diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index a1aec439..f014d2bd 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -1092,8 +1092,12 @@ static PyMethodDef mod_methods[] = { // --- system-related functions {"boot_time", psutil_boot_time, METH_VARARGS}, {"cpu_count_logical", psutil_cpu_count_logical, METH_VARARGS}, + {"cpu_model", psutil_cpu_model, METH_VARARGS}, {"cpu_stats", psutil_cpu_stats, METH_VARARGS}, {"cpu_times", psutil_cpu_times, METH_VARARGS}, +#if defined(PSUTIL_OPENBSD) || defined(PSUTIL_FREEBSD) + {"cpu_vendor", psutil_cpu_vendor, METH_VARARGS}, +#endif {"disk_io_counters", psutil_disk_io_counters, METH_VARARGS}, {"disk_partitions", psutil_disk_partitions, METH_VARARGS}, {"net_io_counters", psutil_net_io_counters, METH_VARARGS}, @@ -1112,13 +1116,6 @@ static PyMethodDef mod_methods[] = { {"sensors_battery", psutil_sensors_battery, METH_VARARGS}, {"sensors_cpu_temperature", psutil_sensors_cpu_temperature, METH_VARARGS}, #endif -#if defined(PSUTIL_NETBSD) - {"cpu_model", psutil_cpu_model, METH_VARARGS, ""}, -#endif -#if defined(PSUTIL_OPENBSD) - {"cpu_vendor", psutil_cpu_vendor, METH_VARARGS, ""}, - {"cpu_model", psutil_cpu_model, METH_VARARGS, ""}, -#endif // --- others {"set_debug", psutil_set_debug, METH_VARARGS}, diff --git a/psutil/arch/freebsd/cpu.c b/psutil/arch/freebsd/cpu.c index 8ab6beac..5c90eb30 100644 --- a/psutil/arch/freebsd/cpu.c +++ b/psutil/arch/freebsd/cpu.c @@ -136,8 +136,10 @@ psutil_cpu_model(PyObject *self, PyObject *args) { size_t size = 0; PyObject *py_str; - if (sysctlbyname("hw.model", NULL, &size, NULL, 0)) + if (sysctlbyname("hw.model", NULL, &size, NULL, 0)) { + psutil_debug("sysctlbyname('hw.model') 1/2 failed"); goto error; + } buf = malloc(size); if (!buf) { @@ -145,8 +147,10 @@ psutil_cpu_model(PyObject *self, PyObject *args) { return NULL; } - if (sysctlbyname("hw.model", buf, &size, NULL, 0)) + if (sysctlbyname("hw.model", buf, &size, NULL, 0)) { + psutil_debug("sysctlbyname('hw.model') 2/2 failed"); goto error; + } py_str = Py_BuildValue("s", buf); free(buf); @@ -157,3 +161,17 @@ error: free(buf); Py_RETURN_NONE; } + + +PyObject * +psutil_cpu_vendor(PyObject *self, PyObject *args) { + char vendor[128]; + size_t size = sizeof(vendor); + + if (sysctlbyname("hw.hv_vendor", &vendor, &size, NULL, 0)) { + psutil_debug("sysctlbyname('hw.hv_vendor') failed"); + Py_RETURN_NONE; + } + return Py_BuildValue("s", vendor); +} + diff --git a/psutil/arch/freebsd/cpu.h b/psutil/arch/freebsd/cpu.h index 9676c523..32eec6a4 100644 --- a/psutil/arch/freebsd/cpu.h +++ b/psutil/arch/freebsd/cpu.h @@ -10,3 +10,4 @@ PyObject* psutil_cpu_freq(PyObject* self, PyObject* args); PyObject* psutil_cpu_stats(PyObject* self, PyObject* args); PyObject* psutil_cpu_topology(PyObject* self, PyObject* args); PyObject* psutil_cpu_model(PyObject* self, PyObject* args); +PyObject* psutil_cpu_vendor(PyObject* self, PyObject* args); |