Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ProcStats.cpp
Go to the documentation of this file.
1/*
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
9#include "tools/ProcStats.h"
10
11#if defined(__Fuchsia__)
12 #include <zircon/process.h>
13 #include <zircon/syscalls.h>
14 #include <zircon/syscalls/object.h>
15 #include <zircon/types.h>
16
18 zx_info_task_stats_t task_stats;
19 zx_handle_t process = zx_process_self();
20 zx_status_t status = zx_object_get_info(
21 process, ZX_INFO_TASK_STATS, &task_stats, sizeof(task_stats), nullptr, nullptr);
22 if (status != ZX_OK) {
23 return -1;
24 }
25 return (task_stats.mem_private_bytes + task_stats.mem_shared_bytes);
26 }
27#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) || defined(SK_BUILD_FOR_ANDROID)
28 #include <sys/resource.h>
30 struct rusage ru;
31 getrusage(RUSAGE_SELF, &ru);
32 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
33 return ru.ru_maxrss; // Darwin reports bytes.
34 #else
35 return ru.ru_maxrss * 1024; // Linux reports kilobytes.
36 #endif
37 }
38#elif defined(SK_BUILD_FOR_WIN)
39 #include <windows.h>
40 #include <psapi.h>
42 PROCESS_MEMORY_COUNTERS info;
43 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
44 return info.PeakWorkingSetSize;
45 }
46#else
47 int64_t sk_tools::getMaxResidentSetSizeBytes() { return -1; }
48#endif
49
50#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
51 #include <mach/mach.h>
53 mach_task_basic_info info;
54 mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
55 if (KERN_SUCCESS !=
56 task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &count)) {
57 return -1;
58 }
59 return info.resident_size;
60 }
61#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) // N.B. /proc is Linux-only.
62 #include <unistd.h>
63 #include <stdio.h>
65 const long pageSize = sysconf(_SC_PAGESIZE);
66 long long rssPages = 0;
67 if (FILE* statm = fopen("/proc/self/statm", "r")) {
68 // statm contains: program-size rss shared text lib data dirty, all in page counts.
69 int rc = fscanf(statm, "%*d %lld", &rssPages);
70 fclose(statm);
71 if (rc != 1) {
72 return -1;
73 }
74 }
75 return rssPages * pageSize;
76 }
77#elif defined(SK_BUILD_FOR_WIN)
79 PROCESS_MEMORY_COUNTERS info;
80 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
81 return info.WorkingSetSize;
82 }
83#else
85#endif
86
89 return bytes < 0 ? -1 : static_cast<int>(bytes / 1024 / 1024);
90}
91
94 return bytes < 0 ? -1 : static_cast<int>(bytes / 1024 / 1024);
95}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
int count
int64_t getCurrResidentSetSizeBytes()
Definition ProcStats.cpp:84
int64_t getMaxResidentSetSizeBytes()
Definition ProcStats.cpp:47
int getCurrResidentSetSizeMB()
Definition ProcStats.cpp:92
int getMaxResidentSetSizeMB()
Definition ProcStats.cpp:87
static void process(const char *inPath, const char *lexer, const char *token, const char *hPath, const char *cppPath)
Definition Main.cpp:114