blob: 1af71917bd365bf917160e8aa82f2e6e9453c9f5 (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/*
* 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
}
#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.
}
#else
int sk_tools::getMaxResidentSetSizeMB() { return -1; }
#endif
#if defined(SK_BUILD_FOR_MAC)
#include <mach/mach.h>
int sk_tools::getCurrResidentSetSizeMB() {
mach_task_basic_info info;
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
if (KERN_SUCCESS !=
task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &count)) {
return -1;
}
return info.resident_size / 1024 / 1024; // Darwin reports bytes.
}
#elif defined(SK_BUILD_FOR_WIN32)
int sk_tools::getCurrResidentSetSizeMB() {
PROCESS_MEMORY_COUNTERS info;
GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
return static_cast<int>(info.WorkingSetSize / 1024 / 1024); // Windows reports bytes.
}
#else
int sk_tools::getCurrResidentSetSizeMB() { return -1; }
#endif
|