aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/ProcStats.cpp
blob: eaa1379301833cb28e218345e7d6d31c95863bb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * 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>
    int sk_tools::getMaxResidentSetSizeMB() {
        struct rusage ru;
        getrusage(RUSAGE_SELF, &ru);
    #if defined(SK_BUILD_FOR_MAC)
        return static_cast<int>(ru.ru_maxrss / 1024 / 1024);  // Darwin reports bytes.
    #else
        return static_cast<int>(ru.ru_maxrss / 1024);  // Linux reports kilobytes.
    #endif
    }

#else

    int sk_tools::getMaxResidentSetSizeMB() {
        return -1;
    }

#endif