@@ -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
711711static PyObject *
712712get_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)
779768error :
780769 kvm_close (kd );
781770 return NULL ;
771+ #endif
782772}
783773#endif
784774
0 commit comments