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 <math.h> | 7 #include <math.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
13 #include "base/profiler/alternate_timer.h" | 13 #include "base/profiler/alternate_timer.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/third_party/valgrind/memcheck.h" | 15 #include "base/third_party/valgrind/memcheck.h" |
16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
17 #include "base/port.h" | 17 #include "base/port.h" |
18 | 18 |
19 using base::TimeDelta; | 19 using base::TimeDelta; |
20 | 20 |
21 namespace tracked_objects { | 21 namespace tracked_objects { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | |
25 // Flag to compile out almost all of the task tracking code. | 24 // Flag to compile out almost all of the task tracking code. |
26 const bool kTrackAllTaskObjects = true; | 25 const bool kTrackAllTaskObjects = true; |
27 | 26 |
28 // TODO(jar): Evaluate the perf impact of enabling this. If the perf impact is | 27 // TODO(jar): Evaluate the perf impact of enabling this. If the perf impact is |
29 // negligible, enable by default. | 28 // negligible, enable by default. |
30 // Flag to compile out parent-child link recording. | 29 // Flag to compile out parent-child link recording. |
31 const bool kTrackParentChildLinks = false; | 30 const bool kTrackParentChildLinks = false; |
32 | 31 |
33 // When ThreadData is first initialized, should we start in an ACTIVE state to | 32 // When ThreadData is first initialized, should we start in an ACTIVE state to |
34 // record all of the startup-time tasks, or should we start up DEACTIVATED, so | 33 // record all of the startup-time tasks, or should we start up DEACTIVATED, so |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 queue_duration_sum_ += queue_duration; | 78 queue_duration_sum_ += queue_duration; |
80 run_duration_sum_ += run_duration; | 79 run_duration_sum_ += run_duration; |
81 | 80 |
82 if (queue_duration_max_ < queue_duration) | 81 if (queue_duration_max_ < queue_duration) |
83 queue_duration_max_ = queue_duration; | 82 queue_duration_max_ = queue_duration; |
84 if (run_duration_max_ < run_duration) | 83 if (run_duration_max_ < run_duration) |
85 run_duration_max_ = run_duration; | 84 run_duration_max_ = run_duration; |
86 | 85 |
87 // Take a uniformly distributed sample over all durations ever supplied. | 86 // Take a uniformly distributed sample over all durations ever supplied. |
88 // The probability that we (instead) use this new sample is 1/count_. This | 87 // The probability that we (instead) use this new sample is 1/count_. This |
89 // results in a completely uniform selection of the sample. | 88 // results in a completely uniform selection of the sample (at least when we |
90 // We ignore the fact that we correlated our selection of a sample of run | 89 // don't clamp count_... but that should be inconsequentially likely). |
91 // and queue times. | 90 // We ignore the fact that we correlated our selection of a sample to the run |
| 91 // and queue times (i.e., we used them to generate random_number). |
| 92 if (count_ <= 0) { // Handle wrapping of count_, such as in bug 138961. |
| 93 CHECK_GE(count_ - 1, 0); // Detect memory corruption. |
| 94 // We'll just clamp at INT_MAX, but we should note this in the UI as such. |
| 95 count_ = INT_MAX; |
| 96 } |
92 if (0 == (random_number % count_)) { | 97 if (0 == (random_number % count_)) { |
93 queue_duration_sample_ = queue_duration; | 98 queue_duration_sample_ = queue_duration; |
94 run_duration_sample_ = run_duration; | 99 run_duration_sample_ = run_duration; |
95 } | 100 } |
96 } | 101 } |
97 | 102 |
98 int DeathData::count() const { return count_; } | 103 int DeathData::count() const { return count_; } |
99 | 104 |
100 int32 DeathData::run_duration_sum() const { return run_duration_sum_; } | 105 int32 DeathData::run_duration_sum() const { return run_duration_sum_; } |
101 | 106 |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 death_data(death_data), | 838 death_data(death_data), |
834 death_thread_name(death_thread_name) { | 839 death_thread_name(death_thread_name) { |
835 } | 840 } |
836 | 841 |
837 TaskSnapshot::~TaskSnapshot() { | 842 TaskSnapshot::~TaskSnapshot() { |
838 } | 843 } |
839 | 844 |
840 //------------------------------------------------------------------------------ | 845 //------------------------------------------------------------------------------ |
841 // ParentChildPairSnapshot | 846 // ParentChildPairSnapshot |
842 | 847 |
843 ParentChildPairSnapshot::ParentChildPairSnapshot(){ | 848 ParentChildPairSnapshot::ParentChildPairSnapshot() { |
844 } | 849 } |
845 | 850 |
846 ParentChildPairSnapshot::ParentChildPairSnapshot( | 851 ParentChildPairSnapshot::ParentChildPairSnapshot( |
847 const ThreadData::ParentChildPair& parent_child) | 852 const ThreadData::ParentChildPair& parent_child) |
848 : parent(*parent_child.first), | 853 : parent(*parent_child.first), |
849 child(*parent_child.second) { | 854 child(*parent_child.second) { |
850 } | 855 } |
851 | 856 |
852 ParentChildPairSnapshot::~ParentChildPairSnapshot() { | 857 ParentChildPairSnapshot::~ParentChildPairSnapshot() { |
853 } | 858 } |
854 | 859 |
855 //------------------------------------------------------------------------------ | 860 //------------------------------------------------------------------------------ |
856 // ProcessDataSnapshot | 861 // ProcessDataSnapshot |
857 | 862 |
858 ProcessDataSnapshot::ProcessDataSnapshot() | 863 ProcessDataSnapshot::ProcessDataSnapshot() |
859 #if !defined(OS_NACL) | 864 #if !defined(OS_NACL) |
860 : process_id(base::GetCurrentProcId()) { | 865 : process_id(base::GetCurrentProcId()) { |
861 #else | 866 #else |
862 : process_id(0) { | 867 : process_id(0) { |
863 #endif | 868 #endif |
864 } | 869 } |
865 | 870 |
866 ProcessDataSnapshot::~ProcessDataSnapshot() { | 871 ProcessDataSnapshot::~ProcessDataSnapshot() { |
867 } | 872 } |
868 | 873 |
869 } // namespace tracked_objects | 874 } // namespace tracked_objects |
OLD | NEW |