2014-08-11 18:33:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ProcStats.h"
|
|
|
|
|
|
|
|
#if defined(SK_BUILD_FOR_UNIX) || \
|
|
|
|
defined(SK_BUILD_FOR_MAC) || \
|
|
|
|
defined(SK_BUILD_FOR_ANDROID)
|
|
|
|
|
|
|
|
#include <sys/resource.h>
|
2014-08-19 22:55:55 +00:00
|
|
|
int sk_tools::getMaxResidentSetSizeMB() {
|
2014-08-11 18:33:51 +00:00
|
|
|
struct rusage ru;
|
|
|
|
getrusage(RUSAGE_SELF, &ru);
|
|
|
|
#if defined(SK_BUILD_FOR_MAC)
|
2014-08-19 22:55:55 +00:00
|
|
|
return static_cast<int>(ru.ru_maxrss / 1024 / 1024); // Darwin reports bytes.
|
2014-08-11 18:33:51 +00:00
|
|
|
#else
|
2014-08-19 22:55:55 +00:00
|
|
|
return static_cast<int>(ru.ru_maxrss / 1024); // Linux reports kilobytes.
|
2014-08-11 18:33:51 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-10-21 19:23:12 +00:00
|
|
|
#elif defined(SK_BUILD_FOR_WIN32)
|
|
|
|
#include <windows.h>
|
|
|
|
#include <psapi.h>
|
|
|
|
int sk_tools::getMaxResidentSetSizeMB() {
|
|
|
|
PROCESS_MEMORY_COUNTERS info;
|
|
|
|
GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
|
|
|
|
return static_cast<int>(info.PeakWorkingSetSize / 1024 / 1024); // Windows reports bytes.
|
|
|
|
}
|
2014-08-11 18:33:51 +00:00
|
|
|
|
2014-10-21 19:23:12 +00:00
|
|
|
#else
|
2014-08-19 22:55:55 +00:00
|
|
|
int sk_tools::getMaxResidentSetSizeMB() {
|
2014-08-11 18:33:51 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|