Fix monitoring script for macos (#88159)

The monitoring script is currently failing with AccessDenied when trying to access uss memory on mac because [psutil.memory_full_info](https://psutil.readthedocs.io/en/latest/index.html?highlight=memory_full_info) requires higher user privileges

Example failures:
* https://gha-artifacts.s3.amazonaws.com/pytorch/pytorch/3363066309/1/artifact/usage-log-test-default-2-2-macos-12_9208104847.zip
* https://gha-artifacts.s3.amazonaws.com/pytorch/pytorch/3363066309/1/artifact/usage-log-test-default-2-2-macos-m1-12_9207913759.zip

I could also make this script run with sudo, effectively granting this permission. But I'm not entirely sure that we need uss memory for mac, so gracefully handling the error looks nicer
Pull Request resolved: https://github.com/pytorch/pytorch/pull/88159
Approved by: https://github.com/clee2000
This commit is contained in:
Huy Do 2022-11-01 05:58:42 +00:00 committed by PyTorch MergeBot
parent 323c646ca9
commit 7c6fe21a38

View File

@ -30,11 +30,22 @@ def get_per_process_cpu_info() -> List[Dict[str, Any]]:
"cmd": " ".join(p.cmdline()),
"cpu_percent": p.cpu_percent(),
"rss_memory": p.memory_info().rss,
"uss_memory": p.memory_full_info().uss,
}
if "pss" in p.memory_full_info():
# only availiable in linux
info["pss_memory"] = p.memory_full_info().pss
# https://psutil.readthedocs.io/en/latest/index.html?highlight=memory_full_info
# requires higher user privileges and could throw AccessDenied error, i.e. mac
try:
memory_full_info = p.memory_full_info()
info["uss_memory"] = memory_full_info.uss
if "pss" in memory_full_info:
# only availiable in linux
info["pss_memory"] = memory_full_info.pss
except psutil.AccessDenied as e:
# It's ok to skip this
pass
per_process_info.append(info)
return per_process_info