-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement climem memory monitor service
- Loading branch information
Showing
13 changed files
with
258 additions
and
0 deletions.
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
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
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
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
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
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,47 @@ | ||
#include "mem-utils.h" | ||
|
||
#include <kj/debug.h> | ||
#include <kj/filesystem.h> | ||
|
||
#if !_WIN32 | ||
#include <fcntl.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#endif | ||
|
||
namespace workerd::util { | ||
|
||
#if defined(__linux__) | ||
kj::Maybe<size_t> tryGetResidentSetMemory() { | ||
int fd_; | ||
KJ_SYSCALL(fd_ = open("/proc/self/stat", O_RDONLY)); | ||
kj::AutoCloseFd fd(fd_); | ||
auto text = kj::FdInputStream(kj::mv(fd)).readAllText(); | ||
auto p = text.begin(); | ||
for (kj::uint i = 0; i < 23; i++) { | ||
p = strchr(p, ' '); | ||
KJ_ASSERT(p != nullptr, "/proc/self/stat format not understood", text); | ||
++p; | ||
} | ||
auto rss = strtoull(p, nullptr, 10); | ||
size_t result = rss * getpagesize(); | ||
return result; | ||
} | ||
#elif defined(__APPLE__) | ||
kj::Maybe<size_t> tryGetResidentSetMemory() { | ||
// TODO(soon): Implement etting the RSS for macOS | ||
return kj::none; | ||
} | ||
#elif defined(_WIN32) | ||
kj::Maybe<size_t> tryGetResidentSetMemory() { | ||
// TODO(soon): Implement getting the RSS for Windows | ||
return kj::none; | ||
} | ||
#elif | ||
kj::Maybe<size_t> tryGetResidentSetMemory() { | ||
// For all other platforms we simply return nothing | ||
return kj::none; | ||
} | ||
#endif | ||
|
||
} // namespace workerd::util |
Oops, something went wrong.