aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/rusage.cpp
diff options
context:
space:
mode:
authorfilmih <filmih@yandex-team.ru>2022-02-10 16:49:59 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:59 +0300
commit693ca74a6530df8930b0d445102e2ea77b8c4e00 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /util/system/rusage.cpp
parent883c643baf3a1698f0f0a31a8973b61411cd311f (diff)
downloadydb-693ca74a6530df8930b0d445102e2ea77b8c4e00.tar.gz
Restoring authorship annotation for <filmih@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system/rusage.cpp')
-rw-r--r--util/system/rusage.cpp90
1 files changed, 45 insertions, 45 deletions
diff --git a/util/system/rusage.cpp b/util/system/rusage.cpp
index 24d4a2a9c3..2befeca875 100644
--- a/util/system/rusage.cpp
+++ b/util/system/rusage.cpp
@@ -1,11 +1,11 @@
#include "platform.h"
-#if defined(__APPLE__) && defined(__MACH__)
-
+#if defined(__APPLE__) && defined(__MACH__)
+
#include <mach/mach.h>
-
-#endif
-
+
+#endif
+
#ifdef _win_
#include "winint.h"
@@ -35,45 +35,45 @@ TDuration FiletimeToDuration(const FILETIME& ft) {
}
#endif
-size_t TRusage::GetCurrentRSS() {
-/*
- * Author: David Robert Nadeau
- * Site: http://NadeauSoftware.com/
- * License: Creative Commons Attribution 3.0 Unported License
- * http://creativecommons.org/licenses/by/3.0/deed.en_US
- */
-#if defined(_WIN32)
- /* Windows -------------------------------------------------- */
- PROCESS_MEMORY_COUNTERS info;
- GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
- return (size_t)info.WorkingSetSize;
-#elif defined(__APPLE__) && defined(__MACH__)
- /* OSX ------------------------------------------------------ */
- struct mach_task_basic_info info;
- mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
- if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
- (task_info_t)&info, &infoCount) != KERN_SUCCESS)
- return (size_t)0L; /* Can't access? */
- return (size_t)info.resident_size;
-#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
- /* Linux ---------------------------------------------------- */
- long rss = 0L;
- FILE* fp = nullptr;
+size_t TRusage::GetCurrentRSS() {
+/*
+ * Author: David Robert Nadeau
+ * Site: http://NadeauSoftware.com/
+ * License: Creative Commons Attribution 3.0 Unported License
+ * http://creativecommons.org/licenses/by/3.0/deed.en_US
+ */
+#if defined(_WIN32)
+ /* Windows -------------------------------------------------- */
+ PROCESS_MEMORY_COUNTERS info;
+ GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
+ return (size_t)info.WorkingSetSize;
+#elif defined(__APPLE__) && defined(__MACH__)
+ /* OSX ------------------------------------------------------ */
+ struct mach_task_basic_info info;
+ mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
+ if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
+ (task_info_t)&info, &infoCount) != KERN_SUCCESS)
+ return (size_t)0L; /* Can't access? */
+ return (size_t)info.resident_size;
+#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
+ /* Linux ---------------------------------------------------- */
+ long rss = 0L;
+ FILE* fp = nullptr;
if ((fp = fopen("/proc/self/statm", "r")) == nullptr) {
- return (size_t)0L; /* Can't open? */
+ return (size_t)0L; /* Can't open? */
+ }
+ if (fscanf(fp, "%*s%ld", &rss) != 1) {
+ fclose(fp);
+ return (size_t)0L; /* Can't read? */
}
- if (fscanf(fp, "%*s%ld", &rss) != 1) {
- fclose(fp);
- return (size_t)0L; /* Can't read? */
- }
- fclose(fp);
- return (size_t)rss * (size_t)sysconf(_SC_PAGESIZE);
-#else
- /* AIX, BSD, Solaris, and Unknown OS ------------------------ */
- return (size_t)0L; /* Unsupported. */
-#endif
-}
-
+ fclose(fp);
+ return (size_t)rss * (size_t)sysconf(_SC_PAGESIZE);
+#else
+ /* AIX, BSD, Solaris, and Unknown OS ------------------------ */
+ return (size_t)0L; /* Unsupported. */
+#endif
+}
+
void TRusage::Fill() {
*this = TRusage();
@@ -98,7 +98,7 @@ void TRusage::Fill() {
ythrow TSystemError() << "GetProcessMemoryInfo failed";
}
- MaxRss = pmc.PeakWorkingSetSize;
+ MaxRss = pmc.PeakWorkingSetSize;
MajorPageFaults = pmc.PageFaultCount;
#else
@@ -110,9 +110,9 @@ void TRusage::Fill() {
#if defined(_darwin_)
// see https://lists.apple.com/archives/darwin-kernel/2009/Mar/msg00005.html
- MaxRss = ru.ru_maxrss;
+ MaxRss = ru.ru_maxrss;
#else
- MaxRss = ru.ru_maxrss * 1024LL;
+ MaxRss = ru.ru_maxrss * 1024LL;
#endif
MajorPageFaults = ru.ru_majflt;
Utime = ru.ru_utime;