-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f705c61
commit 257969b
Showing
6 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef AWS_COMMON_SYSTEM_RESOURCE_UTIL_H | ||
#define AWS_COMMON_SYSTEM_RESOURCE_UTIL_H | ||
|
||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
#include <aws/common/common.h> | ||
|
||
AWS_PUSH_SANE_WARNING_LEVEL | ||
|
||
AWS_EXTERN_C_BEGIN | ||
|
||
struct aws_resource_usage { | ||
size_t maxrss; | ||
|
||
size_t _reserved[8]; | ||
}; | ||
|
||
AWS_COMMON_API int aws_resource_usage_for_current_process(struct aws_resource_usage *resource_usage); | ||
|
||
|
||
AWS_EXTERN_C_END | ||
AWS_POP_SANE_WARNING_LEVEL | ||
|
||
#endif /* AWS_COMMON_SYSTEM_RESOURCE_UTIL_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
#include <aws/common/system_resource_util.h> | ||
|
||
#include <sys/resource.h> | ||
|
||
int aws_resource_usage_for_current_process(struct aws_resource_usage *ru) { | ||
AWS_PRECONDITION(ru); | ||
|
||
struct rusage usage; | ||
|
||
if (getrusage(RUSAGE_SELF, &usage)) { | ||
return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE); | ||
} | ||
|
||
#if defined(AWS_OS_APPLE) | ||
ru->maxrss = usage.ru_maxrss / 1024; | ||
#else | ||
ru->maxrss = usage.ru_maxrss; | ||
#endif | ||
return AWS_OP_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
#include <aws/common/system_resource_util.h> | ||
|
||
#include <windows.h> | ||
#include <psapi.h> | ||
|
||
int aws_resource_usage_for_current_process(struct aws_resource_usage *resource_usage) { | ||
AWS_PRECONDITION(resource_usage); | ||
|
||
HANDLE hProcess = GetCurrentProcess();; | ||
PROCESS_MEMORY_COUNTERS pmc; | ||
|
||
BOOL ret = GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)); | ||
CloseHandle( hProcess ); | ||
|
||
if (!ret) { | ||
return aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE); | ||
} | ||
|
||
ru->maxrss = pmc.PeakWorkingSetSize; | ||
|
||
return AWS_OP_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
#include <aws/common/system_resource_util.h> | ||
|
||
#include <aws/testing/aws_test_harness.h> | ||
|
||
static int s_test_resource_usage_maxrss(struct aws_allocator *allocator, void *ctx) { | ||
(void)ctx; | ||
|
||
struct aws_resource_usage ru; | ||
AWS_ZERO_STRUCT(ru); | ||
ASSERT_SUCCESS(aws_resource_usage_for_current_process(&ru)); | ||
|
||
ASSERT_TRUE(ru.maxrss > 0); | ||
|
||
return 0; | ||
} | ||
|
||
AWS_TEST_CASE(test_resource_usage_maxrss, s_test_resource_usage_maxrss) |