[enhancement](memory) Print memory usage log when memory allocation fails (#13301)

This commit is contained in:
Xinyi Zou
2022-10-12 10:08:25 +08:00
committed by GitHub
parent 16999ef02d
commit 89b295c6cc
2 changed files with 34 additions and 22 deletions

View File

@ -43,8 +43,10 @@ uint8_t* SystemAllocator::allocate_via_malloc(size_t length) {
int res = posix_memalign(&ptr, PAGE_SIZE, length);
if (res != 0) {
char buf[64];
LOG(ERROR) << "fail to allocate mem via posix_memalign, res=" << res
<< ", errmsg=" << strerror_r(res, buf, 64);
auto err = fmt::format("fail to allocate mem via posix_memalign, res={}, errmsg={}.", res,
strerror_r(res, buf, 64));
ExecEnv::GetInstance()->process_mem_tracker()->print_log_usage(err);
LOG(ERROR) << err;
return nullptr;
}
return (uint8_t*)ptr;