OLD | NEW |
---|---|
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 "content/public/app/content_main_runner.h" | 5 #include "content/public/app/content_main_runner.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); | 476 memset(&sandbox_info_, 0, sizeof(sandbox_info_)); |
477 #endif | 477 #endif |
478 } | 478 } |
479 | 479 |
480 ~ContentMainRunnerImpl() { | 480 ~ContentMainRunnerImpl() { |
481 if (is_initialized_ && !is_shutdown_) | 481 if (is_initialized_ && !is_shutdown_) |
482 Shutdown(); | 482 Shutdown(); |
483 } | 483 } |
484 | 484 |
485 #if defined(USE_TCMALLOC) | 485 #if defined(USE_TCMALLOC) |
486 static bool GetPropertyThunk(const char* name, size_t* value) { | 486 static bool GetAllocatorWasteSizeThunk(size_t* size) { |
487 return MallocExtension::instance()->GetNumericProperty(name, value); | 487 size_t heap_size, allocated_bytes, unmapped_bytes; |
488 MallocExtension* ext = MallocExtension::instance(); | |
489 if (ext->GetNumericProperty("generic.heap_size", &heap_size) && | |
darin (slow to review)
2012/10/23 17:28:30
nit: Same comment as before. We shouldn't be hard
alexeif
2012/10/23 18:00:15
I'm not sure. These strings are hardcoded in the t
| |
490 ext->GetNumericProperty("generic.current_allocated_bytes", | |
491 &allocated_bytes) && | |
492 ext->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes", | |
493 &unmapped_bytes)) { | |
494 *size = heap_size - allocated_bytes - unmapped_bytes; | |
495 return true; | |
496 } | |
497 DCHECK(false); | |
498 return false; | |
488 } | 499 } |
489 | 500 |
490 static void GetStatsThunk(char* buffer, int buffer_length) { | 501 static void GetStatsThunk(char* buffer, int buffer_length) { |
491 MallocExtension::instance()->GetStats(buffer, buffer_length); | 502 MallocExtension::instance()->GetStats(buffer, buffer_length); |
492 } | 503 } |
493 | 504 |
494 static void ReleaseFreeMemoryThunk() { | 505 static void ReleaseFreeMemoryThunk() { |
495 MallocExtension::instance()->ReleaseFreeMemory(); | 506 MallocExtension::instance()->ReleaseFreeMemory(); |
496 } | 507 } |
497 #endif | 508 #endif |
(...skipping 27 matching lines...) Expand all Loading... | |
525 #if defined(TYPE_PROFILING) | 536 #if defined(TYPE_PROFILING) |
526 base::type_profiler::InterceptFunctions::SetFunctions( | 537 base::type_profiler::InterceptFunctions::SetFunctions( |
527 base::type_profiler::NewInterceptForTCMalloc, | 538 base::type_profiler::NewInterceptForTCMalloc, |
528 base::type_profiler::DeleteInterceptForTCMalloc); | 539 base::type_profiler::DeleteInterceptForTCMalloc); |
529 #endif | 540 #endif |
530 | 541 |
531 // For tcmalloc, we need to tell it to behave like new. | 542 // For tcmalloc, we need to tell it to behave like new. |
532 tc_set_new_mode(1); | 543 tc_set_new_mode(1); |
533 | 544 |
534 // On windows, we've already set these thunks up in _heap_init() | 545 // On windows, we've already set these thunks up in _heap_init() |
535 base::allocator::SetGetPropertyFunction(GetPropertyThunk); | 546 base::allocator::SetGetAllocatorWasteSizeFunction( |
547 GetAllocatorWasteSizeThunk); | |
536 base::allocator::SetGetStatsFunction(GetStatsThunk); | 548 base::allocator::SetGetStatsFunction(GetStatsThunk); |
537 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); | 549 base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk); |
538 | 550 |
539 // Provide optional hook for monitoring allocation quantities on a | 551 // Provide optional hook for monitoring allocation quantities on a |
540 // per-thread basis. Only set the hook if the environment indicates this | 552 // per-thread basis. Only set the hook if the environment indicates this |
541 // needs to be enabled. | 553 // needs to be enabled. |
542 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); | 554 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); |
543 if (profiling && | 555 if (profiling && |
544 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { | 556 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { |
545 tracked_objects::SetAlternateTimeSource( | 557 tracked_objects::SetAlternateTimeSource( |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
799 | 811 |
800 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 812 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
801 }; | 813 }; |
802 | 814 |
803 // static | 815 // static |
804 ContentMainRunner* ContentMainRunner::Create() { | 816 ContentMainRunner* ContentMainRunner::Create() { |
805 return new ContentMainRunnerImpl(); | 817 return new ContentMainRunnerImpl(); |
806 } | 818 } |
807 | 819 |
808 } // namespace content | 820 } // namespace content |
OLD | NEW |