Skip to content

Commit f31e283

Browse files
committed
Address code review
1 parent e3870ab commit f31e283

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

Modules/_testcapi/mem.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -706,16 +706,17 @@ tracemalloc_track_race(PyObject *self, PyObject *args)
706706
}
707707

708708

709-
#if TARGET_OS_OSX
710-
// Return RSS via proc_pidinfo(PROC_PIDTASKINFO).pti_resident_size.
709+
#if TARGET_OS_OSX || defined(__FreeBSD__)
710+
// Return RSS only. Per-process swap usage isn't readily available
711711
static PyObject*
712712
get_process_memory_usage(PyObject *self, PyObject *args)
713713
{
714714
int pid;
715715
if (!PyArg_ParseTuple(args, "i", &pid)) {
716716
return NULL;
717717
}
718-
718+
#if TARGET_OS_OSX
719+
// macOS: proc_pidinfo(PROC_PIDTASKINFO).pti_resident_size
719720
struct proc_taskinfo pti;
720721
int ret = proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti));
721722
if (ret <= 0) {
@@ -728,20 +729,8 @@ get_process_memory_usage(PyObject *self, PyObject *args)
728729
}
729730

730731
return PyLong_FromUnsignedLongLong(pti.pti_resident_size);
731-
}
732-
#endif
733-
734-
735-
#ifdef __FreeBSD__
736-
// Return RSS only. Per-process swap usage isn't readily available
737-
static PyObject*
738-
get_process_memory_usage(PyObject *self, PyObject *args)
739-
{
740-
int pid;
741-
if (!PyArg_ParseTuple(args, "i", &pid)) {
742-
return NULL;
743-
}
744-
732+
#else
733+
// FreeBSD: kvm_getprocs(KERN_PROC_PID) and ki_rssize * page_size
745734
long page_size = sysconf(_SC_PAGESIZE);
746735
if (page_size <= 0) {
747736
return PyErr_SetFromErrno(PyExc_OSError);
@@ -779,6 +768,7 @@ get_process_memory_usage(PyObject *self, PyObject *args)
779768
error:
780769
kvm_close(kd);
781770
return NULL;
771+
#endif
782772
}
783773
#endif
784774

0 commit comments

Comments
 (0)