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 // Control whether to collect timing information. | |
| 57 enum ProfilerTimingState { | |
|
Mark Mentovai
2013/12/09 14:18:32
You can move this whole enum definition and variab
qsr
2013/12/09 14:48:32
Done.
| |
| 58 UNDEFINED_TIMING, | |
| 59 ENABLED_TIMING, | |
| 60 DISABLED_TIMING, | |
| 61 } g_timing_enabled = UNDEFINED_TIMING; | |
| 62 | |
| 63 inline bool IsProfilerTimingEnabled() { | |
| 64 // This initialization is not thread-safe, so the value of |g_timing_enabled| | |
| 65 // can be computed multiple time. This is not an issue, as the computed value | |
|
Mark Mentovai
2013/12/09 14:18:32
time→times
qsr
2013/12/09 14:48:32
Done.
| |
| 66 // will always be the same, and is side-effect free. | |
| 67 if (g_timing_enabled == UNDEFINED_TIMING) { | |
| 68 g_timing_enabled = (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 69 switches::kProfilerTiming) == | |
| 70 switches::kProfilerTimingDisabledValue) | |
| 71 ? DISABLED_TIMING | |
| 72 : ENABLED_TIMING; | |
| 73 } | |
| 74 return g_timing_enabled == ENABLED_TIMING; | |
| 75 } | |
| 76 | |
| 54 } // namespace | 77 } // namespace |
| 55 | 78 |
| 56 //------------------------------------------------------------------------------ | 79 //------------------------------------------------------------------------------ |
| 57 // DeathData tallies durations when a death takes place. | 80 // DeathData tallies durations when a death takes place. |
| 58 | 81 |
| 59 DeathData::DeathData() { | 82 DeathData::DeathData() { |
| 60 Clear(); | 83 Clear(); |
| 61 } | 84 } |
| 62 | 85 |
| 63 DeathData::DeathData(int count) { | 86 DeathData::DeathData(int count) { |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 void ThreadData::SetAlternateTimeSource(NowFunction* now_function) { | 770 void ThreadData::SetAlternateTimeSource(NowFunction* now_function) { |
| 748 DCHECK(now_function); | 771 DCHECK(now_function); |
| 749 if (kAllowAlternateTimeSourceHandling) | 772 if (kAllowAlternateTimeSourceHandling) |
| 750 now_function_ = now_function; | 773 now_function_ = now_function; |
| 751 } | 774 } |
| 752 | 775 |
| 753 // static | 776 // static |
| 754 TrackedTime ThreadData::Now() { | 777 TrackedTime ThreadData::Now() { |
| 755 if (kAllowAlternateTimeSourceHandling && now_function_) | 778 if (kAllowAlternateTimeSourceHandling && now_function_) |
| 756 return TrackedTime::FromMilliseconds((*now_function_)()); | 779 return TrackedTime::FromMilliseconds((*now_function_)()); |
| 757 if (kTrackAllTaskObjects && TrackingStatus()) | 780 if (kTrackAllTaskObjects && IsProfilerTimingEnabled() && TrackingStatus()) |
| 758 return TrackedTime::Now(); | 781 return TrackedTime::Now(); |
| 759 return TrackedTime(); // Super fast when disabled, or not compiled. | 782 return TrackedTime(); // Super fast when disabled, or not compiled. |
| 760 } | 783 } |
| 761 | 784 |
| 762 // static | 785 // static |
| 763 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { | 786 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { |
| 764 base::AutoLock lock(*list_lock_.Pointer()); | 787 base::AutoLock lock(*list_lock_.Pointer()); |
| 765 if (worker_thread_data_creation_count_ == 0) | 788 if (worker_thread_data_creation_count_ == 0) |
| 766 return; // We haven't really run much, and couldn't have leaked. | 789 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 | 790 // 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()) { | 886 : process_id(base::GetCurrentProcId()) { |
| 864 #else | 887 #else |
| 865 : process_id(0) { | 888 : process_id(0) { |
| 866 #endif | 889 #endif |
| 867 } | 890 } |
| 868 | 891 |
| 869 ProcessDataSnapshot::~ProcessDataSnapshot() { | 892 ProcessDataSnapshot::~ProcessDataSnapshot() { |
| 870 } | 893 } |
| 871 | 894 |
| 872 } // namespace tracked_objects | 895 } // namespace tracked_objects |
| OLD | NEW |