blob: eaa1379301833cb28e218345e7d6d31c95863bb8 [file] [log] [blame]
halcanary0d154ee2014-08-11 11:33:51 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "ProcStats.h"
9
10#if defined(SK_BUILD_FOR_UNIX) || \
11 defined(SK_BUILD_FOR_MAC) || \
12 defined(SK_BUILD_FOR_ANDROID)
13
14 #include <sys/resource.h>
mtkleinafb43792014-08-19 15:55:55 -070015 int sk_tools::getMaxResidentSetSizeMB() {
halcanary0d154ee2014-08-11 11:33:51 -070016 struct rusage ru;
17 getrusage(RUSAGE_SELF, &ru);
18 #if defined(SK_BUILD_FOR_MAC)
mtkleinafb43792014-08-19 15:55:55 -070019 return static_cast<int>(ru.ru_maxrss / 1024 / 1024); // Darwin reports bytes.
halcanary0d154ee2014-08-11 11:33:51 -070020 #else
mtkleinafb43792014-08-19 15:55:55 -070021 return static_cast<int>(ru.ru_maxrss / 1024); // Linux reports kilobytes.
halcanary0d154ee2014-08-11 11:33:51 -070022 #endif
23 }
24
25#else
26
mtkleinafb43792014-08-19 15:55:55 -070027 int sk_tools::getMaxResidentSetSizeMB() {
halcanary0d154ee2014-08-11 11:33:51 -070028 return -1;
29 }
30
31#endif