Debian Codegraph @

crt/aws-c-common/source/posix/system_resource_utils.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/common/system_resource_util.h>
7
8 #include <sys/resource.h>
9
10 int aws_init_memory_usage_for_current_process(struct aws_memory_usage_stats *memory_usage) {
11 AWS_PRECONDITION(memory_usage);
12
13 AWS_ZERO_STRUCT(*memory_usage);
14 struct rusage usage;
15
16 if (getrusage(RUSAGE_SELF, &usage)) {
17 return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE);
18 }
19
20 #if defined(AWS_OS_APPLE)
21 /*
22 * For some reason Apple switched to reporting this in bytes instead of KB
23 * around MacOS 10.6.
24 * Make it back to KB. Result might be slightly off due to rounding.
25 */
26 memory_usage->maxrss = usage.ru_maxrss / 1024;
27 #else
28 memory_usage->maxrss = usage.ru_maxrss;
29 #endif
30 memory_usage->page_faults = usage.ru_majflt;
31 return AWS_OP_SUCCESS;
32 }