Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: base/allocator/allocator_shim.cc

Issue 10825250: Expose memory allocator internal stats and properties. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add jemalloc.h include Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/allocator/allocator_extension_thunks.cc ('k') | content/app/content_main_runner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/allocator/allocator_shim.h" 5 #include "base/allocator/allocator_shim.h"
6 6
7 #include <config.h> 7 #include <config.h>
8 #include "base/allocator/allocator_extension_thunks.h" 8 #include "base/allocator/allocator_extension_thunks.h"
9 #include "base/profiler/alternate_timer.h" 9 #include "base/profiler/alternate_timer.h"
10 #include "base/sysinfo.h" 10 #include "base/sysinfo.h"
11 #include "jemalloc.h"
11 12
12 // When defined, different heap allocators can be used via an environment 13 // When defined, different heap allocators can be used via an environment
13 // variable set before running the program. This may reduce the amount 14 // variable set before running the program. This may reduce the amount
14 // of inlining that we get with malloc/free/etc. Disabling makes it 15 // of inlining that we get with malloc/free/etc. Disabling makes it
15 // so that only tcmalloc can be used. 16 // so that only tcmalloc can be used.
16 #define ENABLE_DYNAMIC_ALLOCATOR_SWITCHING 17 #define ENABLE_DYNAMIC_ALLOCATOR_SWITCHING
17 18
18 // TODO(mbelshe): Ensure that all calls to tcmalloc have the proper call depth 19 // TODO(mbelshe): Ensure that all calls to tcmalloc have the proper call depth
19 // from the "user code" so that debugging tools (HeapChecker) can work. 20 // from the "user code" so that debugging tools (HeapChecker) can work.
20 21
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 225 }
225 #endif 226 #endif
226 return MallocExtension::instance()->GetAllocatedSize(p); 227 return MallocExtension::instance()->GetAllocatedSize(p);
227 } 228 }
228 229
229 // This is included to resolve references from libcmt. 230 // This is included to resolve references from libcmt.
230 extern "C" intptr_t _get_heap_handle() { 231 extern "C" intptr_t _get_heap_handle() {
231 return 0; 232 return 0;
232 } 233 }
233 234
235 static bool get_jemalloc_property_thunk(const char* name, size_t* value) {
236 jemalloc_stats_t stats;
237 jemalloc_stats(&stats);
238 #define EXTRACT_JEMALLOC_PROPERTY(property) \
239 if (strcmp(name, "jemalloc." #property) == 0) \
240 return *value = stats.property, true;
241 EXTRACT_JEMALLOC_PROPERTY(narenas);
242 EXTRACT_JEMALLOC_PROPERTY(balance_threshold);
243 EXTRACT_JEMALLOC_PROPERTY(quantum);
244 EXTRACT_JEMALLOC_PROPERTY(small_max);
245 EXTRACT_JEMALLOC_PROPERTY(large_max);
246 EXTRACT_JEMALLOC_PROPERTY(chunksize);
247 EXTRACT_JEMALLOC_PROPERTY(dirty_max);
248 EXTRACT_JEMALLOC_PROPERTY(reserve_min);
249 EXTRACT_JEMALLOC_PROPERTY(reserve_max);
250 EXTRACT_JEMALLOC_PROPERTY(mapped);
251 EXTRACT_JEMALLOC_PROPERTY(committed);
252 EXTRACT_JEMALLOC_PROPERTY(allocated);
253 EXTRACT_JEMALLOC_PROPERTY(dirty);
254 EXTRACT_JEMALLOC_PROPERTY(reserve_cur);
255 #undef EXTRACT_JEMALLOC_PROPERTY
256 return false;
257 }
258
259 static bool get_property_thunk(const char* name, size_t* value) {
260 #ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING
261 switch (allocator) {
262 case JEMALLOC:
263 return get_jemalloc_property_thunk(name, value);
264 case WINHEAP:
265 case WINLFH:
266 // TODO(alexeif): Implement for other allocators.
267 return false;
268 }
269 #endif
270 return MallocExtension::instance()->GetNumericProperty(name, value);
271 }
272
234 static void get_stats_thunk(char* buffer, int buffer_length) { 273 static void get_stats_thunk(char* buffer, int buffer_length) {
235 MallocExtension::instance()->GetStats(buffer, buffer_length); 274 MallocExtension::instance()->GetStats(buffer, buffer_length);
236 } 275 }
237 276
238 static void release_free_memory_thunk() { 277 static void release_free_memory_thunk() {
239 MallocExtension::instance()->ReleaseFreeMemory(); 278 MallocExtension::instance()->ReleaseFreeMemory();
240 } 279 }
241 280
242 // The CRT heap initialization stub. 281 // The CRT heap initialization stub.
243 extern "C" int _heap_init() { 282 extern "C" int _heap_init() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // basis. Only set the hook if the environment indicates this needs to be 316 // basis. Only set the hook if the environment indicates this needs to be
278 // enabled. 317 // enabled.
279 const char* profiling = 318 const char* profiling =
280 GetenvBeforeMain(tracked_objects::kAlternateProfilerTime); 319 GetenvBeforeMain(tracked_objects::kAlternateProfilerTime);
281 if (profiling && *profiling == '1') { 320 if (profiling && *profiling == '1') {
282 tracked_objects::SetAlternateTimeSource( 321 tracked_objects::SetAlternateTimeSource(
283 tcmalloc::ThreadCache::GetBytesAllocatedOnCurrentThread, 322 tcmalloc::ThreadCache::GetBytesAllocatedOnCurrentThread,
284 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); 323 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC);
285 } 324 }
286 325
326 base::allocator::thunks::SetGetPropertyFunction(get_property_thunk);
287 base::allocator::thunks::SetGetStatsFunction(get_stats_thunk); 327 base::allocator::thunks::SetGetStatsFunction(get_stats_thunk);
288 base::allocator::thunks::SetReleaseFreeMemoryFunction( 328 base::allocator::thunks::SetReleaseFreeMemoryFunction(
289 release_free_memory_thunk); 329 release_free_memory_thunk);
290 330
291 return 1; 331 return 1;
292 } 332 }
293 333
294 // The CRT heap cleanup stub. 334 // The CRT heap cleanup stub.
295 extern "C" void _heap_term() {} 335 extern "C" void _heap_term() {}
296 336
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 void TCMallocDoFreeForTest(void* ptr) { 436 void TCMallocDoFreeForTest(void* ptr) {
397 do_free(ptr); 437 do_free(ptr);
398 } 438 }
399 439
400 size_t ExcludeSpaceForMarkForTest(size_t size) { 440 size_t ExcludeSpaceForMarkForTest(size_t size) {
401 return ExcludeSpaceForMark(size); 441 return ExcludeSpaceForMark(size);
402 } 442 }
403 443
404 } // namespace allocator. 444 } // namespace allocator.
405 } // namespace base. 445 } // namespace base.
OLDNEW
« no previous file with comments | « base/allocator/allocator_extension_thunks.cc ('k') | content/app/content_main_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698