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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/profiler/stack_sampling_profiler.h" | 10 #include "base/profiler/stack_sampling_profiler.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // Searches through the frames in |sample|, returning an iterator to the first | 176 // Searches through the frames in |sample|, returning an iterator to the first |
177 // frame that has an instruction pointer between |function_address| and | 177 // frame that has an instruction pointer between |function_address| and |
178 // |function_address| + |size|. Returns sample.end() if no such frames are | 178 // |function_address| + |size|. Returns sample.end() if no such frames are |
179 // found. | 179 // found. |
180 Sample::const_iterator FindFirstFrameWithinFunction( | 180 Sample::const_iterator FindFirstFrameWithinFunction( |
181 const Sample& sample, | 181 const Sample& sample, |
182 const void* function_address, | 182 const void* function_address, |
183 int function_size) { | 183 int function_size) { |
184 function_address = MaybeFixupFunctionAddressForILT(function_address); | 184 function_address = MaybeFixupFunctionAddressForILT(function_address); |
185 for (auto it = sample.begin(); it != sample.end(); ++it) { | 185 for (auto it = sample.begin(); it != sample.end(); ++it) { |
186 if ((it->instruction_pointer >= function_address) && | 186 if ((reinterpret_cast<const void*>(it->instruction_pointer) >= |
187 (it->instruction_pointer < | 187 function_address) && |
| 188 (reinterpret_cast<const void*>(it->instruction_pointer) < |
188 (static_cast<const unsigned char*>(function_address) + function_size))) | 189 (static_cast<const unsigned char*>(function_address) + function_size))) |
189 return it; | 190 return it; |
190 } | 191 } |
191 return sample.end(); | 192 return sample.end(); |
192 } | 193 } |
193 | 194 |
194 // Formats a sample into a string that can be output for test diagnostics. | 195 // Formats a sample into a string that can be output for test diagnostics. |
195 std::string FormatSampleForDiagnosticOutput( | 196 std::string FormatSampleForDiagnosticOutput( |
196 const Sample& sample, | 197 const Sample& sample, |
197 const std::vector<Module>& modules) { | 198 const std::vector<Module>& modules) { |
198 std::string output; | 199 std::string output; |
199 for (const Frame& frame: sample) { | 200 for (const Frame& frame: sample) { |
200 output += StringPrintf( | 201 output += StringPrintf( |
201 "0x%p %s\n", frame.instruction_pointer, | 202 "0x%p %s\n", reinterpret_cast<const void*>(frame.instruction_pointer), |
202 modules[frame.module_index].filename.AsUTF8Unsafe().c_str()); | 203 modules[frame.module_index].filename.AsUTF8Unsafe().c_str()); |
203 } | 204 } |
204 return output; | 205 return output; |
205 } | 206 } |
206 | 207 |
207 // Returns a duration that is longer than the test timeout. We would use | 208 // Returns a duration that is longer than the test timeout. We would use |
208 // TimeDelta::Max() but https://crbug.com/465948. | 209 // TimeDelta::Max() but https://crbug.com/465948. |
209 TimeDelta AVeryLongTimeDelta() { return TimeDelta::FromDays(1); } | 210 TimeDelta AVeryLongTimeDelta() { return TimeDelta::FromDays(1); } |
210 | 211 |
211 } // namespace | 212 } // namespace |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 sampling_completed[1]->TimedWait(TimeDelta::FromMilliseconds(25))); | 452 sampling_completed[1]->TimedWait(TimeDelta::FromMilliseconds(25))); |
452 | 453 |
453 // Start the second profiler again and it should run. | 454 // Start the second profiler again and it should run. |
454 profiler[1]->Start(); | 455 profiler[1]->Start(); |
455 sampling_completed[1]->Wait(); | 456 sampling_completed[1]->Wait(); |
456 EXPECT_EQ(1u, profiles[1].size()); | 457 EXPECT_EQ(1u, profiles[1].size()); |
457 }); | 458 }); |
458 } | 459 } |
459 | 460 |
460 } // namespace base | 461 } // namespace base |
OLD | NEW |