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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // Signature for a target function that is expected to appear in the stack. See | 78 // Signature for a target function that is expected to appear in the stack. See |
79 // SignalAndWaitUntilSignaled() below. The return value should be a program | 79 // SignalAndWaitUntilSignaled() below. The return value should be a program |
80 // counter pointer near the end of the function. | 80 // counter pointer near the end of the function. |
81 using TargetFunction = const void*(*)(WaitableEvent*, WaitableEvent*, | 81 using TargetFunction = const void*(*)(WaitableEvent*, WaitableEvent*, |
82 const StackConfiguration*); | 82 const StackConfiguration*); |
83 | 83 |
84 // A thread to target for profiling, whose stack is guaranteed to contain | 84 // A thread to target for profiling, whose stack is guaranteed to contain |
85 // SignalAndWaitUntilSignaled() when coordinated with the main thread. | 85 // SignalAndWaitUntilSignaled() when coordinated with the main thread. |
86 class TargetThread : public PlatformThread::Delegate { | 86 class TargetThread : public PlatformThread::Delegate { |
87 public: | 87 public: |
88 TargetThread(const StackConfiguration& stack_config); | 88 explicit TargetThread(const StackConfiguration& stack_config); |
89 | 89 |
90 // PlatformThread::Delegate: | 90 // PlatformThread::Delegate: |
91 void ThreadMain() override; | 91 void ThreadMain() override; |
92 | 92 |
93 // Waits for the thread to have started and be executing in | 93 // Waits for the thread to have started and be executing in |
94 // SignalAndWaitUntilSignaled(). | 94 // SignalAndWaitUntilSignaled(). |
95 void WaitForThreadStart(); | 95 void WaitForThreadStart(); |
96 | 96 |
97 // Allows the thread to return from SignalAndWaitUntilSignaled() and finish | 97 // Allows the thread to return from SignalAndWaitUntilSignaled() and finish |
98 // execution. | 98 // execution. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 264 } |
265 | 265 |
266 // Loads the other library, which defines a function to be called in the | 266 // Loads the other library, which defines a function to be called in the |
267 // WITH_OTHER_LIBRARY configuration. | 267 // WITH_OTHER_LIBRARY configuration. |
268 NativeLibrary LoadOtherLibrary() { | 268 NativeLibrary LoadOtherLibrary() { |
269 // The lambda gymnastics works around the fact that we can't use ASSERT_* | 269 // The lambda gymnastics works around the fact that we can't use ASSERT_* |
270 // macros in a function returning non-null. | 270 // macros in a function returning non-null. |
271 const auto load = [](NativeLibrary* library) { | 271 const auto load = [](NativeLibrary* library) { |
272 FilePath other_library_path; | 272 FilePath other_library_path; |
273 ASSERT_TRUE(PathService::Get(DIR_EXE, &other_library_path)); | 273 ASSERT_TRUE(PathService::Get(DIR_EXE, &other_library_path)); |
274 other_library_path = other_library_path.Append(FilePath::FromUTF16Unsafe( | 274 other_library_path = other_library_path.AppendASCII( |
275 GetNativeLibraryName(ASCIIToUTF16( | 275 GetNativeLibraryName("base_profiler_test_support_library")); |
276 "base_profiler_test_support_library")))); | |
277 NativeLibraryLoadError load_error; | 276 NativeLibraryLoadError load_error; |
278 *library = LoadNativeLibrary(other_library_path, &load_error); | 277 *library = LoadNativeLibrary(other_library_path, &load_error); |
279 ASSERT_TRUE(*library) << "error loading " << other_library_path.value() | 278 ASSERT_TRUE(*library) << "error loading " << other_library_path.value() |
280 << ": " << load_error.ToString(); | 279 << ": " << load_error.ToString(); |
281 }; | 280 }; |
282 | 281 |
283 NativeLibrary library = nullptr; | 282 NativeLibrary library = nullptr; |
284 load(&library); | 283 load(&library); |
285 return library; | 284 return library; |
286 } | 285 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 return it; | 409 return it; |
411 } | 410 } |
412 return sample.end(); | 411 return sample.end(); |
413 } | 412 } |
414 | 413 |
415 // Formats a sample into a string that can be output for test diagnostics. | 414 // Formats a sample into a string that can be output for test diagnostics. |
416 std::string FormatSampleForDiagnosticOutput( | 415 std::string FormatSampleForDiagnosticOutput( |
417 const Sample& sample, | 416 const Sample& sample, |
418 const std::vector<Module>& modules) { | 417 const std::vector<Module>& modules) { |
419 std::string output; | 418 std::string output; |
420 for (const Frame& frame: sample) { | 419 for (const Frame& frame : sample) { |
421 output += StringPrintf( | 420 output += StringPrintf( |
422 "0x%p %s\n", reinterpret_cast<const void*>(frame.instruction_pointer), | 421 "0x%p %s\n", reinterpret_cast<const void*>(frame.instruction_pointer), |
423 modules[frame.module_index].filename.AsUTF8Unsafe().c_str()); | 422 modules[frame.module_index].filename.AsUTF8Unsafe().c_str()); |
424 } | 423 } |
425 return output; | 424 return output; |
426 } | 425 } |
427 | 426 |
428 // Returns a duration that is longer than the test timeout. We would use | 427 // Returns a duration that is longer than the test timeout. We would use |
429 // TimeDelta::Max() but https://crbug.com/465948. | 428 // TimeDelta::Max() but https://crbug.com/465948. |
430 TimeDelta AVeryLongTimeDelta() { return TimeDelta::FromDays(1); } | 429 TimeDelta AVeryLongTimeDelta() { return TimeDelta::FromDays(1); } |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) | 976 #if defined(STACK_SAMPLING_PROFILER_SUPPORTED) |
978 #define MAYBE_UnloadedLibrary UnloadedLibrary | 977 #define MAYBE_UnloadedLibrary UnloadedLibrary |
979 #else | 978 #else |
980 #define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary | 979 #define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary |
981 #endif | 980 #endif |
982 TEST(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) { | 981 TEST(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) { |
983 TestLibraryUnload(true); | 982 TestLibraryUnload(true); |
984 } | 983 } |
985 | 984 |
986 } // namespace base | 985 } // namespace base |
OLD | NEW |