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 bool ChildCallStackProfileCollector::Collect( |
| 69 const CallStackProfileParams& params, |
| 70 base::TimeTicks start_timestamp, |
| 71 std::vector<CallStackProfile> profiles, |
| 72 base::StackSamplingProfiler::SamplingParams* sampling_params) { |
| 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 // False return value indicates that collection should not be started again |
| 77 // with modified |sampling_params|. |
| 78 return false; |
| 79 } |
| 80 |
| 81 void ChildCallStackProfileCollector::CollectImpl( |
69 const CallStackProfileParams& params, | 82 const CallStackProfileParams& params, |
70 base::TimeTicks start_timestamp, | 83 base::TimeTicks start_timestamp, |
71 std::vector<CallStackProfile> profiles) { | 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 |