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/atomicops.h" |
10 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "base/debug/leak_annotations.h" | 14 #include "base/debug/leak_annotations.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/process/process_handle.h" | 16 #include "base/process/process_handle.h" |
16 #include "base/profiler/alternate_timer.h" | 17 #include "base/profiler/alternate_timer.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/third_party/valgrind/memcheck.h" | 19 #include "base/third_party/valgrind/memcheck.h" |
19 #include "base/tracking_info.h" | 20 #include "base/tracking_info.h" |
(...skipping 27 matching lines...) Expand all Loading... |
47 // Control whether an alternate time source (Now() function) is supported by | 48 // Control whether an alternate time source (Now() function) is supported by |
48 // the ThreadData class. This compile time flag should be set to true if we | 49 // the ThreadData class. This compile time flag should be set to true if we |
49 // want other modules (such as a memory allocator, or a thread-specific CPU time | 50 // want other modules (such as a memory allocator, or a thread-specific CPU time |
50 // clock) to be able to provide a thread-specific Now() function. Without this | 51 // clock) to be able to provide a thread-specific Now() function. Without this |
51 // compile-time flag, the code will only support the wall-clock time. This flag | 52 // compile-time flag, the code will only support the wall-clock time. This flag |
52 // can be flipped to efficiently disable this path (if there is a performance | 53 // can be flipped to efficiently disable this path (if there is a performance |
53 // problem with its presence). | 54 // problem with its presence). |
54 static const bool kAllowAlternateTimeSourceHandling = true; | 55 static const bool kAllowAlternateTimeSourceHandling = true; |
55 | 56 |
56 inline bool IsProfilerTimingEnabled() { | 57 inline bool IsProfilerTimingEnabled() { |
57 static enum { | 58 enum { |
58 UNDEFINED_TIMING, | 59 UNDEFINED_TIMING, |
59 ENABLED_TIMING, | 60 ENABLED_TIMING, |
60 DISABLED_TIMING, | 61 DISABLED_TIMING, |
61 } timing_enabled = UNDEFINED_TIMING; | 62 }; |
62 // This initialization is not thread-safe, so the value of |timing_enabled| | 63 static base::subtle::Atomic32 timing_enabled = UNDEFINED_TIMING; |
63 // can be computed multiple times. This is not an issue, as the computed value | 64 // Reading |timing_enabled| is done without barrier because multiple |
64 // will always be the same, and is side-effect free, while needing to use a | 65 // initialization is not an issue while the barrier can be relatively costly |
65 // lock or a memory barrier would be more costly. | 66 // given that this method is sometimes called in a tight loop. |
66 if (timing_enabled == UNDEFINED_TIMING) { | 67 base::subtle::Atomic32 current_timing_enabled = |
| 68 base::subtle::NoBarrier_Load(&timing_enabled); |
| 69 if (current_timing_enabled == UNDEFINED_TIMING) { |
67 if (!CommandLine::InitializedForCurrentProcess()) | 70 if (!CommandLine::InitializedForCurrentProcess()) |
68 return true; | 71 return true; |
69 timing_enabled = (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 72 current_timing_enabled = |
70 switches::kProfilerTiming) == | 73 (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
71 switches::kProfilerTimingDisabledValue) | 74 switches::kProfilerTiming) == |
72 ? DISABLED_TIMING | 75 switches::kProfilerTimingDisabledValue) |
73 : ENABLED_TIMING; | 76 ? DISABLED_TIMING |
| 77 : ENABLED_TIMING; |
| 78 base::subtle::NoBarrier_Store(&timing_enabled, current_timing_enabled); |
74 } | 79 } |
75 return timing_enabled == ENABLED_TIMING; | 80 return current_timing_enabled == ENABLED_TIMING; |
76 } | 81 } |
77 | 82 |
78 } // namespace | 83 } // namespace |
79 | 84 |
80 //------------------------------------------------------------------------------ | 85 //------------------------------------------------------------------------------ |
81 // DeathData tallies durations when a death takes place. | 86 // DeathData tallies durations when a death takes place. |
82 | 87 |
83 DeathData::DeathData() { | 88 DeathData::DeathData() { |
84 Clear(); | 89 Clear(); |
85 } | 90 } |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 : process_id(base::GetCurrentProcId()) { | 892 : process_id(base::GetCurrentProcId()) { |
888 #else | 893 #else |
889 : process_id(0) { | 894 : process_id(0) { |
890 #endif | 895 #endif |
891 } | 896 } |
892 | 897 |
893 ProcessDataSnapshot::~ProcessDataSnapshot() { | 898 ProcessDataSnapshot::~ProcessDataSnapshot() { |
894 } | 899 } |
895 | 900 |
896 } // namespace tracked_objects | 901 } // namespace tracked_objects |
OLD | NEW |