OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/profiler/stack_sampling_profiler.h" | 5 #include "base/profiler/stack_sampling_profiler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // callback. | 35 // callback. |
36 static void Run(PlatformThreadId thread_id, | 36 static void Run(PlatformThreadId thread_id, |
37 const StackSamplingProfiler::SamplingParams& params, | 37 const StackSamplingProfiler::SamplingParams& params, |
38 const StackSamplingProfiler::CompletedCallback& callback); | 38 const StackSamplingProfiler::CompletedCallback& callback); |
39 | 39 |
40 private: | 40 private: |
41 AsyncRunner(); | 41 AsyncRunner(); |
42 | 42 |
43 // Runs the callback and deletes the AsyncRunner instance. | 43 // Runs the callback and deletes the AsyncRunner instance. |
44 static void RunCallbackAndDeleteInstance( | 44 static void RunCallbackAndDeleteInstance( |
45 scoped_ptr<AsyncRunner> object_to_be_deleted, | 45 std::unique_ptr<AsyncRunner> object_to_be_deleted, |
46 const StackSamplingProfiler::CompletedCallback& callback, | 46 const StackSamplingProfiler::CompletedCallback& callback, |
47 scoped_refptr<SingleThreadTaskRunner> task_runner, | 47 scoped_refptr<SingleThreadTaskRunner> task_runner, |
48 const StackSamplingProfiler::CallStackProfiles& profiles); | 48 const StackSamplingProfiler::CallStackProfiles& profiles); |
49 | 49 |
50 scoped_ptr<StackSamplingProfiler> profiler_; | 50 std::unique_ptr<StackSamplingProfiler> profiler_; |
51 | 51 |
52 DISALLOW_COPY_AND_ASSIGN(AsyncRunner); | 52 DISALLOW_COPY_AND_ASSIGN(AsyncRunner); |
53 }; | 53 }; |
54 | 54 |
55 // static | 55 // static |
56 void AsyncRunner::Run( | 56 void AsyncRunner::Run( |
57 PlatformThreadId thread_id, | 57 PlatformThreadId thread_id, |
58 const StackSamplingProfiler::SamplingParams& params, | 58 const StackSamplingProfiler::SamplingParams& params, |
59 const StackSamplingProfiler::CompletedCallback &callback) { | 59 const StackSamplingProfiler::CompletedCallback &callback) { |
60 scoped_ptr<AsyncRunner> runner(new AsyncRunner); | 60 std::unique_ptr<AsyncRunner> runner(new AsyncRunner); |
61 AsyncRunner* temp_ptr = runner.get(); | 61 AsyncRunner* temp_ptr = runner.get(); |
62 temp_ptr->profiler_.reset( | 62 temp_ptr->profiler_.reset( |
63 new StackSamplingProfiler(thread_id, params, | 63 new StackSamplingProfiler(thread_id, params, |
64 Bind(&AsyncRunner::RunCallbackAndDeleteInstance, | 64 Bind(&AsyncRunner::RunCallbackAndDeleteInstance, |
65 Passed(&runner), callback, | 65 Passed(&runner), callback, |
66 ThreadTaskRunnerHandle::Get()))); | 66 ThreadTaskRunnerHandle::Get()))); |
67 // The callback won't be called until after Start(), so temp_ptr will still | 67 // The callback won't be called until after Start(), so temp_ptr will still |
68 // be valid here. | 68 // be valid here. |
69 temp_ptr->profiler_->Start(); | 69 temp_ptr->profiler_->Start(); |
70 } | 70 } |
71 | 71 |
72 AsyncRunner::AsyncRunner() {} | 72 AsyncRunner::AsyncRunner() {} |
73 | 73 |
74 void AsyncRunner::RunCallbackAndDeleteInstance( | 74 void AsyncRunner::RunCallbackAndDeleteInstance( |
75 scoped_ptr<AsyncRunner> object_to_be_deleted, | 75 std::unique_ptr<AsyncRunner> object_to_be_deleted, |
76 const StackSamplingProfiler::CompletedCallback& callback, | 76 const StackSamplingProfiler::CompletedCallback& callback, |
77 scoped_refptr<SingleThreadTaskRunner> task_runner, | 77 scoped_refptr<SingleThreadTaskRunner> task_runner, |
78 const StackSamplingProfiler::CallStackProfiles& profiles) { | 78 const StackSamplingProfiler::CallStackProfiles& profiles) { |
79 callback.Run(profiles); | 79 callback.Run(profiles); |
80 // Delete the instance on the original calling thread. | 80 // Delete the instance on the original calling thread. |
81 task_runner->DeleteSoon(FROM_HERE, object_to_be_deleted.release()); | 81 task_runner->DeleteSoon(FROM_HERE, object_to_be_deleted.release()); |
82 } | 82 } |
83 | 83 |
84 } // namespace | 84 } // namespace |
85 | 85 |
(...skipping 22 matching lines...) Expand all Loading... |
108 StackSamplingProfiler::CallStackProfile::CallStackProfile() {} | 108 StackSamplingProfiler::CallStackProfile::CallStackProfile() {} |
109 | 109 |
110 StackSamplingProfiler::CallStackProfile::CallStackProfile( | 110 StackSamplingProfiler::CallStackProfile::CallStackProfile( |
111 const CallStackProfile& other) = default; | 111 const CallStackProfile& other) = default; |
112 | 112 |
113 StackSamplingProfiler::CallStackProfile::~CallStackProfile() {} | 113 StackSamplingProfiler::CallStackProfile::~CallStackProfile() {} |
114 | 114 |
115 // StackSamplingProfiler::SamplingThread -------------------------------------- | 115 // StackSamplingProfiler::SamplingThread -------------------------------------- |
116 | 116 |
117 StackSamplingProfiler::SamplingThread::SamplingThread( | 117 StackSamplingProfiler::SamplingThread::SamplingThread( |
118 scoped_ptr<NativeStackSampler> native_sampler, | 118 std::unique_ptr<NativeStackSampler> native_sampler, |
119 const SamplingParams& params, | 119 const SamplingParams& params, |
120 const CompletedCallback& completed_callback) | 120 const CompletedCallback& completed_callback) |
121 : native_sampler_(std::move(native_sampler)), | 121 : native_sampler_(std::move(native_sampler)), |
122 params_(params), | 122 params_(params), |
123 stop_event_(false, false), | 123 stop_event_(false, false), |
124 completed_callback_(completed_callback) {} | 124 completed_callback_(completed_callback) {} |
125 | 125 |
126 StackSamplingProfiler::SamplingThread::~SamplingThread() {} | 126 StackSamplingProfiler::SamplingThread::~SamplingThread() {} |
127 | 127 |
128 void StackSamplingProfiler::SamplingThread::ThreadMain() { | 128 void StackSamplingProfiler::SamplingThread::ThreadMain() { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 const SamplingParams& params, | 248 const SamplingParams& params, |
249 const CompletedCallback& callback) { | 249 const CompletedCallback& callback) { |
250 CHECK(ThreadTaskRunnerHandle::Get()); | 250 CHECK(ThreadTaskRunnerHandle::Get()); |
251 AsyncRunner::Run(thread_id, params, callback); | 251 AsyncRunner::Run(thread_id, params, callback); |
252 } | 252 } |
253 | 253 |
254 void StackSamplingProfiler::Start() { | 254 void StackSamplingProfiler::Start() { |
255 if (completed_callback_.is_null()) | 255 if (completed_callback_.is_null()) |
256 return; | 256 return; |
257 | 257 |
258 scoped_ptr<NativeStackSampler> native_sampler = | 258 std::unique_ptr<NativeStackSampler> native_sampler = |
259 NativeStackSampler::Create(thread_id_, test_delegate_); | 259 NativeStackSampler::Create(thread_id_, test_delegate_); |
260 if (!native_sampler) | 260 if (!native_sampler) |
261 return; | 261 return; |
262 | 262 |
263 sampling_thread_.reset(new SamplingThread(std::move(native_sampler), params_, | 263 sampling_thread_.reset(new SamplingThread(std::move(native_sampler), params_, |
264 completed_callback_)); | 264 completed_callback_)); |
265 if (!PlatformThread::Create(0, sampling_thread_.get(), | 265 if (!PlatformThread::Create(0, sampling_thread_.get(), |
266 &sampling_thread_handle_)) | 266 &sampling_thread_handle_)) |
267 sampling_thread_.reset(); | 267 sampling_thread_.reset(); |
268 } | 268 } |
(...skipping 12 matching lines...) Expand all Loading... |
281 } | 281 } |
282 | 282 |
283 bool operator<(const StackSamplingProfiler::Frame &a, | 283 bool operator<(const StackSamplingProfiler::Frame &a, |
284 const StackSamplingProfiler::Frame &b) { | 284 const StackSamplingProfiler::Frame &b) { |
285 return (a.module_index < b.module_index) || | 285 return (a.module_index < b.module_index) || |
286 (a.module_index == b.module_index && | 286 (a.module_index == b.module_index && |
287 a.instruction_pointer < b.instruction_pointer); | 287 a.instruction_pointer < b.instruction_pointer); |
288 } | 288 } |
289 | 289 |
290 } // namespace base | 290 } // namespace base |
OLD | NEW |