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 base::subtle::Atomic32 current_timing_enabled = |
64 // will always be the same, and is side-effect free, while needing to use a | 65 base::subtle::NoBarrier_Load(&timing_enabled); |
65 // lock or a memory barrier would be more costly. | 66 if (current_timing_enabled == UNDEFINED_TIMING) { |
66 if (timing_enabled == UNDEFINED_TIMING) { | |
67 if (!CommandLine::InitializedForCurrentProcess()) | 67 if (!CommandLine::InitializedForCurrentProcess()) |
68 return true; | 68 return true; |
69 timing_enabled = (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 69 current_timing_enabled = |
70 switches::kProfilerTiming) == | 70 (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
71 switches::kProfilerTimingDisabledValue) | 71 switches::kProfilerTiming) == |
72 ? DISABLED_TIMING | 72 switches::kProfilerTimingDisabledValue) |
73 : ENABLED_TIMING; | 73 ? DISABLED_TIMING |
74 : ENABLED_TIMING; | |
75 base::subtle::Release_Store(&timing_enabled, current_timing_enabled); | |
Alexander Potapenko
2013/12/12 09:43:14
This can be a NoBarrier_Store, since you're not ac
qsr
2013/12/12 10:06:20
Done.
| |
74 } | 76 } |
75 return timing_enabled == ENABLED_TIMING; | 77 return current_timing_enabled == ENABLED_TIMING; |
76 } | 78 } |
77 | 79 |
78 } // namespace | 80 } // namespace |
79 | 81 |
80 //------------------------------------------------------------------------------ | 82 //------------------------------------------------------------------------------ |
81 // DeathData tallies durations when a death takes place. | 83 // DeathData tallies durations when a death takes place. |
82 | 84 |
83 DeathData::DeathData() { | 85 DeathData::DeathData() { |
84 Clear(); | 86 Clear(); |
85 } | 87 } |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
887 : process_id(base::GetCurrentProcId()) { | 889 : process_id(base::GetCurrentProcId()) { |
888 #else | 890 #else |
889 : process_id(0) { | 891 : process_id(0) { |
890 #endif | 892 #endif |
891 } | 893 } |
892 | 894 |
893 ProcessDataSnapshot::~ProcessDataSnapshot() { | 895 ProcessDataSnapshot::~ProcessDataSnapshot() { |
894 } | 896 } |
895 | 897 |
896 } // namespace tracked_objects | 898 } // namespace tracked_objects |
OLD | NEW |