OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/metrics/child_call_stack_profile_collector.h" | 5 #include "components/metrics/child_call_stack_profile_collector.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "services/service_manager/public/cpp/interface_provider.h" | 14 #include "services/service_manager/public/cpp/interface_provider.h" |
15 | 15 |
16 namespace metrics { | 16 namespace metrics { |
17 | 17 |
18 ChildCallStackProfileCollector::ProfilesState::ProfilesState() = default; | 18 ChildCallStackProfileCollector::ProfilesState::ProfilesState() = default; |
19 ChildCallStackProfileCollector::ProfilesState::ProfilesState(ProfilesState&&) = | 19 ChildCallStackProfileCollector::ProfilesState::ProfilesState(ProfilesState&&) = |
20 default; | 20 default; |
21 | 21 |
22 ChildCallStackProfileCollector::ProfilesState::ProfilesState( | 22 ChildCallStackProfileCollector::ProfilesState::ProfilesState( |
23 const CallStackProfileParams& params, | 23 const CallStackProfileParams& params, |
24 | |
Mike Wittman
2017/07/06 17:25:53
nit: remove
Alexei Svitkine (slow)
2017/07/06 19:36:26
Done.
| |
24 base::TimeTicks start_timestamp, | 25 base::TimeTicks start_timestamp, |
25 base::StackSamplingProfiler::CallStackProfiles profiles) | 26 base::StackSamplingProfiler::CallStackProfiles profiles) |
26 : params(params), | 27 : params(params), |
27 start_timestamp(start_timestamp), | 28 start_timestamp(start_timestamp), |
28 profiles(std::move(profiles)) {} | 29 profiles(std::move(profiles)) {} |
29 | 30 |
30 ChildCallStackProfileCollector::ProfilesState::~ProfilesState() = default; | 31 ChildCallStackProfileCollector::ProfilesState::~ProfilesState() = default; |
31 | 32 |
32 // Some versions of GCC need this for push_back to work with std::move. | 33 // Some versions of GCC need this for push_back to work with std::move. |
33 ChildCallStackProfileCollector::ProfilesState& | 34 ChildCallStackProfileCollector::ProfilesState& |
(...skipping 24 matching lines...) Expand all Loading... | |
58 parent_collector_ = std::move(parent_collector); | 59 parent_collector_ = std::move(parent_collector); |
59 if (parent_collector_) { | 60 if (parent_collector_) { |
60 for (ProfilesState& state : profiles_) { | 61 for (ProfilesState& state : profiles_) { |
61 parent_collector_->Collect(state.params, state.start_timestamp, | 62 parent_collector_->Collect(state.params, state.start_timestamp, |
62 std::move(state.profiles)); | 63 std::move(state.profiles)); |
63 } | 64 } |
64 } | 65 } |
65 profiles_.clear(); | 66 profiles_.clear(); |
66 } | 67 } |
67 | 68 |
68 void ChildCallStackProfileCollector::Collect( | 69 base::Optional<base::StackSamplingProfiler::SamplingParams> |
70 ChildCallStackProfileCollector::Collect( | |
69 const CallStackProfileParams& params, | 71 const CallStackProfileParams& params, |
70 base::TimeTicks start_timestamp, | 72 base::TimeTicks start_timestamp, |
71 std::vector<CallStackProfile> profiles) { | 73 std::vector<CallStackProfile> profiles) { |
74 // Impl function is used as it needs to PostTask() to itself on a different | |
75 // thread - which only works with a void return value. | |
76 CollectImpl(params, start_timestamp, std::move(profiles)); | |
77 // Empty return value indicates that collection should not be re-started. | |
78 return base::Optional<base::StackSamplingProfiler::SamplingParams>(); | |
79 } | |
80 | |
81 void ChildCallStackProfileCollector::CollectImpl( | |
82 const CallStackProfileParams& params, | |
83 base::TimeTicks start_timestamp, | |
84 std::vector<CallStackProfile> profiles) { | |
72 base::AutoLock alock(lock_); | 85 base::AutoLock alock(lock_); |
73 if (task_runner_ && | 86 if (task_runner_ && |
74 // The profiler thread does not have a task runner. Attempting to | 87 // The profiler thread does not have a task runner. Attempting to |
75 // invoke Get() on it results in a DCHECK. | 88 // invoke Get() on it results in a DCHECK. |
76 (!base::ThreadTaskRunnerHandle::IsSet() || | 89 (!base::ThreadTaskRunnerHandle::IsSet() || |
77 base::ThreadTaskRunnerHandle::Get() != task_runner_)) { | 90 base::ThreadTaskRunnerHandle::Get() != task_runner_)) { |
78 // Post back to the thread that owns the the parent interface. | 91 // Post back to the thread that owns the the parent interface. |
79 task_runner_->PostTask(FROM_HERE, base::Bind( | 92 task_runner_->PostTask( |
80 &ChildCallStackProfileCollector::Collect, | 93 FROM_HERE, base::Bind(&ChildCallStackProfileCollector::CollectImpl, |
81 // This class has lazy instance lifetime. | 94 // This class has lazy instance lifetime. |
82 base::Unretained(this), | 95 base::Unretained(this), params, start_timestamp, |
83 params, | 96 base::Passed(std::move(profiles)))); |
84 start_timestamp, | |
85 base::Passed(std::move(profiles)))); | |
86 return; | 97 return; |
87 } | 98 } |
88 | 99 |
89 if (parent_collector_) { | 100 if (parent_collector_) { |
90 parent_collector_->Collect(params, start_timestamp, std::move(profiles)); | 101 parent_collector_->Collect(params, start_timestamp, std::move(profiles)); |
91 } else if (retain_profiles_) { | 102 } else if (retain_profiles_) { |
92 profiles_.push_back( | 103 profiles_.push_back( |
93 ProfilesState(params, start_timestamp, std::move(profiles))); | 104 ProfilesState(params, start_timestamp, std::move(profiles))); |
94 } | 105 } |
95 } | 106 } |
96 | 107 |
97 } // namespace metrics | 108 } // namespace metrics |
OLD | NEW |