| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/common/system_resource_util.h> |
| 7 |
|
| 8 |
#include <windows.h> |
| 9 |
|
| 10 |
#include <psapi.h> |
| 11 |
|
| 12 |
int aws_init_memory_usage_for_current_process(struct aws_memory_usage_stats *memory_usage) { |
| 13 |
AWS_PRECONDITION(memory_usage); |
| 14 |
|
| 15 |
AWS_ZERO_STRUCT(*memory_usage); |
| 16 |
HANDLE hProcess = GetCurrentProcess(); |
| 17 |
|
| 18 |
PROCESS_MEMORY_COUNTERS pmc; |
| 19 |
|
| 20 |
BOOL ret = GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)); |
| 21 |
CloseHandle(hProcess); |
| 22 |
|
| 23 |
if (!ret) { |
| 24 |
return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE); |
| 25 |
} |
| 26 |
|
| 27 |
memory_usage->maxrss = pmc.PeakWorkingSetSize; |
| 28 |
memory_usage->page_faults = pmc.PageFaultCount; |
| 29 |
|
| 30 |
return AWS_OP_SUCCESS; |
| 31 |
} |