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" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 parent_collector_ = std::move(parent_collector); | 58 parent_collector_ = std::move(parent_collector); |
59 if (parent_collector_) { | 59 if (parent_collector_) { |
60 for (ProfilesState& state : profiles_) { | 60 for (ProfilesState& state : profiles_) { |
61 parent_collector_->Collect(state.params, state.start_timestamp, | 61 parent_collector_->Collect(state.params, state.start_timestamp, |
62 std::move(state.profiles)); | 62 std::move(state.profiles)); |
63 } | 63 } |
64 } | 64 } |
65 profiles_.clear(); | 65 profiles_.clear(); |
66 } | 66 } |
67 | 67 |
68 void ChildCallStackProfileCollector::Collect( | 68 base::Optional<base::StackSamplingProfiler::SamplingParams> |
| 69 ChildCallStackProfileCollector::Collect( |
69 const CallStackProfileParams& params, | 70 const CallStackProfileParams& params, |
70 base::TimeTicks start_timestamp, | 71 base::TimeTicks start_timestamp, |
71 std::vector<CallStackProfile> profiles) { | 72 std::vector<CallStackProfile> profiles) { |
| 73 // Impl function is used as it needs to PostTask() to itself on a different |
| 74 // thread - which only works with a void return value. |
| 75 CollectImpl(params, start_timestamp, std::move(profiles)); |
| 76 // Empty return value indicates that collection should not be re-started. |
| 77 return base::Optional<base::StackSamplingProfiler::SamplingParams>(); |
| 78 } |
| 79 |
| 80 void ChildCallStackProfileCollector::CollectImpl( |
| 81 const CallStackProfileParams& params, |
| 82 base::TimeTicks start_timestamp, |
| 83 std::vector<CallStackProfile> profiles) { |
72 base::AutoLock alock(lock_); | 84 base::AutoLock alock(lock_); |
73 if (task_runner_ && | 85 if (task_runner_ && |
74 // The profiler thread does not have a task runner. Attempting to | 86 // The profiler thread does not have a task runner. Attempting to |
75 // invoke Get() on it results in a DCHECK. | 87 // invoke Get() on it results in a DCHECK. |
76 (!base::ThreadTaskRunnerHandle::IsSet() || | 88 (!base::ThreadTaskRunnerHandle::IsSet() || |
77 base::ThreadTaskRunnerHandle::Get() != task_runner_)) { | 89 base::ThreadTaskRunnerHandle::Get() != task_runner_)) { |
78 // Post back to the thread that owns the the parent interface. | 90 // Post back to the thread that owns the the parent interface. |
79 task_runner_->PostTask(FROM_HERE, base::Bind( | 91 task_runner_->PostTask( |
80 &ChildCallStackProfileCollector::Collect, | 92 FROM_HERE, base::Bind(&ChildCallStackProfileCollector::CollectImpl, |
81 // This class has lazy instance lifetime. | 93 // This class has lazy instance lifetime. |
82 base::Unretained(this), | 94 base::Unretained(this), params, start_timestamp, |
83 params, | 95 base::Passed(std::move(profiles)))); |
84 start_timestamp, | |
85 base::Passed(std::move(profiles)))); | |
86 return; | 96 return; |
87 } | 97 } |
88 | 98 |
89 if (parent_collector_) { | 99 if (parent_collector_) { |
90 parent_collector_->Collect(params, start_timestamp, std::move(profiles)); | 100 parent_collector_->Collect(params, start_timestamp, std::move(profiles)); |
91 } else if (retain_profiles_) { | 101 } else if (retain_profiles_) { |
92 profiles_.push_back( | 102 profiles_.push_back( |
93 ProfilesState(params, start_timestamp, std::move(profiles))); | 103 ProfilesState(params, start_timestamp, std::move(profiles))); |
94 } | 104 } |
95 } | 105 } |
96 | 106 |
97 } // namespace metrics | 107 } // namespace metrics |
OLD | NEW |