Chromium Code Reviews| 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 "base/tracked_objects.h" | 5 #include "base/tracked_objects.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include "base/base_switches.h" | |
| 11 #include "base/command_line.h" | |
| 10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 11 #include "base/debug/leak_annotations.h" | 13 #include "base/debug/leak_annotations.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/process/process_handle.h" | 15 #include "base/process/process_handle.h" |
| 14 #include "base/profiler/alternate_timer.h" | 16 #include "base/profiler/alternate_timer.h" |
| 15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 16 #include "base/third_party/valgrind/memcheck.h" | 18 #include "base/third_party/valgrind/memcheck.h" |
| 17 #include "base/tracking_info.h" | 19 #include "base/tracking_info.h" |
| 18 | 20 |
| 19 using base::TimeDelta; | 21 using base::TimeDelta; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 44 | 46 |
| 45 // Control whether an alternate time source (Now() function) is supported by | 47 // Control whether an alternate time source (Now() function) is supported by |
| 46 // the ThreadData class. This compile time flag should be set to true if we | 48 // the ThreadData class. This compile time flag should be set to true if we |
| 47 // want other modules (such as a memory allocator, or a thread-specific CPU time | 49 // want other modules (such as a memory allocator, or a thread-specific CPU time |
| 48 // clock) to be able to provide a thread-specific Now() function. Without this | 50 // clock) to be able to provide a thread-specific Now() function. Without this |
| 49 // compile-time flag, the code will only support the wall-clock time. This flag | 51 // compile-time flag, the code will only support the wall-clock time. This flag |
| 50 // can be flipped to efficiently disable this path (if there is a performance | 52 // can be flipped to efficiently disable this path (if there is a performance |
| 51 // problem with its presence). | 53 // problem with its presence). |
| 52 static const bool kAllowAlternateTimeSourceHandling = true; | 54 static const bool kAllowAlternateTimeSourceHandling = true; |
| 53 | 55 |
| 56 inline bool IsProfilerTimingEnabled() { | |
| 57 enum { | |
|
no sievers
2013/12/09 20:10:23
missing static
qsr
2013/12/11 09:11:21
Done.
| |
| 58 UNDEFINED_TIMING, | |
| 59 ENABLED_TIMING, | |
| 60 DISABLED_TIMING, | |
| 61 } g_timing_enabled = UNDEFINED_TIMING; | |
|
jar (doing other things)
2013/12/09 20:31:34
It probably *should* be a global static per the g_
Mark Mentovai
2013/12/09 20:42:39
jar wrote:
jar (doing other things)
2013/12/09 20:47:55
<doh> My mistaken... function statics don't need
qsr
2013/12/11 09:11:21
Done.
| |
| 62 // This initialization is not thread-safe, so the value of |g_timing_enabled| | |
| 63 // can be computed multiple times. This is not an issue, as the computed value | |
| 64 // will always be the same, and is side-effect free. | |
| 65 if (g_timing_enabled == UNDEFINED_TIMING) { | |
| 66 g_timing_enabled = (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 67 switches::kProfilerTiming) == | |
| 68 switches::kProfilerTimingDisabledValue) | |
| 69 ? DISABLED_TIMING | |
| 70 : ENABLED_TIMING; | |
| 71 } | |
| 72 return g_timing_enabled == ENABLED_TIMING; | |
| 73 } | |
| 74 | |
| 54 } // namespace | 75 } // namespace |
| 55 | 76 |
| 56 //------------------------------------------------------------------------------ | 77 //------------------------------------------------------------------------------ |
| 57 // DeathData tallies durations when a death takes place. | 78 // DeathData tallies durations when a death takes place. |
| 58 | 79 |
| 59 DeathData::DeathData() { | 80 DeathData::DeathData() { |
| 60 Clear(); | 81 Clear(); |
| 61 } | 82 } |
| 62 | 83 |
| 63 DeathData::DeathData(int count) { | 84 DeathData::DeathData(int count) { |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 void ThreadData::SetAlternateTimeSource(NowFunction* now_function) { | 768 void ThreadData::SetAlternateTimeSource(NowFunction* now_function) { |
| 748 DCHECK(now_function); | 769 DCHECK(now_function); |
| 749 if (kAllowAlternateTimeSourceHandling) | 770 if (kAllowAlternateTimeSourceHandling) |
| 750 now_function_ = now_function; | 771 now_function_ = now_function; |
| 751 } | 772 } |
| 752 | 773 |
| 753 // static | 774 // static |
| 754 TrackedTime ThreadData::Now() { | 775 TrackedTime ThreadData::Now() { |
| 755 if (kAllowAlternateTimeSourceHandling && now_function_) | 776 if (kAllowAlternateTimeSourceHandling && now_function_) |
| 756 return TrackedTime::FromMilliseconds((*now_function_)()); | 777 return TrackedTime::FromMilliseconds((*now_function_)()); |
| 757 if (kTrackAllTaskObjects && TrackingStatus()) | 778 if (kTrackAllTaskObjects && IsProfilerTimingEnabled() && TrackingStatus()) |
| 758 return TrackedTime::Now(); | 779 return TrackedTime::Now(); |
| 759 return TrackedTime(); // Super fast when disabled, or not compiled. | 780 return TrackedTime(); // Super fast when disabled, or not compiled. |
| 760 } | 781 } |
| 761 | 782 |
| 762 // static | 783 // static |
| 763 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { | 784 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { |
| 764 base::AutoLock lock(*list_lock_.Pointer()); | 785 base::AutoLock lock(*list_lock_.Pointer()); |
| 765 if (worker_thread_data_creation_count_ == 0) | 786 if (worker_thread_data_creation_count_ == 0) |
| 766 return; // We haven't really run much, and couldn't have leaked. | 787 return; // We haven't really run much, and couldn't have leaked. |
| 767 // Verify that we've at least shutdown/cleanup the major namesd threads. The | 788 // Verify that we've at least shutdown/cleanup the major namesd threads. The |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 : process_id(base::GetCurrentProcId()) { | 884 : process_id(base::GetCurrentProcId()) { |
| 864 #else | 885 #else |
| 865 : process_id(0) { | 886 : process_id(0) { |
| 866 #endif | 887 #endif |
| 867 } | 888 } |
| 868 | 889 |
| 869 ProcessDataSnapshot::~ProcessDataSnapshot() { | 890 ProcessDataSnapshot::~ProcessDataSnapshot() { |
| 870 } | 891 } |
| 871 | 892 |
| 872 } // namespace tracked_objects | 893 } // namespace tracked_objects |
| OLD | NEW |