OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/process/process_metrics.h" | 5 #include "base/process/process_metrics.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/allocator/partition_allocator/partition_alloc.h" | |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
12 | 13 |
14 #if defined(OS_MACOSX) | |
Primiano Tucci (use gerrit)
2017/06/14 12:10:32
looks like you could split this file in process_me
keishi
2017/06/14 13:21:39
Done.
| |
15 #include <malloc/malloc.h> | |
16 #else | |
17 #include <malloc.h> | |
18 #endif | |
19 #if defined(OS_WIN) | |
20 #include <windows.h> | |
21 #endif | |
22 | |
13 namespace base { | 23 namespace base { |
14 | 24 |
15 SystemMemoryInfoKB::SystemMemoryInfoKB() = default; | 25 SystemMemoryInfoKB::SystemMemoryInfoKB() = default; |
16 | 26 |
17 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) = | 27 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) = |
18 default; | 28 default; |
19 | 29 |
20 SystemMetrics::SystemMetrics() { | 30 SystemMetrics::SystemMetrics() { |
21 committed_memory_ = 0; | 31 committed_memory_ = 0; |
22 } | 32 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 // dropping down into floating point). | 104 // dropping down into floating point). |
95 return (wakeups_delta_for_ms + time_delta / 2) / time_delta; | 105 return (wakeups_delta_for_ms + time_delta / 2) / time_delta; |
96 } | 106 } |
97 #else | 107 #else |
98 int ProcessMetrics::GetIdleWakeupsPerSecond() { | 108 int ProcessMetrics::GetIdleWakeupsPerSecond() { |
99 NOTIMPLEMENTED(); // http://crbug.com/120488 | 109 NOTIMPLEMENTED(); // http://crbug.com/120488 |
100 return 0; | 110 return 0; |
101 } | 111 } |
102 #endif // defined(OS_MACOSX) || defined(OS_LINUX) | 112 #endif // defined(OS_MACOSX) || defined(OS_LINUX) |
103 | 113 |
114 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra | |
115 // when it is possible to run memory-infra without tracing. | |
116 size_t GetMallocUsage() { | |
117 #if defined(OS_WIN) | |
118 // Iterate through whichever heap the CRT is using. | |
119 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); | |
120 if (crt_heap == NULL) | |
121 return 0; | |
122 if (!::HeapLock(crt_heap)) | |
123 return 0; | |
124 size_t malloc_usage = 0; | |
125 PROCESS_HEAP_ENTRY heap_entry; | |
126 heap_entry.lpData = NULL; | |
127 while (::HeapWalk(crt_heap, &heap_entry) != 0) { | |
128 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) | |
129 malloc_usage += heap_entry.cbData; | |
130 } | |
131 ::HeapUnlock(crt_heap); | |
132 return malloc_usage; | |
133 #elif defined(OS_MACOSX) || defined(OS_IOS) | |
134 malloc_statistics_t stats = {0}; | |
135 malloc_zone_statistics(nullptr, &stats); | |
136 return stats.size_in_use; | |
137 #elif defined(OS_LINUX) || defined(OS_ANDROID) | |
138 struct mallinfo minfo = mallinfo(); | |
139 #if defined(USE_TCMALLOC) | |
140 return minfo.uordblks; | |
141 #else | |
142 return minfo.hblkhd + minfo.arena; | |
143 #endif | |
144 #endif | |
145 } | |
146 | |
147 namespace { | |
148 | |
149 class LightPartitionStatsDumperImpl : public base::PartitionStatsDumper { | |
150 public: | |
151 LightPartitionStatsDumperImpl() : total_active_bytes_(0) {} | |
152 | |
153 void PartitionDumpTotals( | |
154 const char* partition_name, | |
155 const base::PartitionMemoryStats* memory_stats) override { | |
156 total_active_bytes_ += memory_stats->total_active_bytes; | |
157 } | |
158 | |
159 void PartitionsDumpBucketStats( | |
160 const char* partition_name, | |
161 const base::PartitionBucketMemoryStats*) override {} | |
162 | |
163 size_t TotalActiveBytes() const { return total_active_bytes_; } | |
164 | |
165 private: | |
166 size_t total_active_bytes_; | |
167 }; | |
168 | |
169 } // namespace | |
170 | |
171 size_t GetPartitionAllocUsage() { | |
172 LightPartitionStatsDumperImpl dumper; | |
Primiano Tucci (use gerrit)
2017/06/14 12:19:49
also, looks like you should call PartitionDumpTot
keishi
2017/06/14 13:21:39
I forgot to call WTF::Partitions::DumpMemoryStats(
| |
173 return dumper.TotalActiveBytes(); | |
174 } | |
175 | |
104 } // namespace base | 176 } // namespace base |
OLD | NEW |